blob: ff2e46a9026bb4dae97308f6c96b56aca07c97e4 [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,
348 llvm::SmallVectorImpl<Expr *> &Outputs,
349 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,
John McCall21ef0fa2010-03-11 09:03:00 +0000523 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregora009b592011-01-07 00:20:55 +0000524 llvm::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
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001184 /// \brief Build a new Objective-C @synchronized statement.
1185 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001186 /// By default, performs semantic analysis to build the new statement.
1187 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001188 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001189 Expr *Object,
1190 Stmt *Body) {
1191 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1192 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001193 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001194
1195 /// \brief Build a new Objective-C fast enumeration statement.
1196 ///
1197 /// By default, performs semantic analysis to build the new statement.
1198 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001199 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001200 SourceLocation LParenLoc,
1201 Stmt *Element,
1202 Expr *Collection,
1203 SourceLocation RParenLoc,
1204 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001205 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001206 Element,
1207 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001208 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001209 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001210 }
Sean Huntc3021132010-05-05 15:23:54 +00001211
Douglas Gregor43959a92009-08-20 07:17:43 +00001212 /// \brief Build a new C++ exception declaration.
1213 ///
1214 /// By default, performs semantic analysis to build the new decaration.
1215 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001216 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001217 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001218 SourceLocation StartLoc,
1219 SourceLocation IdLoc,
1220 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001221 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1222 StartLoc, IdLoc, Id);
1223 if (Var)
1224 getSema().CurContext->addDecl(Var);
1225 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001226 }
1227
1228 /// \brief Build a new C++ catch statement.
1229 ///
1230 /// By default, performs semantic analysis to build the new statement.
1231 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001232 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001233 VarDecl *ExceptionDecl,
1234 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001235 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1236 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001237 }
Mike Stump1eb44332009-09-09 15:08:12 +00001238
Douglas Gregor43959a92009-08-20 07:17:43 +00001239 /// \brief Build a new C++ try statement.
1240 ///
1241 /// By default, performs semantic analysis to build the new statement.
1242 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001243 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001244 Stmt *TryBlock,
1245 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001246 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001247 }
Mike Stump1eb44332009-09-09 15:08:12 +00001248
Richard Smithad762fc2011-04-14 22:09:26 +00001249 /// \brief Build a new C++0x range-based for statement.
1250 ///
1251 /// By default, performs semantic analysis to build the new statement.
1252 /// Subclasses may override this routine to provide different behavior.
1253 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1254 SourceLocation ColonLoc,
1255 Stmt *Range, Stmt *BeginEnd,
1256 Expr *Cond, Expr *Inc,
1257 Stmt *LoopVar,
1258 SourceLocation RParenLoc) {
1259 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1260 Cond, Inc, LoopVar, RParenLoc);
1261 }
1262
1263 /// \brief Attach body to a C++0x range-based for statement.
1264 ///
1265 /// By default, performs semantic analysis to finish the new statement.
1266 /// Subclasses may override this routine to provide different behavior.
1267 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1268 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1269 }
1270
John Wiegley28bbe4b2011-04-28 01:08:34 +00001271 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1272 SourceLocation TryLoc,
1273 Stmt *TryBlock,
1274 Stmt *Handler) {
1275 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1276 }
1277
1278 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1279 Expr *FilterExpr,
1280 Stmt *Block) {
1281 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1282 }
1283
1284 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1285 Stmt *Block) {
1286 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1287 }
1288
Douglas Gregorb98b1992009-08-11 05:31:07 +00001289 /// \brief Build a new expression that references a declaration.
1290 ///
1291 /// By default, performs semantic analysis to build the new expression.
1292 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001293 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001294 LookupResult &R,
1295 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001296 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1297 }
1298
1299
1300 /// \brief Build a new expression that references a declaration.
1301 ///
1302 /// By default, performs semantic analysis to build the new expression.
1303 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001304 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001305 ValueDecl *VD,
1306 const DeclarationNameInfo &NameInfo,
1307 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001308 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001309 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001310
1311 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001312
1313 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001314 }
Mike Stump1eb44332009-09-09 15:08:12 +00001315
Douglas Gregorb98b1992009-08-11 05:31:07 +00001316 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001317 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001318 /// By default, performs semantic analysis to build the new expression.
1319 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001320 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001321 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001322 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001323 }
1324
Douglas Gregora71d8192009-09-04 17:36:40 +00001325 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001326 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001327 /// By default, performs semantic analysis to build the new expression.
1328 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001329 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001330 SourceLocation OperatorLoc,
1331 bool isArrow,
1332 CXXScopeSpec &SS,
1333 TypeSourceInfo *ScopeType,
1334 SourceLocation CCLoc,
1335 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001336 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001337
Douglas Gregorb98b1992009-08-11 05:31:07 +00001338 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001339 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001340 /// By default, performs semantic analysis to build the new expression.
1341 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001342 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001343 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001344 Expr *SubExpr) {
1345 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001346 }
Mike Stump1eb44332009-09-09 15:08:12 +00001347
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001348 /// \brief Build a new builtin offsetof expression.
1349 ///
1350 /// By default, performs semantic analysis to build the new expression.
1351 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001352 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001353 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001354 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001355 unsigned NumComponents,
1356 SourceLocation RParenLoc) {
1357 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1358 NumComponents, RParenLoc);
1359 }
Sean Huntc3021132010-05-05 15:23:54 +00001360
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001361 /// \brief Build a new sizeof, alignof or vec_step expression with a
1362 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001363 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001364 /// By default, performs semantic analysis to build the new expression.
1365 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001366 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1367 SourceLocation OpLoc,
1368 UnaryExprOrTypeTrait ExprKind,
1369 SourceRange R) {
1370 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001371 }
1372
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001373 /// \brief Build a new sizeof, alignof or vec step expression with an
1374 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001375 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 /// By default, performs semantic analysis to build the new expression.
1377 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001378 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1379 UnaryExprOrTypeTrait ExprKind,
1380 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001381 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001382 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001384 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001385
Douglas Gregorb98b1992009-08-11 05:31:07 +00001386 return move(Result);
1387 }
Mike Stump1eb44332009-09-09 15:08:12 +00001388
Douglas Gregorb98b1992009-08-11 05:31:07 +00001389 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001390 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 /// By default, performs semantic analysis to build the new expression.
1392 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001393 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001394 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001395 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001396 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001397 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1398 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001399 RBracketLoc);
1400 }
1401
1402 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001403 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001406 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001407 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001408 SourceLocation RParenLoc,
1409 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001410 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001411 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 }
1413
1414 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001415 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 /// By default, performs semantic analysis to build the new expression.
1417 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001418 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001419 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001420 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001421 const DeclarationNameInfo &MemberNameInfo,
1422 ValueDecl *Member,
1423 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001424 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001425 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001426 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001427 // We have a reference to an unnamed field. This is always the
1428 // base of an anonymous struct/union member access, i.e. the
1429 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001430 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001431 assert(Member->getType()->isRecordType() &&
1432 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001433
John Wiegley429bb272011-04-08 18:41:53 +00001434 ExprResult BaseResult =
1435 getSema().PerformObjectMemberConversion(Base,
1436 QualifierLoc.getNestedNameSpecifier(),
1437 FoundDecl, Member);
1438 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001439 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001440 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001441 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001442 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001443 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001444 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001445 cast<FieldDecl>(Member)->getType(),
1446 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001447 return getSema().Owned(ME);
1448 }
Mike Stump1eb44332009-09-09 15:08:12 +00001449
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001450 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001451 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001452
John Wiegley429bb272011-04-08 18:41:53 +00001453 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1454 if (BaseResult.isInvalid())
1455 return ExprError();
1456 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001457 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001458
John McCall6bb80172010-03-30 21:47:33 +00001459 // FIXME: this involves duplicating earlier analysis in a lot of
1460 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001461 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001462 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001463 R.resolveKind();
1464
John McCall9ae2f072010-08-23 23:25:46 +00001465 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001466 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001467 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001468 }
Mike Stump1eb44332009-09-09 15:08:12 +00001469
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001471 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001472 /// By default, performs semantic analysis to build the new expression.
1473 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001474 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001475 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001476 Expr *LHS, Expr *RHS) {
1477 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 }
1479
1480 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001481 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001484 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001485 SourceLocation QuestionLoc,
1486 Expr *LHS,
1487 SourceLocation ColonLoc,
1488 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001489 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1490 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 }
1492
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001494 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001497 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001498 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001500 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001501 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001502 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 }
Mike Stump1eb44332009-09-09 15:08:12 +00001504
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001506 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001509 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001510 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001512 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001513 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001514 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 }
Mike Stump1eb44332009-09-09 15:08:12 +00001516
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001518 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001519 /// By default, performs semantic analysis to build the new expression.
1520 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001521 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 SourceLocation OpLoc,
1523 SourceLocation AccessorLoc,
1524 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001525
John McCall129e2df2009-11-30 22:42:35 +00001526 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001527 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001528 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001529 OpLoc, /*IsArrow*/ false,
1530 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001531 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001532 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 }
Mike Stump1eb44332009-09-09 15:08:12 +00001534
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001536 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001539 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001540 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001541 SourceLocation RBraceLoc,
1542 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001543 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001544 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1545 if (Result.isInvalid() || ResultTy->isDependentType())
1546 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001547
Douglas Gregore48319a2009-11-09 17:16:50 +00001548 // Patch in the result type we were given, which may have been computed
1549 // when the initial InitListExpr was built.
1550 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1551 ILE->setType(ResultTy);
1552 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001553 }
Mike Stump1eb44332009-09-09 15:08:12 +00001554
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001556 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001557 /// By default, performs semantic analysis to build the new expression.
1558 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001559 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 MultiExprArg ArrayExprs,
1561 SourceLocation EqualOrColonLoc,
1562 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001563 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001564 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001566 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001568 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001569
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 ArrayExprs.release();
1571 return move(Result);
1572 }
Mike Stump1eb44332009-09-09 15:08:12 +00001573
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001575 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001576 /// By default, builds the implicit value initialization without performing
1577 /// any semantic analysis. Subclasses may override this routine to provide
1578 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001579 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1581 }
Mike Stump1eb44332009-09-09 15:08:12 +00001582
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001584 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001587 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001588 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001589 SourceLocation RParenLoc) {
1590 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001591 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001592 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 }
1594
1595 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001596 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001599 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 MultiExprArg SubExprs,
1601 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001602 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001603 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 }
Mike Stump1eb44332009-09-09 15:08:12 +00001605
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001607 ///
1608 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 /// rather than attempting to map the label statement itself.
1610 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001611 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001612 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001613 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 }
Mike Stump1eb44332009-09-09 15:08:12 +00001615
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001617 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 /// By default, performs semantic analysis to build the new expression.
1619 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001620 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001621 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001623 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 }
Mike Stump1eb44332009-09-09 15:08:12 +00001625
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 /// \brief Build a new __builtin_choose_expr expression.
1627 ///
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001630 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001631 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 SourceLocation RParenLoc) {
1633 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001634 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 RParenLoc);
1636 }
Mike Stump1eb44332009-09-09 15:08:12 +00001637
Peter Collingbournef111d932011-04-15 00:35:48 +00001638 /// \brief Build a new generic selection expression.
1639 ///
1640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
1642 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1643 SourceLocation DefaultLoc,
1644 SourceLocation RParenLoc,
1645 Expr *ControllingExpr,
1646 TypeSourceInfo **Types,
1647 Expr **Exprs,
1648 unsigned NumAssocs) {
1649 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1650 ControllingExpr, Types, Exprs,
1651 NumAssocs);
1652 }
1653
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 /// \brief Build a new overloaded operator call expression.
1655 ///
1656 /// By default, performs semantic analysis to build the new expression.
1657 /// The semantic analysis provides the behavior of template instantiation,
1658 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001659 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 /// argument-dependent lookup, etc. Subclasses may override this routine to
1661 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001662 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001664 Expr *Callee,
1665 Expr *First,
1666 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001667
1668 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 /// reinterpret_cast.
1670 ///
1671 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001672 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001674 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 Stmt::StmtClass Class,
1676 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001677 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 SourceLocation RAngleLoc,
1679 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001680 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 SourceLocation RParenLoc) {
1682 switch (Class) {
1683 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001684 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001685 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001686 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687
1688 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001689 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001690 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001691 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001692
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001694 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001695 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001696 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001698
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001700 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001701 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001702 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001703
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 default:
1705 assert(false && "Invalid C++ named cast");
1706 break;
1707 }
Mike Stump1eb44332009-09-09 15:08:12 +00001708
John McCallf312b1e2010-08-26 23:41:50 +00001709 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 }
Mike Stump1eb44332009-09-09 15:08:12 +00001711
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 /// \brief Build a new C++ static_cast expression.
1713 ///
1714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001716 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001718 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 SourceLocation RAngleLoc,
1720 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001721 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001723 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001724 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001725 SourceRange(LAngleLoc, RAngleLoc),
1726 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 }
1728
1729 /// \brief Build a new C++ dynamic_cast expression.
1730 ///
1731 /// By default, performs semantic analysis to build the new expression.
1732 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001733 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001735 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 SourceLocation RAngleLoc,
1737 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001738 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001739 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001740 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001741 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001742 SourceRange(LAngleLoc, RAngleLoc),
1743 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 }
1745
1746 /// \brief Build a new C++ reinterpret_cast expression.
1747 ///
1748 /// By default, performs semantic analysis to build the new expression.
1749 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001750 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001752 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 SourceLocation RAngleLoc,
1754 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001755 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001757 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001758 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001759 SourceRange(LAngleLoc, RAngleLoc),
1760 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 }
1762
1763 /// \brief Build a new C++ const_cast expression.
1764 ///
1765 /// By default, performs semantic analysis to build the new expression.
1766 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001767 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001769 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 SourceLocation RAngleLoc,
1771 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001772 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001774 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001775 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001776 SourceRange(LAngleLoc, RAngleLoc),
1777 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 }
Mike Stump1eb44332009-09-09 15:08:12 +00001779
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 /// \brief Build a new C++ functional-style cast expression.
1781 ///
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001784 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1785 SourceLocation LParenLoc,
1786 Expr *Sub,
1787 SourceLocation RParenLoc) {
1788 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001789 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001790 RParenLoc);
1791 }
Mike Stump1eb44332009-09-09 15:08:12 +00001792
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 /// \brief Build a new C++ typeid(type) expression.
1794 ///
1795 /// By default, performs semantic analysis to build the new expression.
1796 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001797 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001798 SourceLocation TypeidLoc,
1799 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001801 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001802 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 }
Mike Stump1eb44332009-09-09 15:08:12 +00001804
Francois Pichet01b7c302010-09-08 12:20:18 +00001805
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 /// \brief Build a new C++ typeid(expr) expression.
1807 ///
1808 /// By default, performs semantic analysis to build the new expression.
1809 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001810 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001811 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001812 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001814 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001815 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001816 }
1817
Francois Pichet01b7c302010-09-08 12:20:18 +00001818 /// \brief Build a new C++ __uuidof(type) expression.
1819 ///
1820 /// By default, performs semantic analysis to build the new expression.
1821 /// Subclasses may override this routine to provide different behavior.
1822 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1823 SourceLocation TypeidLoc,
1824 TypeSourceInfo *Operand,
1825 SourceLocation RParenLoc) {
1826 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1827 RParenLoc);
1828 }
1829
1830 /// \brief Build a new C++ __uuidof(expr) expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
1834 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1835 SourceLocation TypeidLoc,
1836 Expr *Operand,
1837 SourceLocation RParenLoc) {
1838 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1839 RParenLoc);
1840 }
1841
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 /// \brief Build a new C++ "this" expression.
1843 ///
1844 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001845 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001847 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001848 QualType ThisType,
1849 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001851 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1852 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 }
1854
1855 /// \brief Build a new C++ throw expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001859 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001860 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 }
1862
1863 /// \brief Build a new C++ default-argument expression.
1864 ///
1865 /// By default, builds a new default-argument expression, which does not
1866 /// require any semantic analysis. Subclasses may override this routine to
1867 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001868 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001869 ParmVarDecl *Param) {
1870 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1871 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 }
1873
1874 /// \brief Build a new C++ zero-initialization expression.
1875 ///
1876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001878 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1879 SourceLocation LParenLoc,
1880 SourceLocation RParenLoc) {
1881 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001882 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001883 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 }
Mike Stump1eb44332009-09-09 15:08:12 +00001885
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 /// \brief Build a new C++ "new" expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001890 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001891 bool UseGlobal,
1892 SourceLocation PlacementLParen,
1893 MultiExprArg PlacementArgs,
1894 SourceLocation PlacementRParen,
1895 SourceRange TypeIdParens,
1896 QualType AllocatedType,
1897 TypeSourceInfo *AllocatedTypeInfo,
1898 Expr *ArraySize,
1899 SourceLocation ConstructorLParen,
1900 MultiExprArg ConstructorArgs,
1901 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001902 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001903 PlacementLParen,
1904 move(PlacementArgs),
1905 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001906 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001907 AllocatedType,
1908 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001909 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001910 ConstructorLParen,
1911 move(ConstructorArgs),
1912 ConstructorRParen);
1913 }
Mike Stump1eb44332009-09-09 15:08:12 +00001914
Douglas Gregorb98b1992009-08-11 05:31:07 +00001915 /// \brief Build a new C++ "delete" expression.
1916 ///
1917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001919 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001920 bool IsGlobalDelete,
1921 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001922 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001923 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001924 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001925 }
Mike Stump1eb44332009-09-09 15:08:12 +00001926
Douglas Gregorb98b1992009-08-11 05:31:07 +00001927 /// \brief Build a new unary type trait expression.
1928 ///
1929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001931 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001932 SourceLocation StartLoc,
1933 TypeSourceInfo *T,
1934 SourceLocation RParenLoc) {
1935 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001936 }
1937
Francois Pichet6ad6f282010-12-07 00:08:36 +00001938 /// \brief Build a new binary type trait expression.
1939 ///
1940 /// By default, performs semantic analysis to build the new expression.
1941 /// Subclasses may override this routine to provide different behavior.
1942 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1943 SourceLocation StartLoc,
1944 TypeSourceInfo *LhsT,
1945 TypeSourceInfo *RhsT,
1946 SourceLocation RParenLoc) {
1947 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1948 }
1949
John Wiegley21ff2e52011-04-28 00:16:57 +00001950 /// \brief Build a new array type trait expression.
1951 ///
1952 /// By default, performs semantic analysis to build the new expression.
1953 /// Subclasses may override this routine to provide different behavior.
1954 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1955 SourceLocation StartLoc,
1956 TypeSourceInfo *TSInfo,
1957 Expr *DimExpr,
1958 SourceLocation RParenLoc) {
1959 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1960 }
1961
John Wiegley55262202011-04-25 06:54:41 +00001962 /// \brief Build a new expression trait expression.
1963 ///
1964 /// By default, performs semantic analysis to build the new expression.
1965 /// Subclasses may override this routine to provide different behavior.
1966 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1967 SourceLocation StartLoc,
1968 Expr *Queried,
1969 SourceLocation RParenLoc) {
1970 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1971 }
1972
Mike Stump1eb44332009-09-09 15:08:12 +00001973 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001974 /// expression.
1975 ///
1976 /// By default, performs semantic analysis to build the new expression.
1977 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001978 ExprResult RebuildDependentScopeDeclRefExpr(
1979 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001980 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001981 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001983 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00001984
1985 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001986 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001987 *TemplateArgs);
1988
Abramo Bagnara25777432010-08-11 22:01:17 +00001989 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001990 }
1991
1992 /// \brief Build a new template-id expression.
1993 ///
1994 /// By default, performs semantic analysis to build the new expression.
1995 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001996 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001997 LookupResult &R,
1998 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001999 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00002000 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002001 }
2002
2003 /// \brief Build a new object-construction expression.
2004 ///
2005 /// By default, performs semantic analysis to build the new expression.
2006 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002007 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002008 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 CXXConstructorDecl *Constructor,
2010 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002011 MultiExprArg Args,
2012 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002013 CXXConstructExpr::ConstructionKind ConstructKind,
2014 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002015 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002016 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002017 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002018 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002019
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002020 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002021 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00002022 RequiresZeroInit, ConstructKind,
2023 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002024 }
2025
2026 /// \brief Build a new object-construction expression.
2027 ///
2028 /// By default, performs semantic analysis to build the new expression.
2029 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002030 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2031 SourceLocation LParenLoc,
2032 MultiExprArg Args,
2033 SourceLocation RParenLoc) {
2034 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002035 LParenLoc,
2036 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002037 RParenLoc);
2038 }
2039
2040 /// \brief Build a new object-construction expression.
2041 ///
2042 /// By default, performs semantic analysis to build the new expression.
2043 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002044 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2045 SourceLocation LParenLoc,
2046 MultiExprArg Args,
2047 SourceLocation RParenLoc) {
2048 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002049 LParenLoc,
2050 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002051 RParenLoc);
2052 }
Mike Stump1eb44332009-09-09 15:08:12 +00002053
Douglas Gregorb98b1992009-08-11 05:31:07 +00002054 /// \brief Build a new member reference expression.
2055 ///
2056 /// By default, performs semantic analysis to build the new expression.
2057 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002058 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002059 QualType BaseType,
2060 bool IsArrow,
2061 SourceLocation OperatorLoc,
2062 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002063 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002064 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002065 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002066 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002067 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002068
John McCall9ae2f072010-08-23 23:25:46 +00002069 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002070 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002071 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002072 MemberNameInfo,
2073 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002074 }
2075
John McCall129e2df2009-11-30 22:42:35 +00002076 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002077 ///
2078 /// By default, performs semantic analysis to build the new expression.
2079 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002080 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00002081 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00002082 SourceLocation OperatorLoc,
2083 bool IsArrow,
Douglas Gregor4c9be892011-02-28 20:01:57 +00002084 NestedNameSpecifierLoc QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00002085 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00002086 LookupResult &R,
2087 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002088 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002089 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002090
John McCall9ae2f072010-08-23 23:25:46 +00002091 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002092 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002093 SS, FirstQualifierInScope,
2094 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002095 }
Mike Stump1eb44332009-09-09 15:08:12 +00002096
Sebastian Redl2e156222010-09-10 20:55:43 +00002097 /// \brief Build a new noexcept expression.
2098 ///
2099 /// By default, performs semantic analysis to build the new expression.
2100 /// Subclasses may override this routine to provide different behavior.
2101 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2102 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2103 }
2104
Douglas Gregoree8aff02011-01-04 17:33:58 +00002105 /// \brief Build a new expression to compute the length of a parameter pack.
2106 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2107 SourceLocation PackLoc,
2108 SourceLocation RParenLoc,
2109 unsigned Length) {
2110 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2111 OperatorLoc, Pack, PackLoc,
2112 RParenLoc, Length);
2113 }
2114
Douglas Gregorb98b1992009-08-11 05:31:07 +00002115 /// \brief Build a new Objective-C @encode expression.
2116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002119 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002120 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002121 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002122 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002123 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002124 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002125
Douglas Gregor92e986e2010-04-22 16:44:27 +00002126 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002127 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002128 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002129 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002130 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002131 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002132 MultiExprArg Args,
2133 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002134 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2135 ReceiverTypeInfo->getType(),
2136 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002137 Sel, Method, LBracLoc, SelectorLoc,
2138 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002139 }
2140
2141 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002142 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002143 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002144 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002145 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002146 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002147 MultiExprArg Args,
2148 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002149 return SemaRef.BuildInstanceMessage(Receiver,
2150 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002151 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002152 Sel, Method, LBracLoc, SelectorLoc,
2153 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002154 }
2155
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002156 /// \brief Build a new Objective-C ivar reference expression.
2157 ///
2158 /// By default, performs semantic analysis to build the new expression.
2159 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002160 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002161 SourceLocation IvarLoc,
2162 bool IsArrow, bool IsFreeIvar) {
2163 // FIXME: We lose track of the IsFreeIvar bit.
2164 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002165 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002166 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2167 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002168 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002169 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002170 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002171 false);
John Wiegley429bb272011-04-08 18:41:53 +00002172 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002173 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002174
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002175 if (Result.get())
2176 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002177
John Wiegley429bb272011-04-08 18:41:53 +00002178 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002179 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002180 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002181 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002182 /*TemplateArgs=*/0);
2183 }
Douglas Gregore3303542010-04-26 20:47:02 +00002184
2185 /// \brief Build a new Objective-C property reference expression.
2186 ///
2187 /// By default, performs semantic analysis to build the new expression.
2188 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002189 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002190 ObjCPropertyDecl *Property,
2191 SourceLocation PropertyLoc) {
2192 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002193 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002194 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2195 Sema::LookupMemberName);
2196 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002197 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002198 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002199 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002200 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002201 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002202
Douglas Gregore3303542010-04-26 20:47:02 +00002203 if (Result.get())
2204 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002205
John Wiegley429bb272011-04-08 18:41:53 +00002206 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002207 /*FIXME:*/PropertyLoc, IsArrow,
2208 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002209 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002210 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002211 /*TemplateArgs=*/0);
2212 }
Sean Huntc3021132010-05-05 15:23:54 +00002213
John McCall12f78a62010-12-02 01:19:52 +00002214 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002215 ///
2216 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002217 /// Subclasses may override this routine to provide different behavior.
2218 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2219 ObjCMethodDecl *Getter,
2220 ObjCMethodDecl *Setter,
2221 SourceLocation PropertyLoc) {
2222 // Since these expressions can only be value-dependent, we do not
2223 // need to perform semantic analysis again.
2224 return Owned(
2225 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2226 VK_LValue, OK_ObjCProperty,
2227 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002228 }
2229
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002230 /// \brief Build a new Objective-C "isa" expression.
2231 ///
2232 /// By default, performs semantic analysis to build the new expression.
2233 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002234 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002235 bool IsArrow) {
2236 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002237 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002238 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2239 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002240 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002241 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002242 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002243 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002244 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002245
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002246 if (Result.get())
2247 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002248
John Wiegley429bb272011-04-08 18:41:53 +00002249 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002250 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002251 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002252 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002253 /*TemplateArgs=*/0);
2254 }
Sean Huntc3021132010-05-05 15:23:54 +00002255
Douglas Gregorb98b1992009-08-11 05:31:07 +00002256 /// \brief Build a new shuffle vector expression.
2257 ///
2258 /// By default, performs semantic analysis to build the new expression.
2259 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002260 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002261 MultiExprArg SubExprs,
2262 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002263 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002264 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002265 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2266 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2267 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2268 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002269
Douglas Gregorb98b1992009-08-11 05:31:07 +00002270 // Build a reference to the __builtin_shufflevector builtin
2271 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002272 ExprResult Callee
2273 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2274 VK_LValue, BuiltinLoc));
2275 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2276 if (Callee.isInvalid())
2277 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002278
2279 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002280 unsigned NumSubExprs = SubExprs.size();
2281 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002282 ExprResult TheCall = SemaRef.Owned(
2283 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002284 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002285 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002286 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002287 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002288
Douglas Gregorb98b1992009-08-11 05:31:07 +00002289 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002290 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002291 }
John McCall43fed0d2010-11-12 08:19:04 +00002292
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002293 /// \brief Build a new template argument pack expansion.
2294 ///
2295 /// By default, performs semantic analysis to build a new pack expansion
2296 /// for a template argument. Subclasses may override this routine to provide
2297 /// different behavior.
2298 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002299 SourceLocation EllipsisLoc,
2300 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002301 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002302 case TemplateArgument::Expression: {
2303 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002304 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2305 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002306 if (Result.isInvalid())
2307 return TemplateArgumentLoc();
2308
2309 return TemplateArgumentLoc(Result.get(), Result.get());
2310 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002311
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002312 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002313 return TemplateArgumentLoc(TemplateArgument(
2314 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002315 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002316 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002317 Pattern.getTemplateNameLoc(),
2318 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002319
2320 case TemplateArgument::Null:
2321 case TemplateArgument::Integral:
2322 case TemplateArgument::Declaration:
2323 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002324 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002325 llvm_unreachable("Pack expansion pattern has no parameter packs");
2326
2327 case TemplateArgument::Type:
2328 if (TypeSourceInfo *Expansion
2329 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002330 EllipsisLoc,
2331 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002332 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2333 Expansion);
2334 break;
2335 }
2336
2337 return TemplateArgumentLoc();
2338 }
2339
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002340 /// \brief Build a new expression pack expansion.
2341 ///
2342 /// By default, performs semantic analysis to build a new pack expansion
2343 /// for an expression. Subclasses may override this routine to provide
2344 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002345 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2346 llvm::Optional<unsigned> NumExpansions) {
2347 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002348 }
2349
John McCall43fed0d2010-11-12 08:19:04 +00002350private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002351 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2352 QualType ObjectType,
2353 NamedDecl *FirstQualifierInScope,
2354 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002355
2356 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2357 QualType ObjectType,
2358 NamedDecl *FirstQualifierInScope,
2359 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002360};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002361
Douglas Gregor43959a92009-08-20 07:17:43 +00002362template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002363StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002364 if (!S)
2365 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002366
Douglas Gregor43959a92009-08-20 07:17:43 +00002367 switch (S->getStmtClass()) {
2368 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002369
Douglas Gregor43959a92009-08-20 07:17:43 +00002370 // Transform individual statement nodes
2371#define STMT(Node, Parent) \
2372 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002373#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002374#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002375#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002376
Douglas Gregor43959a92009-08-20 07:17:43 +00002377 // Transform expressions by calling TransformExpr.
2378#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002379#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002380#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002381#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002382 {
John McCall60d7b3a2010-08-24 06:29:42 +00002383 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002384 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002385 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002386
John McCall9ae2f072010-08-23 23:25:46 +00002387 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002388 }
Mike Stump1eb44332009-09-09 15:08:12 +00002389 }
2390
John McCall3fa5cae2010-10-26 07:05:15 +00002391 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002392}
Mike Stump1eb44332009-09-09 15:08:12 +00002393
2394
Douglas Gregor670444e2009-08-04 22:27:00 +00002395template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002396ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002397 if (!E)
2398 return SemaRef.Owned(E);
2399
2400 switch (E->getStmtClass()) {
2401 case Stmt::NoStmtClass: break;
2402#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002403#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002404#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002405 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002406#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002407 }
2408
John McCall3fa5cae2010-10-26 07:05:15 +00002409 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002410}
2411
2412template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002413bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2414 unsigned NumInputs,
2415 bool IsCall,
2416 llvm::SmallVectorImpl<Expr *> &Outputs,
2417 bool *ArgChanged) {
2418 for (unsigned I = 0; I != NumInputs; ++I) {
2419 // If requested, drop call arguments that need to be dropped.
2420 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2421 if (ArgChanged)
2422 *ArgChanged = true;
2423
2424 break;
2425 }
2426
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002427 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2428 Expr *Pattern = Expansion->getPattern();
2429
2430 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2431 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2432 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2433
2434 // Determine whether the set of unexpanded parameter packs can and should
2435 // be expanded.
2436 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002437 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002438 llvm::Optional<unsigned> OrigNumExpansions
2439 = Expansion->getNumExpansions();
2440 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002441 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2442 Pattern->getSourceRange(),
2443 Unexpanded.data(),
2444 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002445 Expand, RetainExpansion,
2446 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002447 return true;
2448
2449 if (!Expand) {
2450 // The transform has determined that we should perform a simple
2451 // transformation on the pack expansion, producing another pack
2452 // expansion.
2453 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2454 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2455 if (OutPattern.isInvalid())
2456 return true;
2457
2458 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002459 Expansion->getEllipsisLoc(),
2460 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002461 if (Out.isInvalid())
2462 return true;
2463
2464 if (ArgChanged)
2465 *ArgChanged = true;
2466 Outputs.push_back(Out.get());
2467 continue;
2468 }
2469
2470 // The transform has determined that we should perform an elementwise
2471 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002472 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002473 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2474 ExprResult Out = getDerived().TransformExpr(Pattern);
2475 if (Out.isInvalid())
2476 return true;
2477
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002478 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002479 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2480 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002481 if (Out.isInvalid())
2482 return true;
2483 }
2484
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002485 if (ArgChanged)
2486 *ArgChanged = true;
2487 Outputs.push_back(Out.get());
2488 }
2489
2490 continue;
2491 }
2492
Douglas Gregoraa165f82011-01-03 19:04:46 +00002493 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2494 if (Result.isInvalid())
2495 return true;
2496
2497 if (Result.get() != Inputs[I] && ArgChanged)
2498 *ArgChanged = true;
2499
2500 Outputs.push_back(Result.get());
2501 }
2502
2503 return false;
2504}
2505
2506template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002507NestedNameSpecifierLoc
2508TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2509 NestedNameSpecifierLoc NNS,
2510 QualType ObjectType,
2511 NamedDecl *FirstQualifierInScope) {
2512 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2513 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2514 Qualifier = Qualifier.getPrefix())
2515 Qualifiers.push_back(Qualifier);
2516
2517 CXXScopeSpec SS;
2518 while (!Qualifiers.empty()) {
2519 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2520 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2521
2522 switch (QNNS->getKind()) {
2523 case NestedNameSpecifier::Identifier:
2524 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2525 *QNNS->getAsIdentifier(),
2526 Q.getLocalBeginLoc(),
2527 Q.getLocalEndLoc(),
2528 ObjectType, false, SS,
2529 FirstQualifierInScope, false))
2530 return NestedNameSpecifierLoc();
2531
2532 break;
2533
2534 case NestedNameSpecifier::Namespace: {
2535 NamespaceDecl *NS
2536 = cast_or_null<NamespaceDecl>(
2537 getDerived().TransformDecl(
2538 Q.getLocalBeginLoc(),
2539 QNNS->getAsNamespace()));
2540 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2541 break;
2542 }
2543
2544 case NestedNameSpecifier::NamespaceAlias: {
2545 NamespaceAliasDecl *Alias
2546 = cast_or_null<NamespaceAliasDecl>(
2547 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2548 QNNS->getAsNamespaceAlias()));
2549 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2550 Q.getLocalEndLoc());
2551 break;
2552 }
2553
2554 case NestedNameSpecifier::Global:
2555 // There is no meaningful transformation that one could perform on the
2556 // global scope.
2557 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2558 break;
2559
2560 case NestedNameSpecifier::TypeSpecWithTemplate:
2561 case NestedNameSpecifier::TypeSpec: {
2562 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2563 FirstQualifierInScope, SS);
2564
2565 if (!TL)
2566 return NestedNameSpecifierLoc();
2567
2568 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2569 (SemaRef.getLangOptions().CPlusPlus0x &&
2570 TL.getType()->isEnumeralType())) {
2571 assert(!TL.getType().hasLocalQualifiers() &&
2572 "Can't get cv-qualifiers here");
2573 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2574 Q.getLocalEndLoc());
2575 break;
2576 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002577 // If the nested-name-specifier is an invalid type def, don't emit an
2578 // error because a previous error should have already been emitted.
2579 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2580 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2581 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2582 << TL.getType() << SS.getRange();
2583 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002584 return NestedNameSpecifierLoc();
2585 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002586 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002587
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002588 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002589 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002590 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002591 }
2592
2593 // Don't rebuild the nested-name-specifier if we don't have to.
2594 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2595 !getDerived().AlwaysRebuild())
2596 return NNS;
2597
2598 // If we can re-use the source-location data from the original
2599 // nested-name-specifier, do so.
2600 if (SS.location_size() == NNS.getDataLength() &&
2601 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2602 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2603
2604 // Allocate new nested-name-specifier location information.
2605 return SS.getWithLocInContext(SemaRef.Context);
2606}
2607
2608template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002609DeclarationNameInfo
2610TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002611::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002612 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002613 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002614 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002615
2616 switch (Name.getNameKind()) {
2617 case DeclarationName::Identifier:
2618 case DeclarationName::ObjCZeroArgSelector:
2619 case DeclarationName::ObjCOneArgSelector:
2620 case DeclarationName::ObjCMultiArgSelector:
2621 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002622 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002623 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002624 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002625
Douglas Gregor81499bb2009-09-03 22:13:48 +00002626 case DeclarationName::CXXConstructorName:
2627 case DeclarationName::CXXDestructorName:
2628 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002629 TypeSourceInfo *NewTInfo;
2630 CanQualType NewCanTy;
2631 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002632 NewTInfo = getDerived().TransformType(OldTInfo);
2633 if (!NewTInfo)
2634 return DeclarationNameInfo();
2635 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002636 }
2637 else {
2638 NewTInfo = 0;
2639 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002640 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002641 if (NewT.isNull())
2642 return DeclarationNameInfo();
2643 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2644 }
Mike Stump1eb44332009-09-09 15:08:12 +00002645
Abramo Bagnara25777432010-08-11 22:01:17 +00002646 DeclarationName NewName
2647 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2648 NewCanTy);
2649 DeclarationNameInfo NewNameInfo(NameInfo);
2650 NewNameInfo.setName(NewName);
2651 NewNameInfo.setNamedTypeInfo(NewTInfo);
2652 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002653 }
Mike Stump1eb44332009-09-09 15:08:12 +00002654 }
2655
Abramo Bagnara25777432010-08-11 22:01:17 +00002656 assert(0 && "Unknown name kind.");
2657 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002658}
2659
2660template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002661TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002662TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2663 TemplateName Name,
2664 SourceLocation NameLoc,
2665 QualType ObjectType,
2666 NamedDecl *FirstQualifierInScope) {
2667 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2668 TemplateDecl *Template = QTN->getTemplateDecl();
2669 assert(Template && "qualified template name must refer to a template");
2670
2671 TemplateDecl *TransTemplate
2672 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2673 Template));
2674 if (!TransTemplate)
2675 return TemplateName();
2676
2677 if (!getDerived().AlwaysRebuild() &&
2678 SS.getScopeRep() == QTN->getQualifier() &&
2679 TransTemplate == Template)
2680 return Name;
2681
2682 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2683 TransTemplate);
2684 }
2685
2686 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2687 if (SS.getScopeRep()) {
2688 // These apply to the scope specifier, not the template.
2689 ObjectType = QualType();
2690 FirstQualifierInScope = 0;
2691 }
2692
2693 if (!getDerived().AlwaysRebuild() &&
2694 SS.getScopeRep() == DTN->getQualifier() &&
2695 ObjectType.isNull())
2696 return Name;
2697
2698 if (DTN->isIdentifier()) {
2699 return getDerived().RebuildTemplateName(SS,
2700 *DTN->getIdentifier(),
2701 NameLoc,
2702 ObjectType,
2703 FirstQualifierInScope);
2704 }
2705
2706 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2707 ObjectType);
2708 }
2709
2710 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2711 TemplateDecl *TransTemplate
2712 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2713 Template));
2714 if (!TransTemplate)
2715 return TemplateName();
2716
2717 if (!getDerived().AlwaysRebuild() &&
2718 TransTemplate == Template)
2719 return Name;
2720
2721 return TemplateName(TransTemplate);
2722 }
2723
2724 if (SubstTemplateTemplateParmPackStorage *SubstPack
2725 = Name.getAsSubstTemplateTemplateParmPack()) {
2726 TemplateTemplateParmDecl *TransParam
2727 = cast_or_null<TemplateTemplateParmDecl>(
2728 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2729 if (!TransParam)
2730 return TemplateName();
2731
2732 if (!getDerived().AlwaysRebuild() &&
2733 TransParam == SubstPack->getParameterPack())
2734 return Name;
2735
2736 return getDerived().RebuildTemplateName(TransParam,
2737 SubstPack->getArgumentPack());
2738 }
2739
2740 // These should be getting filtered out before they reach the AST.
2741 llvm_unreachable("overloaded function decl survived to here");
2742 return TemplateName();
2743}
2744
2745template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002746void TreeTransform<Derived>::InventTemplateArgumentLoc(
2747 const TemplateArgument &Arg,
2748 TemplateArgumentLoc &Output) {
2749 SourceLocation Loc = getDerived().getBaseLocation();
2750 switch (Arg.getKind()) {
2751 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002752 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002753 break;
2754
2755 case TemplateArgument::Type:
2756 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002757 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002758
John McCall833ca992009-10-29 08:12:44 +00002759 break;
2760
Douglas Gregor788cd062009-11-11 01:00:40 +00002761 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002762 case TemplateArgument::TemplateExpansion: {
2763 NestedNameSpecifierLocBuilder Builder;
2764 TemplateName Template = Arg.getAsTemplate();
2765 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2766 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2767 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2768 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2769
2770 if (Arg.getKind() == TemplateArgument::Template)
2771 Output = TemplateArgumentLoc(Arg,
2772 Builder.getWithLocInContext(SemaRef.Context),
2773 Loc);
2774 else
2775 Output = TemplateArgumentLoc(Arg,
2776 Builder.getWithLocInContext(SemaRef.Context),
2777 Loc, Loc);
2778
Douglas Gregor788cd062009-11-11 01:00:40 +00002779 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002780 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002781
John McCall833ca992009-10-29 08:12:44 +00002782 case TemplateArgument::Expression:
2783 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2784 break;
2785
2786 case TemplateArgument::Declaration:
2787 case TemplateArgument::Integral:
2788 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002789 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002790 break;
2791 }
2792}
2793
2794template<typename Derived>
2795bool TreeTransform<Derived>::TransformTemplateArgument(
2796 const TemplateArgumentLoc &Input,
2797 TemplateArgumentLoc &Output) {
2798 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002799 switch (Arg.getKind()) {
2800 case TemplateArgument::Null:
2801 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002802 Output = Input;
2803 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002804
Douglas Gregor670444e2009-08-04 22:27:00 +00002805 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002806 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002807 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002808 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002809
2810 DI = getDerived().TransformType(DI);
2811 if (!DI) return true;
2812
2813 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2814 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002815 }
Mike Stump1eb44332009-09-09 15:08:12 +00002816
Douglas Gregor670444e2009-08-04 22:27:00 +00002817 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002818 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002819 DeclarationName Name;
2820 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2821 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002822 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002823 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002824 if (!D) return true;
2825
John McCall828bff22009-10-29 18:45:58 +00002826 Expr *SourceExpr = Input.getSourceDeclExpression();
2827 if (SourceExpr) {
2828 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002829 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002830 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002831 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002832 }
2833
2834 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002835 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002836 }
Mike Stump1eb44332009-09-09 15:08:12 +00002837
Douglas Gregor788cd062009-11-11 01:00:40 +00002838 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002839 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2840 if (QualifierLoc) {
2841 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2842 if (!QualifierLoc)
2843 return true;
2844 }
2845
Douglas Gregor1d752d72011-03-02 18:46:51 +00002846 CXXScopeSpec SS;
2847 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002848 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002849 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2850 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002851 if (Template.isNull())
2852 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002853
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002854 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002855 Input.getTemplateNameLoc());
2856 return false;
2857 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002858
2859 case TemplateArgument::TemplateExpansion:
2860 llvm_unreachable("Caller should expand pack expansions");
2861
Douglas Gregor670444e2009-08-04 22:27:00 +00002862 case TemplateArgument::Expression: {
2863 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002864 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002865 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002866
John McCall833ca992009-10-29 08:12:44 +00002867 Expr *InputExpr = Input.getSourceExpression();
2868 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2869
Chris Lattner223de242011-04-25 20:37:58 +00002870 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002871 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002872 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002873 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002874 }
Mike Stump1eb44332009-09-09 15:08:12 +00002875
Douglas Gregor670444e2009-08-04 22:27:00 +00002876 case TemplateArgument::Pack: {
2877 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2878 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002879 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002880 AEnd = Arg.pack_end();
2881 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002882
John McCall833ca992009-10-29 08:12:44 +00002883 // FIXME: preserve source information here when we start
2884 // caring about parameter packs.
2885
John McCall828bff22009-10-29 18:45:58 +00002886 TemplateArgumentLoc InputArg;
2887 TemplateArgumentLoc OutputArg;
2888 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2889 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002890 return true;
2891
John McCall828bff22009-10-29 18:45:58 +00002892 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002893 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002894
2895 TemplateArgument *TransformedArgsPtr
2896 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2897 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2898 TransformedArgsPtr);
2899 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2900 TransformedArgs.size()),
2901 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002902 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002903 }
2904 }
Mike Stump1eb44332009-09-09 15:08:12 +00002905
Douglas Gregor670444e2009-08-04 22:27:00 +00002906 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002907 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002908}
2909
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002910/// \brief Iterator adaptor that invents template argument location information
2911/// for each of the template arguments in its underlying iterator.
2912template<typename Derived, typename InputIterator>
2913class TemplateArgumentLocInventIterator {
2914 TreeTransform<Derived> &Self;
2915 InputIterator Iter;
2916
2917public:
2918 typedef TemplateArgumentLoc value_type;
2919 typedef TemplateArgumentLoc reference;
2920 typedef typename std::iterator_traits<InputIterator>::difference_type
2921 difference_type;
2922 typedef std::input_iterator_tag iterator_category;
2923
2924 class pointer {
2925 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002926
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002927 public:
2928 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2929
2930 const TemplateArgumentLoc *operator->() const { return &Arg; }
2931 };
2932
2933 TemplateArgumentLocInventIterator() { }
2934
2935 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2936 InputIterator Iter)
2937 : Self(Self), Iter(Iter) { }
2938
2939 TemplateArgumentLocInventIterator &operator++() {
2940 ++Iter;
2941 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002942 }
2943
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002944 TemplateArgumentLocInventIterator operator++(int) {
2945 TemplateArgumentLocInventIterator Old(*this);
2946 ++(*this);
2947 return Old;
2948 }
2949
2950 reference operator*() const {
2951 TemplateArgumentLoc Result;
2952 Self.InventTemplateArgumentLoc(*Iter, Result);
2953 return Result;
2954 }
2955
2956 pointer operator->() const { return pointer(**this); }
2957
2958 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2959 const TemplateArgumentLocInventIterator &Y) {
2960 return X.Iter == Y.Iter;
2961 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002962
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002963 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2964 const TemplateArgumentLocInventIterator &Y) {
2965 return X.Iter != Y.Iter;
2966 }
2967};
2968
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002969template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002970template<typename InputIterator>
2971bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2972 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002973 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002974 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002975 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002976 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002977
2978 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2979 // Unpack argument packs, which we translate them into separate
2980 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002981 // FIXME: We could do much better if we could guarantee that the
2982 // TemplateArgumentLocInfo for the pack expansion would be usable for
2983 // all of the template arguments in the argument pack.
2984 typedef TemplateArgumentLocInventIterator<Derived,
2985 TemplateArgument::pack_iterator>
2986 PackLocIterator;
2987 if (TransformTemplateArguments(PackLocIterator(*this,
2988 In.getArgument().pack_begin()),
2989 PackLocIterator(*this,
2990 In.getArgument().pack_end()),
2991 Outputs))
2992 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002993
2994 continue;
2995 }
2996
2997 if (In.getArgument().isPackExpansion()) {
2998 // We have a pack expansion, for which we will be substituting into
2999 // the pattern.
3000 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003001 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003002 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003003 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3004 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003005
3006 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3007 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3008 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3009
3010 // Determine whether the set of unexpanded parameter packs can and should
3011 // be expanded.
3012 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003013 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003014 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003015 if (getDerived().TryExpandParameterPacks(Ellipsis,
3016 Pattern.getSourceRange(),
3017 Unexpanded.data(),
3018 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003019 Expand,
3020 RetainExpansion,
3021 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003022 return true;
3023
3024 if (!Expand) {
3025 // The transform has determined that we should perform a simple
3026 // transformation on the pack expansion, producing another pack
3027 // expansion.
3028 TemplateArgumentLoc OutPattern;
3029 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3030 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3031 return true;
3032
Douglas Gregorcded4f62011-01-14 17:04:44 +00003033 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3034 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003035 if (Out.getArgument().isNull())
3036 return true;
3037
3038 Outputs.addArgument(Out);
3039 continue;
3040 }
3041
3042 // The transform has determined that we should perform an elementwise
3043 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003044 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003045 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3046
3047 if (getDerived().TransformTemplateArgument(Pattern, Out))
3048 return true;
3049
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003050 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003051 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3052 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003053 if (Out.getArgument().isNull())
3054 return true;
3055 }
3056
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003057 Outputs.addArgument(Out);
3058 }
3059
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003060 // If we're supposed to retain a pack expansion, do so by temporarily
3061 // forgetting the partially-substituted parameter pack.
3062 if (RetainExpansion) {
3063 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3064
3065 if (getDerived().TransformTemplateArgument(Pattern, Out))
3066 return true;
3067
Douglas Gregorcded4f62011-01-14 17:04:44 +00003068 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3069 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003070 if (Out.getArgument().isNull())
3071 return true;
3072
3073 Outputs.addArgument(Out);
3074 }
Douglas Gregord3731192011-01-10 07:32:04 +00003075
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003076 continue;
3077 }
3078
3079 // The simple case:
3080 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003081 return true;
3082
3083 Outputs.addArgument(Out);
3084 }
3085
3086 return false;
3087
3088}
3089
Douglas Gregor577f75a2009-08-04 16:50:30 +00003090//===----------------------------------------------------------------------===//
3091// Type transformation
3092//===----------------------------------------------------------------------===//
3093
3094template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003095QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003096 if (getDerived().AlreadyTransformed(T))
3097 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003098
John McCalla2becad2009-10-21 00:40:46 +00003099 // Temporary workaround. All of these transformations should
3100 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003101 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3102 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003103
John McCall43fed0d2010-11-12 08:19:04 +00003104 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003105
John McCalla2becad2009-10-21 00:40:46 +00003106 if (!NewDI)
3107 return QualType();
3108
3109 return NewDI->getType();
3110}
3111
3112template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003113TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00003114 if (getDerived().AlreadyTransformed(DI->getType()))
3115 return DI;
3116
3117 TypeLocBuilder TLB;
3118
3119 TypeLoc TL = DI->getTypeLoc();
3120 TLB.reserve(TL.getFullDataSize());
3121
John McCall43fed0d2010-11-12 08:19:04 +00003122 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003123 if (Result.isNull())
3124 return 0;
3125
John McCalla93c9342009-12-07 02:54:59 +00003126 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003127}
3128
3129template<typename Derived>
3130QualType
John McCall43fed0d2010-11-12 08:19:04 +00003131TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003132 switch (T.getTypeLocClass()) {
3133#define ABSTRACT_TYPELOC(CLASS, PARENT)
3134#define TYPELOC(CLASS, PARENT) \
3135 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003136 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003137#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003138 }
Mike Stump1eb44332009-09-09 15:08:12 +00003139
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003140 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003141 return QualType();
3142}
3143
3144/// FIXME: By default, this routine adds type qualifiers only to types
3145/// that can have qualifiers, and silently suppresses those qualifiers
3146/// that are not permitted (e.g., qualifiers on reference or function
3147/// types). This is the right thing for template instantiation, but
3148/// probably not for other clients.
3149template<typename Derived>
3150QualType
3151TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003152 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003153 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003154
John McCall43fed0d2010-11-12 08:19:04 +00003155 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003156 if (Result.isNull())
3157 return QualType();
3158
3159 // Silently suppress qualifiers if the result type can't be qualified.
3160 // FIXME: this is the right thing for template instantiation, but
3161 // probably not for other clients.
3162 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003163 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003164
John McCall28654742010-06-05 06:41:15 +00003165 if (!Quals.empty()) {
3166 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3167 TLB.push<QualifiedTypeLoc>(Result);
3168 // No location information to preserve.
3169 }
John McCalla2becad2009-10-21 00:40:46 +00003170
3171 return Result;
3172}
3173
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003174template<typename Derived>
3175TypeLoc
3176TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3177 QualType ObjectType,
3178 NamedDecl *UnqualLookup,
3179 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003180 QualType T = TL.getType();
3181 if (getDerived().AlreadyTransformed(T))
3182 return TL;
3183
3184 TypeLocBuilder TLB;
3185 QualType Result;
3186
3187 if (isa<TemplateSpecializationType>(T)) {
3188 TemplateSpecializationTypeLoc SpecTL
3189 = cast<TemplateSpecializationTypeLoc>(TL);
3190
3191 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003192 getDerived().TransformTemplateName(SS,
3193 SpecTL.getTypePtr()->getTemplateName(),
3194 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003195 ObjectType, UnqualLookup);
3196 if (Template.isNull())
3197 return TypeLoc();
3198
3199 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3200 Template);
3201 } else if (isa<DependentTemplateSpecializationType>(T)) {
3202 DependentTemplateSpecializationTypeLoc SpecTL
3203 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3204
Douglas Gregora88f09f2011-02-28 17:23:35 +00003205 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003206 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003207 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003208 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003209 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003210 if (Template.isNull())
3211 return TypeLoc();
3212
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003213 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003214 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003215 Template,
3216 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003217 } else {
3218 // Nothing special needs to be done for these.
3219 Result = getDerived().TransformType(TLB, TL);
3220 }
3221
3222 if (Result.isNull())
3223 return TypeLoc();
3224
3225 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3226}
3227
Douglas Gregorb71d8212011-03-02 18:32:08 +00003228template<typename Derived>
3229TypeSourceInfo *
3230TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3231 QualType ObjectType,
3232 NamedDecl *UnqualLookup,
3233 CXXScopeSpec &SS) {
3234 // FIXME: Painfully copy-paste from the above!
3235
3236 QualType T = TSInfo->getType();
3237 if (getDerived().AlreadyTransformed(T))
3238 return TSInfo;
3239
3240 TypeLocBuilder TLB;
3241 QualType Result;
3242
3243 TypeLoc TL = TSInfo->getTypeLoc();
3244 if (isa<TemplateSpecializationType>(T)) {
3245 TemplateSpecializationTypeLoc SpecTL
3246 = cast<TemplateSpecializationTypeLoc>(TL);
3247
3248 TemplateName Template
3249 = getDerived().TransformTemplateName(SS,
3250 SpecTL.getTypePtr()->getTemplateName(),
3251 SpecTL.getTemplateNameLoc(),
3252 ObjectType, UnqualLookup);
3253 if (Template.isNull())
3254 return 0;
3255
3256 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3257 Template);
3258 } else if (isa<DependentTemplateSpecializationType>(T)) {
3259 DependentTemplateSpecializationTypeLoc SpecTL
3260 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3261
3262 TemplateName Template
3263 = getDerived().RebuildTemplateName(SS,
3264 *SpecTL.getTypePtr()->getIdentifier(),
3265 SpecTL.getNameLoc(),
3266 ObjectType, UnqualLookup);
3267 if (Template.isNull())
3268 return 0;
3269
3270 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3271 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003272 Template,
3273 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003274 } else {
3275 // Nothing special needs to be done for these.
3276 Result = getDerived().TransformType(TLB, TL);
3277 }
3278
3279 if (Result.isNull())
3280 return 0;
3281
3282 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3283}
3284
John McCalla2becad2009-10-21 00:40:46 +00003285template <class TyLoc> static inline
3286QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3287 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3288 NewT.setNameLoc(T.getNameLoc());
3289 return T.getType();
3290}
3291
John McCalla2becad2009-10-21 00:40:46 +00003292template<typename Derived>
3293QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003294 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003295 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3296 NewT.setBuiltinLoc(T.getBuiltinLoc());
3297 if (T.needsExtraLocalData())
3298 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3299 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003300}
Mike Stump1eb44332009-09-09 15:08:12 +00003301
Douglas Gregor577f75a2009-08-04 16:50:30 +00003302template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003303QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003304 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003305 // FIXME: recurse?
3306 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003307}
Mike Stump1eb44332009-09-09 15:08:12 +00003308
Douglas Gregor577f75a2009-08-04 16:50:30 +00003309template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003310QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003311 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003312 QualType PointeeType
3313 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003314 if (PointeeType.isNull())
3315 return QualType();
3316
3317 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003318 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003319 // A dependent pointer type 'T *' has is being transformed such
3320 // that an Objective-C class type is being replaced for 'T'. The
3321 // resulting pointer type is an ObjCObjectPointerType, not a
3322 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003323 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003324
John McCallc12c5bb2010-05-15 11:32:37 +00003325 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3326 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003327 return Result;
3328 }
John McCall43fed0d2010-11-12 08:19:04 +00003329
Douglas Gregor92e986e2010-04-22 16:44:27 +00003330 if (getDerived().AlwaysRebuild() ||
3331 PointeeType != TL.getPointeeLoc().getType()) {
3332 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3333 if (Result.isNull())
3334 return QualType();
3335 }
Sean Huntc3021132010-05-05 15:23:54 +00003336
Douglas Gregor92e986e2010-04-22 16:44:27 +00003337 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3338 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003339 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003340}
Mike Stump1eb44332009-09-09 15:08:12 +00003341
3342template<typename Derived>
3343QualType
John McCalla2becad2009-10-21 00:40:46 +00003344TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003345 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003346 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003347 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3348 if (PointeeType.isNull())
3349 return QualType();
3350
3351 QualType Result = TL.getType();
3352 if (getDerived().AlwaysRebuild() ||
3353 PointeeType != TL.getPointeeLoc().getType()) {
3354 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003355 TL.getSigilLoc());
3356 if (Result.isNull())
3357 return QualType();
3358 }
3359
Douglas Gregor39968ad2010-04-22 16:50:51 +00003360 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003361 NewT.setSigilLoc(TL.getSigilLoc());
3362 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003363}
3364
John McCall85737a72009-10-30 00:06:24 +00003365/// Transforms a reference type. Note that somewhat paradoxically we
3366/// don't care whether the type itself is an l-value type or an r-value
3367/// type; we only care if the type was *written* as an l-value type
3368/// or an r-value type.
3369template<typename Derived>
3370QualType
3371TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003372 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003373 const ReferenceType *T = TL.getTypePtr();
3374
3375 // Note that this works with the pointee-as-written.
3376 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3377 if (PointeeType.isNull())
3378 return QualType();
3379
3380 QualType Result = TL.getType();
3381 if (getDerived().AlwaysRebuild() ||
3382 PointeeType != T->getPointeeTypeAsWritten()) {
3383 Result = getDerived().RebuildReferenceType(PointeeType,
3384 T->isSpelledAsLValue(),
3385 TL.getSigilLoc());
3386 if (Result.isNull())
3387 return QualType();
3388 }
3389
3390 // r-value references can be rebuilt as l-value references.
3391 ReferenceTypeLoc NewTL;
3392 if (isa<LValueReferenceType>(Result))
3393 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3394 else
3395 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3396 NewTL.setSigilLoc(TL.getSigilLoc());
3397
3398 return Result;
3399}
3400
Mike Stump1eb44332009-09-09 15:08:12 +00003401template<typename Derived>
3402QualType
John McCalla2becad2009-10-21 00:40:46 +00003403TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003404 LValueReferenceTypeLoc TL) {
3405 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003406}
3407
Mike Stump1eb44332009-09-09 15:08:12 +00003408template<typename Derived>
3409QualType
John McCalla2becad2009-10-21 00:40:46 +00003410TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003411 RValueReferenceTypeLoc TL) {
3412 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003413}
Mike Stump1eb44332009-09-09 15:08:12 +00003414
Douglas Gregor577f75a2009-08-04 16:50:30 +00003415template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003416QualType
John McCalla2becad2009-10-21 00:40:46 +00003417TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003418 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003419 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003420 if (PointeeType.isNull())
3421 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003422
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003423 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3424 TypeSourceInfo* NewClsTInfo = 0;
3425 if (OldClsTInfo) {
3426 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3427 if (!NewClsTInfo)
3428 return QualType();
3429 }
3430
3431 const MemberPointerType *T = TL.getTypePtr();
3432 QualType OldClsType = QualType(T->getClass(), 0);
3433 QualType NewClsType;
3434 if (NewClsTInfo)
3435 NewClsType = NewClsTInfo->getType();
3436 else {
3437 NewClsType = getDerived().TransformType(OldClsType);
3438 if (NewClsType.isNull())
3439 return QualType();
3440 }
Mike Stump1eb44332009-09-09 15:08:12 +00003441
John McCalla2becad2009-10-21 00:40:46 +00003442 QualType Result = TL.getType();
3443 if (getDerived().AlwaysRebuild() ||
3444 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003445 NewClsType != OldClsType) {
3446 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003447 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003448 if (Result.isNull())
3449 return QualType();
3450 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003451
John McCalla2becad2009-10-21 00:40:46 +00003452 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3453 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003454 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003455
3456 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003457}
3458
Mike Stump1eb44332009-09-09 15:08:12 +00003459template<typename Derived>
3460QualType
John McCalla2becad2009-10-21 00:40:46 +00003461TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003462 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003463 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003464 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003465 if (ElementType.isNull())
3466 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003467
John McCalla2becad2009-10-21 00:40:46 +00003468 QualType Result = TL.getType();
3469 if (getDerived().AlwaysRebuild() ||
3470 ElementType != T->getElementType()) {
3471 Result = getDerived().RebuildConstantArrayType(ElementType,
3472 T->getSizeModifier(),
3473 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003474 T->getIndexTypeCVRQualifiers(),
3475 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003476 if (Result.isNull())
3477 return QualType();
3478 }
Sean Huntc3021132010-05-05 15:23:54 +00003479
John McCalla2becad2009-10-21 00:40:46 +00003480 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3481 NewTL.setLBracketLoc(TL.getLBracketLoc());
3482 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003483
John McCalla2becad2009-10-21 00:40:46 +00003484 Expr *Size = TL.getSizeExpr();
3485 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003486 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003487 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3488 }
3489 NewTL.setSizeExpr(Size);
3490
3491 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003492}
Mike Stump1eb44332009-09-09 15:08:12 +00003493
Douglas Gregor577f75a2009-08-04 16:50:30 +00003494template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003495QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003496 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003497 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003498 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003499 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003500 if (ElementType.isNull())
3501 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003502
John McCalla2becad2009-10-21 00:40:46 +00003503 QualType Result = TL.getType();
3504 if (getDerived().AlwaysRebuild() ||
3505 ElementType != T->getElementType()) {
3506 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003507 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003508 T->getIndexTypeCVRQualifiers(),
3509 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003510 if (Result.isNull())
3511 return QualType();
3512 }
Sean Huntc3021132010-05-05 15:23:54 +00003513
John McCalla2becad2009-10-21 00:40:46 +00003514 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3515 NewTL.setLBracketLoc(TL.getLBracketLoc());
3516 NewTL.setRBracketLoc(TL.getRBracketLoc());
3517 NewTL.setSizeExpr(0);
3518
3519 return Result;
3520}
3521
3522template<typename Derived>
3523QualType
3524TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003525 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003526 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003527 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3528 if (ElementType.isNull())
3529 return QualType();
3530
3531 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003532 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003533
John McCall60d7b3a2010-08-24 06:29:42 +00003534 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003535 = getDerived().TransformExpr(T->getSizeExpr());
3536 if (SizeResult.isInvalid())
3537 return QualType();
3538
John McCall9ae2f072010-08-23 23:25:46 +00003539 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003540
3541 QualType Result = TL.getType();
3542 if (getDerived().AlwaysRebuild() ||
3543 ElementType != T->getElementType() ||
3544 Size != T->getSizeExpr()) {
3545 Result = getDerived().RebuildVariableArrayType(ElementType,
3546 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003547 Size,
John McCalla2becad2009-10-21 00:40:46 +00003548 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003549 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003550 if (Result.isNull())
3551 return QualType();
3552 }
Sean Huntc3021132010-05-05 15:23:54 +00003553
John McCalla2becad2009-10-21 00:40:46 +00003554 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3555 NewTL.setLBracketLoc(TL.getLBracketLoc());
3556 NewTL.setRBracketLoc(TL.getRBracketLoc());
3557 NewTL.setSizeExpr(Size);
3558
3559 return Result;
3560}
3561
3562template<typename Derived>
3563QualType
3564TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003565 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003566 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003567 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3568 if (ElementType.isNull())
3569 return QualType();
3570
3571 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003572 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003573
John McCall3b657512011-01-19 10:06:00 +00003574 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3575 Expr *origSize = TL.getSizeExpr();
3576 if (!origSize) origSize = T->getSizeExpr();
3577
3578 ExprResult sizeResult
3579 = getDerived().TransformExpr(origSize);
3580 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003581 return QualType();
3582
John McCall3b657512011-01-19 10:06:00 +00003583 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003584
3585 QualType Result = TL.getType();
3586 if (getDerived().AlwaysRebuild() ||
3587 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003588 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003589 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3590 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003591 size,
John McCalla2becad2009-10-21 00:40:46 +00003592 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003593 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003594 if (Result.isNull())
3595 return QualType();
3596 }
John McCalla2becad2009-10-21 00:40:46 +00003597
3598 // We might have any sort of array type now, but fortunately they
3599 // all have the same location layout.
3600 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3601 NewTL.setLBracketLoc(TL.getLBracketLoc());
3602 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003603 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003604
3605 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003606}
Mike Stump1eb44332009-09-09 15:08:12 +00003607
3608template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003609QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003610 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003611 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003612 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003613
3614 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003615 QualType ElementType = getDerived().TransformType(T->getElementType());
3616 if (ElementType.isNull())
3617 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003618
Douglas Gregor670444e2009-08-04 22:27:00 +00003619 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003620 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003621
John McCall60d7b3a2010-08-24 06:29:42 +00003622 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003623 if (Size.isInvalid())
3624 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003625
John McCalla2becad2009-10-21 00:40:46 +00003626 QualType Result = TL.getType();
3627 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003628 ElementType != T->getElementType() ||
3629 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003630 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003631 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003632 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003633 if (Result.isNull())
3634 return QualType();
3635 }
John McCalla2becad2009-10-21 00:40:46 +00003636
3637 // Result might be dependent or not.
3638 if (isa<DependentSizedExtVectorType>(Result)) {
3639 DependentSizedExtVectorTypeLoc NewTL
3640 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3641 NewTL.setNameLoc(TL.getNameLoc());
3642 } else {
3643 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3644 NewTL.setNameLoc(TL.getNameLoc());
3645 }
3646
3647 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003648}
Mike Stump1eb44332009-09-09 15:08:12 +00003649
3650template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003651QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003652 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003653 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003654 QualType ElementType = getDerived().TransformType(T->getElementType());
3655 if (ElementType.isNull())
3656 return QualType();
3657
John McCalla2becad2009-10-21 00:40:46 +00003658 QualType Result = TL.getType();
3659 if (getDerived().AlwaysRebuild() ||
3660 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003661 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003662 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003663 if (Result.isNull())
3664 return QualType();
3665 }
Sean Huntc3021132010-05-05 15:23:54 +00003666
John McCalla2becad2009-10-21 00:40:46 +00003667 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3668 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003669
John McCalla2becad2009-10-21 00:40:46 +00003670 return Result;
3671}
3672
3673template<typename Derived>
3674QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003675 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003676 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003677 QualType ElementType = getDerived().TransformType(T->getElementType());
3678 if (ElementType.isNull())
3679 return QualType();
3680
3681 QualType Result = TL.getType();
3682 if (getDerived().AlwaysRebuild() ||
3683 ElementType != T->getElementType()) {
3684 Result = getDerived().RebuildExtVectorType(ElementType,
3685 T->getNumElements(),
3686 /*FIXME*/ SourceLocation());
3687 if (Result.isNull())
3688 return QualType();
3689 }
Sean Huntc3021132010-05-05 15:23:54 +00003690
John McCalla2becad2009-10-21 00:40:46 +00003691 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3692 NewTL.setNameLoc(TL.getNameLoc());
3693
3694 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003695}
Mike Stump1eb44332009-09-09 15:08:12 +00003696
3697template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003698ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003699TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003700 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003701 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003702 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003703 TypeSourceInfo *NewDI = 0;
3704
3705 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3706 // If we're substituting into a pack expansion type and we know the
3707 TypeLoc OldTL = OldDI->getTypeLoc();
3708 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3709
3710 TypeLocBuilder TLB;
3711 TypeLoc NewTL = OldDI->getTypeLoc();
3712 TLB.reserve(NewTL.getFullDataSize());
3713
3714 QualType Result = getDerived().TransformType(TLB,
3715 OldExpansionTL.getPatternLoc());
3716 if (Result.isNull())
3717 return 0;
3718
3719 Result = RebuildPackExpansionType(Result,
3720 OldExpansionTL.getPatternLoc().getSourceRange(),
3721 OldExpansionTL.getEllipsisLoc(),
3722 NumExpansions);
3723 if (Result.isNull())
3724 return 0;
3725
3726 PackExpansionTypeLoc NewExpansionTL
3727 = TLB.push<PackExpansionTypeLoc>(Result);
3728 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3729 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3730 } else
3731 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003732 if (!NewDI)
3733 return 0;
3734
John McCallfb44de92011-05-01 22:35:37 +00003735 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003736 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003737
3738 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3739 OldParm->getDeclContext(),
3740 OldParm->getInnerLocStart(),
3741 OldParm->getLocation(),
3742 OldParm->getIdentifier(),
3743 NewDI->getType(),
3744 NewDI,
3745 OldParm->getStorageClass(),
3746 OldParm->getStorageClassAsWritten(),
3747 /* DefArg */ NULL);
3748 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3749 OldParm->getFunctionScopeIndex() + indexAdjustment);
3750 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003751}
3752
3753template<typename Derived>
3754bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003755 TransformFunctionTypeParams(SourceLocation Loc,
3756 ParmVarDecl **Params, unsigned NumParams,
3757 const QualType *ParamTypes,
3758 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3759 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003760 int indexAdjustment = 0;
3761
Douglas Gregora009b592011-01-07 00:20:55 +00003762 for (unsigned i = 0; i != NumParams; ++i) {
3763 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003764 assert(OldParm->getFunctionScopeIndex() == i);
3765
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003766 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003767 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003768 if (OldParm->isParameterPack()) {
3769 // We have a function parameter pack that may need to be expanded.
3770 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003771
Douglas Gregor603cfb42011-01-05 23:12:31 +00003772 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003773 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3774 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3775 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3776 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003777 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3778
Douglas Gregor603cfb42011-01-05 23:12:31 +00003779 // Determine whether we should expand the parameter packs.
3780 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003781 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003782 llvm::Optional<unsigned> OrigNumExpansions
3783 = ExpansionTL.getTypePtr()->getNumExpansions();
3784 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003785 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3786 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003787 Unexpanded.data(),
3788 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003789 ShouldExpand,
3790 RetainExpansion,
3791 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003792 return true;
3793 }
3794
3795 if (ShouldExpand) {
3796 // Expand the function parameter pack into multiple, separate
3797 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003798 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003799 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003800 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3801 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003802 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003803 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003804 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003805 if (!NewParm)
3806 return true;
3807
Douglas Gregora009b592011-01-07 00:20:55 +00003808 OutParamTypes.push_back(NewParm->getType());
3809 if (PVars)
3810 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003811 }
Douglas Gregord3731192011-01-10 07:32:04 +00003812
3813 // If we're supposed to retain a pack expansion, do so by temporarily
3814 // forgetting the partially-substituted parameter pack.
3815 if (RetainExpansion) {
3816 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3817 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003818 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003819 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003820 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003821 if (!NewParm)
3822 return true;
3823
3824 OutParamTypes.push_back(NewParm->getType());
3825 if (PVars)
3826 PVars->push_back(NewParm);
3827 }
3828
John McCallfb44de92011-05-01 22:35:37 +00003829 // The next parameter should have the same adjustment as the
3830 // last thing we pushed, but we post-incremented indexAdjustment
3831 // on every push. Also, if we push nothing, the adjustment should
3832 // go down by one.
3833 indexAdjustment--;
3834
Douglas Gregor603cfb42011-01-05 23:12:31 +00003835 // We're done with the pack expansion.
3836 continue;
3837 }
3838
3839 // We'll substitute the parameter now without expanding the pack
3840 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003841 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3842 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003843 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003844 NumExpansions);
3845 } else {
3846 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003847 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003848 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003849 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003850
John McCall21ef0fa2010-03-11 09:03:00 +00003851 if (!NewParm)
3852 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003853
Douglas Gregora009b592011-01-07 00:20:55 +00003854 OutParamTypes.push_back(NewParm->getType());
3855 if (PVars)
3856 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003857 continue;
3858 }
John McCall21ef0fa2010-03-11 09:03:00 +00003859
3860 // Deal with the possibility that we don't have a parameter
3861 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003862 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003863 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003864 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003865 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003866 if (const PackExpansionType *Expansion
3867 = dyn_cast<PackExpansionType>(OldType)) {
3868 // We have a function parameter pack that may need to be expanded.
3869 QualType Pattern = Expansion->getPattern();
3870 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3871 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3872
3873 // Determine whether we should expand the parameter packs.
3874 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003875 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003876 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003877 Unexpanded.data(),
3878 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003879 ShouldExpand,
3880 RetainExpansion,
3881 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003882 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003883 }
3884
3885 if (ShouldExpand) {
3886 // Expand the function parameter pack into multiple, separate
3887 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003888 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003889 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3890 QualType NewType = getDerived().TransformType(Pattern);
3891 if (NewType.isNull())
3892 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003893
Douglas Gregora009b592011-01-07 00:20:55 +00003894 OutParamTypes.push_back(NewType);
3895 if (PVars)
3896 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003897 }
3898
3899 // We're done with the pack expansion.
3900 continue;
3901 }
3902
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003903 // If we're supposed to retain a pack expansion, do so by temporarily
3904 // forgetting the partially-substituted parameter pack.
3905 if (RetainExpansion) {
3906 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3907 QualType NewType = getDerived().TransformType(Pattern);
3908 if (NewType.isNull())
3909 return true;
3910
3911 OutParamTypes.push_back(NewType);
3912 if (PVars)
3913 PVars->push_back(0);
3914 }
Douglas Gregord3731192011-01-10 07:32:04 +00003915
Douglas Gregor603cfb42011-01-05 23:12:31 +00003916 // We'll substitute the parameter now without expanding the pack
3917 // expansion.
3918 OldType = Expansion->getPattern();
3919 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003920 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3921 NewType = getDerived().TransformType(OldType);
3922 } else {
3923 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003924 }
3925
Douglas Gregor603cfb42011-01-05 23:12:31 +00003926 if (NewType.isNull())
3927 return true;
3928
3929 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00003930 NewType = getSema().Context.getPackExpansionType(NewType,
3931 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003932
Douglas Gregora009b592011-01-07 00:20:55 +00003933 OutParamTypes.push_back(NewType);
3934 if (PVars)
3935 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003936 }
3937
John McCallfb44de92011-05-01 22:35:37 +00003938#ifndef NDEBUG
3939 if (PVars) {
3940 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3941 if (ParmVarDecl *parm = (*PVars)[i])
3942 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003943 }
John McCallfb44de92011-05-01 22:35:37 +00003944#endif
3945
3946 return false;
3947}
John McCall21ef0fa2010-03-11 09:03:00 +00003948
3949template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003950QualType
John McCalla2becad2009-10-21 00:40:46 +00003951TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003952 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003953 // Transform the parameters and return type.
3954 //
3955 // We instantiate in source order, with the return type first followed by
3956 // the parameters, because users tend to expect this (even if they shouldn't
3957 // rely on it!).
3958 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003959 // When the function has a trailing return type, we instantiate the
3960 // parameters before the return type, since the return type can then refer
3961 // to the parameters themselves (via decltype, sizeof, etc.).
3962 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003963 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003964 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00003965 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003966
Douglas Gregordab60ad2010-10-01 18:44:50 +00003967 QualType ResultType;
3968
3969 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003970 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3971 TL.getParmArray(),
3972 TL.getNumArgs(),
3973 TL.getTypePtr()->arg_type_begin(),
3974 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003975 return QualType();
3976
3977 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3978 if (ResultType.isNull())
3979 return QualType();
3980 }
3981 else {
3982 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3983 if (ResultType.isNull())
3984 return QualType();
3985
Douglas Gregora009b592011-01-07 00:20:55 +00003986 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3987 TL.getParmArray(),
3988 TL.getNumArgs(),
3989 TL.getTypePtr()->arg_type_begin(),
3990 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003991 return QualType();
3992 }
3993
John McCalla2becad2009-10-21 00:40:46 +00003994 QualType Result = TL.getType();
3995 if (getDerived().AlwaysRebuild() ||
3996 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00003997 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00003998 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3999 Result = getDerived().RebuildFunctionProtoType(ResultType,
4000 ParamTypes.data(),
4001 ParamTypes.size(),
4002 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004003 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004004 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004005 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004006 if (Result.isNull())
4007 return QualType();
4008 }
Mike Stump1eb44332009-09-09 15:08:12 +00004009
John McCalla2becad2009-10-21 00:40:46 +00004010 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004011 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4012 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004013 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004014 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4015 NewTL.setArg(i, ParamDecls[i]);
4016
4017 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004018}
Mike Stump1eb44332009-09-09 15:08:12 +00004019
Douglas Gregor577f75a2009-08-04 16:50:30 +00004020template<typename Derived>
4021QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004022 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004023 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004024 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004025 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4026 if (ResultType.isNull())
4027 return QualType();
4028
4029 QualType Result = TL.getType();
4030 if (getDerived().AlwaysRebuild() ||
4031 ResultType != T->getResultType())
4032 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4033
4034 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004035 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4036 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004037 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004038
4039 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004040}
Mike Stump1eb44332009-09-09 15:08:12 +00004041
John McCalled976492009-12-04 22:46:56 +00004042template<typename Derived> QualType
4043TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004044 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004045 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004046 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004047 if (!D)
4048 return QualType();
4049
4050 QualType Result = TL.getType();
4051 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4052 Result = getDerived().RebuildUnresolvedUsingType(D);
4053 if (Result.isNull())
4054 return QualType();
4055 }
4056
4057 // We might get an arbitrary type spec type back. We should at
4058 // least always get a type spec type, though.
4059 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4060 NewTL.setNameLoc(TL.getNameLoc());
4061
4062 return Result;
4063}
4064
Douglas Gregor577f75a2009-08-04 16:50:30 +00004065template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004066QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004067 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004068 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004069 TypedefNameDecl *Typedef
4070 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4071 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004072 if (!Typedef)
4073 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004074
John McCalla2becad2009-10-21 00:40:46 +00004075 QualType Result = TL.getType();
4076 if (getDerived().AlwaysRebuild() ||
4077 Typedef != T->getDecl()) {
4078 Result = getDerived().RebuildTypedefType(Typedef);
4079 if (Result.isNull())
4080 return QualType();
4081 }
Mike Stump1eb44332009-09-09 15:08:12 +00004082
John McCalla2becad2009-10-21 00:40:46 +00004083 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4084 NewTL.setNameLoc(TL.getNameLoc());
4085
4086 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004087}
Mike Stump1eb44332009-09-09 15:08:12 +00004088
Douglas Gregor577f75a2009-08-04 16:50:30 +00004089template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004090QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004091 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004092 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004093 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004094
John McCall60d7b3a2010-08-24 06:29:42 +00004095 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004096 if (E.isInvalid())
4097 return QualType();
4098
John McCalla2becad2009-10-21 00:40:46 +00004099 QualType Result = TL.getType();
4100 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004101 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004102 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004103 if (Result.isNull())
4104 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004105 }
John McCalla2becad2009-10-21 00:40:46 +00004106 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004107
John McCalla2becad2009-10-21 00:40:46 +00004108 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004109 NewTL.setTypeofLoc(TL.getTypeofLoc());
4110 NewTL.setLParenLoc(TL.getLParenLoc());
4111 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004112
4113 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004114}
Mike Stump1eb44332009-09-09 15:08:12 +00004115
4116template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004117QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004118 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004119 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4120 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4121 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004122 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004123
John McCalla2becad2009-10-21 00:40:46 +00004124 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004125 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4126 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004127 if (Result.isNull())
4128 return QualType();
4129 }
Mike Stump1eb44332009-09-09 15:08:12 +00004130
John McCalla2becad2009-10-21 00:40:46 +00004131 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004132 NewTL.setTypeofLoc(TL.getTypeofLoc());
4133 NewTL.setLParenLoc(TL.getLParenLoc());
4134 NewTL.setRParenLoc(TL.getRParenLoc());
4135 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004136
4137 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004138}
Mike Stump1eb44332009-09-09 15:08:12 +00004139
4140template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004141QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004142 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004143 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004144
Douglas Gregor670444e2009-08-04 22:27:00 +00004145 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004146 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004147
John McCall60d7b3a2010-08-24 06:29:42 +00004148 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004149 if (E.isInvalid())
4150 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004151
John McCalla2becad2009-10-21 00:40:46 +00004152 QualType Result = TL.getType();
4153 if (getDerived().AlwaysRebuild() ||
4154 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004155 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004156 if (Result.isNull())
4157 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004158 }
John McCalla2becad2009-10-21 00:40:46 +00004159 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004160
John McCalla2becad2009-10-21 00:40:46 +00004161 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4162 NewTL.setNameLoc(TL.getNameLoc());
4163
4164 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004165}
4166
4167template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004168QualType TreeTransform<Derived>::TransformUnaryTransformType(
4169 TypeLocBuilder &TLB,
4170 UnaryTransformTypeLoc TL) {
4171 QualType Result = TL.getType();
4172 if (Result->isDependentType()) {
4173 const UnaryTransformType *T = TL.getTypePtr();
4174 QualType NewBase =
4175 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4176 Result = getDerived().RebuildUnaryTransformType(NewBase,
4177 T->getUTTKind(),
4178 TL.getKWLoc());
4179 if (Result.isNull())
4180 return QualType();
4181 }
4182
4183 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4184 NewTL.setKWLoc(TL.getKWLoc());
4185 NewTL.setParensRange(TL.getParensRange());
4186 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4187 return Result;
4188}
4189
4190template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004191QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4192 AutoTypeLoc TL) {
4193 const AutoType *T = TL.getTypePtr();
4194 QualType OldDeduced = T->getDeducedType();
4195 QualType NewDeduced;
4196 if (!OldDeduced.isNull()) {
4197 NewDeduced = getDerived().TransformType(OldDeduced);
4198 if (NewDeduced.isNull())
4199 return QualType();
4200 }
4201
4202 QualType Result = TL.getType();
4203 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4204 Result = getDerived().RebuildAutoType(NewDeduced);
4205 if (Result.isNull())
4206 return QualType();
4207 }
4208
4209 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4210 NewTL.setNameLoc(TL.getNameLoc());
4211
4212 return Result;
4213}
4214
4215template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004216QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004217 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004218 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004219 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004220 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4221 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004222 if (!Record)
4223 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004224
John McCalla2becad2009-10-21 00:40:46 +00004225 QualType Result = TL.getType();
4226 if (getDerived().AlwaysRebuild() ||
4227 Record != T->getDecl()) {
4228 Result = getDerived().RebuildRecordType(Record);
4229 if (Result.isNull())
4230 return QualType();
4231 }
Mike Stump1eb44332009-09-09 15:08:12 +00004232
John McCalla2becad2009-10-21 00:40:46 +00004233 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4234 NewTL.setNameLoc(TL.getNameLoc());
4235
4236 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004237}
Mike Stump1eb44332009-09-09 15:08:12 +00004238
4239template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004240QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004241 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004242 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004243 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004244 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4245 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004246 if (!Enum)
4247 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004248
John McCalla2becad2009-10-21 00:40:46 +00004249 QualType Result = TL.getType();
4250 if (getDerived().AlwaysRebuild() ||
4251 Enum != T->getDecl()) {
4252 Result = getDerived().RebuildEnumType(Enum);
4253 if (Result.isNull())
4254 return QualType();
4255 }
Mike Stump1eb44332009-09-09 15:08:12 +00004256
John McCalla2becad2009-10-21 00:40:46 +00004257 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4258 NewTL.setNameLoc(TL.getNameLoc());
4259
4260 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004261}
John McCall7da24312009-09-05 00:15:47 +00004262
John McCall3cb0ebd2010-03-10 03:28:59 +00004263template<typename Derived>
4264QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4265 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004266 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004267 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4268 TL.getTypePtr()->getDecl());
4269 if (!D) return QualType();
4270
4271 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4272 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4273 return T;
4274}
4275
Douglas Gregor577f75a2009-08-04 16:50:30 +00004276template<typename Derived>
4277QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004278 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004279 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004280 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004281}
4282
Mike Stump1eb44332009-09-09 15:08:12 +00004283template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004284QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004285 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004286 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004287 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4288
4289 // Substitute into the replacement type, which itself might involve something
4290 // that needs to be transformed. This only tends to occur with default
4291 // template arguments of template template parameters.
4292 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4293 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4294 if (Replacement.isNull())
4295 return QualType();
4296
4297 // Always canonicalize the replacement type.
4298 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4299 QualType Result
4300 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4301 Replacement);
4302
4303 // Propagate type-source information.
4304 SubstTemplateTypeParmTypeLoc NewTL
4305 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4306 NewTL.setNameLoc(TL.getNameLoc());
4307 return Result;
4308
John McCall49a832b2009-10-18 09:09:24 +00004309}
4310
4311template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004312QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4313 TypeLocBuilder &TLB,
4314 SubstTemplateTypeParmPackTypeLoc TL) {
4315 return TransformTypeSpecType(TLB, TL);
4316}
4317
4318template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004319QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004320 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004321 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004322 const TemplateSpecializationType *T = TL.getTypePtr();
4323
Douglas Gregor1d752d72011-03-02 18:46:51 +00004324 // The nested-name-specifier never matters in a TemplateSpecializationType,
4325 // because we can't have a dependent nested-name-specifier anyway.
4326 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004327 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004328 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4329 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004330 if (Template.isNull())
4331 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004332
John McCall43fed0d2010-11-12 08:19:04 +00004333 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4334}
4335
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004336namespace {
4337 /// \brief Simple iterator that traverses the template arguments in a
4338 /// container that provides a \c getArgLoc() member function.
4339 ///
4340 /// This iterator is intended to be used with the iterator form of
4341 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4342 template<typename ArgLocContainer>
4343 class TemplateArgumentLocContainerIterator {
4344 ArgLocContainer *Container;
4345 unsigned Index;
4346
4347 public:
4348 typedef TemplateArgumentLoc value_type;
4349 typedef TemplateArgumentLoc reference;
4350 typedef int difference_type;
4351 typedef std::input_iterator_tag iterator_category;
4352
4353 class pointer {
4354 TemplateArgumentLoc Arg;
4355
4356 public:
4357 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4358
4359 const TemplateArgumentLoc *operator->() const {
4360 return &Arg;
4361 }
4362 };
4363
4364
4365 TemplateArgumentLocContainerIterator() {}
4366
4367 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4368 unsigned Index)
4369 : Container(&Container), Index(Index) { }
4370
4371 TemplateArgumentLocContainerIterator &operator++() {
4372 ++Index;
4373 return *this;
4374 }
4375
4376 TemplateArgumentLocContainerIterator operator++(int) {
4377 TemplateArgumentLocContainerIterator Old(*this);
4378 ++(*this);
4379 return Old;
4380 }
4381
4382 TemplateArgumentLoc operator*() const {
4383 return Container->getArgLoc(Index);
4384 }
4385
4386 pointer operator->() const {
4387 return pointer(Container->getArgLoc(Index));
4388 }
4389
4390 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004391 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004392 return X.Container == Y.Container && X.Index == Y.Index;
4393 }
4394
4395 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004396 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004397 return !(X == Y);
4398 }
4399 };
4400}
4401
4402
John McCall43fed0d2010-11-12 08:19:04 +00004403template <typename Derived>
4404QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4405 TypeLocBuilder &TLB,
4406 TemplateSpecializationTypeLoc TL,
4407 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004408 TemplateArgumentListInfo NewTemplateArgs;
4409 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4410 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004411 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4412 ArgIterator;
4413 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4414 ArgIterator(TL, TL.getNumArgs()),
4415 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004416 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004417
John McCall833ca992009-10-29 08:12:44 +00004418 // FIXME: maybe don't rebuild if all the template arguments are the same.
4419
4420 QualType Result =
4421 getDerived().RebuildTemplateSpecializationType(Template,
4422 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004423 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004424
4425 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004426 // Specializations of template template parameters are represented as
4427 // TemplateSpecializationTypes, and substitution of type alias templates
4428 // within a dependent context can transform them into
4429 // DependentTemplateSpecializationTypes.
4430 if (isa<DependentTemplateSpecializationType>(Result)) {
4431 DependentTemplateSpecializationTypeLoc NewTL
4432 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4433 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4434 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4435 NewTL.setNameLoc(TL.getTemplateNameLoc());
4436 NewTL.setLAngleLoc(TL.getLAngleLoc());
4437 NewTL.setRAngleLoc(TL.getRAngleLoc());
4438 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4439 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4440 return Result;
4441 }
4442
John McCall833ca992009-10-29 08:12:44 +00004443 TemplateSpecializationTypeLoc NewTL
4444 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4445 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4446 NewTL.setLAngleLoc(TL.getLAngleLoc());
4447 NewTL.setRAngleLoc(TL.getRAngleLoc());
4448 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4449 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004450 }
Mike Stump1eb44332009-09-09 15:08:12 +00004451
John McCall833ca992009-10-29 08:12:44 +00004452 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004453}
Mike Stump1eb44332009-09-09 15:08:12 +00004454
Douglas Gregora88f09f2011-02-28 17:23:35 +00004455template <typename Derived>
4456QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4457 TypeLocBuilder &TLB,
4458 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004459 TemplateName Template,
4460 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004461 TemplateArgumentListInfo NewTemplateArgs;
4462 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4463 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4464 typedef TemplateArgumentLocContainerIterator<
4465 DependentTemplateSpecializationTypeLoc> ArgIterator;
4466 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4467 ArgIterator(TL, TL.getNumArgs()),
4468 NewTemplateArgs))
4469 return QualType();
4470
4471 // FIXME: maybe don't rebuild if all the template arguments are the same.
4472
4473 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4474 QualType Result
4475 = getSema().Context.getDependentTemplateSpecializationType(
4476 TL.getTypePtr()->getKeyword(),
4477 DTN->getQualifier(),
4478 DTN->getIdentifier(),
4479 NewTemplateArgs);
4480
4481 DependentTemplateSpecializationTypeLoc NewTL
4482 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4483 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004484
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004485 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004486 NewTL.setNameLoc(TL.getNameLoc());
4487 NewTL.setLAngleLoc(TL.getLAngleLoc());
4488 NewTL.setRAngleLoc(TL.getRAngleLoc());
4489 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4490 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4491 return Result;
4492 }
4493
4494 QualType Result
4495 = getDerived().RebuildTemplateSpecializationType(Template,
4496 TL.getNameLoc(),
4497 NewTemplateArgs);
4498
4499 if (!Result.isNull()) {
4500 /// FIXME: Wrap this in an elaborated-type-specifier?
4501 TemplateSpecializationTypeLoc NewTL
4502 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4503 NewTL.setTemplateNameLoc(TL.getNameLoc());
4504 NewTL.setLAngleLoc(TL.getLAngleLoc());
4505 NewTL.setRAngleLoc(TL.getRAngleLoc());
4506 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4507 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4508 }
4509
4510 return Result;
4511}
4512
Mike Stump1eb44332009-09-09 15:08:12 +00004513template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004514QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004515TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004516 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004517 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004518
Douglas Gregor9e876872011-03-01 18:12:44 +00004519 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004520 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004521 if (TL.getQualifierLoc()) {
4522 QualifierLoc
4523 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4524 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004525 return QualType();
4526 }
Mike Stump1eb44332009-09-09 15:08:12 +00004527
John McCall43fed0d2010-11-12 08:19:04 +00004528 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4529 if (NamedT.isNull())
4530 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004531
Richard Smith3e4c6c42011-05-05 21:57:07 +00004532 // C++0x [dcl.type.elab]p2:
4533 // If the identifier resolves to a typedef-name or the simple-template-id
4534 // resolves to an alias template specialization, the
4535 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004536 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4537 if (const TemplateSpecializationType *TST =
4538 NamedT->getAs<TemplateSpecializationType>()) {
4539 TemplateName Template = TST->getTemplateName();
4540 if (TypeAliasTemplateDecl *TAT =
4541 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4542 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4543 diag::err_tag_reference_non_tag) << 4;
4544 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4545 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004546 }
4547 }
4548
John McCalla2becad2009-10-21 00:40:46 +00004549 QualType Result = TL.getType();
4550 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004551 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004552 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004553 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004554 T->getKeyword(),
4555 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004556 if (Result.isNull())
4557 return QualType();
4558 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004559
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004560 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004561 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004562 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004563 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004564}
Mike Stump1eb44332009-09-09 15:08:12 +00004565
4566template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004567QualType TreeTransform<Derived>::TransformAttributedType(
4568 TypeLocBuilder &TLB,
4569 AttributedTypeLoc TL) {
4570 const AttributedType *oldType = TL.getTypePtr();
4571 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4572 if (modifiedType.isNull())
4573 return QualType();
4574
4575 QualType result = TL.getType();
4576
4577 // FIXME: dependent operand expressions?
4578 if (getDerived().AlwaysRebuild() ||
4579 modifiedType != oldType->getModifiedType()) {
4580 // TODO: this is really lame; we should really be rebuilding the
4581 // equivalent type from first principles.
4582 QualType equivalentType
4583 = getDerived().TransformType(oldType->getEquivalentType());
4584 if (equivalentType.isNull())
4585 return QualType();
4586 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4587 modifiedType,
4588 equivalentType);
4589 }
4590
4591 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4592 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4593 if (TL.hasAttrOperand())
4594 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4595 if (TL.hasAttrExprOperand())
4596 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4597 else if (TL.hasAttrEnumOperand())
4598 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4599
4600 return result;
4601}
4602
4603template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004604QualType
4605TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4606 ParenTypeLoc TL) {
4607 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4608 if (Inner.isNull())
4609 return QualType();
4610
4611 QualType Result = TL.getType();
4612 if (getDerived().AlwaysRebuild() ||
4613 Inner != TL.getInnerLoc().getType()) {
4614 Result = getDerived().RebuildParenType(Inner);
4615 if (Result.isNull())
4616 return QualType();
4617 }
4618
4619 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4620 NewTL.setLParenLoc(TL.getLParenLoc());
4621 NewTL.setRParenLoc(TL.getRParenLoc());
4622 return Result;
4623}
4624
4625template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004626QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004627 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004628 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004629
Douglas Gregor2494dd02011-03-01 01:34:45 +00004630 NestedNameSpecifierLoc QualifierLoc
4631 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4632 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004633 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004634
John McCall33500952010-06-11 00:33:02 +00004635 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004636 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004637 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004638 QualifierLoc,
4639 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004640 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004641 if (Result.isNull())
4642 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004643
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004644 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4645 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004646 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4647
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004648 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4649 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004650 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004651 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004652 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4653 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004654 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004655 NewTL.setNameLoc(TL.getNameLoc());
4656 }
John McCalla2becad2009-10-21 00:40:46 +00004657 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004658}
Mike Stump1eb44332009-09-09 15:08:12 +00004659
Douglas Gregor577f75a2009-08-04 16:50:30 +00004660template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004661QualType TreeTransform<Derived>::
4662 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004663 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004664 NestedNameSpecifierLoc QualifierLoc;
4665 if (TL.getQualifierLoc()) {
4666 QualifierLoc
4667 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4668 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004669 return QualType();
4670 }
4671
John McCall43fed0d2010-11-12 08:19:04 +00004672 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004673 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004674}
4675
4676template<typename Derived>
4677QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004678TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4679 DependentTemplateSpecializationTypeLoc TL,
4680 NestedNameSpecifierLoc QualifierLoc) {
4681 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4682
4683 TemplateArgumentListInfo NewTemplateArgs;
4684 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4685 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4686
4687 typedef TemplateArgumentLocContainerIterator<
4688 DependentTemplateSpecializationTypeLoc> ArgIterator;
4689 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4690 ArgIterator(TL, TL.getNumArgs()),
4691 NewTemplateArgs))
4692 return QualType();
4693
4694 QualType Result
4695 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4696 QualifierLoc,
4697 T->getIdentifier(),
4698 TL.getNameLoc(),
4699 NewTemplateArgs);
4700 if (Result.isNull())
4701 return QualType();
4702
4703 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4704 QualType NamedT = ElabT->getNamedType();
4705
4706 // Copy information relevant to the template specialization.
4707 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004708 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004709 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004710 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4711 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004712 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004713 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004714
4715 // Copy information relevant to the elaborated type.
4716 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4717 NewTL.setKeywordLoc(TL.getKeywordLoc());
4718 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004719 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4720 DependentTemplateSpecializationTypeLoc SpecTL
4721 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004722 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004723 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004724 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004725 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4726 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004727 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004728 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004729 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004730 TemplateSpecializationTypeLoc SpecTL
4731 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004732 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004733 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4734 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004735 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004736 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004737 }
4738 return Result;
4739}
4740
4741template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004742QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4743 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004744 QualType Pattern
4745 = getDerived().TransformType(TLB, TL.getPatternLoc());
4746 if (Pattern.isNull())
4747 return QualType();
4748
4749 QualType Result = TL.getType();
4750 if (getDerived().AlwaysRebuild() ||
4751 Pattern != TL.getPatternLoc().getType()) {
4752 Result = getDerived().RebuildPackExpansionType(Pattern,
4753 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004754 TL.getEllipsisLoc(),
4755 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004756 if (Result.isNull())
4757 return QualType();
4758 }
4759
4760 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4761 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4762 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004763}
4764
4765template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004766QualType
4767TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004768 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004769 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004770 TLB.pushFullCopy(TL);
4771 return TL.getType();
4772}
4773
4774template<typename Derived>
4775QualType
4776TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004777 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004778 // ObjCObjectType is never dependent.
4779 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004780 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004781}
Mike Stump1eb44332009-09-09 15:08:12 +00004782
4783template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004784QualType
4785TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004786 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004787 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004788 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004789 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004790}
4791
Douglas Gregor577f75a2009-08-04 16:50:30 +00004792//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004793// Statement transformation
4794//===----------------------------------------------------------------------===//
4795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004796StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004797TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004798 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004799}
4800
4801template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004802StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004803TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4804 return getDerived().TransformCompoundStmt(S, false);
4805}
4806
4807template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004808StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004809TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004810 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004811 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004812 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004813 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004814 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4815 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004816 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004817 if (Result.isInvalid()) {
4818 // Immediately fail if this was a DeclStmt, since it's very
4819 // likely that this will cause problems for future statements.
4820 if (isa<DeclStmt>(*B))
4821 return StmtError();
4822
4823 // Otherwise, just keep processing substatements and fail later.
4824 SubStmtInvalid = true;
4825 continue;
4826 }
Mike Stump1eb44332009-09-09 15:08:12 +00004827
Douglas Gregor43959a92009-08-20 07:17:43 +00004828 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4829 Statements.push_back(Result.takeAs<Stmt>());
4830 }
Mike Stump1eb44332009-09-09 15:08:12 +00004831
John McCall7114cba2010-08-27 19:56:05 +00004832 if (SubStmtInvalid)
4833 return StmtError();
4834
Douglas Gregor43959a92009-08-20 07:17:43 +00004835 if (!getDerived().AlwaysRebuild() &&
4836 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004837 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004838
4839 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4840 move_arg(Statements),
4841 S->getRBracLoc(),
4842 IsStmtExpr);
4843}
Mike Stump1eb44332009-09-09 15:08:12 +00004844
Douglas Gregor43959a92009-08-20 07:17:43 +00004845template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004846StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004847TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004848 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004849 {
4850 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004851 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004852
Eli Friedman264c1f82009-11-19 03:14:00 +00004853 // Transform the left-hand case value.
4854 LHS = getDerived().TransformExpr(S->getLHS());
4855 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004856 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004857
Eli Friedman264c1f82009-11-19 03:14:00 +00004858 // Transform the right-hand case value (for the GNU case-range extension).
4859 RHS = getDerived().TransformExpr(S->getRHS());
4860 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004861 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004862 }
Mike Stump1eb44332009-09-09 15:08:12 +00004863
Douglas Gregor43959a92009-08-20 07:17:43 +00004864 // Build the case statement.
4865 // Case statements are always rebuilt so that they will attached to their
4866 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004867 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004868 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004869 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004870 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004871 S->getColonLoc());
4872 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004873 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004874
Douglas Gregor43959a92009-08-20 07:17:43 +00004875 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004876 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004877 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004878 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004879
Douglas Gregor43959a92009-08-20 07:17:43 +00004880 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004881 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004882}
4883
4884template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004885StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004886TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004887 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004888 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004889 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004890 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004891
Douglas Gregor43959a92009-08-20 07:17:43 +00004892 // Default statements are always rebuilt
4893 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004894 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004895}
Mike Stump1eb44332009-09-09 15:08:12 +00004896
Douglas Gregor43959a92009-08-20 07:17:43 +00004897template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004898StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004899TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004900 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004901 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004902 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004903
Chris Lattner57ad3782011-02-17 20:34:02 +00004904 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4905 S->getDecl());
4906 if (!LD)
4907 return StmtError();
4908
4909
Douglas Gregor43959a92009-08-20 07:17:43 +00004910 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00004911 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00004912 cast<LabelDecl>(LD), SourceLocation(),
4913 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004914}
Mike Stump1eb44332009-09-09 15:08:12 +00004915
Douglas Gregor43959a92009-08-20 07:17:43 +00004916template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004917StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004918TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004919 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004920 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004921 VarDecl *ConditionVar = 0;
4922 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004923 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004924 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004925 getDerived().TransformDefinition(
4926 S->getConditionVariable()->getLocation(),
4927 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004928 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004929 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004930 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004931 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004932
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004933 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004934 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004935
4936 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004937 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004938 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4939 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004940 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004941 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004942
John McCall9ae2f072010-08-23 23:25:46 +00004943 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004944 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004945 }
Sean Huntc3021132010-05-05 15:23:54 +00004946
John McCall9ae2f072010-08-23 23:25:46 +00004947 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4948 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004949 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004950
Douglas Gregor43959a92009-08-20 07:17:43 +00004951 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004952 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004953 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004954 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004955
Douglas Gregor43959a92009-08-20 07:17:43 +00004956 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004957 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004958 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004959 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004960
Douglas Gregor43959a92009-08-20 07:17:43 +00004961 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004962 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004963 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004964 Then.get() == S->getThen() &&
4965 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004966 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004967
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004968 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004969 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004970 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004971}
4972
4973template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004974StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004975TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004976 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004977 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004978 VarDecl *ConditionVar = 0;
4979 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004980 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004981 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004982 getDerived().TransformDefinition(
4983 S->getConditionVariable()->getLocation(),
4984 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004985 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004986 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004987 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004988 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004989
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004990 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004991 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004992 }
Mike Stump1eb44332009-09-09 15:08:12 +00004993
Douglas Gregor43959a92009-08-20 07:17:43 +00004994 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004995 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004996 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004997 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004998 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004999 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005000
Douglas Gregor43959a92009-08-20 07:17:43 +00005001 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005002 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005003 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005004 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005005
Douglas Gregor43959a92009-08-20 07:17:43 +00005006 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005007 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5008 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005009}
Mike Stump1eb44332009-09-09 15:08:12 +00005010
Douglas Gregor43959a92009-08-20 07:17:43 +00005011template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005012StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005013TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005014 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005015 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005016 VarDecl *ConditionVar = 0;
5017 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005018 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005019 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005020 getDerived().TransformDefinition(
5021 S->getConditionVariable()->getLocation(),
5022 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005023 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005024 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005025 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005026 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005027
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005028 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005029 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005030
5031 if (S->getCond()) {
5032 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005033 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5034 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005035 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005036 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005037 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005038 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005039 }
Mike Stump1eb44332009-09-09 15:08:12 +00005040
John McCall9ae2f072010-08-23 23:25:46 +00005041 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5042 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005043 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005044
Douglas Gregor43959a92009-08-20 07:17:43 +00005045 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005046 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005047 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005048 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005049
Douglas Gregor43959a92009-08-20 07:17:43 +00005050 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005051 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005052 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005053 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005054 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005055
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005056 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005057 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005058}
Mike Stump1eb44332009-09-09 15:08:12 +00005059
Douglas Gregor43959a92009-08-20 07:17:43 +00005060template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005061StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005062TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005063 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005064 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005065 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005066 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005067
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005068 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005069 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005070 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005071 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005072
Douglas Gregor43959a92009-08-20 07:17:43 +00005073 if (!getDerived().AlwaysRebuild() &&
5074 Cond.get() == S->getCond() &&
5075 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005076 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005077
John McCall9ae2f072010-08-23 23:25:46 +00005078 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5079 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005080 S->getRParenLoc());
5081}
Mike Stump1eb44332009-09-09 15:08:12 +00005082
Douglas Gregor43959a92009-08-20 07:17:43 +00005083template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005084StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005085TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005086 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005087 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005088 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005089 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005090
Douglas Gregor43959a92009-08-20 07:17:43 +00005091 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005092 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005093 VarDecl *ConditionVar = 0;
5094 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005095 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005096 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005097 getDerived().TransformDefinition(
5098 S->getConditionVariable()->getLocation(),
5099 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005100 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005101 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005102 } else {
5103 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005104
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005105 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005106 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005107
5108 if (S->getCond()) {
5109 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005110 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5111 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005112 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005113 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005114
John McCall9ae2f072010-08-23 23:25:46 +00005115 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005116 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005117 }
Mike Stump1eb44332009-09-09 15:08:12 +00005118
John McCall9ae2f072010-08-23 23:25:46 +00005119 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5120 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005121 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005122
Douglas Gregor43959a92009-08-20 07:17:43 +00005123 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005124 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005126 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005127
John McCall9ae2f072010-08-23 23:25:46 +00005128 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5129 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005130 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005131
Douglas Gregor43959a92009-08-20 07:17:43 +00005132 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005133 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005134 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005135 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005136
Douglas Gregor43959a92009-08-20 07:17:43 +00005137 if (!getDerived().AlwaysRebuild() &&
5138 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005139 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005140 Inc.get() == S->getInc() &&
5141 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005142 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005143
Douglas Gregor43959a92009-08-20 07:17:43 +00005144 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005145 Init.get(), FullCond, ConditionVar,
5146 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005147}
5148
5149template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005150StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005151TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005152 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5153 S->getLabel());
5154 if (!LD)
5155 return StmtError();
5156
Douglas Gregor43959a92009-08-20 07:17:43 +00005157 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005158 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005159 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005160}
5161
5162template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005163StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005164TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005165 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005166 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005167 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005168
Douglas Gregor43959a92009-08-20 07:17:43 +00005169 if (!getDerived().AlwaysRebuild() &&
5170 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005171 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005172
5173 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005174 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005175}
5176
5177template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005178StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005179TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005180 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005181}
Mike Stump1eb44332009-09-09 15:08:12 +00005182
Douglas Gregor43959a92009-08-20 07:17:43 +00005183template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005184StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005185TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005186 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005187}
Mike Stump1eb44332009-09-09 15:08:12 +00005188
Douglas Gregor43959a92009-08-20 07:17:43 +00005189template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005190StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005191TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005192 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005193 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005194 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005195
Mike Stump1eb44332009-09-09 15:08:12 +00005196 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005197 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005198 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005199}
Mike Stump1eb44332009-09-09 15:08:12 +00005200
Douglas Gregor43959a92009-08-20 07:17:43 +00005201template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005202StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005203TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005204 bool DeclChanged = false;
5205 llvm::SmallVector<Decl *, 4> Decls;
5206 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5207 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005208 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5209 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005210 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005211 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005212
Douglas Gregor43959a92009-08-20 07:17:43 +00005213 if (Transformed != *D)
5214 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005215
Douglas Gregor43959a92009-08-20 07:17:43 +00005216 Decls.push_back(Transformed);
5217 }
Mike Stump1eb44332009-09-09 15:08:12 +00005218
Douglas Gregor43959a92009-08-20 07:17:43 +00005219 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005220 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005221
5222 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005223 S->getStartLoc(), S->getEndLoc());
5224}
Mike Stump1eb44332009-09-09 15:08:12 +00005225
Douglas Gregor43959a92009-08-20 07:17:43 +00005226template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005227StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005228TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005229
John McCallca0408f2010-08-23 06:44:23 +00005230 ASTOwningVector<Expr*> Constraints(getSema());
5231 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005232 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005233
John McCall60d7b3a2010-08-24 06:29:42 +00005234 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005235 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005236
5237 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005238
Anders Carlsson703e3942010-01-24 05:50:09 +00005239 // Go through the outputs.
5240 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005241 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005242
Anders Carlsson703e3942010-01-24 05:50:09 +00005243 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005244 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005245
Anders Carlsson703e3942010-01-24 05:50:09 +00005246 // Transform the output expr.
5247 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005248 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005249 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005250 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005251
Anders Carlsson703e3942010-01-24 05:50:09 +00005252 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005253
John McCall9ae2f072010-08-23 23:25:46 +00005254 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005255 }
Sean Huntc3021132010-05-05 15:23:54 +00005256
Anders Carlsson703e3942010-01-24 05:50:09 +00005257 // Go through the inputs.
5258 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005259 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005260
Anders Carlsson703e3942010-01-24 05:50:09 +00005261 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005262 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005263
Anders Carlsson703e3942010-01-24 05:50:09 +00005264 // Transform the input expr.
5265 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005266 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005267 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005268 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005269
Anders Carlsson703e3942010-01-24 05:50:09 +00005270 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005271
John McCall9ae2f072010-08-23 23:25:46 +00005272 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005273 }
Sean Huntc3021132010-05-05 15:23:54 +00005274
Anders Carlsson703e3942010-01-24 05:50:09 +00005275 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005276 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005277
5278 // Go through the clobbers.
5279 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005280 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005281
5282 // No need to transform the asm string literal.
5283 AsmString = SemaRef.Owned(S->getAsmString());
5284
5285 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5286 S->isSimple(),
5287 S->isVolatile(),
5288 S->getNumOutputs(),
5289 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005290 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005291 move_arg(Constraints),
5292 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005293 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005294 move_arg(Clobbers),
5295 S->getRParenLoc(),
5296 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005297}
5298
5299
5300template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005301StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005302TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005303 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005304 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005305 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005306 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005307
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005308 // Transform the @catch statements (if present).
5309 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005310 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005311 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005312 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005313 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005314 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005315 if (Catch.get() != S->getCatchStmt(I))
5316 AnyCatchChanged = true;
5317 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005318 }
Sean Huntc3021132010-05-05 15:23:54 +00005319
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005320 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005321 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005322 if (S->getFinallyStmt()) {
5323 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5324 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005325 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005326 }
5327
5328 // If nothing changed, just retain this statement.
5329 if (!getDerived().AlwaysRebuild() &&
5330 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005331 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005332 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005333 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005334
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005335 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005336 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5337 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005338}
Mike Stump1eb44332009-09-09 15:08:12 +00005339
Douglas Gregor43959a92009-08-20 07:17:43 +00005340template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005341StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005342TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005343 // Transform the @catch parameter, if there is one.
5344 VarDecl *Var = 0;
5345 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5346 TypeSourceInfo *TSInfo = 0;
5347 if (FromVar->getTypeSourceInfo()) {
5348 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5349 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005350 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005351 }
Sean Huntc3021132010-05-05 15:23:54 +00005352
Douglas Gregorbe270a02010-04-26 17:57:08 +00005353 QualType T;
5354 if (TSInfo)
5355 T = TSInfo->getType();
5356 else {
5357 T = getDerived().TransformType(FromVar->getType());
5358 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005359 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005360 }
Sean Huntc3021132010-05-05 15:23:54 +00005361
Douglas Gregorbe270a02010-04-26 17:57:08 +00005362 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5363 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005364 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005365 }
Sean Huntc3021132010-05-05 15:23:54 +00005366
John McCall60d7b3a2010-08-24 06:29:42 +00005367 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005368 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005369 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005370
5371 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005372 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005373 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005374}
Mike Stump1eb44332009-09-09 15:08:12 +00005375
Douglas Gregor43959a92009-08-20 07:17:43 +00005376template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005377StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005378TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005379 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005380 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005381 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005382 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005383
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005384 // If nothing changed, just retain this statement.
5385 if (!getDerived().AlwaysRebuild() &&
5386 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005387 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005388
5389 // Build a new statement.
5390 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005391 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005392}
Mike Stump1eb44332009-09-09 15:08:12 +00005393
Douglas Gregor43959a92009-08-20 07:17:43 +00005394template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005395StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005396TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005397 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005398 if (S->getThrowExpr()) {
5399 Operand = getDerived().TransformExpr(S->getThrowExpr());
5400 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005401 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005402 }
Sean Huntc3021132010-05-05 15:23:54 +00005403
Douglas Gregord1377b22010-04-22 21:44:01 +00005404 if (!getDerived().AlwaysRebuild() &&
5405 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005406 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005407
John McCall9ae2f072010-08-23 23:25:46 +00005408 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005409}
Mike Stump1eb44332009-09-09 15:08:12 +00005410
Douglas Gregor43959a92009-08-20 07:17:43 +00005411template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005412StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005413TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005414 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005415 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005416 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005417 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005418 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005419
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005420 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005421 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005422 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005423 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005424
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005425 // If nothing change, just retain the current statement.
5426 if (!getDerived().AlwaysRebuild() &&
5427 Object.get() == S->getSynchExpr() &&
5428 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005429 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005430
5431 // Build a new statement.
5432 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005433 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005434}
5435
5436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005437StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005438TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005439 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005440 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005441 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005442 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005443 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005444
Douglas Gregorc3203e72010-04-22 23:10:45 +00005445 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005446 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005447 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005448 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005449
Douglas Gregorc3203e72010-04-22 23:10:45 +00005450 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005451 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005452 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005453 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005454
Douglas Gregorc3203e72010-04-22 23:10:45 +00005455 // If nothing changed, just retain this statement.
5456 if (!getDerived().AlwaysRebuild() &&
5457 Element.get() == S->getElement() &&
5458 Collection.get() == S->getCollection() &&
5459 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005460 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005461
Douglas Gregorc3203e72010-04-22 23:10:45 +00005462 // Build a new statement.
5463 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5464 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005465 Element.get(),
5466 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005467 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005468 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005469}
5470
5471
5472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005473StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005474TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5475 // Transform the exception declaration, if any.
5476 VarDecl *Var = 0;
5477 if (S->getExceptionDecl()) {
5478 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005479 TypeSourceInfo *T = getDerived().TransformType(
5480 ExceptionDecl->getTypeSourceInfo());
5481 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005482 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005483
Douglas Gregor83cb9422010-09-09 17:09:21 +00005484 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005485 ExceptionDecl->getInnerLocStart(),
5486 ExceptionDecl->getLocation(),
5487 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005488 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005489 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005490 }
Mike Stump1eb44332009-09-09 15:08:12 +00005491
Douglas Gregor43959a92009-08-20 07:17:43 +00005492 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005493 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005494 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005495 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005496
Douglas Gregor43959a92009-08-20 07:17:43 +00005497 if (!getDerived().AlwaysRebuild() &&
5498 !Var &&
5499 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005500 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005501
5502 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5503 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005504 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005505}
Mike Stump1eb44332009-09-09 15:08:12 +00005506
Douglas Gregor43959a92009-08-20 07:17:43 +00005507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005508StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005509TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5510 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005511 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005512 = getDerived().TransformCompoundStmt(S->getTryBlock());
5513 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005514 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005515
Douglas Gregor43959a92009-08-20 07:17:43 +00005516 // Transform the handlers.
5517 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005518 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005519 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005520 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005521 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5522 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005523 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005524
Douglas Gregor43959a92009-08-20 07:17:43 +00005525 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5526 Handlers.push_back(Handler.takeAs<Stmt>());
5527 }
Mike Stump1eb44332009-09-09 15:08:12 +00005528
Douglas Gregor43959a92009-08-20 07:17:43 +00005529 if (!getDerived().AlwaysRebuild() &&
5530 TryBlock.get() == S->getTryBlock() &&
5531 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005532 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005533
John McCall9ae2f072010-08-23 23:25:46 +00005534 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005535 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005536}
Mike Stump1eb44332009-09-09 15:08:12 +00005537
Richard Smithad762fc2011-04-14 22:09:26 +00005538template<typename Derived>
5539StmtResult
5540TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5541 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5542 if (Range.isInvalid())
5543 return StmtError();
5544
5545 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5546 if (BeginEnd.isInvalid())
5547 return StmtError();
5548
5549 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5550 if (Cond.isInvalid())
5551 return StmtError();
5552
5553 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5554 if (Inc.isInvalid())
5555 return StmtError();
5556
5557 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5558 if (LoopVar.isInvalid())
5559 return StmtError();
5560
5561 StmtResult NewStmt = S;
5562 if (getDerived().AlwaysRebuild() ||
5563 Range.get() != S->getRangeStmt() ||
5564 BeginEnd.get() != S->getBeginEndStmt() ||
5565 Cond.get() != S->getCond() ||
5566 Inc.get() != S->getInc() ||
5567 LoopVar.get() != S->getLoopVarStmt())
5568 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5569 S->getColonLoc(), Range.get(),
5570 BeginEnd.get(), Cond.get(),
5571 Inc.get(), LoopVar.get(),
5572 S->getRParenLoc());
5573
5574 StmtResult Body = getDerived().TransformStmt(S->getBody());
5575 if (Body.isInvalid())
5576 return StmtError();
5577
5578 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5579 // it now so we have a new statement to attach the body to.
5580 if (Body.get() != S->getBody() && NewStmt.get() == S)
5581 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5582 S->getColonLoc(), Range.get(),
5583 BeginEnd.get(), Cond.get(),
5584 Inc.get(), LoopVar.get(),
5585 S->getRParenLoc());
5586
5587 if (NewStmt.get() == S)
5588 return SemaRef.Owned(S);
5589
5590 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5591}
5592
John Wiegley28bbe4b2011-04-28 01:08:34 +00005593template<typename Derived>
5594StmtResult
5595TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5596 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5597 if(TryBlock.isInvalid()) return StmtError();
5598
5599 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5600 if(!getDerived().AlwaysRebuild() &&
5601 TryBlock.get() == S->getTryBlock() &&
5602 Handler.get() == S->getHandler())
5603 return SemaRef.Owned(S);
5604
5605 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5606 S->getTryLoc(),
5607 TryBlock.take(),
5608 Handler.take());
5609}
5610
5611template<typename Derived>
5612StmtResult
5613TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5614 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5615 if(Block.isInvalid()) return StmtError();
5616
5617 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5618 Block.take());
5619}
5620
5621template<typename Derived>
5622StmtResult
5623TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5624 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5625 if(FilterExpr.isInvalid()) return StmtError();
5626
5627 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5628 if(Block.isInvalid()) return StmtError();
5629
5630 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5631 FilterExpr.take(),
5632 Block.take());
5633}
5634
5635template<typename Derived>
5636StmtResult
5637TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5638 if(isa<SEHFinallyStmt>(Handler))
5639 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5640 else
5641 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5642}
5643
Douglas Gregor43959a92009-08-20 07:17:43 +00005644//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005645// Expression transformation
5646//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005647template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005648ExprResult
John McCall454feb92009-12-08 09:21:05 +00005649TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005650 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005651}
Mike Stump1eb44332009-09-09 15:08:12 +00005652
5653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005654ExprResult
John McCall454feb92009-12-08 09:21:05 +00005655TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005656 NestedNameSpecifierLoc QualifierLoc;
5657 if (E->getQualifierLoc()) {
5658 QualifierLoc
5659 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5660 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005661 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005662 }
John McCalldbd872f2009-12-08 09:08:17 +00005663
5664 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005665 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5666 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005667 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005668 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005669
John McCallec8045d2010-08-17 21:27:17 +00005670 DeclarationNameInfo NameInfo = E->getNameInfo();
5671 if (NameInfo.getName()) {
5672 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5673 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005674 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005675 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005676
5677 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005678 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005679 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005680 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005681 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005682
5683 // Mark it referenced in the new context regardless.
5684 // FIXME: this is a bit instantiation-specific.
5685 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5686
John McCall3fa5cae2010-10-26 07:05:15 +00005687 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005688 }
John McCalldbd872f2009-12-08 09:08:17 +00005689
5690 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005691 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005692 TemplateArgs = &TransArgs;
5693 TransArgs.setLAngleLoc(E->getLAngleLoc());
5694 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005695 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5696 E->getNumTemplateArgs(),
5697 TransArgs))
5698 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005699 }
5700
Douglas Gregor40d96a62011-02-28 21:54:11 +00005701 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5702 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005703}
Mike Stump1eb44332009-09-09 15:08:12 +00005704
Douglas Gregorb98b1992009-08-11 05:31:07 +00005705template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005706ExprResult
John McCall454feb92009-12-08 09:21:05 +00005707TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005708 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005709}
Mike Stump1eb44332009-09-09 15:08:12 +00005710
Douglas Gregorb98b1992009-08-11 05:31:07 +00005711template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005712ExprResult
John McCall454feb92009-12-08 09:21:05 +00005713TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005714 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005715}
Mike Stump1eb44332009-09-09 15:08:12 +00005716
Douglas Gregorb98b1992009-08-11 05:31:07 +00005717template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005718ExprResult
John McCall454feb92009-12-08 09:21:05 +00005719TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005720 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005721}
Mike Stump1eb44332009-09-09 15:08:12 +00005722
Douglas Gregorb98b1992009-08-11 05:31:07 +00005723template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005724ExprResult
John McCall454feb92009-12-08 09:21:05 +00005725TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005726 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005727}
Mike Stump1eb44332009-09-09 15:08:12 +00005728
Douglas Gregorb98b1992009-08-11 05:31:07 +00005729template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005730ExprResult
John McCall454feb92009-12-08 09:21:05 +00005731TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005732 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005733}
5734
5735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005736ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005737TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5738 ExprResult ControllingExpr =
5739 getDerived().TransformExpr(E->getControllingExpr());
5740 if (ControllingExpr.isInvalid())
5741 return ExprError();
5742
5743 llvm::SmallVector<Expr *, 4> AssocExprs;
5744 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5745 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5746 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5747 if (TS) {
5748 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5749 if (!AssocType)
5750 return ExprError();
5751 AssocTypes.push_back(AssocType);
5752 } else {
5753 AssocTypes.push_back(0);
5754 }
5755
5756 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5757 if (AssocExpr.isInvalid())
5758 return ExprError();
5759 AssocExprs.push_back(AssocExpr.release());
5760 }
5761
5762 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5763 E->getDefaultLoc(),
5764 E->getRParenLoc(),
5765 ControllingExpr.release(),
5766 AssocTypes.data(),
5767 AssocExprs.data(),
5768 E->getNumAssocs());
5769}
5770
5771template<typename Derived>
5772ExprResult
John McCall454feb92009-12-08 09:21:05 +00005773TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005774 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005775 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005776 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005777
Douglas Gregorb98b1992009-08-11 05:31:07 +00005778 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005779 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005780
John McCall9ae2f072010-08-23 23:25:46 +00005781 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005782 E->getRParen());
5783}
5784
Mike Stump1eb44332009-09-09 15:08:12 +00005785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005786ExprResult
John McCall454feb92009-12-08 09:21:05 +00005787TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005788 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005789 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005790 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005791
Douglas Gregorb98b1992009-08-11 05:31:07 +00005792 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005793 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005794
Douglas Gregorb98b1992009-08-11 05:31:07 +00005795 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5796 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005797 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005798}
Mike Stump1eb44332009-09-09 15:08:12 +00005799
Douglas Gregorb98b1992009-08-11 05:31:07 +00005800template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005801ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005802TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5803 // Transform the type.
5804 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5805 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005806 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005807
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005808 // Transform all of the components into components similar to what the
5809 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005810 // FIXME: It would be slightly more efficient in the non-dependent case to
5811 // just map FieldDecls, rather than requiring the rebuilder to look for
5812 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005813 // template code that we don't care.
5814 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005815 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005816 typedef OffsetOfExpr::OffsetOfNode Node;
5817 llvm::SmallVector<Component, 4> Components;
5818 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5819 const Node &ON = E->getComponent(I);
5820 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005821 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00005822 Comp.LocStart = ON.getSourceRange().getBegin();
5823 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005824 switch (ON.getKind()) {
5825 case Node::Array: {
5826 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005827 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005828 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005829 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005830
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005831 ExprChanged = ExprChanged || Index.get() != FromIndex;
5832 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005833 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005834 break;
5835 }
Sean Huntc3021132010-05-05 15:23:54 +00005836
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005837 case Node::Field:
5838 case Node::Identifier:
5839 Comp.isBrackets = false;
5840 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005841 if (!Comp.U.IdentInfo)
5842 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005843
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005844 break;
Sean Huntc3021132010-05-05 15:23:54 +00005845
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005846 case Node::Base:
5847 // Will be recomputed during the rebuild.
5848 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005849 }
Sean Huntc3021132010-05-05 15:23:54 +00005850
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005851 Components.push_back(Comp);
5852 }
Sean Huntc3021132010-05-05 15:23:54 +00005853
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005854 // If nothing changed, retain the existing expression.
5855 if (!getDerived().AlwaysRebuild() &&
5856 Type == E->getTypeSourceInfo() &&
5857 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005858 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005859
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005860 // Build a new offsetof expression.
5861 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5862 Components.data(), Components.size(),
5863 E->getRParenLoc());
5864}
5865
5866template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005867ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005868TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5869 assert(getDerived().AlreadyTransformed(E->getType()) &&
5870 "opaque value expression requires transformation");
5871 return SemaRef.Owned(E);
5872}
5873
5874template<typename Derived>
5875ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005876TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5877 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005878 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005879 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005880
John McCalla93c9342009-12-07 02:54:59 +00005881 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005882 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005883 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005884
John McCall5ab75172009-11-04 07:28:41 +00005885 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005886 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005887
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005888 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5889 E->getKind(),
5890 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005891 }
Mike Stump1eb44332009-09-09 15:08:12 +00005892
John McCall60d7b3a2010-08-24 06:29:42 +00005893 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005894 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005895 // C++0x [expr.sizeof]p1:
5896 // The operand is either an expression, which is an unevaluated operand
5897 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005898 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005899
Douglas Gregorb98b1992009-08-11 05:31:07 +00005900 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5901 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005902 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005903
Douglas Gregorb98b1992009-08-11 05:31:07 +00005904 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005905 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005906 }
Mike Stump1eb44332009-09-09 15:08:12 +00005907
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005908 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5909 E->getOperatorLoc(),
5910 E->getKind(),
5911 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005912}
Mike Stump1eb44332009-09-09 15:08:12 +00005913
Douglas Gregorb98b1992009-08-11 05:31:07 +00005914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005915ExprResult
John McCall454feb92009-12-08 09:21:05 +00005916TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005917 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005918 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005919 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005920
John McCall60d7b3a2010-08-24 06:29:42 +00005921 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005922 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005923 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005924
5925
Douglas Gregorb98b1992009-08-11 05:31:07 +00005926 if (!getDerived().AlwaysRebuild() &&
5927 LHS.get() == E->getLHS() &&
5928 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005929 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005930
John McCall9ae2f072010-08-23 23:25:46 +00005931 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005932 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005933 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005934 E->getRBracketLoc());
5935}
Mike Stump1eb44332009-09-09 15:08:12 +00005936
5937template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005938ExprResult
John McCall454feb92009-12-08 09:21:05 +00005939TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005940 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005941 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005942 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005943 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005944
5945 // Transform arguments.
5946 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005947 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005948 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5949 &ArgChanged))
5950 return ExprError();
5951
Douglas Gregorb98b1992009-08-11 05:31:07 +00005952 if (!getDerived().AlwaysRebuild() &&
5953 Callee.get() == E->getCallee() &&
5954 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005955 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005956
Douglas Gregorb98b1992009-08-11 05:31:07 +00005957 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005958 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005959 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005960 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005961 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005962 E->getRParenLoc());
5963}
Mike Stump1eb44332009-09-09 15:08:12 +00005964
5965template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005966ExprResult
John McCall454feb92009-12-08 09:21:05 +00005967TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005968 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005969 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005970 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005971
Douglas Gregor40d96a62011-02-28 21:54:11 +00005972 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005973 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005974 QualifierLoc
5975 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5976
5977 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005978 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005979 }
Mike Stump1eb44332009-09-09 15:08:12 +00005980
Eli Friedmanf595cc42009-12-04 06:40:45 +00005981 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005982 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5983 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005984 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005985 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005986
John McCall6bb80172010-03-30 21:47:33 +00005987 NamedDecl *FoundDecl = E->getFoundDecl();
5988 if (FoundDecl == E->getMemberDecl()) {
5989 FoundDecl = Member;
5990 } else {
5991 FoundDecl = cast_or_null<NamedDecl>(
5992 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5993 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005994 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005995 }
5996
Douglas Gregorb98b1992009-08-11 05:31:07 +00005997 if (!getDerived().AlwaysRebuild() &&
5998 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005999 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006000 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006001 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006002 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006003
Anders Carlsson1f240322009-12-22 05:24:09 +00006004 // Mark it referenced in the new context regardless.
6005 // FIXME: this is a bit instantiation-specific.
6006 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00006007 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006008 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006009
John McCalld5532b62009-11-23 01:53:49 +00006010 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006011 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006012 TransArgs.setLAngleLoc(E->getLAngleLoc());
6013 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006014 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6015 E->getNumTemplateArgs(),
6016 TransArgs))
6017 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006018 }
Sean Huntc3021132010-05-05 15:23:54 +00006019
Douglas Gregorb98b1992009-08-11 05:31:07 +00006020 // FIXME: Bogus source location for the operator
6021 SourceLocation FakeOperatorLoc
6022 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6023
John McCallc2233c52010-01-15 08:34:02 +00006024 // FIXME: to do this check properly, we will need to preserve the
6025 // first-qualifier-in-scope here, just in case we had a dependent
6026 // base (and therefore couldn't do the check) and a
6027 // nested-name-qualifier (and therefore could do the lookup).
6028 NamedDecl *FirstQualifierInScope = 0;
6029
John McCall9ae2f072010-08-23 23:25:46 +00006030 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006031 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006032 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006033 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006034 Member,
John McCall6bb80172010-03-30 21:47:33 +00006035 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006036 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006037 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006038 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006039}
Mike Stump1eb44332009-09-09 15:08:12 +00006040
Douglas Gregorb98b1992009-08-11 05:31:07 +00006041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006042ExprResult
John McCall454feb92009-12-08 09:21:05 +00006043TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006044 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006045 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006046 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006047
John McCall60d7b3a2010-08-24 06:29:42 +00006048 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006049 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006050 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006051
Douglas Gregorb98b1992009-08-11 05:31:07 +00006052 if (!getDerived().AlwaysRebuild() &&
6053 LHS.get() == E->getLHS() &&
6054 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006055 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006056
Douglas Gregorb98b1992009-08-11 05:31:07 +00006057 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006058 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059}
6060
Mike Stump1eb44332009-09-09 15:08:12 +00006061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006062ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006063TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006064 CompoundAssignOperator *E) {
6065 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006066}
Mike Stump1eb44332009-09-09 15:08:12 +00006067
Douglas Gregorb98b1992009-08-11 05:31:07 +00006068template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006069ExprResult TreeTransform<Derived>::
6070TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6071 // Just rebuild the common and RHS expressions and see whether we
6072 // get any changes.
6073
6074 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6075 if (commonExpr.isInvalid())
6076 return ExprError();
6077
6078 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6079 if (rhs.isInvalid())
6080 return ExprError();
6081
6082 if (!getDerived().AlwaysRebuild() &&
6083 commonExpr.get() == e->getCommon() &&
6084 rhs.get() == e->getFalseExpr())
6085 return SemaRef.Owned(e);
6086
6087 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6088 e->getQuestionLoc(),
6089 0,
6090 e->getColonLoc(),
6091 rhs.get());
6092}
6093
6094template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006095ExprResult
John McCall454feb92009-12-08 09:21:05 +00006096TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006097 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006098 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006099 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006100
John McCall60d7b3a2010-08-24 06:29:42 +00006101 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006102 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006103 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006104
John McCall60d7b3a2010-08-24 06:29:42 +00006105 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006106 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006107 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006108
Douglas Gregorb98b1992009-08-11 05:31:07 +00006109 if (!getDerived().AlwaysRebuild() &&
6110 Cond.get() == E->getCond() &&
6111 LHS.get() == E->getLHS() &&
6112 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006113 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006114
John McCall9ae2f072010-08-23 23:25:46 +00006115 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006116 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006117 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006118 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006119 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120}
Mike Stump1eb44332009-09-09 15:08:12 +00006121
6122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006123ExprResult
John McCall454feb92009-12-08 09:21:05 +00006124TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006125 // Implicit casts are eliminated during transformation, since they
6126 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006127 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006128}
Mike Stump1eb44332009-09-09 15:08:12 +00006129
Douglas Gregorb98b1992009-08-11 05:31:07 +00006130template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006131ExprResult
John McCall454feb92009-12-08 09:21:05 +00006132TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006133 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6134 if (!Type)
6135 return ExprError();
6136
John McCall60d7b3a2010-08-24 06:29:42 +00006137 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006138 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006140 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006141
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006143 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006145 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006146
John McCall9d125032010-01-15 18:39:57 +00006147 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006148 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006149 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006150 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006151}
Mike Stump1eb44332009-09-09 15:08:12 +00006152
Douglas Gregorb98b1992009-08-11 05:31:07 +00006153template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006154ExprResult
John McCall454feb92009-12-08 09:21:05 +00006155TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006156 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6157 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6158 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006159 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006160
John McCall60d7b3a2010-08-24 06:29:42 +00006161 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006162 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006163 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006164
Douglas Gregorb98b1992009-08-11 05:31:07 +00006165 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006166 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006167 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00006168 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006169
John McCall1d7d8d62010-01-19 22:33:45 +00006170 // Note: the expression type doesn't necessarily match the
6171 // type-as-written, but that's okay, because it should always be
6172 // derivable from the initializer.
6173
John McCall42f56b52010-01-18 19:35:47 +00006174 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006175 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006176 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006177}
Mike Stump1eb44332009-09-09 15:08:12 +00006178
Douglas Gregorb98b1992009-08-11 05:31:07 +00006179template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006180ExprResult
John McCall454feb92009-12-08 09:21:05 +00006181TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006182 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006183 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006184 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006185
Douglas Gregorb98b1992009-08-11 05:31:07 +00006186 if (!getDerived().AlwaysRebuild() &&
6187 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006188 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006189
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006191 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006192 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006193 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006194 E->getAccessorLoc(),
6195 E->getAccessor());
6196}
Mike Stump1eb44332009-09-09 15:08:12 +00006197
Douglas Gregorb98b1992009-08-11 05:31:07 +00006198template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006199ExprResult
John McCall454feb92009-12-08 09:21:05 +00006200TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006201 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006202
John McCallca0408f2010-08-23 06:44:23 +00006203 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006204 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6205 Inits, &InitChanged))
6206 return ExprError();
6207
Douglas Gregorb98b1992009-08-11 05:31:07 +00006208 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006209 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006210
Douglas Gregorb98b1992009-08-11 05:31:07 +00006211 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006212 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213}
Mike Stump1eb44332009-09-09 15:08:12 +00006214
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006216ExprResult
John McCall454feb92009-12-08 09:21:05 +00006217TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006218 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006219
Douglas Gregor43959a92009-08-20 07:17:43 +00006220 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006221 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006223 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006224
Douglas Gregor43959a92009-08-20 07:17:43 +00006225 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006226 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006227 bool ExprChanged = false;
6228 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6229 DEnd = E->designators_end();
6230 D != DEnd; ++D) {
6231 if (D->isFieldDesignator()) {
6232 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6233 D->getDotLoc(),
6234 D->getFieldLoc()));
6235 continue;
6236 }
Mike Stump1eb44332009-09-09 15:08:12 +00006237
Douglas Gregorb98b1992009-08-11 05:31:07 +00006238 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006239 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006241 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006242
6243 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006244 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006245
Douglas Gregorb98b1992009-08-11 05:31:07 +00006246 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6247 ArrayExprs.push_back(Index.release());
6248 continue;
6249 }
Mike Stump1eb44332009-09-09 15:08:12 +00006250
Douglas Gregorb98b1992009-08-11 05:31:07 +00006251 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006252 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006253 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6254 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006255 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006256
John McCall60d7b3a2010-08-24 06:29:42 +00006257 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006258 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006259 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006260
6261 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006262 End.get(),
6263 D->getLBracketLoc(),
6264 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006265
Douglas Gregorb98b1992009-08-11 05:31:07 +00006266 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6267 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006268
Douglas Gregorb98b1992009-08-11 05:31:07 +00006269 ArrayExprs.push_back(Start.release());
6270 ArrayExprs.push_back(End.release());
6271 }
Mike Stump1eb44332009-09-09 15:08:12 +00006272
Douglas Gregorb98b1992009-08-11 05:31:07 +00006273 if (!getDerived().AlwaysRebuild() &&
6274 Init.get() == E->getInit() &&
6275 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006276 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006277
Douglas Gregorb98b1992009-08-11 05:31:07 +00006278 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6279 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006280 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006281}
Mike Stump1eb44332009-09-09 15:08:12 +00006282
Douglas Gregorb98b1992009-08-11 05:31:07 +00006283template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006284ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006285TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006286 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006287 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006288
Douglas Gregor5557b252009-10-28 00:29:27 +00006289 // FIXME: Will we ever have proper type location here? Will we actually
6290 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006291 QualType T = getDerived().TransformType(E->getType());
6292 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006293 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006294
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295 if (!getDerived().AlwaysRebuild() &&
6296 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006297 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006298
Douglas Gregorb98b1992009-08-11 05:31:07 +00006299 return getDerived().RebuildImplicitValueInitExpr(T);
6300}
Mike Stump1eb44332009-09-09 15:08:12 +00006301
Douglas Gregorb98b1992009-08-11 05:31:07 +00006302template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006303ExprResult
John McCall454feb92009-12-08 09:21:05 +00006304TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006305 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6306 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006307 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006308
John McCall60d7b3a2010-08-24 06:29:42 +00006309 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006310 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006311 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006312
Douglas Gregorb98b1992009-08-11 05:31:07 +00006313 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006314 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006315 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006316 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006317
John McCall9ae2f072010-08-23 23:25:46 +00006318 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006319 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006320}
6321
6322template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006323ExprResult
John McCall454feb92009-12-08 09:21:05 +00006324TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006325 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006326 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006327 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6328 &ArgumentChanged))
6329 return ExprError();
6330
Douglas Gregorb98b1992009-08-11 05:31:07 +00006331 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6332 move_arg(Inits),
6333 E->getRParenLoc());
6334}
Mike Stump1eb44332009-09-09 15:08:12 +00006335
Douglas Gregorb98b1992009-08-11 05:31:07 +00006336/// \brief Transform an address-of-label expression.
6337///
6338/// By default, the transformation of an address-of-label expression always
6339/// rebuilds the expression, so that the label identifier can be resolved to
6340/// the corresponding label statement by semantic analysis.
6341template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006342ExprResult
John McCall454feb92009-12-08 09:21:05 +00006343TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006344 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6345 E->getLabel());
6346 if (!LD)
6347 return ExprError();
6348
Douglas Gregorb98b1992009-08-11 05:31:07 +00006349 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006350 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351}
Mike Stump1eb44332009-09-09 15:08:12 +00006352
6353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006354ExprResult
John McCall454feb92009-12-08 09:21:05 +00006355TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006356 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006357 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6358 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006359 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006360
Douglas Gregorb98b1992009-08-11 05:31:07 +00006361 if (!getDerived().AlwaysRebuild() &&
6362 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006363 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006364
6365 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006366 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006367 E->getRParenLoc());
6368}
Mike Stump1eb44332009-09-09 15:08:12 +00006369
Douglas Gregorb98b1992009-08-11 05:31:07 +00006370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006371ExprResult
John McCall454feb92009-12-08 09:21:05 +00006372TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006373 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006375 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006376
John McCall60d7b3a2010-08-24 06:29:42 +00006377 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006378 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006379 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006380
John McCall60d7b3a2010-08-24 06:29:42 +00006381 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006382 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006383 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006384
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385 if (!getDerived().AlwaysRebuild() &&
6386 Cond.get() == E->getCond() &&
6387 LHS.get() == E->getLHS() &&
6388 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006389 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006390
Douglas Gregorb98b1992009-08-11 05:31:07 +00006391 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006392 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393 E->getRParenLoc());
6394}
Mike Stump1eb44332009-09-09 15:08:12 +00006395
Douglas Gregorb98b1992009-08-11 05:31:07 +00006396template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006397ExprResult
John McCall454feb92009-12-08 09:21:05 +00006398TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006399 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400}
6401
6402template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006403ExprResult
John McCall454feb92009-12-08 09:21:05 +00006404TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006405 switch (E->getOperator()) {
6406 case OO_New:
6407 case OO_Delete:
6408 case OO_Array_New:
6409 case OO_Array_Delete:
6410 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006411 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006412
Douglas Gregor668d6d92009-12-13 20:44:55 +00006413 case OO_Call: {
6414 // This is a call to an object's operator().
6415 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6416
6417 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006418 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006419 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006420 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006421
6422 // FIXME: Poor location information
6423 SourceLocation FakeLParenLoc
6424 = SemaRef.PP.getLocForEndOfToken(
6425 static_cast<Expr *>(Object.get())->getLocEnd());
6426
6427 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006428 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006429 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6430 Args))
6431 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006432
John McCall9ae2f072010-08-23 23:25:46 +00006433 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006434 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006435 E->getLocEnd());
6436 }
6437
6438#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6439 case OO_##Name:
6440#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6441#include "clang/Basic/OperatorKinds.def"
6442 case OO_Subscript:
6443 // Handled below.
6444 break;
6445
6446 case OO_Conditional:
6447 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006448 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006449
6450 case OO_None:
6451 case NUM_OVERLOADED_OPERATORS:
6452 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006453 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006454 }
6455
John McCall60d7b3a2010-08-24 06:29:42 +00006456 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006458 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006459
John McCall60d7b3a2010-08-24 06:29:42 +00006460 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006462 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463
John McCall60d7b3a2010-08-24 06:29:42 +00006464 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465 if (E->getNumArgs() == 2) {
6466 Second = getDerived().TransformExpr(E->getArg(1));
6467 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006468 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006469 }
Mike Stump1eb44332009-09-09 15:08:12 +00006470
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471 if (!getDerived().AlwaysRebuild() &&
6472 Callee.get() == E->getCallee() &&
6473 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006474 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006475 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006476
Douglas Gregorb98b1992009-08-11 05:31:07 +00006477 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6478 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006479 Callee.get(),
6480 First.get(),
6481 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482}
Mike Stump1eb44332009-09-09 15:08:12 +00006483
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006485ExprResult
John McCall454feb92009-12-08 09:21:05 +00006486TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6487 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488}
Mike Stump1eb44332009-09-09 15:08:12 +00006489
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006491ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006492TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6493 // Transform the callee.
6494 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6495 if (Callee.isInvalid())
6496 return ExprError();
6497
6498 // Transform exec config.
6499 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6500 if (EC.isInvalid())
6501 return ExprError();
6502
6503 // Transform arguments.
6504 bool ArgChanged = false;
6505 ASTOwningVector<Expr*> Args(SemaRef);
6506 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6507 &ArgChanged))
6508 return ExprError();
6509
6510 if (!getDerived().AlwaysRebuild() &&
6511 Callee.get() == E->getCallee() &&
6512 !ArgChanged)
6513 return SemaRef.Owned(E);
6514
6515 // FIXME: Wrong source location information for the '('.
6516 SourceLocation FakeLParenLoc
6517 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6518 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6519 move_arg(Args),
6520 E->getRParenLoc(), EC.get());
6521}
6522
6523template<typename Derived>
6524ExprResult
John McCall454feb92009-12-08 09:21:05 +00006525TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006526 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6527 if (!Type)
6528 return ExprError();
6529
John McCall60d7b3a2010-08-24 06:29:42 +00006530 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006531 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006533 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006534
Douglas Gregorb98b1992009-08-11 05:31:07 +00006535 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006536 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006538 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006539
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006541 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006542 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6543 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6544 SourceLocation FakeRParenLoc
6545 = SemaRef.PP.getLocForEndOfToken(
6546 E->getSubExpr()->getSourceRange().getEnd());
6547 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006548 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006549 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006550 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551 FakeRAngleLoc,
6552 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006553 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006554 FakeRParenLoc);
6555}
Mike Stump1eb44332009-09-09 15:08:12 +00006556
Douglas Gregorb98b1992009-08-11 05:31:07 +00006557template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006558ExprResult
John McCall454feb92009-12-08 09:21:05 +00006559TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6560 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561}
Mike Stump1eb44332009-09-09 15:08:12 +00006562
6563template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006564ExprResult
John McCall454feb92009-12-08 09:21:05 +00006565TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6566 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006567}
6568
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006570ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006572 CXXReinterpretCastExpr *E) {
6573 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006574}
Mike Stump1eb44332009-09-09 15:08:12 +00006575
Douglas Gregorb98b1992009-08-11 05:31:07 +00006576template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006577ExprResult
John McCall454feb92009-12-08 09:21:05 +00006578TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6579 return getDerived().TransformCXXNamedCastExpr(E);
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
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006585 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006586 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6587 if (!Type)
6588 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006589
John McCall60d7b3a2010-08-24 06:29:42 +00006590 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006591 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006592 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006593 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006594
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006596 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006598 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006599
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006600 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006601 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006602 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006603 E->getRParenLoc());
6604}
Mike Stump1eb44332009-09-09 15:08:12 +00006605
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006607ExprResult
John McCall454feb92009-12-08 09:21:05 +00006608TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006610 TypeSourceInfo *TInfo
6611 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6612 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006613 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006614
Douglas Gregorb98b1992009-08-11 05:31:07 +00006615 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006616 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006617 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006618
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006619 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6620 E->getLocStart(),
6621 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622 E->getLocEnd());
6623 }
Mike Stump1eb44332009-09-09 15:08:12 +00006624
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625 // We don't know whether the expression is potentially evaluated until
6626 // after we perform semantic analysis, so the expression is potentially
6627 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006628 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006629 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006630
John McCall60d7b3a2010-08-24 06:29:42 +00006631 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006633 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006634
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 if (!getDerived().AlwaysRebuild() &&
6636 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006637 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006638
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006639 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6640 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006641 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 E->getLocEnd());
6643}
6644
6645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006646ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006647TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6648 if (E->isTypeOperand()) {
6649 TypeSourceInfo *TInfo
6650 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6651 if (!TInfo)
6652 return ExprError();
6653
6654 if (!getDerived().AlwaysRebuild() &&
6655 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006656 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006657
Douglas Gregor3c52a212011-03-06 17:40:41 +00006658 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006659 E->getLocStart(),
6660 TInfo,
6661 E->getLocEnd());
6662 }
6663
6664 // We don't know whether the expression is potentially evaluated until
6665 // after we perform semantic analysis, so the expression is potentially
6666 // potentially evaluated.
6667 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6668
6669 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6670 if (SubExpr.isInvalid())
6671 return ExprError();
6672
6673 if (!getDerived().AlwaysRebuild() &&
6674 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006675 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006676
6677 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6678 E->getLocStart(),
6679 SubExpr.get(),
6680 E->getLocEnd());
6681}
6682
6683template<typename Derived>
6684ExprResult
John McCall454feb92009-12-08 09:21:05 +00006685TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006686 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687}
Mike Stump1eb44332009-09-09 15:08:12 +00006688
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006690ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006691TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006692 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006693 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694}
Mike Stump1eb44332009-09-09 15:08:12 +00006695
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006697ExprResult
John McCall454feb92009-12-08 09:21:05 +00006698TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006699 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006700 QualType T;
6701 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6702 T = MD->getThisType(getSema().Context);
6703 else
6704 T = getSema().Context.getPointerType(
6705 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00006706
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006707 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006708 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006709
Douglas Gregor828a1972010-01-07 23:12:05 +00006710 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711}
Mike Stump1eb44332009-09-09 15:08:12 +00006712
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006714ExprResult
John McCall454feb92009-12-08 09:21:05 +00006715TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006716 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006718 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006719
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720 if (!getDerived().AlwaysRebuild() &&
6721 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006722 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723
John McCall9ae2f072010-08-23 23:25:46 +00006724 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725}
Mike Stump1eb44332009-09-09 15:08:12 +00006726
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006728ExprResult
John McCall454feb92009-12-08 09:21:05 +00006729TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006730 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006731 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6732 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006734 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006735
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006736 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006738 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006739
Douglas Gregor036aed12009-12-23 23:03:06 +00006740 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741}
Mike Stump1eb44332009-09-09 15:08:12 +00006742
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006744ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006745TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6746 CXXScalarValueInitExpr *E) {
6747 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6748 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006749 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006750
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006752 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006753 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006754
Douglas Gregorab6677e2010-09-08 00:15:04 +00006755 return getDerived().RebuildCXXScalarValueInitExpr(T,
6756 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006757 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758}
Mike Stump1eb44332009-09-09 15:08:12 +00006759
Douglas Gregorb98b1992009-08-11 05:31:07 +00006760template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006761ExprResult
John McCall454feb92009-12-08 09:21:05 +00006762TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006764 TypeSourceInfo *AllocTypeInfo
6765 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6766 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006767 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006770 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006771 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006772 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006773
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774 // Transform the placement arguments (if any).
6775 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006776 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006777 if (getDerived().TransformExprs(E->getPlacementArgs(),
6778 E->getNumPlacementArgs(), true,
6779 PlacementArgs, &ArgumentChanged))
6780 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006781
Douglas Gregor43959a92009-08-20 07:17:43 +00006782 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006783 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006784 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6785 ConstructorArgs, &ArgumentChanged))
6786 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006787
Douglas Gregor1af74512010-02-26 00:38:10 +00006788 // Transform constructor, new operator, and delete operator.
6789 CXXConstructorDecl *Constructor = 0;
6790 if (E->getConstructor()) {
6791 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006792 getDerived().TransformDecl(E->getLocStart(),
6793 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006794 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006795 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006796 }
6797
6798 FunctionDecl *OperatorNew = 0;
6799 if (E->getOperatorNew()) {
6800 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006801 getDerived().TransformDecl(E->getLocStart(),
6802 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006803 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006804 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006805 }
6806
6807 FunctionDecl *OperatorDelete = 0;
6808 if (E->getOperatorDelete()) {
6809 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006810 getDerived().TransformDecl(E->getLocStart(),
6811 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006812 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006813 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006814 }
Sean Huntc3021132010-05-05 15:23:54 +00006815
Douglas Gregorb98b1992009-08-11 05:31:07 +00006816 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006817 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006819 Constructor == E->getConstructor() &&
6820 OperatorNew == E->getOperatorNew() &&
6821 OperatorDelete == E->getOperatorDelete() &&
6822 !ArgumentChanged) {
6823 // Mark any declarations we need as referenced.
6824 // FIXME: instantiation-specific.
6825 if (Constructor)
6826 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6827 if (OperatorNew)
6828 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6829 if (OperatorDelete)
6830 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006831 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006832 }
Mike Stump1eb44332009-09-09 15:08:12 +00006833
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006834 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006835 if (!ArraySize.get()) {
6836 // If no array size was specified, but the new expression was
6837 // instantiated with an array type (e.g., "new T" where T is
6838 // instantiated with "int[4]"), extract the outer bound from the
6839 // array type as our array size. We do this with constant and
6840 // dependently-sized array types.
6841 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6842 if (!ArrayT) {
6843 // Do nothing
6844 } else if (const ConstantArrayType *ConsArrayT
6845 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006846 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006847 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6848 ConsArrayT->getSize(),
6849 SemaRef.Context.getSizeType(),
6850 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006851 AllocType = ConsArrayT->getElementType();
6852 } else if (const DependentSizedArrayType *DepArrayT
6853 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6854 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006855 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006856 AllocType = DepArrayT->getElementType();
6857 }
6858 }
6859 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006860
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6862 E->isGlobalNew(),
6863 /*FIXME:*/E->getLocStart(),
6864 move_arg(PlacementArgs),
6865 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006866 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006868 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006869 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870 /*FIXME:*/E->getLocStart(),
6871 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006872 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006873}
Mike Stump1eb44332009-09-09 15:08:12 +00006874
Douglas Gregorb98b1992009-08-11 05:31:07 +00006875template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006876ExprResult
John McCall454feb92009-12-08 09:21:05 +00006877TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006878 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006879 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006880 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006881
Douglas Gregor1af74512010-02-26 00:38:10 +00006882 // Transform the delete operator, if known.
6883 FunctionDecl *OperatorDelete = 0;
6884 if (E->getOperatorDelete()) {
6885 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006886 getDerived().TransformDecl(E->getLocStart(),
6887 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006888 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006889 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006890 }
Sean Huntc3021132010-05-05 15:23:54 +00006891
Douglas Gregorb98b1992009-08-11 05:31:07 +00006892 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006893 Operand.get() == E->getArgument() &&
6894 OperatorDelete == E->getOperatorDelete()) {
6895 // Mark any declarations we need as referenced.
6896 // FIXME: instantiation-specific.
6897 if (OperatorDelete)
6898 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006899
6900 if (!E->getArgument()->isTypeDependent()) {
6901 QualType Destroyed = SemaRef.Context.getBaseElementType(
6902 E->getDestroyedType());
6903 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6904 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6905 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6906 SemaRef.LookupDestructor(Record));
6907 }
6908 }
6909
John McCall3fa5cae2010-10-26 07:05:15 +00006910 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006911 }
Mike Stump1eb44332009-09-09 15:08:12 +00006912
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6914 E->isGlobalDelete(),
6915 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006916 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917}
Mike Stump1eb44332009-09-09 15:08:12 +00006918
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006920ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006921TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006922 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006923 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006924 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006925 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006926
John McCallb3d87482010-08-24 05:47:05 +00006927 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006928 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006929 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006930 E->getOperatorLoc(),
6931 E->isArrow()? tok::arrow : tok::period,
6932 ObjectTypePtr,
6933 MayBePseudoDestructor);
6934 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006935 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006936
John McCallb3d87482010-08-24 05:47:05 +00006937 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006938 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6939 if (QualifierLoc) {
6940 QualifierLoc
6941 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6942 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00006943 return ExprError();
6944 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006945 CXXScopeSpec SS;
6946 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00006947
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006948 PseudoDestructorTypeStorage Destroyed;
6949 if (E->getDestroyedTypeInfo()) {
6950 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006951 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00006952 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006953 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006954 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006955 Destroyed = DestroyedTypeInfo;
6956 } else if (ObjectType->isDependentType()) {
6957 // We aren't likely to be able to resolve the identifier down to a type
6958 // now anyway, so just retain the identifier.
6959 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6960 E->getDestroyedTypeLoc());
6961 } else {
6962 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00006963 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006964 *E->getDestroyedTypeIdentifier(),
6965 E->getDestroyedTypeLoc(),
6966 /*Scope=*/0,
6967 SS, ObjectTypePtr,
6968 false);
6969 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006970 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006971
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006972 Destroyed
6973 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6974 E->getDestroyedTypeLoc());
6975 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006976
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006977 TypeSourceInfo *ScopeTypeInfo = 0;
6978 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006979 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006980 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006981 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006982 }
Sean Huntc3021132010-05-05 15:23:54 +00006983
John McCall9ae2f072010-08-23 23:25:46 +00006984 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006985 E->getOperatorLoc(),
6986 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006987 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006988 ScopeTypeInfo,
6989 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006990 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006991 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006992}
Mike Stump1eb44332009-09-09 15:08:12 +00006993
Douglas Gregora71d8192009-09-04 17:36:40 +00006994template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006995ExprResult
John McCallba135432009-11-21 08:51:07 +00006996TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006997 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006998 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6999 Sema::LookupOrdinaryName);
7000
7001 // Transform all the decls.
7002 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7003 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007004 NamedDecl *InstD = static_cast<NamedDecl*>(
7005 getDerived().TransformDecl(Old->getNameLoc(),
7006 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007007 if (!InstD) {
7008 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7009 // This can happen because of dependent hiding.
7010 if (isa<UsingShadowDecl>(*I))
7011 continue;
7012 else
John McCallf312b1e2010-08-26 23:41:50 +00007013 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007014 }
John McCallf7a1a742009-11-24 19:00:30 +00007015
7016 // Expand using declarations.
7017 if (isa<UsingDecl>(InstD)) {
7018 UsingDecl *UD = cast<UsingDecl>(InstD);
7019 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7020 E = UD->shadow_end(); I != E; ++I)
7021 R.addDecl(*I);
7022 continue;
7023 }
7024
7025 R.addDecl(InstD);
7026 }
7027
7028 // Resolve a kind, but don't do any further analysis. If it's
7029 // ambiguous, the callee needs to deal with it.
7030 R.resolveKind();
7031
7032 // Rebuild the nested-name qualifier, if present.
7033 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007034 if (Old->getQualifierLoc()) {
7035 NestedNameSpecifierLoc QualifierLoc
7036 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7037 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007038 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007039
Douglas Gregor4c9be892011-02-28 20:01:57 +00007040 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007041 }
7042
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007043 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007044 CXXRecordDecl *NamingClass
7045 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7046 Old->getNameLoc(),
7047 Old->getNamingClass()));
7048 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007049 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007050
Douglas Gregor66c45152010-04-27 16:10:10 +00007051 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007052 }
7053
7054 // If we have no template arguments, it's a normal declaration name.
7055 if (!Old->hasExplicitTemplateArgs())
7056 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7057
7058 // If we have template arguments, rebuild them, then rebuild the
7059 // templateid expression.
7060 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007061 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7062 Old->getNumTemplateArgs(),
7063 TransArgs))
7064 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007065
7066 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7067 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068}
Mike Stump1eb44332009-09-09 15:08:12 +00007069
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007071ExprResult
John McCall454feb92009-12-08 09:21:05 +00007072TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007073 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7074 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007075 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007076
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007078 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007079 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007080
Mike Stump1eb44332009-09-09 15:08:12 +00007081 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007083 T,
7084 E->getLocEnd());
7085}
Mike Stump1eb44332009-09-09 15:08:12 +00007086
Douglas Gregorb98b1992009-08-11 05:31:07 +00007087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007088ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007089TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7090 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7091 if (!LhsT)
7092 return ExprError();
7093
7094 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7095 if (!RhsT)
7096 return ExprError();
7097
7098 if (!getDerived().AlwaysRebuild() &&
7099 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7100 return SemaRef.Owned(E);
7101
7102 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7103 E->getLocStart(),
7104 LhsT, RhsT,
7105 E->getLocEnd());
7106}
7107
7108template<typename Derived>
7109ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007110TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7111 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7112 if (!T)
7113 return ExprError();
7114
7115 if (!getDerived().AlwaysRebuild() &&
7116 T == E->getQueriedTypeSourceInfo())
7117 return SemaRef.Owned(E);
7118
7119 ExprResult SubExpr;
7120 {
7121 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7122 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7123 if (SubExpr.isInvalid())
7124 return ExprError();
7125
7126 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7127 return SemaRef.Owned(E);
7128 }
7129
7130 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7131 E->getLocStart(),
7132 T,
7133 SubExpr.get(),
7134 E->getLocEnd());
7135}
7136
7137template<typename Derived>
7138ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007139TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7140 ExprResult SubExpr;
7141 {
7142 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7143 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7144 if (SubExpr.isInvalid())
7145 return ExprError();
7146
7147 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7148 return SemaRef.Owned(E);
7149 }
7150
7151 return getDerived().RebuildExpressionTrait(
7152 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7153}
7154
7155template<typename Derived>
7156ExprResult
John McCall865d4472009-11-19 22:55:06 +00007157TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007158 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007159 NestedNameSpecifierLoc QualifierLoc
7160 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7161 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007162 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007163
John McCall43fed0d2010-11-12 08:19:04 +00007164 // TODO: If this is a conversion-function-id, verify that the
7165 // destination type name (if present) resolves the same way after
7166 // instantiation as it did in the local scope.
7167
Abramo Bagnara25777432010-08-11 22:01:17 +00007168 DeclarationNameInfo NameInfo
7169 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7170 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007171 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007172
John McCallf7a1a742009-11-24 19:00:30 +00007173 if (!E->hasExplicitTemplateArgs()) {
7174 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007175 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007176 // Note: it is sufficient to compare the Name component of NameInfo:
7177 // if name has not changed, DNLoc has not changed either.
7178 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007179 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007180
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007181 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007182 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007183 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007184 }
John McCalld5532b62009-11-23 01:53:49 +00007185
7186 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007187 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7188 E->getNumTemplateArgs(),
7189 TransArgs))
7190 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007191
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007192 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007193 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007194 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007195}
7196
7197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007198ExprResult
John McCall454feb92009-12-08 09:21:05 +00007199TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007200 // CXXConstructExprs are always implicit, so when we have a
7201 // 1-argument construction we just transform that argument.
7202 if (E->getNumArgs() == 1 ||
7203 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7204 return getDerived().TransformExpr(E->getArg(0));
7205
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7207
7208 QualType T = getDerived().TransformType(E->getType());
7209 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007210 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007211
7212 CXXConstructorDecl *Constructor
7213 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007214 getDerived().TransformDecl(E->getLocStart(),
7215 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007217 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007218
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007220 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007221 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7222 &ArgumentChanged))
7223 return ExprError();
7224
Douglas Gregorb98b1992009-08-11 05:31:07 +00007225 if (!getDerived().AlwaysRebuild() &&
7226 T == E->getType() &&
7227 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007228 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007229 // Mark the constructor as referenced.
7230 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007231 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007232 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007233 }
Mike Stump1eb44332009-09-09 15:08:12 +00007234
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007235 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7236 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007237 move_arg(Args),
7238 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007239 E->getConstructionKind(),
7240 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007241}
Mike Stump1eb44332009-09-09 15:08:12 +00007242
Douglas Gregorb98b1992009-08-11 05:31:07 +00007243/// \brief Transform a C++ temporary-binding expression.
7244///
Douglas Gregor51326552009-12-24 18:51:59 +00007245/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7246/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007247template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007248ExprResult
John McCall454feb92009-12-08 09:21:05 +00007249TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007250 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007251}
Mike Stump1eb44332009-09-09 15:08:12 +00007252
John McCall4765fa02010-12-06 08:20:24 +00007253/// \brief Transform a C++ expression that contains cleanups that should
7254/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007255///
John McCall4765fa02010-12-06 08:20:24 +00007256/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007257/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007259ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007260TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007261 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007262}
Mike Stump1eb44332009-09-09 15:08:12 +00007263
Douglas Gregorb98b1992009-08-11 05:31:07 +00007264template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007265ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007266TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007267 CXXTemporaryObjectExpr *E) {
7268 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7269 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007270 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007271
Douglas Gregorb98b1992009-08-11 05:31:07 +00007272 CXXConstructorDecl *Constructor
7273 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007274 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007275 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007276 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007277 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007278
Douglas Gregorb98b1992009-08-11 05:31:07 +00007279 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007280 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007281 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007282 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7283 &ArgumentChanged))
7284 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007285
Douglas Gregorb98b1992009-08-11 05:31:07 +00007286 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007287 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007288 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007289 !ArgumentChanged) {
7290 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007291 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007292 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007293 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007294
7295 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7296 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007297 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007298 E->getLocEnd());
7299}
Mike Stump1eb44332009-09-09 15:08:12 +00007300
Douglas Gregorb98b1992009-08-11 05:31:07 +00007301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007302ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007303TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007304 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007305 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7306 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007307 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007308
Douglas Gregorb98b1992009-08-11 05:31:07 +00007309 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007310 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007311 Args.reserve(E->arg_size());
7312 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7313 &ArgumentChanged))
7314 return ExprError();
7315
Douglas Gregorb98b1992009-08-11 05:31:07 +00007316 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007317 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007318 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007319 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007320
Douglas Gregorb98b1992009-08-11 05:31:07 +00007321 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007322 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007323 E->getLParenLoc(),
7324 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007325 E->getRParenLoc());
7326}
Mike Stump1eb44332009-09-09 15:08:12 +00007327
Douglas Gregorb98b1992009-08-11 05:31:07 +00007328template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007329ExprResult
John McCall865d4472009-11-19 22:55:06 +00007330TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007331 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007332 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007333 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007334 Expr *OldBase;
7335 QualType BaseType;
7336 QualType ObjectType;
7337 if (!E->isImplicitAccess()) {
7338 OldBase = E->getBase();
7339 Base = getDerived().TransformExpr(OldBase);
7340 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007341 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007342
John McCallaa81e162009-12-01 22:10:20 +00007343 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007344 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007345 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007346 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007347 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007348 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007349 ObjectTy,
7350 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007351 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007352 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007353
John McCallb3d87482010-08-24 05:47:05 +00007354 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007355 BaseType = ((Expr*) Base.get())->getType();
7356 } else {
7357 OldBase = 0;
7358 BaseType = getDerived().TransformType(E->getBaseType());
7359 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7360 }
Mike Stump1eb44332009-09-09 15:08:12 +00007361
Douglas Gregor6cd21982009-10-20 05:58:46 +00007362 // Transform the first part of the nested-name-specifier that qualifies
7363 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007364 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007365 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007366 E->getFirstQualifierFoundInScope(),
7367 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007368
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007369 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007370 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007371 QualifierLoc
7372 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7373 ObjectType,
7374 FirstQualifierInScope);
7375 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007376 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007377 }
Mike Stump1eb44332009-09-09 15:08:12 +00007378
John McCall43fed0d2010-11-12 08:19:04 +00007379 // TODO: If this is a conversion-function-id, verify that the
7380 // destination type name (if present) resolves the same way after
7381 // instantiation as it did in the local scope.
7382
Abramo Bagnara25777432010-08-11 22:01:17 +00007383 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007384 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007385 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007386 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007387
John McCallaa81e162009-12-01 22:10:20 +00007388 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007389 // This is a reference to a member without an explicitly-specified
7390 // template argument list. Optimize for this common case.
7391 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007392 Base.get() == OldBase &&
7393 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007394 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007395 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007396 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007397 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007398
John McCall9ae2f072010-08-23 23:25:46 +00007399 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007400 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007401 E->isArrow(),
7402 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007403 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007404 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007405 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007406 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007407 }
7408
John McCalld5532b62009-11-23 01:53:49 +00007409 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007410 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7411 E->getNumTemplateArgs(),
7412 TransArgs))
7413 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007414
John McCall9ae2f072010-08-23 23:25:46 +00007415 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007416 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007417 E->isArrow(),
7418 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007419 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007420 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007421 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007422 &TransArgs);
7423}
7424
7425template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007426ExprResult
John McCall454feb92009-12-08 09:21:05 +00007427TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007428 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007429 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007430 QualType BaseType;
7431 if (!Old->isImplicitAccess()) {
7432 Base = getDerived().TransformExpr(Old->getBase());
7433 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007434 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007435 BaseType = ((Expr*) Base.get())->getType();
7436 } else {
7437 BaseType = getDerived().TransformType(Old->getBaseType());
7438 }
John McCall129e2df2009-11-30 22:42:35 +00007439
Douglas Gregor4c9be892011-02-28 20:01:57 +00007440 NestedNameSpecifierLoc QualifierLoc;
7441 if (Old->getQualifierLoc()) {
7442 QualifierLoc
7443 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7444 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007445 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007446 }
7447
Abramo Bagnara25777432010-08-11 22:01:17 +00007448 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007449 Sema::LookupOrdinaryName);
7450
7451 // Transform all the decls.
7452 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7453 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007454 NamedDecl *InstD = static_cast<NamedDecl*>(
7455 getDerived().TransformDecl(Old->getMemberLoc(),
7456 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007457 if (!InstD) {
7458 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7459 // This can happen because of dependent hiding.
7460 if (isa<UsingShadowDecl>(*I))
7461 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007462 else {
7463 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007464 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007465 }
John McCall9f54ad42009-12-10 09:41:52 +00007466 }
John McCall129e2df2009-11-30 22:42:35 +00007467
7468 // Expand using declarations.
7469 if (isa<UsingDecl>(InstD)) {
7470 UsingDecl *UD = cast<UsingDecl>(InstD);
7471 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7472 E = UD->shadow_end(); I != E; ++I)
7473 R.addDecl(*I);
7474 continue;
7475 }
7476
7477 R.addDecl(InstD);
7478 }
7479
7480 R.resolveKind();
7481
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007482 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007483 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007484 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007485 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007486 Old->getMemberLoc(),
7487 Old->getNamingClass()));
7488 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007489 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007490
Douglas Gregor66c45152010-04-27 16:10:10 +00007491 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007492 }
Sean Huntc3021132010-05-05 15:23:54 +00007493
John McCall129e2df2009-11-30 22:42:35 +00007494 TemplateArgumentListInfo TransArgs;
7495 if (Old->hasExplicitTemplateArgs()) {
7496 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7497 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007498 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7499 Old->getNumTemplateArgs(),
7500 TransArgs))
7501 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007502 }
John McCallc2233c52010-01-15 08:34:02 +00007503
7504 // FIXME: to do this check properly, we will need to preserve the
7505 // first-qualifier-in-scope here, just in case we had a dependent
7506 // base (and therefore couldn't do the check) and a
7507 // nested-name-qualifier (and therefore could do the lookup).
7508 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007509
John McCall9ae2f072010-08-23 23:25:46 +00007510 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007511 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007512 Old->getOperatorLoc(),
7513 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007514 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007515 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007516 R,
7517 (Old->hasExplicitTemplateArgs()
7518 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007519}
7520
7521template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007522ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007523TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007524 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007525 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7526 if (SubExpr.isInvalid())
7527 return ExprError();
7528
7529 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007530 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007531
7532 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7533}
7534
7535template<typename Derived>
7536ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007537TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007538 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7539 if (Pattern.isInvalid())
7540 return ExprError();
7541
7542 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7543 return SemaRef.Owned(E);
7544
Douglas Gregor67fd1252011-01-14 21:20:45 +00007545 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7546 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007547}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007548
7549template<typename Derived>
7550ExprResult
7551TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7552 // If E is not value-dependent, then nothing will change when we transform it.
7553 // Note: This is an instantiation-centric view.
7554 if (!E->isValueDependent())
7555 return SemaRef.Owned(E);
7556
7557 // Note: None of the implementations of TryExpandParameterPacks can ever
7558 // produce a diagnostic when given only a single unexpanded parameter pack,
7559 // so
7560 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7561 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007562 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007563 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007564 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7565 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00007566 ShouldExpand, RetainExpansion,
7567 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007568 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007569
Douglas Gregord3731192011-01-10 07:32:04 +00007570 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007571 return SemaRef.Owned(E);
7572
7573 // We now know the length of the parameter pack, so build a new expression
7574 // that stores that length.
7575 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7576 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00007577 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007578}
7579
Douglas Gregorbe230c32011-01-03 17:17:50 +00007580template<typename Derived>
7581ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007582TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7583 SubstNonTypeTemplateParmPackExpr *E) {
7584 // Default behavior is to do nothing with this transformation.
7585 return SemaRef.Owned(E);
7586}
7587
7588template<typename Derived>
7589ExprResult
John McCall454feb92009-12-08 09:21:05 +00007590TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007591 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007592}
7593
Mike Stump1eb44332009-09-09 15:08:12 +00007594template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007595ExprResult
John McCall454feb92009-12-08 09:21:05 +00007596TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007597 TypeSourceInfo *EncodedTypeInfo
7598 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7599 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007600 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007601
Douglas Gregorb98b1992009-08-11 05:31:07 +00007602 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007603 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007604 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007605
7606 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007607 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007608 E->getRParenLoc());
7609}
Mike Stump1eb44332009-09-09 15:08:12 +00007610
Douglas Gregorb98b1992009-08-11 05:31:07 +00007611template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007612ExprResult
John McCall454feb92009-12-08 09:21:05 +00007613TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007614 // Transform arguments.
7615 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007616 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007617 Args.reserve(E->getNumArgs());
7618 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7619 &ArgChanged))
7620 return ExprError();
7621
Douglas Gregor92e986e2010-04-22 16:44:27 +00007622 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7623 // Class message: transform the receiver type.
7624 TypeSourceInfo *ReceiverTypeInfo
7625 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7626 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007627 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007628
Douglas Gregor92e986e2010-04-22 16:44:27 +00007629 // If nothing changed, just retain the existing message send.
7630 if (!getDerived().AlwaysRebuild() &&
7631 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007632 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007633
7634 // Build a new class message send.
7635 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7636 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007637 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007638 E->getMethodDecl(),
7639 E->getLeftLoc(),
7640 move_arg(Args),
7641 E->getRightLoc());
7642 }
7643
7644 // Instance message: transform the receiver
7645 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7646 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007647 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007648 = getDerived().TransformExpr(E->getInstanceReceiver());
7649 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007650 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007651
7652 // If nothing changed, just retain the existing message send.
7653 if (!getDerived().AlwaysRebuild() &&
7654 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007655 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007656
Douglas Gregor92e986e2010-04-22 16:44:27 +00007657 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00007658 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007659 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007660 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007661 E->getMethodDecl(),
7662 E->getLeftLoc(),
7663 move_arg(Args),
7664 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007665}
7666
Mike Stump1eb44332009-09-09 15:08:12 +00007667template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007668ExprResult
John McCall454feb92009-12-08 09:21:05 +00007669TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007670 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007671}
7672
Mike Stump1eb44332009-09-09 15:08:12 +00007673template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007674ExprResult
John McCall454feb92009-12-08 09:21:05 +00007675TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007676 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007677}
7678
Mike Stump1eb44332009-09-09 15:08:12 +00007679template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007680ExprResult
John McCall454feb92009-12-08 09:21:05 +00007681TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007682 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007683 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007684 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007685 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007686
7687 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007688
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007689 // If nothing changed, just retain the existing expression.
7690 if (!getDerived().AlwaysRebuild() &&
7691 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007692 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007693
John McCall9ae2f072010-08-23 23:25:46 +00007694 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007695 E->getLocation(),
7696 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007697}
7698
Mike Stump1eb44332009-09-09 15:08:12 +00007699template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007700ExprResult
John McCall454feb92009-12-08 09:21:05 +00007701TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007702 // 'super' and types never change. Property never changes. Just
7703 // retain the existing expression.
7704 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007705 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007706
Douglas Gregore3303542010-04-26 20:47:02 +00007707 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007708 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007709 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007710 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007711
Douglas Gregore3303542010-04-26 20:47:02 +00007712 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007713
Douglas Gregore3303542010-04-26 20:47:02 +00007714 // If nothing changed, just retain the existing expression.
7715 if (!getDerived().AlwaysRebuild() &&
7716 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007717 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007718
John McCall12f78a62010-12-02 01:19:52 +00007719 if (E->isExplicitProperty())
7720 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7721 E->getExplicitProperty(),
7722 E->getLocation());
7723
7724 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7725 E->getType(),
7726 E->getImplicitPropertyGetter(),
7727 E->getImplicitPropertySetter(),
7728 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007729}
7730
Mike Stump1eb44332009-09-09 15:08:12 +00007731template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007732ExprResult
John McCall454feb92009-12-08 09:21:05 +00007733TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007734 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007735 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007736 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007737 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007738
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007739 // If nothing changed, just retain the existing expression.
7740 if (!getDerived().AlwaysRebuild() &&
7741 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007742 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007743
John McCall9ae2f072010-08-23 23:25:46 +00007744 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007745 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007746}
7747
Mike Stump1eb44332009-09-09 15:08:12 +00007748template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007749ExprResult
John McCall454feb92009-12-08 09:21:05 +00007750TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007751 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007752 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007753 SubExprs.reserve(E->getNumSubExprs());
7754 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7755 SubExprs, &ArgumentChanged))
7756 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007757
Douglas Gregorb98b1992009-08-11 05:31:07 +00007758 if (!getDerived().AlwaysRebuild() &&
7759 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007760 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007761
Douglas Gregorb98b1992009-08-11 05:31:07 +00007762 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7763 move_arg(SubExprs),
7764 E->getRParenLoc());
7765}
7766
Mike Stump1eb44332009-09-09 15:08:12 +00007767template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007768ExprResult
John McCall454feb92009-12-08 09:21:05 +00007769TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00007770 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007771
John McCallc6ac9c32011-02-04 18:33:18 +00007772 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7773 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7774
7775 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanianff365592011-05-05 17:18:12 +00007776 // We built a new blockScopeInfo in call to ActOnBlockStart
7777 // in above, CapturesCXXThis need be set here from the block
7778 // expression.
7779 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7780
John McCallc6ac9c32011-02-04 18:33:18 +00007781 llvm::SmallVector<ParmVarDecl*, 4> params;
7782 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007783
7784 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00007785 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7786 oldBlock->param_begin(),
7787 oldBlock->param_size(),
7788 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00007789 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00007790
7791 const FunctionType *exprFunctionType = E->getFunctionType();
7792 QualType exprResultType = exprFunctionType->getResultType();
7793 if (!exprResultType.isNull()) {
7794 if (!exprResultType->isDependentType())
7795 blockScope->ReturnType = exprResultType;
7796 else if (exprResultType != getSema().Context.DependentTy)
7797 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007798 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00007799
7800 // If the return type has not been determined yet, leave it as a dependent
7801 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00007802 if (blockScope->ReturnType.isNull())
7803 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007804
7805 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00007806 if (blockScope->ReturnType->isObjCObjectType()) {
7807 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00007808 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00007809 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007810 return ExprError();
7811 }
John McCall711c52b2011-01-05 12:14:39 +00007812
John McCallc6ac9c32011-02-04 18:33:18 +00007813 QualType functionType = getDerived().RebuildFunctionProtoType(
7814 blockScope->ReturnType,
7815 paramTypes.data(),
7816 paramTypes.size(),
7817 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00007818 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00007819 exprFunctionType->getExtInfo());
7820 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00007821
7822 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00007823 if (!params.empty())
7824 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregora779d9c2011-01-19 21:32:01 +00007825
7826 // If the return type wasn't explicitly set, it will have been marked as a
7827 // dependent type (DependentTy); clear out the return type setting so
7828 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00007829 if (blockScope->ReturnType == getSema().Context.DependentTy)
7830 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00007831
John McCall711c52b2011-01-05 12:14:39 +00007832 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00007833 StmtResult body = getDerived().TransformStmt(E->getBody());
7834 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00007835 return ExprError();
7836
John McCallc6ac9c32011-02-04 18:33:18 +00007837#ifndef NDEBUG
7838 // In builds with assertions, make sure that we captured everything we
7839 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00007840 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
7841 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7842 e = oldBlock->capture_end(); i != e; ++i) {
7843 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00007844
Douglas Gregorfc921372011-05-20 15:32:55 +00007845 // Ignore parameter packs.
7846 if (isa<ParmVarDecl>(oldCapture) &&
7847 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7848 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00007849
Douglas Gregorfc921372011-05-20 15:32:55 +00007850 VarDecl *newCapture =
7851 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7852 oldCapture));
7853 assert(blockScope->CaptureMap.count(newCapture));
7854 }
John McCallc6ac9c32011-02-04 18:33:18 +00007855 }
7856#endif
7857
7858 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7859 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007860}
7861
Mike Stump1eb44332009-09-09 15:08:12 +00007862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007863ExprResult
John McCall454feb92009-12-08 09:21:05 +00007864TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007865 ValueDecl *ND
7866 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7867 E->getDecl()));
7868 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007869 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007870
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007871 if (!getDerived().AlwaysRebuild() &&
7872 ND == E->getDecl()) {
7873 // Mark it referenced in the new context regardless.
7874 // FIXME: this is a bit instantiation-specific.
7875 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7876
John McCall3fa5cae2010-10-26 07:05:15 +00007877 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007878 }
7879
Abramo Bagnara25777432010-08-11 22:01:17 +00007880 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00007881 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007882 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007883}
Mike Stump1eb44332009-09-09 15:08:12 +00007884
Tanya Lattner61eee0c2011-06-04 00:47:47 +00007885template<typename Derived>
7886ExprResult
7887TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
7888 assert(false && "Cannot transform asType expressions yet");
7889 return SemaRef.Owned(E);
7890}
7891
Douglas Gregorb98b1992009-08-11 05:31:07 +00007892//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007893// Type reconstruction
7894//===----------------------------------------------------------------------===//
7895
Mike Stump1eb44332009-09-09 15:08:12 +00007896template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007897QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7898 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007899 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007900 getDerived().getBaseEntity());
7901}
7902
Mike Stump1eb44332009-09-09 15:08:12 +00007903template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007904QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7905 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007906 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007907 getDerived().getBaseEntity());
7908}
7909
Mike Stump1eb44332009-09-09 15:08:12 +00007910template<typename Derived>
7911QualType
John McCall85737a72009-10-30 00:06:24 +00007912TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7913 bool WrittenAsLValue,
7914 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007915 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007916 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007917}
7918
7919template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007920QualType
John McCall85737a72009-10-30 00:06:24 +00007921TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7922 QualType ClassType,
7923 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007924 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007925 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007926}
7927
7928template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007929QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007930TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7931 ArrayType::ArraySizeModifier SizeMod,
7932 const llvm::APInt *Size,
7933 Expr *SizeExpr,
7934 unsigned IndexTypeQuals,
7935 SourceRange BracketsRange) {
7936 if (SizeExpr || !Size)
7937 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7938 IndexTypeQuals, BracketsRange,
7939 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007940
7941 QualType Types[] = {
7942 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7943 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7944 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007945 };
7946 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7947 QualType SizeType;
7948 for (unsigned I = 0; I != NumTypes; ++I)
7949 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7950 SizeType = Types[I];
7951 break;
7952 }
Mike Stump1eb44332009-09-09 15:08:12 +00007953
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007954 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7955 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007956 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007957 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007958 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007959}
Mike Stump1eb44332009-09-09 15:08:12 +00007960
Douglas Gregor577f75a2009-08-04 16:50:30 +00007961template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007962QualType
7963TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007964 ArrayType::ArraySizeModifier SizeMod,
7965 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007966 unsigned IndexTypeQuals,
7967 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007968 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007969 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007970}
7971
7972template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007973QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007974TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007975 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007976 unsigned IndexTypeQuals,
7977 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007978 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007979 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007980}
Mike Stump1eb44332009-09-09 15:08:12 +00007981
Douglas Gregor577f75a2009-08-04 16:50:30 +00007982template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007983QualType
7984TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007985 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007986 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007987 unsigned IndexTypeQuals,
7988 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007989 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007990 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007991 IndexTypeQuals, BracketsRange);
7992}
7993
7994template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007995QualType
7996TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007997 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007998 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007999 unsigned IndexTypeQuals,
8000 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008001 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008002 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008003 IndexTypeQuals, BracketsRange);
8004}
8005
8006template<typename Derived>
8007QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008008 unsigned NumElements,
8009 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008010 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008011 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008012}
Mike Stump1eb44332009-09-09 15:08:12 +00008013
Douglas Gregor577f75a2009-08-04 16:50:30 +00008014template<typename Derived>
8015QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8016 unsigned NumElements,
8017 SourceLocation AttributeLoc) {
8018 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8019 NumElements, true);
8020 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008021 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8022 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008023 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008024}
Mike Stump1eb44332009-09-09 15:08:12 +00008025
Douglas Gregor577f75a2009-08-04 16:50:30 +00008026template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008027QualType
8028TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008029 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008030 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008031 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008032}
Mike Stump1eb44332009-09-09 15:08:12 +00008033
Douglas Gregor577f75a2009-08-04 16:50:30 +00008034template<typename Derived>
8035QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008036 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008037 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008038 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00008039 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008040 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008041 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008042 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00008043 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008044 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008045 getDerived().getBaseEntity(),
8046 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008047}
Mike Stump1eb44332009-09-09 15:08:12 +00008048
Douglas Gregor577f75a2009-08-04 16:50:30 +00008049template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008050QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8051 return SemaRef.Context.getFunctionNoProtoType(T);
8052}
8053
8054template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008055QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8056 assert(D && "no decl found");
8057 if (D->isInvalidDecl()) return QualType();
8058
Douglas Gregor92e986e2010-04-22 16:44:27 +00008059 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008060 TypeDecl *Ty;
8061 if (isa<UsingDecl>(D)) {
8062 UsingDecl *Using = cast<UsingDecl>(D);
8063 assert(Using->isTypeName() &&
8064 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8065
8066 // A valid resolved using typename decl points to exactly one type decl.
8067 assert(++Using->shadow_begin() == Using->shadow_end());
8068 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008069
John McCalled976492009-12-04 22:46:56 +00008070 } else {
8071 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8072 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8073 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8074 }
8075
8076 return SemaRef.Context.getTypeDeclType(Ty);
8077}
8078
8079template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008080QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8081 SourceLocation Loc) {
8082 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008083}
8084
8085template<typename Derived>
8086QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8087 return SemaRef.Context.getTypeOfType(Underlying);
8088}
8089
8090template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008091QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8092 SourceLocation Loc) {
8093 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008094}
8095
8096template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008097QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8098 UnaryTransformType::UTTKind UKind,
8099 SourceLocation Loc) {
8100 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8101}
8102
8103template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008104QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008105 TemplateName Template,
8106 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008107 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008108 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008109}
Mike Stump1eb44332009-09-09 15:08:12 +00008110
Douglas Gregordcee1a12009-08-06 05:28:30 +00008111template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008112TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008113TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008114 bool TemplateKW,
8115 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008116 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008117 Template);
8118}
8119
8120template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008121TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008122TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8123 const IdentifierInfo &Name,
8124 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008125 QualType ObjectType,
8126 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008127 UnqualifiedId TemplateName;
8128 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008129 Sema::TemplateTy Template;
8130 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008131 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008132 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008133 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008134 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008135 /*EnteringContext=*/false,
8136 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008137 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008138}
Mike Stump1eb44332009-09-09 15:08:12 +00008139
Douglas Gregorb98b1992009-08-11 05:31:07 +00008140template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008141TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008142TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008143 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008144 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008145 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008146 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008147 // FIXME: Bogus location information.
8148 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8149 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008150 Sema::TemplateTy Template;
8151 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008152 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008153 SS,
8154 Name,
John McCallb3d87482010-08-24 05:47:05 +00008155 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008156 /*EnteringContext=*/false,
8157 Template);
8158 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008159}
Sean Huntc3021132010-05-05 15:23:54 +00008160
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008162ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008163TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8164 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008165 Expr *OrigCallee,
8166 Expr *First,
8167 Expr *Second) {
8168 Expr *Callee = OrigCallee->IgnoreParenCasts();
8169 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008170
Douglas Gregorb98b1992009-08-11 05:31:07 +00008171 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008172 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008173 if (!First->getType()->isOverloadableType() &&
8174 !Second->getType()->isOverloadableType())
8175 return getSema().CreateBuiltinArraySubscriptExpr(First,
8176 Callee->getLocStart(),
8177 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008178 } else if (Op == OO_Arrow) {
8179 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008180 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8181 } else if (Second == 0 || isPostIncDec) {
8182 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008183 // The argument is not of overloadable type, so try to create a
8184 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008185 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008186 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008187
John McCall9ae2f072010-08-23 23:25:46 +00008188 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008189 }
8190 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008191 if (!First->getType()->isOverloadableType() &&
8192 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008193 // Neither of the arguments is an overloadable type, so try to
8194 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008195 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008196 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008197 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008198 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008199 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008200
Douglas Gregorb98b1992009-08-11 05:31:07 +00008201 return move(Result);
8202 }
8203 }
Mike Stump1eb44332009-09-09 15:08:12 +00008204
8205 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008206 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008207 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008208
John McCall9ae2f072010-08-23 23:25:46 +00008209 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008210 assert(ULE->requiresADL());
8211
8212 // FIXME: Do we have to check
8213 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008214 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008215 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008216 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008217 }
Mike Stump1eb44332009-09-09 15:08:12 +00008218
Douglas Gregorb98b1992009-08-11 05:31:07 +00008219 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008220 Expr *Args[2] = { First, Second };
8221 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008222
Douglas Gregorb98b1992009-08-11 05:31:07 +00008223 // Create the overloaded operator invocation for unary operators.
8224 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008225 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008226 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008227 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008228 }
Mike Stump1eb44332009-09-09 15:08:12 +00008229
Sebastian Redlf322ed62009-10-29 20:17:01 +00008230 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00008231 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00008232 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008233 First,
8234 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00008235
Douglas Gregorb98b1992009-08-11 05:31:07 +00008236 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008237 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008238 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008239 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8240 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008241 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008242
Mike Stump1eb44332009-09-09 15:08:12 +00008243 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008244}
Mike Stump1eb44332009-09-09 15:08:12 +00008245
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008246template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008247ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008248TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008249 SourceLocation OperatorLoc,
8250 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008251 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008252 TypeSourceInfo *ScopeType,
8253 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008254 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008255 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008256 QualType BaseType = Base->getType();
8257 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008258 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008259 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008260 !BaseType->getAs<PointerType>()->getPointeeType()
8261 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008262 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008263 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008264 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008265 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008266 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008267 /*FIXME?*/true);
8268 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008269
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008270 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008271 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8272 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8273 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8274 NameInfo.setNamedTypeInfo(DestroyedType);
8275
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008276 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008277
John McCall9ae2f072010-08-23 23:25:46 +00008278 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008279 OperatorLoc, isArrow,
8280 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008281 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008282 /*TemplateArgs*/ 0);
8283}
8284
Douglas Gregor577f75a2009-08-04 16:50:30 +00008285} // end namespace clang
8286
8287#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H