blob: 33aaf92d813b749af245aeaff6f2a6a25e8d6a61 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-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 Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-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 Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
101
102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
106
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000114
Mike Stump11289f42009-09-09 15:08:12 +0000115public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000116 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000117 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000118
Douglas Gregord6ff3322009-08-04 16:50:30 +0000119 /// \brief Retrieves a reference to the derived class.
120 Derived &getDerived() { return static_cast<Derived&>(*this); }
121
122 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000123 const Derived &getDerived() const {
124 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 }
126
John McCalldadc5752010-08-24 06:29:42 +0000127 static inline ExprResult Owned(Expr *E) { return E; }
128 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Retrieves a reference to the semantic analysis object used for
131 /// this tree transform.
132 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000133
Douglas Gregord6ff3322009-08-04 16:50:30 +0000134 /// \brief Whether the transformation should always rebuild AST nodes, even
135 /// if none of the children have changed.
136 ///
137 /// Subclasses may override this function to specify when the transformation
138 /// should rebuild all AST nodes.
139 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000140
Douglas Gregord6ff3322009-08-04 16:50:30 +0000141 /// \brief Returns the location of the entity being transformed, if that
142 /// information was not available elsewhere in the AST.
143 ///
Mike Stump11289f42009-09-09 15:08:12 +0000144 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000145 /// provide an alternative implementation that provides better location
146 /// information.
147 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregord6ff3322009-08-04 16:50:30 +0000149 /// \brief Returns the name of the entity being transformed, if that
150 /// information was not available elsewhere in the AST.
151 ///
152 /// By default, returns an empty name. Subclasses can provide an alternative
153 /// implementation with a more precise name.
154 DeclarationName getBaseEntity() { return DeclarationName(); }
155
Douglas Gregora16548e2009-08-11 05:31:07 +0000156 /// \brief Sets the "base" location and entity when that
157 /// information is known based on another transformation.
158 ///
159 /// By default, the source location and entity are ignored. Subclasses can
160 /// override this function to provide a customized implementation.
161 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000162
Douglas Gregora16548e2009-08-11 05:31:07 +0000163 /// \brief RAII object that temporarily sets the base location and entity
164 /// used for reporting diagnostics in types.
165 class TemporaryBase {
166 TreeTransform &Self;
167 SourceLocation OldLocation;
168 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000169
Douglas Gregora16548e2009-08-11 05:31:07 +0000170 public:
171 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000172 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 OldLocation = Self.getDerived().getBaseLocation();
174 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000175
176 if (Location.isValid())
177 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 }
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 ~TemporaryBase() {
181 Self.getDerived().setBase(OldLocation, OldEntity);
182 }
183 };
Mike Stump11289f42009-09-09 15:08:12 +0000184
185 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000186 /// transformed.
187 ///
188 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000189 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000190 /// not change. For example, template instantiation need not traverse
191 /// non-dependent types.
192 bool AlreadyTransformed(QualType T) {
193 return T.isNull();
194 }
195
Douglas Gregord196a582009-12-14 19:27:10 +0000196 /// \brief Determine whether the given call argument should be dropped, e.g.,
197 /// because it is a default argument.
198 ///
199 /// Subclasses can provide an alternative implementation of this routine to
200 /// determine which kinds of call arguments get dropped. By default,
201 /// CXXDefaultArgument nodes are dropped (prior to transformation).
202 bool DropCallArgument(Expr *E) {
203 return E->isDefaultArgument();
204 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000205
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000206 /// \brief Determine whether we should expand a pack expansion with the
207 /// given set of parameter packs into separate arguments by repeatedly
208 /// transforming the pattern.
209 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000210 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000211 /// Subclasses can override this routine to provide different behavior.
212 ///
213 /// \param EllipsisLoc The location of the ellipsis that identifies the
214 /// pack expansion.
215 ///
216 /// \param PatternRange The source range that covers the entire pattern of
217 /// the pack expansion.
218 ///
219 /// \param Unexpanded The set of unexpanded parameter packs within the
220 /// pattern.
221 ///
222 /// \param NumUnexpanded The number of unexpanded parameter packs in
223 /// \p Unexpanded.
224 ///
225 /// \param ShouldExpand Will be set to \c true if the transformer should
226 /// expand the corresponding pack expansions into separate arguments. When
227 /// set, \c NumExpansions must also be set.
228 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000229 /// \param RetainExpansion Whether the caller should add an unexpanded
230 /// pack expansion after all of the expanded arguments. This is used
231 /// when extending explicitly-specified template argument packs per
232 /// C++0x [temp.arg.explicit]p9.
233 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000234 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000235 /// the expanded form of the corresponding pack expansion. This is both an
236 /// input and an output parameter, which can be set by the caller if the
237 /// number of expansions is known a priori (e.g., due to a prior substitution)
238 /// and will be set by the callee when the number of expansions is known.
239 /// The callee must set this value when \c ShouldExpand is \c true; it may
240 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 ///
242 /// \returns true if an error occurred (e.g., because the parameter packs
243 /// are to be instantiated with arguments of different lengths), false
244 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
245 /// must be set.
246 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
247 SourceRange PatternRange,
David Blaikieb9c168a2011-09-22 02:34:54 +0000248 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000249 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregora8bac7f2011-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 Gregorf3010112011-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 Gregord6ff3322009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCall550e0c22009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-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 McCallbcd03502009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000286
John McCall550e0c22009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
John McCall550e0c22009-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 McCall31f82722010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-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 McCall31f82722010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000302
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000304 ///
Mike Stump11289f42009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-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 McCalldadc5752010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000313
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregora16548e2009-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 McCalldadc5752010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000323
Douglas Gregora3efea12011-01-03 19:04:46 +0000324 /// \brief Transform the given list of expressions.
325 ///
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
331 ///
332 /// \param Inputs The set of expressions to be transformed.
333 ///
334 /// \param NumInputs The number of expressions in \c Inputs.
335 ///
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
338 /// be.
339 ///
340 /// \param Outputs The transformed input expressions will be added to this
341 /// vector.
342 ///
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
345 ///
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000348 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 bool *ArgChanged = 0);
350
Douglas Gregord6ff3322009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregor1135c352009-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 Gregora04f2ca2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump11289f42009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000364 }
Mike Stump11289f42009-09-09 15:08:12 +0000365
Douglas Gregora5cb6da2009-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 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-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.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000377 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000378
Douglas Gregor14454802011-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 Gregorf816bd72009-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 Bagnarad6d2f182010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000398
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000400 ///
Douglas Gregor9db53502011-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 Gregord6ff3322009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump11289f42009-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 Gregore922c772009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall0ad16662009-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 Gregor62e06f22010-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 Gregorfe921a72010-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 Gregor62e06f22010-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 Gregorfe921a72010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor42cafa82010-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 Gregorfe921a72010-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 Gregor42cafa82010-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 Gregorfe921a72010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000478
John McCall0ad16662009-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 McCallbcd03502009-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 McCall0ad16662009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump11289f42009-09-09 15:08:12 +0000488
John McCall550e0c22009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493
John Wiegley1c0675e2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall31f82722010-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 Gregor23648d72011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall58f10c32010-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 Gregordd472162011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000523 SmallVectorImpl<QualType> &PTypes,
524 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000534
John McCall31f82722010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000536
John McCalldadc5752010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000539
Douglas Gregorebe10102009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000546
Douglas Gregord6ff3322009-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 McCall70dd5f62009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump11289f42009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558
John McCall70dd5f62009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 ///
John McCall70dd5f62009-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 Gregord6ff3322009-08-04 16:50:30 +0000564 ///
John McCall70dd5f62009-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 Stump11289f42009-09-09 15:08:12 +0000570
Douglas Gregord6ff3322009-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 McCall70dd5f62009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000578
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000592
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000603
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000613
Mike Stump11289f42009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump11289f42009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregord6ff3322009-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 Thompson22334602010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000643
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000660
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000671
John McCall550e0c22009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCallb96ec562009-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 Gregord6ff3322009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-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 McCallfcc33b02009-09-05 00:15:47 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-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 McCall36e7fe32010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000699
Mike Stump11289f42009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Alexis Hunte852b102011-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 Stump11289f42009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-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 McCall36e7fe32010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000715
Richard Smith30482bc2011-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 Gregord6ff3322009-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 McCall0ad16662009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000731
Abramo Bagnara924a8f32010-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 Gregord6ff3322009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara6150c882010-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 McCall954b5de2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000752 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarad7548482010-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 McCallc392f372010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-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 Gregord6ff3322009-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 Bagnarad7548482010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000808
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-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 Gregor3d0da5f2011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara6150c882010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarad7548482010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCallbf8c5192010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregore677daf2010-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;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000840
Douglas Gregore677daf2010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000844
Douglas Gregore677daf2010-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();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000849
Douglas Gregore677daf2010-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 Lewycky0c438082011-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 Smith3f1b5d02011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-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 Smith3f1b5d02011-05-05 21:57:07 +0000872 }
Nick Lewycky0c438082011-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 Gregore677daf2010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000881
Richard Trieucaa33d32011-06-10 03:11:26 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-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 Gregor3d0da5f2011-03-01 01:34:45 +0000891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
893 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000894 }
Mike Stump11289f42009-09-09 15:08:12 +0000895
Douglas Gregor822d0302011-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 Gregor0dca5fd2011-01-14 17:04:44 +0000902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000906 }
907
Eli Friedman0dfb8892011-10-06 23:00:33 +0000908 /// \brief Build a new atomic type given its value type.
909 ///
910 /// By default, performs semantic analysis when building the atomic type.
911 /// Subclasses may override this routine to provide different behavior.
912 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
913
Douglas Gregor71dc5092009-08-06 06:41:21 +0000914 /// \brief Build a new template name given a nested name specifier, a flag
915 /// indicating whether the "template" keyword was provided, and the template
916 /// that the template name refers to.
917 ///
918 /// By default, builds the new template name directly. Subclasses may override
919 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000920 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000921 bool TemplateKW,
922 TemplateDecl *Template);
923
Douglas Gregor71dc5092009-08-06 06:41:21 +0000924 /// \brief Build a new template name given a nested name specifier and the
925 /// name that is referred to as a template.
926 ///
927 /// By default, performs semantic analysis to determine whether the name can
928 /// be resolved to a specific template, then builds the appropriate kind of
929 /// template name. Subclasses may override this routine to provide different
930 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000931 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
932 const IdentifierInfo &Name,
933 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000934 QualType ObjectType,
935 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000936
Douglas Gregor71395fa2009-11-04 00:56:37 +0000937 /// \brief Build a new template name given a nested name specifier and the
938 /// overloaded operator name that is referred to as a template.
939 ///
940 /// By default, performs semantic analysis to determine whether the name can
941 /// be resolved to a specific template, then builds the appropriate kind of
942 /// template name. Subclasses may override this routine to provide different
943 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000944 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000945 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000946 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000947 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000948
949 /// \brief Build a new template name given a template template parameter pack
950 /// and the
951 ///
952 /// By default, performs semantic analysis to determine whether the name can
953 /// be resolved to a specific template, then builds the appropriate kind of
954 /// template name. Subclasses may override this routine to provide different
955 /// behavior.
956 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
957 const TemplateArgument &ArgPack) {
958 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
959 }
960
Douglas Gregorebe10102009-08-20 07:17:43 +0000961 /// \brief Build a new compound statement.
962 ///
963 /// By default, performs semantic analysis to build the new statement.
964 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000965 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000966 MultiStmtArg Statements,
967 SourceLocation RBraceLoc,
968 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000969 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000970 IsStmtExpr);
971 }
972
973 /// \brief Build a new case statement.
974 ///
975 /// By default, performs semantic analysis to build the new statement.
976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000977 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000978 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000979 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000980 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000981 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000982 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 ColonLoc);
984 }
Mike Stump11289f42009-09-09 15:08:12 +0000985
Douglas Gregorebe10102009-08-20 07:17:43 +0000986 /// \brief Attach the body to a new case statement.
987 ///
988 /// By default, performs semantic analysis to build the new statement.
989 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000990 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000991 getSema().ActOnCaseStmtBody(S, Body);
992 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 }
Mike Stump11289f42009-09-09 15:08:12 +0000994
Douglas Gregorebe10102009-08-20 07:17:43 +0000995 /// \brief Build a new default statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000999 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001001 Stmt *SubStmt) {
1002 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 /*CurScope=*/0);
1004 }
Mike Stump11289f42009-09-09 15:08:12 +00001005
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 /// \brief Build a new label statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001010 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1011 SourceLocation ColonLoc, Stmt *SubStmt) {
1012 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001013 }
Mike Stump11289f42009-09-09 15:08:12 +00001014
Douglas Gregorebe10102009-08-20 07:17:43 +00001015 /// \brief Build a new "if" statement.
1016 ///
1017 /// By default, performs semantic analysis to build the new statement.
1018 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001019 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001020 VarDecl *CondVar, Stmt *Then,
1021 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001022 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001023 }
Mike Stump11289f42009-09-09 15:08:12 +00001024
Douglas Gregorebe10102009-08-20 07:17:43 +00001025 /// \brief Start building a new switch statement.
1026 ///
1027 /// By default, performs semantic analysis to build the new statement.
1028 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001029 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001030 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001031 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001032 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001033 }
Mike Stump11289f42009-09-09 15:08:12 +00001034
Douglas Gregorebe10102009-08-20 07:17:43 +00001035 /// \brief Attach the body to the switch statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001039 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001040 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001041 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001042 }
1043
1044 /// \brief Build a new while statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001048 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1049 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001050 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 }
Mike Stump11289f42009-09-09 15:08:12 +00001052
Douglas Gregorebe10102009-08-20 07:17:43 +00001053 /// \brief Build a new do-while statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001058 SourceLocation WhileLoc, SourceLocation LParenLoc,
1059 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001060 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1061 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 }
1063
1064 /// \brief Build a new for statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001068 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1069 Stmt *Init, Sema::FullExprArg Cond,
1070 VarDecl *CondVar, Sema::FullExprArg Inc,
1071 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001072 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001073 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001074 }
Mike Stump11289f42009-09-09 15:08:12 +00001075
Douglas Gregorebe10102009-08-20 07:17:43 +00001076 /// \brief Build a new goto statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001080 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1081 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001082 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001083 }
1084
1085 /// \brief Build a new indirect goto statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001089 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001090 SourceLocation StarLoc,
1091 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001092 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 /// \brief Build a new return statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001099 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001100 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001101 }
Mike Stump11289f42009-09-09 15:08:12 +00001102
Douglas Gregorebe10102009-08-20 07:17:43 +00001103 /// \brief Build a new declaration statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001107 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001108 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001110 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1111 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001112 }
Mike Stump11289f42009-09-09 15:08:12 +00001113
Anders Carlssonaaeef072010-01-24 05:50:09 +00001114 /// \brief Build a new inline asm statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001118 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001119 bool IsSimple,
1120 bool IsVolatile,
1121 unsigned NumOutputs,
1122 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001123 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001124 MultiExprArg Constraints,
1125 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001126 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001127 MultiExprArg Clobbers,
1128 SourceLocation RParenLoc,
1129 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001130 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001131 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001132 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001133 RParenLoc, MSAsm);
1134 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001135
1136 /// \brief Build a new Objective-C @try statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001140 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001141 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001142 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001143 Stmt *Finally) {
1144 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1145 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001146 }
1147
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001148 /// \brief Rebuild an Objective-C exception declaration.
1149 ///
1150 /// By default, performs semantic analysis to build the new declaration.
1151 /// Subclasses may override this routine to provide different behavior.
1152 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1153 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001154 return getSema().BuildObjCExceptionDecl(TInfo, T,
1155 ExceptionDecl->getInnerLocStart(),
1156 ExceptionDecl->getLocation(),
1157 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001158 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001159
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001160 /// \brief Build a new Objective-C @catch statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001165 SourceLocation RParenLoc,
1166 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001167 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001168 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001169 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001170 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001171
Douglas Gregor306de2f2010-04-22 23:59:56 +00001172 /// \brief Build a new Objective-C @finally statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001176 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001177 Stmt *Body) {
1178 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001179 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001180
Douglas Gregor6148de72010-04-22 22:01:21 +00001181 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001185 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001186 Expr *Operand) {
1187 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001188 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001189
John McCalld9bb7432011-07-27 21:50:02 +00001190 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1191 ///
1192 /// By default, performs semantic analysis to build the new statement.
1193 /// Subclasses may override this routine to provide different behavior.
1194 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1195 Expr *object) {
1196 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1197 }
1198
Douglas Gregor6148de72010-04-22 22:01:21 +00001199 /// \brief Build a new Objective-C @synchronized statement.
1200 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001201 /// By default, performs semantic analysis to build the new statement.
1202 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001203 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001204 Expr *Object, Stmt *Body) {
1205 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001206 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001207
John McCall31168b02011-06-15 23:02:42 +00001208 /// \brief Build a new Objective-C @autoreleasepool statement.
1209 ///
1210 /// By default, performs semantic analysis to build the new statement.
1211 /// Subclasses may override this routine to provide different behavior.
1212 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1213 Stmt *Body) {
1214 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1215 }
John McCall53848232011-07-27 01:07:15 +00001216
1217 /// \brief Build the collection operand to a new Objective-C fast
1218 /// enumeration statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
1222 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1223 Expr *collection) {
1224 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1225 }
John McCall31168b02011-06-15 23:02:42 +00001226
Douglas Gregorf68a5082010-04-22 23:10:45 +00001227 /// \brief Build a new Objective-C fast enumeration statement.
1228 ///
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001231 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001232 SourceLocation LParenLoc,
1233 Stmt *Element,
1234 Expr *Collection,
1235 SourceLocation RParenLoc,
1236 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001237 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001238 Element,
1239 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001240 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001241 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001242 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001243
Douglas Gregorebe10102009-08-20 07:17:43 +00001244 /// \brief Build a new C++ exception declaration.
1245 ///
1246 /// By default, performs semantic analysis to build the new decaration.
1247 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001248 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001249 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001250 SourceLocation StartLoc,
1251 SourceLocation IdLoc,
1252 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001253 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1254 StartLoc, IdLoc, Id);
1255 if (Var)
1256 getSema().CurContext->addDecl(Var);
1257 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001258 }
1259
1260 /// \brief Build a new C++ catch statement.
1261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001264 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001265 VarDecl *ExceptionDecl,
1266 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001267 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1268 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001269 }
Mike Stump11289f42009-09-09 15:08:12 +00001270
Douglas Gregorebe10102009-08-20 07:17:43 +00001271 /// \brief Build a new C++ try statement.
1272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001275 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001276 Stmt *TryBlock,
1277 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001278 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001279 }
Mike Stump11289f42009-09-09 15:08:12 +00001280
Richard Smith02e85f32011-04-14 22:09:26 +00001281 /// \brief Build a new C++0x range-based for statement.
1282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
1285 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1286 SourceLocation ColonLoc,
1287 Stmt *Range, Stmt *BeginEnd,
1288 Expr *Cond, Expr *Inc,
1289 Stmt *LoopVar,
1290 SourceLocation RParenLoc) {
1291 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1292 Cond, Inc, LoopVar, RParenLoc);
1293 }
1294
1295 /// \brief Attach body to a C++0x range-based for statement.
1296 ///
1297 /// By default, performs semantic analysis to finish the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
1299 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1300 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1301 }
1302
John Wiegley1c0675e2011-04-28 01:08:34 +00001303 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1304 SourceLocation TryLoc,
1305 Stmt *TryBlock,
1306 Stmt *Handler) {
1307 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1308 }
1309
1310 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1311 Expr *FilterExpr,
1312 Stmt *Block) {
1313 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1314 }
1315
1316 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1317 Stmt *Block) {
1318 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1319 }
1320
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// \brief Build a new expression that references a declaration.
1322 ///
1323 /// By default, performs semantic analysis to build the new expression.
1324 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001325 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001326 LookupResult &R,
1327 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001328 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1329 }
1330
1331
1332 /// \brief Build a new expression that references a declaration.
1333 ///
1334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001336 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001337 ValueDecl *VD,
1338 const DeclarationNameInfo &NameInfo,
1339 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001340 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001341 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001342
1343 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001344
1345 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 }
Mike Stump11289f42009-09-09 15:08:12 +00001347
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001349 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 /// By default, performs semantic analysis to build the new expression.
1351 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001352 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001354 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 }
1356
Douglas Gregorad8a3362009-09-04 17:36:40 +00001357 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001358 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001359 /// By default, performs semantic analysis to build the new expression.
1360 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001361 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001362 SourceLocation OperatorLoc,
1363 bool isArrow,
1364 CXXScopeSpec &SS,
1365 TypeSourceInfo *ScopeType,
1366 SourceLocation CCLoc,
1367 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001368 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001369
Douglas Gregora16548e2009-08-11 05:31:07 +00001370 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001371 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001374 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001375 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001376 Expr *SubExpr) {
1377 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 }
Mike Stump11289f42009-09-09 15:08:12 +00001379
Douglas Gregor882211c2010-04-28 22:16:22 +00001380 /// \brief Build a new builtin offsetof expression.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001384 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001385 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001386 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001387 unsigned NumComponents,
1388 SourceLocation RParenLoc) {
1389 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1390 NumComponents, RParenLoc);
1391 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001392
Peter Collingbournee190dee2011-03-11 19:24:49 +00001393 /// \brief Build a new sizeof, alignof or vec_step expression with a
1394 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001395 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001396 /// By default, performs semantic analysis to build the new expression.
1397 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001398 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1399 SourceLocation OpLoc,
1400 UnaryExprOrTypeTrait ExprKind,
1401 SourceRange R) {
1402 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001403 }
1404
Peter Collingbournee190dee2011-03-11 19:24:49 +00001405 /// \brief Build a new sizeof, alignof or vec step expression with an
1406 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001407 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 /// By default, performs semantic analysis to build the new expression.
1409 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001410 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1411 UnaryExprOrTypeTrait ExprKind,
1412 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001413 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001414 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001416 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001417
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 return move(Result);
1419 }
Mike Stump11289f42009-09-09 15:08:12 +00001420
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001422 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 /// By default, performs semantic analysis to build the new expression.
1424 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001425 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001427 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001429 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1430 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 RBracketLoc);
1432 }
1433
1434 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001435 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001438 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001440 SourceLocation RParenLoc,
1441 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001442 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001443 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 }
1445
1446 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001447 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001450 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001451 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001452 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001453 const DeclarationNameInfo &MemberNameInfo,
1454 ValueDecl *Member,
1455 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001456 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001457 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001458 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001459 // We have a reference to an unnamed field. This is always the
1460 // base of an anonymous struct/union member access, i.e. the
1461 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001462 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001463 assert(Member->getType()->isRecordType() &&
1464 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001465
John Wiegley01296292011-04-08 18:41:53 +00001466 ExprResult BaseResult =
1467 getSema().PerformObjectMemberConversion(Base,
1468 QualifierLoc.getNestedNameSpecifier(),
1469 FoundDecl, Member);
1470 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001471 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001472 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001473 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001474 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001475 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001476 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001477 cast<FieldDecl>(Member)->getType(),
1478 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001479 return getSema().Owned(ME);
1480 }
Mike Stump11289f42009-09-09 15:08:12 +00001481
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001482 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001483 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001484
John Wiegley01296292011-04-08 18:41:53 +00001485 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1486 if (BaseResult.isInvalid())
1487 return ExprError();
1488 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001489 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001490
John McCall16df1e52010-03-30 21:47:33 +00001491 // FIXME: this involves duplicating earlier analysis in a lot of
1492 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001493 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001494 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001495 R.resolveKind();
1496
John McCallb268a282010-08-23 23:25:46 +00001497 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001498 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001499 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 }
Mike Stump11289f42009-09-09 15:08:12 +00001501
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001503 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001506 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001507 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001508 Expr *LHS, Expr *RHS) {
1509 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 }
1511
1512 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001513 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 /// By default, performs semantic analysis to build the new expression.
1515 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001516 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001517 SourceLocation QuestionLoc,
1518 Expr *LHS,
1519 SourceLocation ColonLoc,
1520 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001521 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1522 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 }
1524
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001526 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001529 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001530 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001532 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001533 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001534 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 }
Mike Stump11289f42009-09-09 15:08:12 +00001536
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001538 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001541 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001542 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001544 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001545 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001546 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 }
Mike Stump11289f42009-09-09 15:08:12 +00001548
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001550 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001553 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 SourceLocation OpLoc,
1555 SourceLocation AccessorLoc,
1556 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001557
John McCall10eae182009-11-30 22:42:35 +00001558 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001559 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001560 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001561 OpLoc, /*IsArrow*/ false,
1562 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001563 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001564 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 }
Mike Stump11289f42009-09-09 15:08:12 +00001566
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001568 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001571 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001572 MultiExprArg Inits,
1573 SourceLocation RBraceLoc,
1574 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001575 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001576 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1577 if (Result.isInvalid() || ResultTy->isDependentType())
1578 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001579
Douglas Gregord3d93062009-11-09 17:16:50 +00001580 // Patch in the result type we were given, which may have been computed
1581 // when the initial InitListExpr was built.
1582 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1583 ILE->setType(ResultTy);
1584 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 }
Mike Stump11289f42009-09-09 15:08:12 +00001586
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001588 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 /// By default, performs semantic analysis to build the new expression.
1590 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001591 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 MultiExprArg ArrayExprs,
1593 SourceLocation EqualOrColonLoc,
1594 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001595 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001596 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001598 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001601
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 ArrayExprs.release();
1603 return move(Result);
1604 }
Mike Stump11289f42009-09-09 15:08:12 +00001605
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001607 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 /// By default, builds the implicit value initialization without performing
1609 /// any semantic analysis. Subclasses may override this routine to provide
1610 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001611 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1613 }
Mike Stump11289f42009-09-09 15:08:12 +00001614
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001616 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 /// By default, performs semantic analysis to build the new expression.
1618 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001619 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001620 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001621 SourceLocation RParenLoc) {
1622 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001623 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001624 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 }
1626
1627 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001628 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001631 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 MultiExprArg SubExprs,
1633 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001634 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001635 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 }
Mike Stump11289f42009-09-09 15:08:12 +00001637
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001639 ///
1640 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 /// rather than attempting to map the label statement itself.
1642 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001643 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001644 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001645 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 }
Mike Stump11289f42009-09-09 15:08:12 +00001647
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001649 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001652 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001653 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001655 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 }
Mike Stump11289f42009-09-09 15:08:12 +00001657
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 /// \brief Build a new __builtin_choose_expr expression.
1659 ///
1660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001662 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001663 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 SourceLocation RParenLoc) {
1665 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001666 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 RParenLoc);
1668 }
Mike Stump11289f42009-09-09 15:08:12 +00001669
Peter Collingbourne91147592011-04-15 00:35:48 +00001670 /// \brief Build a new generic selection expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
1674 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1675 SourceLocation DefaultLoc,
1676 SourceLocation RParenLoc,
1677 Expr *ControllingExpr,
1678 TypeSourceInfo **Types,
1679 Expr **Exprs,
1680 unsigned NumAssocs) {
1681 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1682 ControllingExpr, Types, Exprs,
1683 NumAssocs);
1684 }
1685
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 /// \brief Build a new overloaded operator call expression.
1687 ///
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// The semantic analysis provides the behavior of template instantiation,
1690 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001691 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 /// argument-dependent lookup, etc. Subclasses may override this routine to
1693 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001694 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001696 Expr *Callee,
1697 Expr *First,
1698 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001699
1700 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 /// reinterpret_cast.
1702 ///
1703 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001704 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001706 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 Stmt::StmtClass Class,
1708 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001709 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 SourceLocation RAngleLoc,
1711 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001712 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 SourceLocation RParenLoc) {
1714 switch (Class) {
1715 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001716 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001717 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001718 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001719
1720 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001721 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001722 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001723 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001724
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001726 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001727 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001728 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001730
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001732 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001733 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001734 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001735
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001737 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 }
Mike Stump11289f42009-09-09 15:08:12 +00001739
John McCallfaf5fb42010-08-26 23:41:50 +00001740 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 }
Mike Stump11289f42009-09-09 15:08:12 +00001742
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 /// \brief Build a new C++ static_cast expression.
1744 ///
1745 /// By default, performs semantic analysis to build the new expression.
1746 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001747 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001749 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001750 SourceLocation RAngleLoc,
1751 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001752 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001754 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001755 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001756 SourceRange(LAngleLoc, RAngleLoc),
1757 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 }
1759
1760 /// \brief Build a new C++ dynamic_cast expression.
1761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001764 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001766 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 SourceLocation RAngleLoc,
1768 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001769 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001771 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001772 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001773 SourceRange(LAngleLoc, RAngleLoc),
1774 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 }
1776
1777 /// \brief Build a new C++ reinterpret_cast expression.
1778 ///
1779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001781 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001783 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001784 SourceLocation RAngleLoc,
1785 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001786 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001788 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001789 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001790 SourceRange(LAngleLoc, RAngleLoc),
1791 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 }
1793
1794 /// \brief Build a new C++ const_cast expression.
1795 ///
1796 /// By default, performs semantic analysis to build the new expression.
1797 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001798 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001800 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001801 SourceLocation RAngleLoc,
1802 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001803 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001805 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001806 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001807 SourceRange(LAngleLoc, RAngleLoc),
1808 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001809 }
Mike Stump11289f42009-09-09 15:08:12 +00001810
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 /// \brief Build a new C++ functional-style cast expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001815 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1816 SourceLocation LParenLoc,
1817 Expr *Sub,
1818 SourceLocation RParenLoc) {
1819 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001820 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 RParenLoc);
1822 }
Mike Stump11289f42009-09-09 15:08:12 +00001823
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 /// \brief Build a new C++ typeid(type) expression.
1825 ///
1826 /// By default, performs semantic analysis to build the new expression.
1827 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001828 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001829 SourceLocation TypeidLoc,
1830 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001832 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001833 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 }
Mike Stump11289f42009-09-09 15:08:12 +00001835
Francois Pichet9f4f2072010-09-08 12:20:18 +00001836
Douglas Gregora16548e2009-08-11 05:31:07 +00001837 /// \brief Build a new C++ typeid(expr) expression.
1838 ///
1839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001841 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001842 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001843 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001845 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001846 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001847 }
1848
Francois Pichet9f4f2072010-09-08 12:20:18 +00001849 /// \brief Build a new C++ __uuidof(type) expression.
1850 ///
1851 /// By default, performs semantic analysis to build the new expression.
1852 /// Subclasses may override this routine to provide different behavior.
1853 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1854 SourceLocation TypeidLoc,
1855 TypeSourceInfo *Operand,
1856 SourceLocation RParenLoc) {
1857 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1858 RParenLoc);
1859 }
1860
1861 /// \brief Build a new C++ __uuidof(expr) expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
1865 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1866 SourceLocation TypeidLoc,
1867 Expr *Operand,
1868 SourceLocation RParenLoc) {
1869 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1870 RParenLoc);
1871 }
1872
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 /// \brief Build a new C++ "this" expression.
1874 ///
1875 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001876 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001878 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001879 QualType ThisType,
1880 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001882 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1883 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001884 }
1885
1886 /// \brief Build a new C++ throw expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001890 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1891 bool IsThrownVariableInScope) {
1892 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 }
1894
1895 /// \brief Build a new C++ default-argument expression.
1896 ///
1897 /// By default, builds a new default-argument expression, which does not
1898 /// require any semantic analysis. Subclasses may override this routine to
1899 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001900 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001901 ParmVarDecl *Param) {
1902 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1903 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 }
1905
1906 /// \brief Build a new C++ zero-initialization expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001910 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1911 SourceLocation LParenLoc,
1912 SourceLocation RParenLoc) {
1913 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001914 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001915 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 }
Mike Stump11289f42009-09-09 15:08:12 +00001917
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 /// \brief Build a new C++ "new" expression.
1919 ///
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001922 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001923 bool UseGlobal,
1924 SourceLocation PlacementLParen,
1925 MultiExprArg PlacementArgs,
1926 SourceLocation PlacementRParen,
1927 SourceRange TypeIdParens,
1928 QualType AllocatedType,
1929 TypeSourceInfo *AllocatedTypeInfo,
1930 Expr *ArraySize,
1931 SourceLocation ConstructorLParen,
1932 MultiExprArg ConstructorArgs,
1933 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001934 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 PlacementLParen,
1936 move(PlacementArgs),
1937 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001938 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001939 AllocatedType,
1940 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001941 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 ConstructorLParen,
1943 move(ConstructorArgs),
1944 ConstructorRParen);
1945 }
Mike Stump11289f42009-09-09 15:08:12 +00001946
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 /// \brief Build a new C++ "delete" expression.
1948 ///
1949 /// By default, performs semantic analysis to build the new expression.
1950 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001951 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 bool IsGlobalDelete,
1953 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001954 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001956 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 }
Mike Stump11289f42009-09-09 15:08:12 +00001958
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 /// \brief Build a new unary type trait expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001963 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001964 SourceLocation StartLoc,
1965 TypeSourceInfo *T,
1966 SourceLocation RParenLoc) {
1967 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 }
1969
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001970 /// \brief Build a new binary type trait expression.
1971 ///
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
1974 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1975 SourceLocation StartLoc,
1976 TypeSourceInfo *LhsT,
1977 TypeSourceInfo *RhsT,
1978 SourceLocation RParenLoc) {
1979 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1980 }
1981
John Wiegley6242b6a2011-04-28 00:16:57 +00001982 /// \brief Build a new array type trait expression.
1983 ///
1984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
1986 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1987 SourceLocation StartLoc,
1988 TypeSourceInfo *TSInfo,
1989 Expr *DimExpr,
1990 SourceLocation RParenLoc) {
1991 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1992 }
1993
John Wiegleyf9f65842011-04-25 06:54:41 +00001994 /// \brief Build a new expression trait expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
1998 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1999 SourceLocation StartLoc,
2000 Expr *Queried,
2001 SourceLocation RParenLoc) {
2002 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2003 }
2004
Mike Stump11289f42009-09-09 15:08:12 +00002005 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 /// expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002010 ExprResult RebuildDependentScopeDeclRefExpr(
2011 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002012 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002013 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002015 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002016
2017 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002018 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002019 *TemplateArgs);
2020
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002021 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00002022 }
2023
2024 /// \brief Build a new template-id expression.
2025 ///
2026 /// By default, performs semantic analysis to build the new expression.
2027 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002028 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00002029 LookupResult &R,
2030 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00002031 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00002032 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 }
2034
2035 /// \brief Build a new object-construction expression.
2036 ///
2037 /// By default, performs semantic analysis to build the new expression.
2038 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002039 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002040 SourceLocation Loc,
2041 CXXConstructorDecl *Constructor,
2042 bool IsElidable,
2043 MultiExprArg Args,
2044 bool HadMultipleCandidates,
2045 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002046 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002047 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002048 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002049 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002050 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002051 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002052
Douglas Gregordb121ba2009-12-14 16:27:04 +00002053 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002054 move_arg(ConvertedArgs),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002055 HadMultipleCandidates,
Chandler Carruth01718152010-10-25 08:47:36 +00002056 RequiresZeroInit, ConstructKind,
2057 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 }
2059
2060 /// \brief Build a new object-construction expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002064 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2065 SourceLocation LParenLoc,
2066 MultiExprArg Args,
2067 SourceLocation RParenLoc) {
2068 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 LParenLoc,
2070 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 RParenLoc);
2072 }
2073
2074 /// \brief Build a new object-construction expression.
2075 ///
2076 /// By default, performs semantic analysis to build the new expression.
2077 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002078 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2079 SourceLocation LParenLoc,
2080 MultiExprArg Args,
2081 SourceLocation RParenLoc) {
2082 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002083 LParenLoc,
2084 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002085 RParenLoc);
2086 }
Mike Stump11289f42009-09-09 15:08:12 +00002087
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 /// \brief Build a new member reference expression.
2089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002092 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002093 QualType BaseType,
2094 bool IsArrow,
2095 SourceLocation OperatorLoc,
2096 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002097 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002098 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002099 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002101 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002102
John McCallb268a282010-08-23 23:25:46 +00002103 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002104 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002105 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002106 MemberNameInfo,
2107 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 }
2109
John McCall10eae182009-11-30 22:42:35 +00002110 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002111 ///
2112 /// By default, performs semantic analysis to build the new expression.
2113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002114 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002115 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002116 SourceLocation OperatorLoc,
2117 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002118 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002119 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002120 LookupResult &R,
2121 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002122 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002123 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002124
John McCallb268a282010-08-23 23:25:46 +00002125 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002126 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002127 SS, FirstQualifierInScope,
2128 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002129 }
Mike Stump11289f42009-09-09 15:08:12 +00002130
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002131 /// \brief Build a new noexcept expression.
2132 ///
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
2135 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2136 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2137 }
2138
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002139 /// \brief Build a new expression to compute the length of a parameter pack.
2140 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2141 SourceLocation PackLoc,
2142 SourceLocation RParenLoc,
2143 unsigned Length) {
2144 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2145 OperatorLoc, Pack, PackLoc,
2146 RParenLoc, Length);
2147 }
2148
Douglas Gregora16548e2009-08-11 05:31:07 +00002149 /// \brief Build a new Objective-C @encode expression.
2150 ///
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002153 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002154 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002156 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002158 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002159
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002160 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002161 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002162 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002163 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002164 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002165 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002166 MultiExprArg Args,
2167 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002168 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2169 ReceiverTypeInfo->getType(),
2170 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002171 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002172 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002173 }
2174
2175 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002176 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002177 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002178 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002179 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002180 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002181 MultiExprArg Args,
2182 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002183 return SemaRef.BuildInstanceMessage(Receiver,
2184 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002185 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002186 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002187 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002188 }
2189
Douglas Gregord51d90d2010-04-26 20:11:03 +00002190 /// \brief Build a new Objective-C ivar reference expression.
2191 ///
2192 /// By default, performs semantic analysis to build the new expression.
2193 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002194 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002195 SourceLocation IvarLoc,
2196 bool IsArrow, bool IsFreeIvar) {
2197 // FIXME: We lose track of the IsFreeIvar bit.
2198 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002199 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002200 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2201 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002202 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002203 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002204 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002205 false);
John Wiegley01296292011-04-08 18:41:53 +00002206 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002207 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002208
Douglas Gregord51d90d2010-04-26 20:11:03 +00002209 if (Result.get())
2210 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002211
John Wiegley01296292011-04-08 18:41:53 +00002212 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002213 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002214 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002215 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002216 /*TemplateArgs=*/0);
2217 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002218
2219 /// \brief Build a new Objective-C property reference expression.
2220 ///
2221 /// By default, performs semantic analysis to build the new expression.
2222 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002223 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002224 ObjCPropertyDecl *Property,
2225 SourceLocation PropertyLoc) {
2226 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002227 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002228 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2229 Sema::LookupMemberName);
2230 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002231 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002232 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002233 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002234 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002235 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002236
Douglas Gregor9faee212010-04-26 20:47:02 +00002237 if (Result.get())
2238 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002239
John Wiegley01296292011-04-08 18:41:53 +00002240 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002241 /*FIXME:*/PropertyLoc, IsArrow,
2242 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002243 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002244 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002245 /*TemplateArgs=*/0);
2246 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002247
John McCallb7bd14f2010-12-02 01:19:52 +00002248 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002249 ///
2250 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002251 /// Subclasses may override this routine to provide different behavior.
2252 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2253 ObjCMethodDecl *Getter,
2254 ObjCMethodDecl *Setter,
2255 SourceLocation PropertyLoc) {
2256 // Since these expressions can only be value-dependent, we do not
2257 // need to perform semantic analysis again.
2258 return Owned(
2259 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2260 VK_LValue, OK_ObjCProperty,
2261 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002262 }
2263
Douglas Gregord51d90d2010-04-26 20:11:03 +00002264 /// \brief Build a new Objective-C "isa" expression.
2265 ///
2266 /// By default, performs semantic analysis to build the new expression.
2267 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002268 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002269 bool IsArrow) {
2270 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002271 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002272 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2273 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002274 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002275 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002276 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002277 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002278 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002279
Douglas Gregord51d90d2010-04-26 20:11:03 +00002280 if (Result.get())
2281 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002282
John Wiegley01296292011-04-08 18:41:53 +00002283 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002284 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002285 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002286 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002287 /*TemplateArgs=*/0);
2288 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002289
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 /// \brief Build a new shuffle vector expression.
2291 ///
2292 /// By default, performs semantic analysis to build the new expression.
2293 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002294 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002295 MultiExprArg SubExprs,
2296 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002297 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002298 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2300 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2301 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2302 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002303
Douglas Gregora16548e2009-08-11 05:31:07 +00002304 // Build a reference to the __builtin_shufflevector builtin
2305 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002306 ExprResult Callee
2307 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2308 VK_LValue, BuiltinLoc));
2309 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2310 if (Callee.isInvalid())
2311 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002312
2313 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 unsigned NumSubExprs = SubExprs.size();
2315 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002316 ExprResult TheCall = SemaRef.Owned(
2317 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002318 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002319 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002320 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002321 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002322
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002324 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002325 }
John McCall31f82722010-11-12 08:19:04 +00002326
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002327 /// \brief Build a new template argument pack expansion.
2328 ///
2329 /// By default, performs semantic analysis to build a new pack expansion
2330 /// for a template argument. Subclasses may override this routine to provide
2331 /// different behavior.
2332 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002333 SourceLocation EllipsisLoc,
2334 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002335 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002336 case TemplateArgument::Expression: {
2337 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002338 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2339 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002340 if (Result.isInvalid())
2341 return TemplateArgumentLoc();
2342
2343 return TemplateArgumentLoc(Result.get(), Result.get());
2344 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002345
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002346 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002347 return TemplateArgumentLoc(TemplateArgument(
2348 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002349 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002350 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002351 Pattern.getTemplateNameLoc(),
2352 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002353
2354 case TemplateArgument::Null:
2355 case TemplateArgument::Integral:
2356 case TemplateArgument::Declaration:
2357 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002358 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002359 llvm_unreachable("Pack expansion pattern has no parameter packs");
2360
2361 case TemplateArgument::Type:
2362 if (TypeSourceInfo *Expansion
2363 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002364 EllipsisLoc,
2365 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002366 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2367 Expansion);
2368 break;
2369 }
2370
2371 return TemplateArgumentLoc();
2372 }
2373
Douglas Gregor968f23a2011-01-03 19:31:53 +00002374 /// \brief Build a new expression pack expansion.
2375 ///
2376 /// By default, performs semantic analysis to build a new pack expansion
2377 /// for an expression. Subclasses may override this routine to provide
2378 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002379 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2380 llvm::Optional<unsigned> NumExpansions) {
2381 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002382 }
2383
John McCall31f82722010-11-12 08:19:04 +00002384private:
Douglas Gregor14454802011-02-25 02:25:35 +00002385 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2386 QualType ObjectType,
2387 NamedDecl *FirstQualifierInScope,
2388 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002389
2390 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2391 QualType ObjectType,
2392 NamedDecl *FirstQualifierInScope,
2393 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002394};
Douglas Gregora16548e2009-08-11 05:31:07 +00002395
Douglas Gregorebe10102009-08-20 07:17:43 +00002396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002397StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002398 if (!S)
2399 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002400
Douglas Gregorebe10102009-08-20 07:17:43 +00002401 switch (S->getStmtClass()) {
2402 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002403
Douglas Gregorebe10102009-08-20 07:17:43 +00002404 // Transform individual statement nodes
2405#define STMT(Node, Parent) \
2406 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002407#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002408#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002409#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002410
Douglas Gregorebe10102009-08-20 07:17:43 +00002411 // Transform expressions by calling TransformExpr.
2412#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002413#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002414#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002415#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002416 {
John McCalldadc5752010-08-24 06:29:42 +00002417 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002418 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002419 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002420
John McCallb268a282010-08-23 23:25:46 +00002421 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002422 }
Mike Stump11289f42009-09-09 15:08:12 +00002423 }
2424
John McCallc3007a22010-10-26 07:05:15 +00002425 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002426}
Mike Stump11289f42009-09-09 15:08:12 +00002427
2428
Douglas Gregore922c772009-08-04 22:27:00 +00002429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002430ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002431 if (!E)
2432 return SemaRef.Owned(E);
2433
2434 switch (E->getStmtClass()) {
2435 case Stmt::NoStmtClass: break;
2436#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002437#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002438#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002439 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002440#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002441 }
2442
John McCallc3007a22010-10-26 07:05:15 +00002443 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002444}
2445
2446template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002447bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2448 unsigned NumInputs,
2449 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002450 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002451 bool *ArgChanged) {
2452 for (unsigned I = 0; I != NumInputs; ++I) {
2453 // If requested, drop call arguments that need to be dropped.
2454 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2455 if (ArgChanged)
2456 *ArgChanged = true;
2457
2458 break;
2459 }
2460
Douglas Gregor968f23a2011-01-03 19:31:53 +00002461 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2462 Expr *Pattern = Expansion->getPattern();
2463
Chris Lattner01cf8db2011-07-20 06:58:45 +00002464 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002465 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2466 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2467
2468 // Determine whether the set of unexpanded parameter packs can and should
2469 // be expanded.
2470 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002471 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002472 llvm::Optional<unsigned> OrigNumExpansions
2473 = Expansion->getNumExpansions();
2474 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002475 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2476 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002477 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002478 Expand, RetainExpansion,
2479 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002480 return true;
2481
2482 if (!Expand) {
2483 // The transform has determined that we should perform a simple
2484 // transformation on the pack expansion, producing another pack
2485 // expansion.
2486 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2487 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2488 if (OutPattern.isInvalid())
2489 return true;
2490
2491 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002492 Expansion->getEllipsisLoc(),
2493 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002494 if (Out.isInvalid())
2495 return true;
2496
2497 if (ArgChanged)
2498 *ArgChanged = true;
2499 Outputs.push_back(Out.get());
2500 continue;
2501 }
John McCall542e7c62011-07-06 07:30:07 +00002502
2503 // Record right away that the argument was changed. This needs
2504 // to happen even if the array expands to nothing.
2505 if (ArgChanged) *ArgChanged = true;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002506
2507 // The transform has determined that we should perform an elementwise
2508 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002509 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002510 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2511 ExprResult Out = getDerived().TransformExpr(Pattern);
2512 if (Out.isInvalid())
2513 return true;
2514
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002515 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002516 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2517 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002518 if (Out.isInvalid())
2519 return true;
2520 }
2521
Douglas Gregor968f23a2011-01-03 19:31:53 +00002522 Outputs.push_back(Out.get());
2523 }
2524
2525 continue;
2526 }
2527
Douglas Gregora3efea12011-01-03 19:04:46 +00002528 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2529 if (Result.isInvalid())
2530 return true;
2531
2532 if (Result.get() != Inputs[I] && ArgChanged)
2533 *ArgChanged = true;
2534
2535 Outputs.push_back(Result.get());
2536 }
2537
2538 return false;
2539}
2540
2541template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002542NestedNameSpecifierLoc
2543TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2544 NestedNameSpecifierLoc NNS,
2545 QualType ObjectType,
2546 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002547 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregor14454802011-02-25 02:25:35 +00002548 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2549 Qualifier = Qualifier.getPrefix())
2550 Qualifiers.push_back(Qualifier);
2551
2552 CXXScopeSpec SS;
2553 while (!Qualifiers.empty()) {
2554 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2555 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2556
2557 switch (QNNS->getKind()) {
2558 case NestedNameSpecifier::Identifier:
2559 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2560 *QNNS->getAsIdentifier(),
2561 Q.getLocalBeginLoc(),
2562 Q.getLocalEndLoc(),
2563 ObjectType, false, SS,
2564 FirstQualifierInScope, false))
2565 return NestedNameSpecifierLoc();
2566
2567 break;
2568
2569 case NestedNameSpecifier::Namespace: {
2570 NamespaceDecl *NS
2571 = cast_or_null<NamespaceDecl>(
2572 getDerived().TransformDecl(
2573 Q.getLocalBeginLoc(),
2574 QNNS->getAsNamespace()));
2575 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2576 break;
2577 }
2578
2579 case NestedNameSpecifier::NamespaceAlias: {
2580 NamespaceAliasDecl *Alias
2581 = cast_or_null<NamespaceAliasDecl>(
2582 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2583 QNNS->getAsNamespaceAlias()));
2584 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2585 Q.getLocalEndLoc());
2586 break;
2587 }
2588
2589 case NestedNameSpecifier::Global:
2590 // There is no meaningful transformation that one could perform on the
2591 // global scope.
2592 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2593 break;
2594
2595 case NestedNameSpecifier::TypeSpecWithTemplate:
2596 case NestedNameSpecifier::TypeSpec: {
2597 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2598 FirstQualifierInScope, SS);
2599
2600 if (!TL)
2601 return NestedNameSpecifierLoc();
2602
2603 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2604 (SemaRef.getLangOptions().CPlusPlus0x &&
2605 TL.getType()->isEnumeralType())) {
2606 assert(!TL.getType().hasLocalQualifiers() &&
2607 "Can't get cv-qualifiers here");
2608 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2609 Q.getLocalEndLoc());
2610 break;
2611 }
Richard Trieude756fb2011-05-07 01:36:37 +00002612 // If the nested-name-specifier is an invalid type def, don't emit an
2613 // error because a previous error should have already been emitted.
2614 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2615 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2616 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2617 << TL.getType() << SS.getRange();
2618 }
Douglas Gregor14454802011-02-25 02:25:35 +00002619 return NestedNameSpecifierLoc();
2620 }
Douglas Gregore16af532011-02-28 18:50:33 +00002621 }
Douglas Gregor14454802011-02-25 02:25:35 +00002622
Douglas Gregore16af532011-02-28 18:50:33 +00002623 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002624 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002625 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002626 }
2627
2628 // Don't rebuild the nested-name-specifier if we don't have to.
2629 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2630 !getDerived().AlwaysRebuild())
2631 return NNS;
2632
2633 // If we can re-use the source-location data from the original
2634 // nested-name-specifier, do so.
2635 if (SS.location_size() == NNS.getDataLength() &&
2636 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2637 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2638
2639 // Allocate new nested-name-specifier location information.
2640 return SS.getWithLocInContext(SemaRef.Context);
2641}
2642
2643template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002644DeclarationNameInfo
2645TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002646::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002647 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002648 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002649 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002650
2651 switch (Name.getNameKind()) {
2652 case DeclarationName::Identifier:
2653 case DeclarationName::ObjCZeroArgSelector:
2654 case DeclarationName::ObjCOneArgSelector:
2655 case DeclarationName::ObjCMultiArgSelector:
2656 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002657 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002658 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002659 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002660
Douglas Gregorf816bd72009-09-03 22:13:48 +00002661 case DeclarationName::CXXConstructorName:
2662 case DeclarationName::CXXDestructorName:
2663 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002664 TypeSourceInfo *NewTInfo;
2665 CanQualType NewCanTy;
2666 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002667 NewTInfo = getDerived().TransformType(OldTInfo);
2668 if (!NewTInfo)
2669 return DeclarationNameInfo();
2670 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002671 }
2672 else {
2673 NewTInfo = 0;
2674 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002675 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002676 if (NewT.isNull())
2677 return DeclarationNameInfo();
2678 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2679 }
Mike Stump11289f42009-09-09 15:08:12 +00002680
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002681 DeclarationName NewName
2682 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2683 NewCanTy);
2684 DeclarationNameInfo NewNameInfo(NameInfo);
2685 NewNameInfo.setName(NewName);
2686 NewNameInfo.setNamedTypeInfo(NewTInfo);
2687 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002688 }
Mike Stump11289f42009-09-09 15:08:12 +00002689 }
2690
David Blaikie83d382b2011-09-23 05:06:16 +00002691 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00002692}
2693
2694template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002695TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002696TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2697 TemplateName Name,
2698 SourceLocation NameLoc,
2699 QualType ObjectType,
2700 NamedDecl *FirstQualifierInScope) {
2701 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2702 TemplateDecl *Template = QTN->getTemplateDecl();
2703 assert(Template && "qualified template name must refer to a template");
2704
2705 TemplateDecl *TransTemplate
2706 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2707 Template));
2708 if (!TransTemplate)
2709 return TemplateName();
2710
2711 if (!getDerived().AlwaysRebuild() &&
2712 SS.getScopeRep() == QTN->getQualifier() &&
2713 TransTemplate == Template)
2714 return Name;
2715
2716 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2717 TransTemplate);
2718 }
2719
2720 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2721 if (SS.getScopeRep()) {
2722 // These apply to the scope specifier, not the template.
2723 ObjectType = QualType();
2724 FirstQualifierInScope = 0;
2725 }
2726
2727 if (!getDerived().AlwaysRebuild() &&
2728 SS.getScopeRep() == DTN->getQualifier() &&
2729 ObjectType.isNull())
2730 return Name;
2731
2732 if (DTN->isIdentifier()) {
2733 return getDerived().RebuildTemplateName(SS,
2734 *DTN->getIdentifier(),
2735 NameLoc,
2736 ObjectType,
2737 FirstQualifierInScope);
2738 }
2739
2740 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2741 ObjectType);
2742 }
2743
2744 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2745 TemplateDecl *TransTemplate
2746 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2747 Template));
2748 if (!TransTemplate)
2749 return TemplateName();
2750
2751 if (!getDerived().AlwaysRebuild() &&
2752 TransTemplate == Template)
2753 return Name;
2754
2755 return TemplateName(TransTemplate);
2756 }
2757
2758 if (SubstTemplateTemplateParmPackStorage *SubstPack
2759 = Name.getAsSubstTemplateTemplateParmPack()) {
2760 TemplateTemplateParmDecl *TransParam
2761 = cast_or_null<TemplateTemplateParmDecl>(
2762 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2763 if (!TransParam)
2764 return TemplateName();
2765
2766 if (!getDerived().AlwaysRebuild() &&
2767 TransParam == SubstPack->getParameterPack())
2768 return Name;
2769
2770 return getDerived().RebuildTemplateName(TransParam,
2771 SubstPack->getArgumentPack());
2772 }
2773
2774 // These should be getting filtered out before they reach the AST.
2775 llvm_unreachable("overloaded function decl survived to here");
2776 return TemplateName();
2777}
2778
2779template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002780void TreeTransform<Derived>::InventTemplateArgumentLoc(
2781 const TemplateArgument &Arg,
2782 TemplateArgumentLoc &Output) {
2783 SourceLocation Loc = getDerived().getBaseLocation();
2784 switch (Arg.getKind()) {
2785 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002786 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002787 break;
2788
2789 case TemplateArgument::Type:
2790 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002791 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002792
John McCall0ad16662009-10-29 08:12:44 +00002793 break;
2794
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002795 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002796 case TemplateArgument::TemplateExpansion: {
2797 NestedNameSpecifierLocBuilder Builder;
2798 TemplateName Template = Arg.getAsTemplate();
2799 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2800 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2801 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2802 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2803
2804 if (Arg.getKind() == TemplateArgument::Template)
2805 Output = TemplateArgumentLoc(Arg,
2806 Builder.getWithLocInContext(SemaRef.Context),
2807 Loc);
2808 else
2809 Output = TemplateArgumentLoc(Arg,
2810 Builder.getWithLocInContext(SemaRef.Context),
2811 Loc, Loc);
2812
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002813 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002814 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002815
John McCall0ad16662009-10-29 08:12:44 +00002816 case TemplateArgument::Expression:
2817 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2818 break;
2819
2820 case TemplateArgument::Declaration:
2821 case TemplateArgument::Integral:
2822 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002823 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002824 break;
2825 }
2826}
2827
2828template<typename Derived>
2829bool TreeTransform<Derived>::TransformTemplateArgument(
2830 const TemplateArgumentLoc &Input,
2831 TemplateArgumentLoc &Output) {
2832 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002833 switch (Arg.getKind()) {
2834 case TemplateArgument::Null:
2835 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002836 Output = Input;
2837 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002838
Douglas Gregore922c772009-08-04 22:27:00 +00002839 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002840 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002841 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002842 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002843
2844 DI = getDerived().TransformType(DI);
2845 if (!DI) return true;
2846
2847 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2848 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002849 }
Mike Stump11289f42009-09-09 15:08:12 +00002850
Douglas Gregore922c772009-08-04 22:27:00 +00002851 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002852 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002853 DeclarationName Name;
2854 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2855 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002856 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002857 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002858 if (!D) return true;
2859
John McCall0d07eb32009-10-29 18:45:58 +00002860 Expr *SourceExpr = Input.getSourceDeclExpression();
2861 if (SourceExpr) {
2862 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002863 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002864 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002865 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002866 }
2867
2868 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002869 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002870 }
Mike Stump11289f42009-09-09 15:08:12 +00002871
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002872 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002873 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2874 if (QualifierLoc) {
2875 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2876 if (!QualifierLoc)
2877 return true;
2878 }
2879
Douglas Gregordf846d12011-03-02 18:46:51 +00002880 CXXScopeSpec SS;
2881 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002882 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002883 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2884 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002885 if (Template.isNull())
2886 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002887
Douglas Gregor9d802122011-03-02 17:09:35 +00002888 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002889 Input.getTemplateNameLoc());
2890 return false;
2891 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002892
2893 case TemplateArgument::TemplateExpansion:
2894 llvm_unreachable("Caller should expand pack expansions");
2895
Douglas Gregore922c772009-08-04 22:27:00 +00002896 case TemplateArgument::Expression: {
2897 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002898 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002899 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002900
John McCall0ad16662009-10-29 08:12:44 +00002901 Expr *InputExpr = Input.getSourceExpression();
2902 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2903
Chris Lattnercdb591a2011-04-25 20:37:58 +00002904 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002905 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002906 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002907 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002908 }
Mike Stump11289f42009-09-09 15:08:12 +00002909
Douglas Gregore922c772009-08-04 22:27:00 +00002910 case TemplateArgument::Pack: {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002911 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregore922c772009-08-04 22:27:00 +00002912 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002913 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002914 AEnd = Arg.pack_end();
2915 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002916
John McCall0ad16662009-10-29 08:12:44 +00002917 // FIXME: preserve source information here when we start
2918 // caring about parameter packs.
2919
John McCall0d07eb32009-10-29 18:45:58 +00002920 TemplateArgumentLoc InputArg;
2921 TemplateArgumentLoc OutputArg;
2922 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2923 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002924 return true;
2925
John McCall0d07eb32009-10-29 18:45:58 +00002926 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002927 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002928
2929 TemplateArgument *TransformedArgsPtr
2930 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2931 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2932 TransformedArgsPtr);
2933 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2934 TransformedArgs.size()),
2935 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002936 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002937 }
2938 }
Mike Stump11289f42009-09-09 15:08:12 +00002939
Douglas Gregore922c772009-08-04 22:27:00 +00002940 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002941 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002942}
2943
Douglas Gregorfe921a72010-12-20 23:36:19 +00002944/// \brief Iterator adaptor that invents template argument location information
2945/// for each of the template arguments in its underlying iterator.
2946template<typename Derived, typename InputIterator>
2947class TemplateArgumentLocInventIterator {
2948 TreeTransform<Derived> &Self;
2949 InputIterator Iter;
2950
2951public:
2952 typedef TemplateArgumentLoc value_type;
2953 typedef TemplateArgumentLoc reference;
2954 typedef typename std::iterator_traits<InputIterator>::difference_type
2955 difference_type;
2956 typedef std::input_iterator_tag iterator_category;
2957
2958 class pointer {
2959 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002960
Douglas Gregorfe921a72010-12-20 23:36:19 +00002961 public:
2962 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2963
2964 const TemplateArgumentLoc *operator->() const { return &Arg; }
2965 };
2966
2967 TemplateArgumentLocInventIterator() { }
2968
2969 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2970 InputIterator Iter)
2971 : Self(Self), Iter(Iter) { }
2972
2973 TemplateArgumentLocInventIterator &operator++() {
2974 ++Iter;
2975 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002976 }
2977
Douglas Gregorfe921a72010-12-20 23:36:19 +00002978 TemplateArgumentLocInventIterator operator++(int) {
2979 TemplateArgumentLocInventIterator Old(*this);
2980 ++(*this);
2981 return Old;
2982 }
2983
2984 reference operator*() const {
2985 TemplateArgumentLoc Result;
2986 Self.InventTemplateArgumentLoc(*Iter, Result);
2987 return Result;
2988 }
2989
2990 pointer operator->() const { return pointer(**this); }
2991
2992 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2993 const TemplateArgumentLocInventIterator &Y) {
2994 return X.Iter == Y.Iter;
2995 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002996
Douglas Gregorfe921a72010-12-20 23:36:19 +00002997 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2998 const TemplateArgumentLocInventIterator &Y) {
2999 return X.Iter != Y.Iter;
3000 }
3001};
3002
Douglas Gregor42cafa82010-12-20 17:42:22 +00003003template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003004template<typename InputIterator>
3005bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3006 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003007 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003008 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003009 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003010 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003011
3012 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3013 // Unpack argument packs, which we translate them into separate
3014 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003015 // FIXME: We could do much better if we could guarantee that the
3016 // TemplateArgumentLocInfo for the pack expansion would be usable for
3017 // all of the template arguments in the argument pack.
3018 typedef TemplateArgumentLocInventIterator<Derived,
3019 TemplateArgument::pack_iterator>
3020 PackLocIterator;
3021 if (TransformTemplateArguments(PackLocIterator(*this,
3022 In.getArgument().pack_begin()),
3023 PackLocIterator(*this,
3024 In.getArgument().pack_end()),
3025 Outputs))
3026 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003027
3028 continue;
3029 }
3030
3031 if (In.getArgument().isPackExpansion()) {
3032 // We have a pack expansion, for which we will be substituting into
3033 // the pattern.
3034 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003035 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003036 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003037 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3038 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003039
Chris Lattner01cf8db2011-07-20 06:58:45 +00003040 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003041 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3042 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3043
3044 // Determine whether the set of unexpanded parameter packs can and should
3045 // be expanded.
3046 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003047 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003048 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003049 if (getDerived().TryExpandParameterPacks(Ellipsis,
3050 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003051 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003052 Expand,
3053 RetainExpansion,
3054 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003055 return true;
3056
3057 if (!Expand) {
3058 // The transform has determined that we should perform a simple
3059 // transformation on the pack expansion, producing another pack
3060 // expansion.
3061 TemplateArgumentLoc OutPattern;
3062 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3063 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3064 return true;
3065
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003066 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3067 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003068 if (Out.getArgument().isNull())
3069 return true;
3070
3071 Outputs.addArgument(Out);
3072 continue;
3073 }
3074
3075 // The transform has determined that we should perform an elementwise
3076 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003077 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003078 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3079
3080 if (getDerived().TransformTemplateArgument(Pattern, Out))
3081 return true;
3082
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003083 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003084 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3085 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003086 if (Out.getArgument().isNull())
3087 return true;
3088 }
3089
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003090 Outputs.addArgument(Out);
3091 }
3092
Douglas Gregor48d24112011-01-10 20:53:55 +00003093 // If we're supposed to retain a pack expansion, do so by temporarily
3094 // forgetting the partially-substituted parameter pack.
3095 if (RetainExpansion) {
3096 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3097
3098 if (getDerived().TransformTemplateArgument(Pattern, Out))
3099 return true;
3100
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003101 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3102 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003103 if (Out.getArgument().isNull())
3104 return true;
3105
3106 Outputs.addArgument(Out);
3107 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003108
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003109 continue;
3110 }
3111
3112 // The simple case:
3113 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003114 return true;
3115
3116 Outputs.addArgument(Out);
3117 }
3118
3119 return false;
3120
3121}
3122
Douglas Gregord6ff3322009-08-04 16:50:30 +00003123//===----------------------------------------------------------------------===//
3124// Type transformation
3125//===----------------------------------------------------------------------===//
3126
3127template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003128QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003129 if (getDerived().AlreadyTransformed(T))
3130 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003131
John McCall550e0c22009-10-21 00:40:46 +00003132 // Temporary workaround. All of these transformations should
3133 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003134 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3135 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003136
John McCall31f82722010-11-12 08:19:04 +00003137 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003138
John McCall550e0c22009-10-21 00:40:46 +00003139 if (!NewDI)
3140 return QualType();
3141
3142 return NewDI->getType();
3143}
3144
3145template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003146TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003147 if (getDerived().AlreadyTransformed(DI->getType()))
3148 return DI;
3149
3150 TypeLocBuilder TLB;
3151
3152 TypeLoc TL = DI->getTypeLoc();
3153 TLB.reserve(TL.getFullDataSize());
3154
John McCall31f82722010-11-12 08:19:04 +00003155 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003156 if (Result.isNull())
3157 return 0;
3158
John McCallbcd03502009-12-07 02:54:59 +00003159 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003160}
3161
3162template<typename Derived>
3163QualType
John McCall31f82722010-11-12 08:19:04 +00003164TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003165 switch (T.getTypeLocClass()) {
3166#define ABSTRACT_TYPELOC(CLASS, PARENT)
3167#define TYPELOC(CLASS, PARENT) \
3168 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003169 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003170#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003171 }
Mike Stump11289f42009-09-09 15:08:12 +00003172
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003173 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003174 return QualType();
3175}
3176
3177/// FIXME: By default, this routine adds type qualifiers only to types
3178/// that can have qualifiers, and silently suppresses those qualifiers
3179/// that are not permitted (e.g., qualifiers on reference or function
3180/// types). This is the right thing for template instantiation, but
3181/// probably not for other clients.
3182template<typename Derived>
3183QualType
3184TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003185 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003186 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003187
John McCall31f82722010-11-12 08:19:04 +00003188 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003189 if (Result.isNull())
3190 return QualType();
3191
3192 // Silently suppress qualifiers if the result type can't be qualified.
3193 // FIXME: this is the right thing for template instantiation, but
3194 // probably not for other clients.
3195 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003196 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003197
John McCall31168b02011-06-15 23:02:42 +00003198 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003199 // resulting type.
3200 if (Quals.hasObjCLifetime()) {
3201 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3202 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003203 else if (Result.getObjCLifetime()) {
Douglas Gregore46db902011-06-17 22:11:49 +00003204 // Objective-C ARC:
3205 // A lifetime qualifier applied to a substituted template parameter
3206 // overrides the lifetime qualifier from the template argument.
3207 if (const SubstTemplateTypeParmType *SubstTypeParam
3208 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3209 QualType Replacement = SubstTypeParam->getReplacementType();
3210 Qualifiers Qs = Replacement.getQualifiers();
3211 Qs.removeObjCLifetime();
3212 Replacement
3213 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3214 Qs);
3215 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3216 SubstTypeParam->getReplacedParameter(),
3217 Replacement);
3218 TLB.TypeWasModifiedSafely(Result);
3219 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003220 // Otherwise, complain about the addition of a qualifier to an
3221 // already-qualified type.
3222 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003223 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003224 << Result << R;
3225
Douglas Gregore46db902011-06-17 22:11:49 +00003226 Quals.removeObjCLifetime();
3227 }
3228 }
3229 }
John McCallcb0f89a2010-06-05 06:41:15 +00003230 if (!Quals.empty()) {
3231 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3232 TLB.push<QualifiedTypeLoc>(Result);
3233 // No location information to preserve.
3234 }
John McCall550e0c22009-10-21 00:40:46 +00003235
3236 return Result;
3237}
3238
Douglas Gregor14454802011-02-25 02:25:35 +00003239template<typename Derived>
3240TypeLoc
3241TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3242 QualType ObjectType,
3243 NamedDecl *UnqualLookup,
3244 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003245 QualType T = TL.getType();
3246 if (getDerived().AlreadyTransformed(T))
3247 return TL;
3248
3249 TypeLocBuilder TLB;
3250 QualType Result;
3251
3252 if (isa<TemplateSpecializationType>(T)) {
3253 TemplateSpecializationTypeLoc SpecTL
3254 = cast<TemplateSpecializationTypeLoc>(TL);
3255
3256 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003257 getDerived().TransformTemplateName(SS,
3258 SpecTL.getTypePtr()->getTemplateName(),
3259 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003260 ObjectType, UnqualLookup);
3261 if (Template.isNull())
3262 return TypeLoc();
3263
3264 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3265 Template);
3266 } else if (isa<DependentTemplateSpecializationType>(T)) {
3267 DependentTemplateSpecializationTypeLoc SpecTL
3268 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3269
Douglas Gregor5a064722011-02-28 17:23:35 +00003270 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003271 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003272 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003273 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003274 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003275 if (Template.isNull())
3276 return TypeLoc();
3277
Douglas Gregor14454802011-02-25 02:25:35 +00003278 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003279 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003280 Template,
3281 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003282 } else {
3283 // Nothing special needs to be done for these.
3284 Result = getDerived().TransformType(TLB, TL);
3285 }
3286
3287 if (Result.isNull())
3288 return TypeLoc();
3289
3290 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3291}
3292
Douglas Gregor579c15f2011-03-02 18:32:08 +00003293template<typename Derived>
3294TypeSourceInfo *
3295TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3296 QualType ObjectType,
3297 NamedDecl *UnqualLookup,
3298 CXXScopeSpec &SS) {
3299 // FIXME: Painfully copy-paste from the above!
3300
3301 QualType T = TSInfo->getType();
3302 if (getDerived().AlreadyTransformed(T))
3303 return TSInfo;
3304
3305 TypeLocBuilder TLB;
3306 QualType Result;
3307
3308 TypeLoc TL = TSInfo->getTypeLoc();
3309 if (isa<TemplateSpecializationType>(T)) {
3310 TemplateSpecializationTypeLoc SpecTL
3311 = cast<TemplateSpecializationTypeLoc>(TL);
3312
3313 TemplateName Template
3314 = getDerived().TransformTemplateName(SS,
3315 SpecTL.getTypePtr()->getTemplateName(),
3316 SpecTL.getTemplateNameLoc(),
3317 ObjectType, UnqualLookup);
3318 if (Template.isNull())
3319 return 0;
3320
3321 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3322 Template);
3323 } else if (isa<DependentTemplateSpecializationType>(T)) {
3324 DependentTemplateSpecializationTypeLoc SpecTL
3325 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3326
3327 TemplateName Template
3328 = getDerived().RebuildTemplateName(SS,
3329 *SpecTL.getTypePtr()->getIdentifier(),
3330 SpecTL.getNameLoc(),
3331 ObjectType, UnqualLookup);
3332 if (Template.isNull())
3333 return 0;
3334
3335 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3336 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003337 Template,
3338 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003339 } else {
3340 // Nothing special needs to be done for these.
3341 Result = getDerived().TransformType(TLB, TL);
3342 }
3343
3344 if (Result.isNull())
3345 return 0;
3346
3347 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3348}
3349
John McCall550e0c22009-10-21 00:40:46 +00003350template <class TyLoc> static inline
3351QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3352 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3353 NewT.setNameLoc(T.getNameLoc());
3354 return T.getType();
3355}
3356
John McCall550e0c22009-10-21 00:40:46 +00003357template<typename Derived>
3358QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003359 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003360 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3361 NewT.setBuiltinLoc(T.getBuiltinLoc());
3362 if (T.needsExtraLocalData())
3363 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3364 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003365}
Mike Stump11289f42009-09-09 15:08:12 +00003366
Douglas Gregord6ff3322009-08-04 16:50:30 +00003367template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003368QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003369 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003370 // FIXME: recurse?
3371 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003372}
Mike Stump11289f42009-09-09 15:08:12 +00003373
Douglas Gregord6ff3322009-08-04 16:50:30 +00003374template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003375QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003376 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003377 QualType PointeeType
3378 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003379 if (PointeeType.isNull())
3380 return QualType();
3381
3382 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003383 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003384 // A dependent pointer type 'T *' has is being transformed such
3385 // that an Objective-C class type is being replaced for 'T'. The
3386 // resulting pointer type is an ObjCObjectPointerType, not a
3387 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003388 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003389
John McCall8b07ec22010-05-15 11:32:37 +00003390 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3391 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003392 return Result;
3393 }
John McCall31f82722010-11-12 08:19:04 +00003394
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003395 if (getDerived().AlwaysRebuild() ||
3396 PointeeType != TL.getPointeeLoc().getType()) {
3397 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3398 if (Result.isNull())
3399 return QualType();
3400 }
John McCall31168b02011-06-15 23:02:42 +00003401
3402 // Objective-C ARC can add lifetime qualifiers to the type that we're
3403 // pointing to.
3404 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3405
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003406 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3407 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003408 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003409}
Mike Stump11289f42009-09-09 15:08:12 +00003410
3411template<typename Derived>
3412QualType
John McCall550e0c22009-10-21 00:40:46 +00003413TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003414 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003415 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003416 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3417 if (PointeeType.isNull())
3418 return QualType();
3419
3420 QualType Result = TL.getType();
3421 if (getDerived().AlwaysRebuild() ||
3422 PointeeType != TL.getPointeeLoc().getType()) {
3423 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003424 TL.getSigilLoc());
3425 if (Result.isNull())
3426 return QualType();
3427 }
3428
Douglas Gregor049211a2010-04-22 16:50:51 +00003429 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003430 NewT.setSigilLoc(TL.getSigilLoc());
3431 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003432}
3433
John McCall70dd5f62009-10-30 00:06:24 +00003434/// Transforms a reference type. Note that somewhat paradoxically we
3435/// don't care whether the type itself is an l-value type or an r-value
3436/// type; we only care if the type was *written* as an l-value type
3437/// or an r-value type.
3438template<typename Derived>
3439QualType
3440TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003441 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003442 const ReferenceType *T = TL.getTypePtr();
3443
3444 // Note that this works with the pointee-as-written.
3445 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3446 if (PointeeType.isNull())
3447 return QualType();
3448
3449 QualType Result = TL.getType();
3450 if (getDerived().AlwaysRebuild() ||
3451 PointeeType != T->getPointeeTypeAsWritten()) {
3452 Result = getDerived().RebuildReferenceType(PointeeType,
3453 T->isSpelledAsLValue(),
3454 TL.getSigilLoc());
3455 if (Result.isNull())
3456 return QualType();
3457 }
3458
John McCall31168b02011-06-15 23:02:42 +00003459 // Objective-C ARC can add lifetime qualifiers to the type that we're
3460 // referring to.
3461 TLB.TypeWasModifiedSafely(
3462 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3463
John McCall70dd5f62009-10-30 00:06:24 +00003464 // r-value references can be rebuilt as l-value references.
3465 ReferenceTypeLoc NewTL;
3466 if (isa<LValueReferenceType>(Result))
3467 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3468 else
3469 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3470 NewTL.setSigilLoc(TL.getSigilLoc());
3471
3472 return Result;
3473}
3474
Mike Stump11289f42009-09-09 15:08:12 +00003475template<typename Derived>
3476QualType
John McCall550e0c22009-10-21 00:40:46 +00003477TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003478 LValueReferenceTypeLoc TL) {
3479 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003480}
3481
Mike Stump11289f42009-09-09 15:08:12 +00003482template<typename Derived>
3483QualType
John McCall550e0c22009-10-21 00:40:46 +00003484TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003485 RValueReferenceTypeLoc TL) {
3486 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003487}
Mike Stump11289f42009-09-09 15:08:12 +00003488
Douglas Gregord6ff3322009-08-04 16:50:30 +00003489template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003490QualType
John McCall550e0c22009-10-21 00:40:46 +00003491TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003492 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003493 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003494 if (PointeeType.isNull())
3495 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003496
Abramo Bagnara509357842011-03-05 14:42:21 +00003497 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3498 TypeSourceInfo* NewClsTInfo = 0;
3499 if (OldClsTInfo) {
3500 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3501 if (!NewClsTInfo)
3502 return QualType();
3503 }
3504
3505 const MemberPointerType *T = TL.getTypePtr();
3506 QualType OldClsType = QualType(T->getClass(), 0);
3507 QualType NewClsType;
3508 if (NewClsTInfo)
3509 NewClsType = NewClsTInfo->getType();
3510 else {
3511 NewClsType = getDerived().TransformType(OldClsType);
3512 if (NewClsType.isNull())
3513 return QualType();
3514 }
Mike Stump11289f42009-09-09 15:08:12 +00003515
John McCall550e0c22009-10-21 00:40:46 +00003516 QualType Result = TL.getType();
3517 if (getDerived().AlwaysRebuild() ||
3518 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003519 NewClsType != OldClsType) {
3520 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003521 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003522 if (Result.isNull())
3523 return QualType();
3524 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003525
John McCall550e0c22009-10-21 00:40:46 +00003526 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3527 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003528 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003529
3530 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003531}
3532
Mike Stump11289f42009-09-09 15:08:12 +00003533template<typename Derived>
3534QualType
John McCall550e0c22009-10-21 00:40:46 +00003535TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003536 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003537 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003538 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003539 if (ElementType.isNull())
3540 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003541
John McCall550e0c22009-10-21 00:40:46 +00003542 QualType Result = TL.getType();
3543 if (getDerived().AlwaysRebuild() ||
3544 ElementType != T->getElementType()) {
3545 Result = getDerived().RebuildConstantArrayType(ElementType,
3546 T->getSizeModifier(),
3547 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003548 T->getIndexTypeCVRQualifiers(),
3549 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003550 if (Result.isNull())
3551 return QualType();
3552 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003553
John McCall550e0c22009-10-21 00:40:46 +00003554 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3555 NewTL.setLBracketLoc(TL.getLBracketLoc());
3556 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003557
John McCall550e0c22009-10-21 00:40:46 +00003558 Expr *Size = TL.getSizeExpr();
3559 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003560 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003561 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3562 }
3563 NewTL.setSizeExpr(Size);
3564
3565 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003566}
Mike Stump11289f42009-09-09 15:08:12 +00003567
Douglas Gregord6ff3322009-08-04 16:50:30 +00003568template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003569QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003570 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003571 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003572 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003573 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003574 if (ElementType.isNull())
3575 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003576
John McCall550e0c22009-10-21 00:40:46 +00003577 QualType Result = TL.getType();
3578 if (getDerived().AlwaysRebuild() ||
3579 ElementType != T->getElementType()) {
3580 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003581 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003582 T->getIndexTypeCVRQualifiers(),
3583 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003584 if (Result.isNull())
3585 return QualType();
3586 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003587
John McCall550e0c22009-10-21 00:40:46 +00003588 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3589 NewTL.setLBracketLoc(TL.getLBracketLoc());
3590 NewTL.setRBracketLoc(TL.getRBracketLoc());
3591 NewTL.setSizeExpr(0);
3592
3593 return Result;
3594}
3595
3596template<typename Derived>
3597QualType
3598TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003599 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003600 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003601 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3602 if (ElementType.isNull())
3603 return QualType();
3604
3605 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003606 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003607
John McCalldadc5752010-08-24 06:29:42 +00003608 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003609 = getDerived().TransformExpr(T->getSizeExpr());
3610 if (SizeResult.isInvalid())
3611 return QualType();
3612
John McCallb268a282010-08-23 23:25:46 +00003613 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003614
3615 QualType Result = TL.getType();
3616 if (getDerived().AlwaysRebuild() ||
3617 ElementType != T->getElementType() ||
3618 Size != T->getSizeExpr()) {
3619 Result = getDerived().RebuildVariableArrayType(ElementType,
3620 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003621 Size,
John McCall550e0c22009-10-21 00:40:46 +00003622 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003623 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003624 if (Result.isNull())
3625 return QualType();
3626 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003627
John McCall550e0c22009-10-21 00:40:46 +00003628 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3629 NewTL.setLBracketLoc(TL.getLBracketLoc());
3630 NewTL.setRBracketLoc(TL.getRBracketLoc());
3631 NewTL.setSizeExpr(Size);
3632
3633 return Result;
3634}
3635
3636template<typename Derived>
3637QualType
3638TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003639 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003640 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003641 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3642 if (ElementType.isNull())
3643 return QualType();
3644
3645 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003646 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003647
John McCall33ddac02011-01-19 10:06:00 +00003648 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3649 Expr *origSize = TL.getSizeExpr();
3650 if (!origSize) origSize = T->getSizeExpr();
3651
3652 ExprResult sizeResult
3653 = getDerived().TransformExpr(origSize);
3654 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003655 return QualType();
3656
John McCall33ddac02011-01-19 10:06:00 +00003657 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003658
3659 QualType Result = TL.getType();
3660 if (getDerived().AlwaysRebuild() ||
3661 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003662 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003663 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3664 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003665 size,
John McCall550e0c22009-10-21 00:40:46 +00003666 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003667 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003668 if (Result.isNull())
3669 return QualType();
3670 }
John McCall550e0c22009-10-21 00:40:46 +00003671
3672 // We might have any sort of array type now, but fortunately they
3673 // all have the same location layout.
3674 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3675 NewTL.setLBracketLoc(TL.getLBracketLoc());
3676 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003677 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003678
3679 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003680}
Mike Stump11289f42009-09-09 15:08:12 +00003681
3682template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003683QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003684 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003685 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003686 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003687
3688 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003689 QualType ElementType = getDerived().TransformType(T->getElementType());
3690 if (ElementType.isNull())
3691 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003692
Douglas Gregore922c772009-08-04 22:27:00 +00003693 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003694 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003695
John McCalldadc5752010-08-24 06:29:42 +00003696 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003697 if (Size.isInvalid())
3698 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003699
John McCall550e0c22009-10-21 00:40:46 +00003700 QualType Result = TL.getType();
3701 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003702 ElementType != T->getElementType() ||
3703 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003704 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003705 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003706 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003707 if (Result.isNull())
3708 return QualType();
3709 }
John McCall550e0c22009-10-21 00:40:46 +00003710
3711 // Result might be dependent or not.
3712 if (isa<DependentSizedExtVectorType>(Result)) {
3713 DependentSizedExtVectorTypeLoc NewTL
3714 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3715 NewTL.setNameLoc(TL.getNameLoc());
3716 } else {
3717 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3718 NewTL.setNameLoc(TL.getNameLoc());
3719 }
3720
3721 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003722}
Mike Stump11289f42009-09-09 15:08:12 +00003723
3724template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003725QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003726 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003727 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003728 QualType ElementType = getDerived().TransformType(T->getElementType());
3729 if (ElementType.isNull())
3730 return QualType();
3731
John McCall550e0c22009-10-21 00:40:46 +00003732 QualType Result = TL.getType();
3733 if (getDerived().AlwaysRebuild() ||
3734 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003735 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003736 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003737 if (Result.isNull())
3738 return QualType();
3739 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003740
John McCall550e0c22009-10-21 00:40:46 +00003741 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3742 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003743
John McCall550e0c22009-10-21 00:40:46 +00003744 return Result;
3745}
3746
3747template<typename Derived>
3748QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003749 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003750 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003751 QualType ElementType = getDerived().TransformType(T->getElementType());
3752 if (ElementType.isNull())
3753 return QualType();
3754
3755 QualType Result = TL.getType();
3756 if (getDerived().AlwaysRebuild() ||
3757 ElementType != T->getElementType()) {
3758 Result = getDerived().RebuildExtVectorType(ElementType,
3759 T->getNumElements(),
3760 /*FIXME*/ SourceLocation());
3761 if (Result.isNull())
3762 return QualType();
3763 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003764
John McCall550e0c22009-10-21 00:40:46 +00003765 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3766 NewTL.setNameLoc(TL.getNameLoc());
3767
3768 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003769}
Mike Stump11289f42009-09-09 15:08:12 +00003770
3771template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003772ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003773TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003774 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003775 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003776 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003777 TypeSourceInfo *NewDI = 0;
3778
3779 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3780 // If we're substituting into a pack expansion type and we know the
3781 TypeLoc OldTL = OldDI->getTypeLoc();
3782 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3783
3784 TypeLocBuilder TLB;
3785 TypeLoc NewTL = OldDI->getTypeLoc();
3786 TLB.reserve(NewTL.getFullDataSize());
3787
3788 QualType Result = getDerived().TransformType(TLB,
3789 OldExpansionTL.getPatternLoc());
3790 if (Result.isNull())
3791 return 0;
3792
3793 Result = RebuildPackExpansionType(Result,
3794 OldExpansionTL.getPatternLoc().getSourceRange(),
3795 OldExpansionTL.getEllipsisLoc(),
3796 NumExpansions);
3797 if (Result.isNull())
3798 return 0;
3799
3800 PackExpansionTypeLoc NewExpansionTL
3801 = TLB.push<PackExpansionTypeLoc>(Result);
3802 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3803 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3804 } else
3805 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003806 if (!NewDI)
3807 return 0;
3808
John McCall8fb0d9d2011-05-01 22:35:37 +00003809 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003810 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003811
3812 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3813 OldParm->getDeclContext(),
3814 OldParm->getInnerLocStart(),
3815 OldParm->getLocation(),
3816 OldParm->getIdentifier(),
3817 NewDI->getType(),
3818 NewDI,
3819 OldParm->getStorageClass(),
3820 OldParm->getStorageClassAsWritten(),
3821 /* DefArg */ NULL);
3822 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3823 OldParm->getFunctionScopeIndex() + indexAdjustment);
3824 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003825}
3826
3827template<typename Derived>
3828bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003829 TransformFunctionTypeParams(SourceLocation Loc,
3830 ParmVarDecl **Params, unsigned NumParams,
3831 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003832 SmallVectorImpl<QualType> &OutParamTypes,
3833 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003834 int indexAdjustment = 0;
3835
Douglas Gregordd472162011-01-07 00:20:55 +00003836 for (unsigned i = 0; i != NumParams; ++i) {
3837 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003838 assert(OldParm->getFunctionScopeIndex() == i);
3839
Douglas Gregor715e4612011-01-14 22:40:04 +00003840 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003841 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003842 if (OldParm->isParameterPack()) {
3843 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00003844 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003845
Douglas Gregor5499af42011-01-05 23:12:31 +00003846 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003847 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3848 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3849 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3850 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003851 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3852
Douglas Gregor5499af42011-01-05 23:12:31 +00003853 // Determine whether we should expand the parameter packs.
3854 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003855 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003856 llvm::Optional<unsigned> OrigNumExpansions
3857 = ExpansionTL.getTypePtr()->getNumExpansions();
3858 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003859 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3860 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003861 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003862 ShouldExpand,
3863 RetainExpansion,
3864 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003865 return true;
3866 }
3867
3868 if (ShouldExpand) {
3869 // Expand the function parameter pack into multiple, separate
3870 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003871 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003872 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003873 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3874 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003875 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003876 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003877 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003878 if (!NewParm)
3879 return true;
3880
Douglas Gregordd472162011-01-07 00:20:55 +00003881 OutParamTypes.push_back(NewParm->getType());
3882 if (PVars)
3883 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003884 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003885
3886 // If we're supposed to retain a pack expansion, do so by temporarily
3887 // forgetting the partially-substituted parameter pack.
3888 if (RetainExpansion) {
3889 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3890 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003891 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003892 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003893 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003894 if (!NewParm)
3895 return true;
3896
3897 OutParamTypes.push_back(NewParm->getType());
3898 if (PVars)
3899 PVars->push_back(NewParm);
3900 }
3901
John McCall8fb0d9d2011-05-01 22:35:37 +00003902 // The next parameter should have the same adjustment as the
3903 // last thing we pushed, but we post-incremented indexAdjustment
3904 // on every push. Also, if we push nothing, the adjustment should
3905 // go down by one.
3906 indexAdjustment--;
3907
Douglas Gregor5499af42011-01-05 23:12:31 +00003908 // We're done with the pack expansion.
3909 continue;
3910 }
3911
3912 // We'll substitute the parameter now without expanding the pack
3913 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003914 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3915 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003916 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003917 NumExpansions);
3918 } else {
3919 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003920 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003921 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003922 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003923
John McCall58f10c32010-03-11 09:03:00 +00003924 if (!NewParm)
3925 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003926
Douglas Gregordd472162011-01-07 00:20:55 +00003927 OutParamTypes.push_back(NewParm->getType());
3928 if (PVars)
3929 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003930 continue;
3931 }
John McCall58f10c32010-03-11 09:03:00 +00003932
3933 // Deal with the possibility that we don't have a parameter
3934 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003935 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003936 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003937 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003938 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003939 if (const PackExpansionType *Expansion
3940 = dyn_cast<PackExpansionType>(OldType)) {
3941 // We have a function parameter pack that may need to be expanded.
3942 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00003943 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00003944 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3945
3946 // Determine whether we should expand the parameter packs.
3947 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003948 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003949 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003950 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003951 ShouldExpand,
3952 RetainExpansion,
3953 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003954 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003955 }
3956
3957 if (ShouldExpand) {
3958 // Expand the function parameter pack into multiple, separate
3959 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003960 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003961 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3962 QualType NewType = getDerived().TransformType(Pattern);
3963 if (NewType.isNull())
3964 return true;
John McCall58f10c32010-03-11 09:03:00 +00003965
Douglas Gregordd472162011-01-07 00:20:55 +00003966 OutParamTypes.push_back(NewType);
3967 if (PVars)
3968 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003969 }
3970
3971 // We're done with the pack expansion.
3972 continue;
3973 }
3974
Douglas Gregor48d24112011-01-10 20:53:55 +00003975 // If we're supposed to retain a pack expansion, do so by temporarily
3976 // forgetting the partially-substituted parameter pack.
3977 if (RetainExpansion) {
3978 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3979 QualType NewType = getDerived().TransformType(Pattern);
3980 if (NewType.isNull())
3981 return true;
3982
3983 OutParamTypes.push_back(NewType);
3984 if (PVars)
3985 PVars->push_back(0);
3986 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003987
Douglas Gregor5499af42011-01-05 23:12:31 +00003988 // We'll substitute the parameter now without expanding the pack
3989 // expansion.
3990 OldType = Expansion->getPattern();
3991 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003992 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3993 NewType = getDerived().TransformType(OldType);
3994 } else {
3995 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003996 }
3997
Douglas Gregor5499af42011-01-05 23:12:31 +00003998 if (NewType.isNull())
3999 return true;
4000
4001 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004002 NewType = getSema().Context.getPackExpansionType(NewType,
4003 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00004004
Douglas Gregordd472162011-01-07 00:20:55 +00004005 OutParamTypes.push_back(NewType);
4006 if (PVars)
4007 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004008 }
4009
John McCall8fb0d9d2011-05-01 22:35:37 +00004010#ifndef NDEBUG
4011 if (PVars) {
4012 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4013 if (ParmVarDecl *parm = (*PVars)[i])
4014 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004015 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004016#endif
4017
4018 return false;
4019}
John McCall58f10c32010-03-11 09:03:00 +00004020
4021template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004022QualType
John McCall550e0c22009-10-21 00:40:46 +00004023TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004024 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004025 // Transform the parameters and return type.
4026 //
4027 // We instantiate in source order, with the return type first followed by
4028 // the parameters, because users tend to expect this (even if they shouldn't
4029 // rely on it!).
4030 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00004031 // When the function has a trailing return type, we instantiate the
4032 // parameters before the return type, since the return type can then refer
4033 // to the parameters themselves (via decltype, sizeof, etc.).
4034 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004035 SmallVector<QualType, 4> ParamTypes;
4036 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004037 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004038
Douglas Gregor7fb25412010-10-01 18:44:50 +00004039 QualType ResultType;
4040
4041 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004042 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4043 TL.getParmArray(),
4044 TL.getNumArgs(),
4045 TL.getTypePtr()->arg_type_begin(),
4046 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004047 return QualType();
4048
4049 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4050 if (ResultType.isNull())
4051 return QualType();
4052 }
4053 else {
4054 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4055 if (ResultType.isNull())
4056 return QualType();
4057
Douglas Gregordd472162011-01-07 00:20:55 +00004058 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4059 TL.getParmArray(),
4060 TL.getNumArgs(),
4061 TL.getTypePtr()->arg_type_begin(),
4062 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004063 return QualType();
4064 }
4065
John McCall550e0c22009-10-21 00:40:46 +00004066 QualType Result = TL.getType();
4067 if (getDerived().AlwaysRebuild() ||
4068 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004069 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004070 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4071 Result = getDerived().RebuildFunctionProtoType(ResultType,
4072 ParamTypes.data(),
4073 ParamTypes.size(),
4074 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004075 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004076 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004077 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004078 if (Result.isNull())
4079 return QualType();
4080 }
Mike Stump11289f42009-09-09 15:08:12 +00004081
John McCall550e0c22009-10-21 00:40:46 +00004082 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004083 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4084 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004085 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004086 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4087 NewTL.setArg(i, ParamDecls[i]);
4088
4089 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004090}
Mike Stump11289f42009-09-09 15:08:12 +00004091
Douglas Gregord6ff3322009-08-04 16:50:30 +00004092template<typename Derived>
4093QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004094 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004095 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004096 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004097 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4098 if (ResultType.isNull())
4099 return QualType();
4100
4101 QualType Result = TL.getType();
4102 if (getDerived().AlwaysRebuild() ||
4103 ResultType != T->getResultType())
4104 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4105
4106 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004107 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4108 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004109 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004110
4111 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004112}
Mike Stump11289f42009-09-09 15:08:12 +00004113
John McCallb96ec562009-12-04 22:46:56 +00004114template<typename Derived> QualType
4115TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004116 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004117 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004118 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004119 if (!D)
4120 return QualType();
4121
4122 QualType Result = TL.getType();
4123 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4124 Result = getDerived().RebuildUnresolvedUsingType(D);
4125 if (Result.isNull())
4126 return QualType();
4127 }
4128
4129 // We might get an arbitrary type spec type back. We should at
4130 // least always get a type spec type, though.
4131 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4132 NewTL.setNameLoc(TL.getNameLoc());
4133
4134 return Result;
4135}
4136
Douglas Gregord6ff3322009-08-04 16:50:30 +00004137template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004138QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004139 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004140 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004141 TypedefNameDecl *Typedef
4142 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4143 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004144 if (!Typedef)
4145 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004146
John McCall550e0c22009-10-21 00:40:46 +00004147 QualType Result = TL.getType();
4148 if (getDerived().AlwaysRebuild() ||
4149 Typedef != T->getDecl()) {
4150 Result = getDerived().RebuildTypedefType(Typedef);
4151 if (Result.isNull())
4152 return QualType();
4153 }
Mike Stump11289f42009-09-09 15:08:12 +00004154
John McCall550e0c22009-10-21 00:40:46 +00004155 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4156 NewTL.setNameLoc(TL.getNameLoc());
4157
4158 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004159}
Mike Stump11289f42009-09-09 15:08:12 +00004160
Douglas Gregord6ff3322009-08-04 16:50:30 +00004161template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004162QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004163 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004164 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004165 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004166
John McCalldadc5752010-08-24 06:29:42 +00004167 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004168 if (E.isInvalid())
4169 return QualType();
4170
John McCall550e0c22009-10-21 00:40:46 +00004171 QualType Result = TL.getType();
4172 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004173 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004174 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004175 if (Result.isNull())
4176 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004177 }
John McCall550e0c22009-10-21 00:40:46 +00004178 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004179
John McCall550e0c22009-10-21 00:40:46 +00004180 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004181 NewTL.setTypeofLoc(TL.getTypeofLoc());
4182 NewTL.setLParenLoc(TL.getLParenLoc());
4183 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004184
4185 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004186}
Mike Stump11289f42009-09-09 15:08:12 +00004187
4188template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004189QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004190 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004191 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4192 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4193 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004194 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004195
John McCall550e0c22009-10-21 00:40:46 +00004196 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004197 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4198 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004199 if (Result.isNull())
4200 return QualType();
4201 }
Mike Stump11289f42009-09-09 15:08:12 +00004202
John McCall550e0c22009-10-21 00:40:46 +00004203 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004204 NewTL.setTypeofLoc(TL.getTypeofLoc());
4205 NewTL.setLParenLoc(TL.getLParenLoc());
4206 NewTL.setRParenLoc(TL.getRParenLoc());
4207 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004208
4209 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004210}
Mike Stump11289f42009-09-09 15:08:12 +00004211
4212template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004213QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004214 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004215 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004216
Douglas Gregore922c772009-08-04 22:27:00 +00004217 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004218 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004219
John McCalldadc5752010-08-24 06:29:42 +00004220 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004221 if (E.isInvalid())
4222 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004223
John McCall550e0c22009-10-21 00:40:46 +00004224 QualType Result = TL.getType();
4225 if (getDerived().AlwaysRebuild() ||
4226 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004227 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004228 if (Result.isNull())
4229 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004230 }
John McCall550e0c22009-10-21 00:40:46 +00004231 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004232
John McCall550e0c22009-10-21 00:40:46 +00004233 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4234 NewTL.setNameLoc(TL.getNameLoc());
4235
4236 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004237}
4238
4239template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004240QualType TreeTransform<Derived>::TransformUnaryTransformType(
4241 TypeLocBuilder &TLB,
4242 UnaryTransformTypeLoc TL) {
4243 QualType Result = TL.getType();
4244 if (Result->isDependentType()) {
4245 const UnaryTransformType *T = TL.getTypePtr();
4246 QualType NewBase =
4247 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4248 Result = getDerived().RebuildUnaryTransformType(NewBase,
4249 T->getUTTKind(),
4250 TL.getKWLoc());
4251 if (Result.isNull())
4252 return QualType();
4253 }
4254
4255 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4256 NewTL.setKWLoc(TL.getKWLoc());
4257 NewTL.setParensRange(TL.getParensRange());
4258 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4259 return Result;
4260}
4261
4262template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004263QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4264 AutoTypeLoc TL) {
4265 const AutoType *T = TL.getTypePtr();
4266 QualType OldDeduced = T->getDeducedType();
4267 QualType NewDeduced;
4268 if (!OldDeduced.isNull()) {
4269 NewDeduced = getDerived().TransformType(OldDeduced);
4270 if (NewDeduced.isNull())
4271 return QualType();
4272 }
4273
4274 QualType Result = TL.getType();
4275 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4276 Result = getDerived().RebuildAutoType(NewDeduced);
4277 if (Result.isNull())
4278 return QualType();
4279 }
4280
4281 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4282 NewTL.setNameLoc(TL.getNameLoc());
4283
4284 return Result;
4285}
4286
4287template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004288QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004289 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004290 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004291 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004292 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4293 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004294 if (!Record)
4295 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004296
John McCall550e0c22009-10-21 00:40:46 +00004297 QualType Result = TL.getType();
4298 if (getDerived().AlwaysRebuild() ||
4299 Record != T->getDecl()) {
4300 Result = getDerived().RebuildRecordType(Record);
4301 if (Result.isNull())
4302 return QualType();
4303 }
Mike Stump11289f42009-09-09 15:08:12 +00004304
John McCall550e0c22009-10-21 00:40:46 +00004305 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4306 NewTL.setNameLoc(TL.getNameLoc());
4307
4308 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004309}
Mike Stump11289f42009-09-09 15:08:12 +00004310
4311template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004312QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004313 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004314 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004315 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004316 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4317 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004318 if (!Enum)
4319 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004320
John McCall550e0c22009-10-21 00:40:46 +00004321 QualType Result = TL.getType();
4322 if (getDerived().AlwaysRebuild() ||
4323 Enum != T->getDecl()) {
4324 Result = getDerived().RebuildEnumType(Enum);
4325 if (Result.isNull())
4326 return QualType();
4327 }
Mike Stump11289f42009-09-09 15:08:12 +00004328
John McCall550e0c22009-10-21 00:40:46 +00004329 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4330 NewTL.setNameLoc(TL.getNameLoc());
4331
4332 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004333}
John McCallfcc33b02009-09-05 00:15:47 +00004334
John McCalle78aac42010-03-10 03:28:59 +00004335template<typename Derived>
4336QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4337 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004338 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004339 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4340 TL.getTypePtr()->getDecl());
4341 if (!D) return QualType();
4342
4343 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4344 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4345 return T;
4346}
4347
Douglas Gregord6ff3322009-08-04 16:50:30 +00004348template<typename Derived>
4349QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004350 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004351 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004352 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004353}
4354
Mike Stump11289f42009-09-09 15:08:12 +00004355template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004356QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004357 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004358 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004359 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4360
4361 // Substitute into the replacement type, which itself might involve something
4362 // that needs to be transformed. This only tends to occur with default
4363 // template arguments of template template parameters.
4364 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4365 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4366 if (Replacement.isNull())
4367 return QualType();
4368
4369 // Always canonicalize the replacement type.
4370 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4371 QualType Result
4372 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4373 Replacement);
4374
4375 // Propagate type-source information.
4376 SubstTemplateTypeParmTypeLoc NewTL
4377 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4378 NewTL.setNameLoc(TL.getNameLoc());
4379 return Result;
4380
John McCallcebee162009-10-18 09:09:24 +00004381}
4382
4383template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004384QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4385 TypeLocBuilder &TLB,
4386 SubstTemplateTypeParmPackTypeLoc TL) {
4387 return TransformTypeSpecType(TLB, TL);
4388}
4389
4390template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004391QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004392 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004393 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004394 const TemplateSpecializationType *T = TL.getTypePtr();
4395
Douglas Gregordf846d12011-03-02 18:46:51 +00004396 // The nested-name-specifier never matters in a TemplateSpecializationType,
4397 // because we can't have a dependent nested-name-specifier anyway.
4398 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004399 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004400 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4401 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004402 if (Template.isNull())
4403 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004404
John McCall31f82722010-11-12 08:19:04 +00004405 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4406}
4407
Eli Friedman0dfb8892011-10-06 23:00:33 +00004408template<typename Derived>
4409QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4410 AtomicTypeLoc TL) {
4411 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4412 if (ValueType.isNull())
4413 return QualType();
4414
4415 QualType Result = TL.getType();
4416 if (getDerived().AlwaysRebuild() ||
4417 ValueType != TL.getValueLoc().getType()) {
4418 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4419 if (Result.isNull())
4420 return QualType();
4421 }
4422
4423 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4424 NewTL.setKWLoc(TL.getKWLoc());
4425 NewTL.setLParenLoc(TL.getLParenLoc());
4426 NewTL.setRParenLoc(TL.getRParenLoc());
4427
4428 return Result;
4429}
4430
Douglas Gregorfe921a72010-12-20 23:36:19 +00004431namespace {
4432 /// \brief Simple iterator that traverses the template arguments in a
4433 /// container that provides a \c getArgLoc() member function.
4434 ///
4435 /// This iterator is intended to be used with the iterator form of
4436 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4437 template<typename ArgLocContainer>
4438 class TemplateArgumentLocContainerIterator {
4439 ArgLocContainer *Container;
4440 unsigned Index;
4441
4442 public:
4443 typedef TemplateArgumentLoc value_type;
4444 typedef TemplateArgumentLoc reference;
4445 typedef int difference_type;
4446 typedef std::input_iterator_tag iterator_category;
4447
4448 class pointer {
4449 TemplateArgumentLoc Arg;
4450
4451 public:
4452 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4453
4454 const TemplateArgumentLoc *operator->() const {
4455 return &Arg;
4456 }
4457 };
4458
4459
4460 TemplateArgumentLocContainerIterator() {}
4461
4462 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4463 unsigned Index)
4464 : Container(&Container), Index(Index) { }
4465
4466 TemplateArgumentLocContainerIterator &operator++() {
4467 ++Index;
4468 return *this;
4469 }
4470
4471 TemplateArgumentLocContainerIterator operator++(int) {
4472 TemplateArgumentLocContainerIterator Old(*this);
4473 ++(*this);
4474 return Old;
4475 }
4476
4477 TemplateArgumentLoc operator*() const {
4478 return Container->getArgLoc(Index);
4479 }
4480
4481 pointer operator->() const {
4482 return pointer(Container->getArgLoc(Index));
4483 }
4484
4485 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004486 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004487 return X.Container == Y.Container && X.Index == Y.Index;
4488 }
4489
4490 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004491 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004492 return !(X == Y);
4493 }
4494 };
4495}
4496
4497
John McCall31f82722010-11-12 08:19:04 +00004498template <typename Derived>
4499QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4500 TypeLocBuilder &TLB,
4501 TemplateSpecializationTypeLoc TL,
4502 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004503 TemplateArgumentListInfo NewTemplateArgs;
4504 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4505 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004506 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4507 ArgIterator;
4508 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4509 ArgIterator(TL, TL.getNumArgs()),
4510 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004511 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004512
John McCall0ad16662009-10-29 08:12:44 +00004513 // FIXME: maybe don't rebuild if all the template arguments are the same.
4514
4515 QualType Result =
4516 getDerived().RebuildTemplateSpecializationType(Template,
4517 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004518 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004519
4520 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004521 // Specializations of template template parameters are represented as
4522 // TemplateSpecializationTypes, and substitution of type alias templates
4523 // within a dependent context can transform them into
4524 // DependentTemplateSpecializationTypes.
4525 if (isa<DependentTemplateSpecializationType>(Result)) {
4526 DependentTemplateSpecializationTypeLoc NewTL
4527 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4528 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4529 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4530 NewTL.setNameLoc(TL.getTemplateNameLoc());
4531 NewTL.setLAngleLoc(TL.getLAngleLoc());
4532 NewTL.setRAngleLoc(TL.getRAngleLoc());
4533 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4534 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4535 return Result;
4536 }
4537
John McCall0ad16662009-10-29 08:12:44 +00004538 TemplateSpecializationTypeLoc NewTL
4539 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4540 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4541 NewTL.setLAngleLoc(TL.getLAngleLoc());
4542 NewTL.setRAngleLoc(TL.getRAngleLoc());
4543 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4544 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004545 }
Mike Stump11289f42009-09-09 15:08:12 +00004546
John McCall0ad16662009-10-29 08:12:44 +00004547 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004548}
Mike Stump11289f42009-09-09 15:08:12 +00004549
Douglas Gregor5a064722011-02-28 17:23:35 +00004550template <typename Derived>
4551QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4552 TypeLocBuilder &TLB,
4553 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004554 TemplateName Template,
4555 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004556 TemplateArgumentListInfo NewTemplateArgs;
4557 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4558 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4559 typedef TemplateArgumentLocContainerIterator<
4560 DependentTemplateSpecializationTypeLoc> ArgIterator;
4561 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4562 ArgIterator(TL, TL.getNumArgs()),
4563 NewTemplateArgs))
4564 return QualType();
4565
4566 // FIXME: maybe don't rebuild if all the template arguments are the same.
4567
4568 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4569 QualType Result
4570 = getSema().Context.getDependentTemplateSpecializationType(
4571 TL.getTypePtr()->getKeyword(),
4572 DTN->getQualifier(),
4573 DTN->getIdentifier(),
4574 NewTemplateArgs);
4575
4576 DependentTemplateSpecializationTypeLoc NewTL
4577 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4578 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004579
Douglas Gregora7a795b2011-03-01 20:11:18 +00004580 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004581 NewTL.setNameLoc(TL.getNameLoc());
4582 NewTL.setLAngleLoc(TL.getLAngleLoc());
4583 NewTL.setRAngleLoc(TL.getRAngleLoc());
4584 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4585 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4586 return Result;
4587 }
4588
4589 QualType Result
4590 = getDerived().RebuildTemplateSpecializationType(Template,
4591 TL.getNameLoc(),
4592 NewTemplateArgs);
4593
4594 if (!Result.isNull()) {
4595 /// FIXME: Wrap this in an elaborated-type-specifier?
4596 TemplateSpecializationTypeLoc NewTL
4597 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4598 NewTL.setTemplateNameLoc(TL.getNameLoc());
4599 NewTL.setLAngleLoc(TL.getLAngleLoc());
4600 NewTL.setRAngleLoc(TL.getRAngleLoc());
4601 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4602 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4603 }
4604
4605 return Result;
4606}
4607
Mike Stump11289f42009-09-09 15:08:12 +00004608template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004609QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004610TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004611 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004612 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004613
Douglas Gregor844cb502011-03-01 18:12:44 +00004614 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004615 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004616 if (TL.getQualifierLoc()) {
4617 QualifierLoc
4618 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4619 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004620 return QualType();
4621 }
Mike Stump11289f42009-09-09 15:08:12 +00004622
John McCall31f82722010-11-12 08:19:04 +00004623 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4624 if (NamedT.isNull())
4625 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004626
Richard Smith3f1b5d02011-05-05 21:57:07 +00004627 // C++0x [dcl.type.elab]p2:
4628 // If the identifier resolves to a typedef-name or the simple-template-id
4629 // resolves to an alias template specialization, the
4630 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004631 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4632 if (const TemplateSpecializationType *TST =
4633 NamedT->getAs<TemplateSpecializationType>()) {
4634 TemplateName Template = TST->getTemplateName();
4635 if (TypeAliasTemplateDecl *TAT =
4636 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4637 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4638 diag::err_tag_reference_non_tag) << 4;
4639 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4640 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004641 }
4642 }
4643
John McCall550e0c22009-10-21 00:40:46 +00004644 QualType Result = TL.getType();
4645 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004646 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004647 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004648 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004649 T->getKeyword(),
4650 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004651 if (Result.isNull())
4652 return QualType();
4653 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004654
Abramo Bagnara6150c882010-05-11 21:36:43 +00004655 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004656 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004657 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004658 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004659}
Mike Stump11289f42009-09-09 15:08:12 +00004660
4661template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004662QualType TreeTransform<Derived>::TransformAttributedType(
4663 TypeLocBuilder &TLB,
4664 AttributedTypeLoc TL) {
4665 const AttributedType *oldType = TL.getTypePtr();
4666 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4667 if (modifiedType.isNull())
4668 return QualType();
4669
4670 QualType result = TL.getType();
4671
4672 // FIXME: dependent operand expressions?
4673 if (getDerived().AlwaysRebuild() ||
4674 modifiedType != oldType->getModifiedType()) {
4675 // TODO: this is really lame; we should really be rebuilding the
4676 // equivalent type from first principles.
4677 QualType equivalentType
4678 = getDerived().TransformType(oldType->getEquivalentType());
4679 if (equivalentType.isNull())
4680 return QualType();
4681 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4682 modifiedType,
4683 equivalentType);
4684 }
4685
4686 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4687 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4688 if (TL.hasAttrOperand())
4689 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4690 if (TL.hasAttrExprOperand())
4691 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4692 else if (TL.hasAttrEnumOperand())
4693 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4694
4695 return result;
4696}
4697
4698template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004699QualType
4700TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4701 ParenTypeLoc TL) {
4702 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4703 if (Inner.isNull())
4704 return QualType();
4705
4706 QualType Result = TL.getType();
4707 if (getDerived().AlwaysRebuild() ||
4708 Inner != TL.getInnerLoc().getType()) {
4709 Result = getDerived().RebuildParenType(Inner);
4710 if (Result.isNull())
4711 return QualType();
4712 }
4713
4714 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4715 NewTL.setLParenLoc(TL.getLParenLoc());
4716 NewTL.setRParenLoc(TL.getRParenLoc());
4717 return Result;
4718}
4719
4720template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004721QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004722 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004723 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004724
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004725 NestedNameSpecifierLoc QualifierLoc
4726 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4727 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004728 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004729
John McCallc392f372010-06-11 00:33:02 +00004730 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004731 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004732 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004733 QualifierLoc,
4734 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004735 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004736 if (Result.isNull())
4737 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004738
Abramo Bagnarad7548482010-05-19 21:37:53 +00004739 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4740 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004741 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4742
Abramo Bagnarad7548482010-05-19 21:37:53 +00004743 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4744 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004745 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004746 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004747 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4748 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004749 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004750 NewTL.setNameLoc(TL.getNameLoc());
4751 }
John McCall550e0c22009-10-21 00:40:46 +00004752 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004753}
Mike Stump11289f42009-09-09 15:08:12 +00004754
Douglas Gregord6ff3322009-08-04 16:50:30 +00004755template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004756QualType TreeTransform<Derived>::
4757 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004758 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004759 NestedNameSpecifierLoc QualifierLoc;
4760 if (TL.getQualifierLoc()) {
4761 QualifierLoc
4762 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4763 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004764 return QualType();
4765 }
4766
John McCall31f82722010-11-12 08:19:04 +00004767 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004768 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004769}
4770
4771template<typename Derived>
4772QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004773TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4774 DependentTemplateSpecializationTypeLoc TL,
4775 NestedNameSpecifierLoc QualifierLoc) {
4776 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4777
4778 TemplateArgumentListInfo NewTemplateArgs;
4779 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4780 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4781
4782 typedef TemplateArgumentLocContainerIterator<
4783 DependentTemplateSpecializationTypeLoc> ArgIterator;
4784 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4785 ArgIterator(TL, TL.getNumArgs()),
4786 NewTemplateArgs))
4787 return QualType();
4788
4789 QualType Result
4790 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4791 QualifierLoc,
4792 T->getIdentifier(),
4793 TL.getNameLoc(),
4794 NewTemplateArgs);
4795 if (Result.isNull())
4796 return QualType();
4797
4798 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4799 QualType NamedT = ElabT->getNamedType();
4800
4801 // Copy information relevant to the template specialization.
4802 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004803 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004804 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004805 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4806 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004807 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004808 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004809
4810 // Copy information relevant to the elaborated type.
4811 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4812 NewTL.setKeywordLoc(TL.getKeywordLoc());
4813 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004814 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4815 DependentTemplateSpecializationTypeLoc SpecTL
4816 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004817 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004818 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004819 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004820 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4821 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004822 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004823 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004824 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004825 TemplateSpecializationTypeLoc SpecTL
4826 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004827 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004828 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4829 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004830 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004831 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004832 }
4833 return Result;
4834}
4835
4836template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004837QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4838 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004839 QualType Pattern
4840 = getDerived().TransformType(TLB, TL.getPatternLoc());
4841 if (Pattern.isNull())
4842 return QualType();
4843
4844 QualType Result = TL.getType();
4845 if (getDerived().AlwaysRebuild() ||
4846 Pattern != TL.getPatternLoc().getType()) {
4847 Result = getDerived().RebuildPackExpansionType(Pattern,
4848 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004849 TL.getEllipsisLoc(),
4850 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004851 if (Result.isNull())
4852 return QualType();
4853 }
4854
4855 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4856 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4857 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004858}
4859
4860template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004861QualType
4862TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004863 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004864 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004865 TLB.pushFullCopy(TL);
4866 return TL.getType();
4867}
4868
4869template<typename Derived>
4870QualType
4871TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004872 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004873 // ObjCObjectType is never dependent.
4874 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004875 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004876}
Mike Stump11289f42009-09-09 15:08:12 +00004877
4878template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004879QualType
4880TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004881 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004882 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004883 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004884 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004885}
4886
Douglas Gregord6ff3322009-08-04 16:50:30 +00004887//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004888// Statement transformation
4889//===----------------------------------------------------------------------===//
4890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004891StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004892TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004893 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004894}
4895
4896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004897StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004898TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4899 return getDerived().TransformCompoundStmt(S, false);
4900}
4901
4902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004903StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004904TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004905 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004906 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004907 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004908 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004909 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4910 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004911 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004912 if (Result.isInvalid()) {
4913 // Immediately fail if this was a DeclStmt, since it's very
4914 // likely that this will cause problems for future statements.
4915 if (isa<DeclStmt>(*B))
4916 return StmtError();
4917
4918 // Otherwise, just keep processing substatements and fail later.
4919 SubStmtInvalid = true;
4920 continue;
4921 }
Mike Stump11289f42009-09-09 15:08:12 +00004922
Douglas Gregorebe10102009-08-20 07:17:43 +00004923 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4924 Statements.push_back(Result.takeAs<Stmt>());
4925 }
Mike Stump11289f42009-09-09 15:08:12 +00004926
John McCall1ababa62010-08-27 19:56:05 +00004927 if (SubStmtInvalid)
4928 return StmtError();
4929
Douglas Gregorebe10102009-08-20 07:17:43 +00004930 if (!getDerived().AlwaysRebuild() &&
4931 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004932 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004933
4934 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4935 move_arg(Statements),
4936 S->getRBracLoc(),
4937 IsStmtExpr);
4938}
Mike Stump11289f42009-09-09 15:08:12 +00004939
Douglas Gregorebe10102009-08-20 07:17:43 +00004940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004941StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004942TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004943 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004944 {
4945 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004946 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004947
Eli Friedman06577382009-11-19 03:14:00 +00004948 // Transform the left-hand case value.
4949 LHS = getDerived().TransformExpr(S->getLHS());
4950 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004951 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004952
Eli Friedman06577382009-11-19 03:14:00 +00004953 // Transform the right-hand case value (for the GNU case-range extension).
4954 RHS = getDerived().TransformExpr(S->getRHS());
4955 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004956 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004957 }
Mike Stump11289f42009-09-09 15:08:12 +00004958
Douglas Gregorebe10102009-08-20 07:17:43 +00004959 // Build the case statement.
4960 // Case statements are always rebuilt so that they will attached to their
4961 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004962 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004963 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004964 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004965 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004966 S->getColonLoc());
4967 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004968 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004969
Douglas Gregorebe10102009-08-20 07:17:43 +00004970 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004971 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004972 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004973 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004974
Douglas Gregorebe10102009-08-20 07:17:43 +00004975 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004976 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004977}
4978
4979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004980StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004981TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004982 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004983 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004984 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004985 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004986
Douglas Gregorebe10102009-08-20 07:17:43 +00004987 // Default statements are always rebuilt
4988 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004989 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004990}
Mike Stump11289f42009-09-09 15:08:12 +00004991
Douglas Gregorebe10102009-08-20 07:17:43 +00004992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004993StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004994TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004995 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004996 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004997 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004998
Chris Lattnercab02a62011-02-17 20:34:02 +00004999 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5000 S->getDecl());
5001 if (!LD)
5002 return StmtError();
5003
5004
Douglas Gregorebe10102009-08-20 07:17:43 +00005005 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005006 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005007 cast<LabelDecl>(LD), SourceLocation(),
5008 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005009}
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregorebe10102009-08-20 07:17:43 +00005011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005012StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005013TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005014 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005015 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005016 VarDecl *ConditionVar = 0;
5017 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005018 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005019 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005020 getDerived().TransformDefinition(
5021 S->getConditionVariable()->getLocation(),
5022 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005023 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005024 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005025 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005026 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005027
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005028 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005029 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005030
5031 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005032 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005033 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5034 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005035 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005036 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005037
John McCallb268a282010-08-23 23:25:46 +00005038 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005039 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005040 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005041
John McCallb268a282010-08-23 23:25:46 +00005042 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5043 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005044 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005045
Douglas Gregorebe10102009-08-20 07:17:43 +00005046 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005047 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005048 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005049 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005050
Douglas Gregorebe10102009-08-20 07:17:43 +00005051 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005052 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005053 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005054 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005055
Douglas Gregorebe10102009-08-20 07:17:43 +00005056 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005057 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005058 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005059 Then.get() == S->getThen() &&
5060 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005061 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005062
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005063 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005064 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005065 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005066}
5067
5068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005069StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005070TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005071 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005072 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005073 VarDecl *ConditionVar = 0;
5074 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005075 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005076 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005077 getDerived().TransformDefinition(
5078 S->getConditionVariable()->getLocation(),
5079 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005080 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005081 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005082 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005083 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005084
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005085 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005086 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005087 }
Mike Stump11289f42009-09-09 15:08:12 +00005088
Douglas Gregorebe10102009-08-20 07:17:43 +00005089 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005090 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005091 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005092 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005093 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005094 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005095
Douglas Gregorebe10102009-08-20 07:17:43 +00005096 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005097 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005098 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005099 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005100
Douglas Gregorebe10102009-08-20 07:17:43 +00005101 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005102 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5103 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005104}
Mike Stump11289f42009-09-09 15:08:12 +00005105
Douglas Gregorebe10102009-08-20 07:17:43 +00005106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005107StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005108TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005109 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005110 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005111 VarDecl *ConditionVar = 0;
5112 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005113 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005114 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005115 getDerived().TransformDefinition(
5116 S->getConditionVariable()->getLocation(),
5117 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005118 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005119 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005120 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005121 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005122
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005123 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005124 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005125
5126 if (S->getCond()) {
5127 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005128 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5129 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005130 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005131 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005132 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005133 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005134 }
Mike Stump11289f42009-09-09 15:08:12 +00005135
John McCallb268a282010-08-23 23:25:46 +00005136 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5137 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005138 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005139
Douglas Gregorebe10102009-08-20 07:17:43 +00005140 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005141 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005142 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005143 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005144
Douglas Gregorebe10102009-08-20 07:17:43 +00005145 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005146 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005147 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005148 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005149 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005151 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005152 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005153}
Mike Stump11289f42009-09-09 15:08:12 +00005154
Douglas Gregorebe10102009-08-20 07:17:43 +00005155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005156StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005157TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005158 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005159 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005160 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005161 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005162
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005163 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005164 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005165 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005166 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005167
Douglas Gregorebe10102009-08-20 07:17:43 +00005168 if (!getDerived().AlwaysRebuild() &&
5169 Cond.get() == S->getCond() &&
5170 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005171 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005172
John McCallb268a282010-08-23 23:25:46 +00005173 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5174 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005175 S->getRParenLoc());
5176}
Mike Stump11289f42009-09-09 15:08:12 +00005177
Douglas Gregorebe10102009-08-20 07:17:43 +00005178template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005179StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005180TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005181 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005182 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005183 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005184 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005185
Douglas Gregorebe10102009-08-20 07:17:43 +00005186 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005187 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005188 VarDecl *ConditionVar = 0;
5189 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005190 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005191 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005192 getDerived().TransformDefinition(
5193 S->getConditionVariable()->getLocation(),
5194 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005195 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005196 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005197 } else {
5198 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005199
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005200 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005201 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005202
5203 if (S->getCond()) {
5204 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005205 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5206 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005207 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005208 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005209
John McCallb268a282010-08-23 23:25:46 +00005210 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005211 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005212 }
Mike Stump11289f42009-09-09 15:08:12 +00005213
John McCallb268a282010-08-23 23:25:46 +00005214 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5215 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005216 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005217
Douglas Gregorebe10102009-08-20 07:17:43 +00005218 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005219 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005220 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005221 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005222
John McCallb268a282010-08-23 23:25:46 +00005223 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5224 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005225 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005226
Douglas Gregorebe10102009-08-20 07:17:43 +00005227 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005228 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005229 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005230 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005231
Douglas Gregorebe10102009-08-20 07:17:43 +00005232 if (!getDerived().AlwaysRebuild() &&
5233 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005234 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005235 Inc.get() == S->getInc() &&
5236 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005237 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005238
Douglas Gregorebe10102009-08-20 07:17:43 +00005239 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005240 Init.get(), FullCond, ConditionVar,
5241 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005242}
5243
5244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005245StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005246TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005247 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5248 S->getLabel());
5249 if (!LD)
5250 return StmtError();
5251
Douglas Gregorebe10102009-08-20 07:17:43 +00005252 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005253 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005254 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005255}
5256
5257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005258StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005259TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005260 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005261 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005262 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005263
Douglas Gregorebe10102009-08-20 07:17:43 +00005264 if (!getDerived().AlwaysRebuild() &&
5265 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005266 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005267
5268 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005269 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005270}
5271
5272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005273StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005274TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005275 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005276}
Mike Stump11289f42009-09-09 15:08:12 +00005277
Douglas Gregorebe10102009-08-20 07:17:43 +00005278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005279StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005280TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005281 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005282}
Mike Stump11289f42009-09-09 15:08:12 +00005283
Douglas Gregorebe10102009-08-20 07:17:43 +00005284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005285StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005286TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005287 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005288 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005289 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005290
Mike Stump11289f42009-09-09 15:08:12 +00005291 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005292 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005293 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005294}
Mike Stump11289f42009-09-09 15:08:12 +00005295
Douglas Gregorebe10102009-08-20 07:17:43 +00005296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005297StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005298TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005299 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005300 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005301 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5302 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005303 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5304 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005305 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005306 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005307
Douglas Gregorebe10102009-08-20 07:17:43 +00005308 if (Transformed != *D)
5309 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005310
Douglas Gregorebe10102009-08-20 07:17:43 +00005311 Decls.push_back(Transformed);
5312 }
Mike Stump11289f42009-09-09 15:08:12 +00005313
Douglas Gregorebe10102009-08-20 07:17:43 +00005314 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005315 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005316
5317 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005318 S->getStartLoc(), S->getEndLoc());
5319}
Mike Stump11289f42009-09-09 15:08:12 +00005320
Douglas Gregorebe10102009-08-20 07:17:43 +00005321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005322StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005323TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005324
John McCall37ad5512010-08-23 06:44:23 +00005325 ASTOwningVector<Expr*> Constraints(getSema());
5326 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner01cf8db2011-07-20 06:58:45 +00005327 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005328
John McCalldadc5752010-08-24 06:29:42 +00005329 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005330 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005331
5332 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005333
Anders Carlssonaaeef072010-01-24 05:50:09 +00005334 // Go through the outputs.
5335 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005336 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005337
Anders Carlssonaaeef072010-01-24 05:50:09 +00005338 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005339 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005340
Anders Carlssonaaeef072010-01-24 05:50:09 +00005341 // Transform the output expr.
5342 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005343 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005344 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005345 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005346
Anders Carlssonaaeef072010-01-24 05:50:09 +00005347 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005348
John McCallb268a282010-08-23 23:25:46 +00005349 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005350 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005351
Anders Carlssonaaeef072010-01-24 05:50:09 +00005352 // Go through the inputs.
5353 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005354 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005355
Anders Carlssonaaeef072010-01-24 05:50:09 +00005356 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005357 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005358
Anders Carlssonaaeef072010-01-24 05:50:09 +00005359 // Transform the input expr.
5360 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005361 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005362 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005363 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005364
Anders Carlssonaaeef072010-01-24 05:50:09 +00005365 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005366
John McCallb268a282010-08-23 23:25:46 +00005367 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005368 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005369
Anders Carlssonaaeef072010-01-24 05:50:09 +00005370 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005371 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005372
5373 // Go through the clobbers.
5374 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005375 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005376
5377 // No need to transform the asm string literal.
5378 AsmString = SemaRef.Owned(S->getAsmString());
5379
5380 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5381 S->isSimple(),
5382 S->isVolatile(),
5383 S->getNumOutputs(),
5384 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005385 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005386 move_arg(Constraints),
5387 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005388 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005389 move_arg(Clobbers),
5390 S->getRParenLoc(),
5391 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005392}
5393
5394
5395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005396StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005397TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005398 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005399 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005400 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005401 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005402
Douglas Gregor96c79492010-04-23 22:50:49 +00005403 // Transform the @catch statements (if present).
5404 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005405 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005406 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005407 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005408 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005409 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005410 if (Catch.get() != S->getCatchStmt(I))
5411 AnyCatchChanged = true;
5412 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005413 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005414
Douglas Gregor306de2f2010-04-22 23:59:56 +00005415 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005416 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005417 if (S->getFinallyStmt()) {
5418 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5419 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005420 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005421 }
5422
5423 // If nothing changed, just retain this statement.
5424 if (!getDerived().AlwaysRebuild() &&
5425 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005426 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005427 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005428 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005429
Douglas Gregor306de2f2010-04-22 23:59:56 +00005430 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005431 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5432 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005433}
Mike Stump11289f42009-09-09 15:08:12 +00005434
Douglas Gregorebe10102009-08-20 07:17:43 +00005435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005436StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005437TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005438 // Transform the @catch parameter, if there is one.
5439 VarDecl *Var = 0;
5440 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5441 TypeSourceInfo *TSInfo = 0;
5442 if (FromVar->getTypeSourceInfo()) {
5443 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5444 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005445 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005446 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005447
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005448 QualType T;
5449 if (TSInfo)
5450 T = TSInfo->getType();
5451 else {
5452 T = getDerived().TransformType(FromVar->getType());
5453 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005454 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005455 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005456
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005457 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5458 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005459 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005460 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005461
John McCalldadc5752010-08-24 06:29:42 +00005462 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005463 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005464 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005465
5466 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005467 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005468 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005469}
Mike Stump11289f42009-09-09 15:08:12 +00005470
Douglas Gregorebe10102009-08-20 07:17:43 +00005471template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005472StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005473TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005474 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005475 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005476 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005477 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005478
Douglas Gregor306de2f2010-04-22 23:59:56 +00005479 // If nothing changed, just retain this statement.
5480 if (!getDerived().AlwaysRebuild() &&
5481 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005482 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005483
5484 // Build a new statement.
5485 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005486 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005487}
Mike Stump11289f42009-09-09 15:08:12 +00005488
Douglas Gregorebe10102009-08-20 07:17:43 +00005489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005490StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005491TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005492 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005493 if (S->getThrowExpr()) {
5494 Operand = getDerived().TransformExpr(S->getThrowExpr());
5495 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005496 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005497 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005498
Douglas Gregor2900c162010-04-22 21:44:01 +00005499 if (!getDerived().AlwaysRebuild() &&
5500 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005501 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005502
John McCallb268a282010-08-23 23:25:46 +00005503 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005504}
Mike Stump11289f42009-09-09 15:08:12 +00005505
Douglas Gregorebe10102009-08-20 07:17:43 +00005506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005507StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005508TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005509 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005510 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005511 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005512 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005513 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005514 Object =
5515 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5516 Object.get());
5517 if (Object.isInvalid())
5518 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005519
Douglas Gregor6148de72010-04-22 22:01:21 +00005520 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005521 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005522 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005523 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005524
Douglas Gregor6148de72010-04-22 22:01:21 +00005525 // If nothing change, just retain the current statement.
5526 if (!getDerived().AlwaysRebuild() &&
5527 Object.get() == S->getSynchExpr() &&
5528 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005529 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005530
5531 // Build a new statement.
5532 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005533 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005534}
5535
5536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005537StmtResult
John McCall31168b02011-06-15 23:02:42 +00005538TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5539 ObjCAutoreleasePoolStmt *S) {
5540 // Transform the body.
5541 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5542 if (Body.isInvalid())
5543 return StmtError();
5544
5545 // If nothing changed, just retain this statement.
5546 if (!getDerived().AlwaysRebuild() &&
5547 Body.get() == S->getSubStmt())
5548 return SemaRef.Owned(S);
5549
5550 // Build a new statement.
5551 return getDerived().RebuildObjCAutoreleasePoolStmt(
5552 S->getAtLoc(), Body.get());
5553}
5554
5555template<typename Derived>
5556StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005557TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005558 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005559 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005560 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005561 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005562 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005563
Douglas Gregorf68a5082010-04-22 23:10:45 +00005564 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005565 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005566 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005567 return StmtError();
John McCall53848232011-07-27 01:07:15 +00005568 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5569 Collection.take());
5570 if (Collection.isInvalid())
5571 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005572
Douglas Gregorf68a5082010-04-22 23:10:45 +00005573 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005574 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005575 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005576 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005577
Douglas Gregorf68a5082010-04-22 23:10:45 +00005578 // If nothing changed, just retain this statement.
5579 if (!getDerived().AlwaysRebuild() &&
5580 Element.get() == S->getElement() &&
5581 Collection.get() == S->getCollection() &&
5582 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005583 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005584
Douglas Gregorf68a5082010-04-22 23:10:45 +00005585 // Build a new statement.
5586 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5587 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005588 Element.get(),
5589 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005590 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005591 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005592}
5593
5594
5595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005596StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005597TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5598 // Transform the exception declaration, if any.
5599 VarDecl *Var = 0;
5600 if (S->getExceptionDecl()) {
5601 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005602 TypeSourceInfo *T = getDerived().TransformType(
5603 ExceptionDecl->getTypeSourceInfo());
5604 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005605 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005606
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005607 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005608 ExceptionDecl->getInnerLocStart(),
5609 ExceptionDecl->getLocation(),
5610 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005611 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005612 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005613 }
Mike Stump11289f42009-09-09 15:08:12 +00005614
Douglas Gregorebe10102009-08-20 07:17:43 +00005615 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005616 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005617 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005618 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005619
Douglas Gregorebe10102009-08-20 07:17:43 +00005620 if (!getDerived().AlwaysRebuild() &&
5621 !Var &&
5622 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005623 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005624
5625 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5626 Var,
John McCallb268a282010-08-23 23:25:46 +00005627 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005628}
Mike Stump11289f42009-09-09 15:08:12 +00005629
Douglas Gregorebe10102009-08-20 07:17:43 +00005630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005631StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005632TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5633 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005634 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005635 = getDerived().TransformCompoundStmt(S->getTryBlock());
5636 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005637 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005638
Douglas Gregorebe10102009-08-20 07:17:43 +00005639 // Transform the handlers.
5640 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005641 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005642 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005643 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005644 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5645 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005646 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005647
Douglas Gregorebe10102009-08-20 07:17:43 +00005648 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5649 Handlers.push_back(Handler.takeAs<Stmt>());
5650 }
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregorebe10102009-08-20 07:17:43 +00005652 if (!getDerived().AlwaysRebuild() &&
5653 TryBlock.get() == S->getTryBlock() &&
5654 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005655 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005656
John McCallb268a282010-08-23 23:25:46 +00005657 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005658 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005659}
Mike Stump11289f42009-09-09 15:08:12 +00005660
Richard Smith02e85f32011-04-14 22:09:26 +00005661template<typename Derived>
5662StmtResult
5663TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5664 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5665 if (Range.isInvalid())
5666 return StmtError();
5667
5668 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5669 if (BeginEnd.isInvalid())
5670 return StmtError();
5671
5672 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5673 if (Cond.isInvalid())
5674 return StmtError();
5675
5676 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5677 if (Inc.isInvalid())
5678 return StmtError();
5679
5680 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5681 if (LoopVar.isInvalid())
5682 return StmtError();
5683
5684 StmtResult NewStmt = S;
5685 if (getDerived().AlwaysRebuild() ||
5686 Range.get() != S->getRangeStmt() ||
5687 BeginEnd.get() != S->getBeginEndStmt() ||
5688 Cond.get() != S->getCond() ||
5689 Inc.get() != S->getInc() ||
5690 LoopVar.get() != S->getLoopVarStmt())
5691 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5692 S->getColonLoc(), Range.get(),
5693 BeginEnd.get(), Cond.get(),
5694 Inc.get(), LoopVar.get(),
5695 S->getRParenLoc());
5696
5697 StmtResult Body = getDerived().TransformStmt(S->getBody());
5698 if (Body.isInvalid())
5699 return StmtError();
5700
5701 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5702 // it now so we have a new statement to attach the body to.
5703 if (Body.get() != S->getBody() && NewStmt.get() == S)
5704 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5705 S->getColonLoc(), Range.get(),
5706 BeginEnd.get(), Cond.get(),
5707 Inc.get(), LoopVar.get(),
5708 S->getRParenLoc());
5709
5710 if (NewStmt.get() == S)
5711 return SemaRef.Owned(S);
5712
5713 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5714}
5715
John Wiegley1c0675e2011-04-28 01:08:34 +00005716template<typename Derived>
5717StmtResult
5718TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5719 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5720 if(TryBlock.isInvalid()) return StmtError();
5721
5722 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5723 if(!getDerived().AlwaysRebuild() &&
5724 TryBlock.get() == S->getTryBlock() &&
5725 Handler.get() == S->getHandler())
5726 return SemaRef.Owned(S);
5727
5728 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5729 S->getTryLoc(),
5730 TryBlock.take(),
5731 Handler.take());
5732}
5733
5734template<typename Derived>
5735StmtResult
5736TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5737 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5738 if(Block.isInvalid()) return StmtError();
5739
5740 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5741 Block.take());
5742}
5743
5744template<typename Derived>
5745StmtResult
5746TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5747 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5748 if(FilterExpr.isInvalid()) return StmtError();
5749
5750 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5751 if(Block.isInvalid()) return StmtError();
5752
5753 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5754 FilterExpr.take(),
5755 Block.take());
5756}
5757
5758template<typename Derived>
5759StmtResult
5760TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5761 if(isa<SEHFinallyStmt>(Handler))
5762 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5763 else
5764 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5765}
5766
Douglas Gregorebe10102009-08-20 07:17:43 +00005767//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005768// Expression transformation
5769//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005771ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005772TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005773 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005774}
Mike Stump11289f42009-09-09 15:08:12 +00005775
5776template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005777ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005778TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005779 NestedNameSpecifierLoc QualifierLoc;
5780 if (E->getQualifierLoc()) {
5781 QualifierLoc
5782 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5783 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005784 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005785 }
John McCallce546572009-12-08 09:08:17 +00005786
5787 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005788 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5789 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005790 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005791 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005792
John McCall815039a2010-08-17 21:27:17 +00005793 DeclarationNameInfo NameInfo = E->getNameInfo();
5794 if (NameInfo.getName()) {
5795 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5796 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005797 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005798 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005799
5800 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005801 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005802 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005803 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005804 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005805
5806 // Mark it referenced in the new context regardless.
5807 // FIXME: this is a bit instantiation-specific.
5808 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5809
John McCallc3007a22010-10-26 07:05:15 +00005810 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005811 }
John McCallce546572009-12-08 09:08:17 +00005812
5813 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005814 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005815 TemplateArgs = &TransArgs;
5816 TransArgs.setLAngleLoc(E->getLAngleLoc());
5817 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005818 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5819 E->getNumTemplateArgs(),
5820 TransArgs))
5821 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005822 }
5823
Douglas Gregorea972d32011-02-28 21:54:11 +00005824 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5825 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005826}
Mike Stump11289f42009-09-09 15:08:12 +00005827
Douglas Gregora16548e2009-08-11 05:31:07 +00005828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005829ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005830TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005831 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005832}
Mike Stump11289f42009-09-09 15:08:12 +00005833
Douglas Gregora16548e2009-08-11 05:31:07 +00005834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005835ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005836TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005837 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005838}
Mike Stump11289f42009-09-09 15:08:12 +00005839
Douglas Gregora16548e2009-08-11 05:31:07 +00005840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005841ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005842TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005843 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005844}
Mike Stump11289f42009-09-09 15:08:12 +00005845
Douglas Gregora16548e2009-08-11 05:31:07 +00005846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005847ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005848TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005849 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005850}
Mike Stump11289f42009-09-09 15:08:12 +00005851
Douglas Gregora16548e2009-08-11 05:31:07 +00005852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005854TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005855 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005856}
5857
5858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005859ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005860TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5861 ExprResult ControllingExpr =
5862 getDerived().TransformExpr(E->getControllingExpr());
5863 if (ControllingExpr.isInvalid())
5864 return ExprError();
5865
Chris Lattner01cf8db2011-07-20 06:58:45 +00005866 SmallVector<Expr *, 4> AssocExprs;
5867 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00005868 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5869 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5870 if (TS) {
5871 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5872 if (!AssocType)
5873 return ExprError();
5874 AssocTypes.push_back(AssocType);
5875 } else {
5876 AssocTypes.push_back(0);
5877 }
5878
5879 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5880 if (AssocExpr.isInvalid())
5881 return ExprError();
5882 AssocExprs.push_back(AssocExpr.release());
5883 }
5884
5885 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5886 E->getDefaultLoc(),
5887 E->getRParenLoc(),
5888 ControllingExpr.release(),
5889 AssocTypes.data(),
5890 AssocExprs.data(),
5891 E->getNumAssocs());
5892}
5893
5894template<typename Derived>
5895ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005896TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005897 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005898 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005899 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005900
Douglas Gregora16548e2009-08-11 05:31:07 +00005901 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005902 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005903
John McCallb268a282010-08-23 23:25:46 +00005904 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005905 E->getRParen());
5906}
5907
Mike Stump11289f42009-09-09 15:08:12 +00005908template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005909ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005910TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005911 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005912 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005913 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005914
Douglas Gregora16548e2009-08-11 05:31:07 +00005915 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005916 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005917
Douglas Gregora16548e2009-08-11 05:31:07 +00005918 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5919 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005920 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005921}
Mike Stump11289f42009-09-09 15:08:12 +00005922
Douglas Gregora16548e2009-08-11 05:31:07 +00005923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005924ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005925TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5926 // Transform the type.
5927 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5928 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005929 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005930
Douglas Gregor882211c2010-04-28 22:16:22 +00005931 // Transform all of the components into components similar to what the
5932 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005933 // FIXME: It would be slightly more efficient in the non-dependent case to
5934 // just map FieldDecls, rather than requiring the rebuilder to look for
5935 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005936 // template code that we don't care.
5937 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005938 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005939 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005940 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00005941 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5942 const Node &ON = E->getComponent(I);
5943 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005944 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005945 Comp.LocStart = ON.getSourceRange().getBegin();
5946 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005947 switch (ON.getKind()) {
5948 case Node::Array: {
5949 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005950 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005951 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005952 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005953
Douglas Gregor882211c2010-04-28 22:16:22 +00005954 ExprChanged = ExprChanged || Index.get() != FromIndex;
5955 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005956 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005957 break;
5958 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005959
Douglas Gregor882211c2010-04-28 22:16:22 +00005960 case Node::Field:
5961 case Node::Identifier:
5962 Comp.isBrackets = false;
5963 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005964 if (!Comp.U.IdentInfo)
5965 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005966
Douglas Gregor882211c2010-04-28 22:16:22 +00005967 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005968
Douglas Gregord1702062010-04-29 00:18:15 +00005969 case Node::Base:
5970 // Will be recomputed during the rebuild.
5971 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005972 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005973
Douglas Gregor882211c2010-04-28 22:16:22 +00005974 Components.push_back(Comp);
5975 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005976
Douglas Gregor882211c2010-04-28 22:16:22 +00005977 // If nothing changed, retain the existing expression.
5978 if (!getDerived().AlwaysRebuild() &&
5979 Type == E->getTypeSourceInfo() &&
5980 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005981 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005982
Douglas Gregor882211c2010-04-28 22:16:22 +00005983 // Build a new offsetof expression.
5984 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5985 Components.data(), Components.size(),
5986 E->getRParenLoc());
5987}
5988
5989template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005990ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005991TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5992 assert(getDerived().AlreadyTransformed(E->getType()) &&
5993 "opaque value expression requires transformation");
5994 return SemaRef.Owned(E);
5995}
5996
5997template<typename Derived>
5998ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005999TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6000 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006001 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006002 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006003
John McCallbcd03502009-12-07 02:54:59 +00006004 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006005 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006006 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006007
John McCall4c98fd82009-11-04 07:28:41 +00006008 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006009 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006010
Peter Collingbournee190dee2011-03-11 19:24:49 +00006011 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6012 E->getKind(),
6013 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 }
Mike Stump11289f42009-09-09 15:08:12 +00006015
John McCalldadc5752010-08-24 06:29:42 +00006016 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00006017 {
Douglas Gregora16548e2009-08-11 05:31:07 +00006018 // C++0x [expr.sizeof]p1:
6019 // The operand is either an expression, which is an unevaluated operand
6020 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00006021 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006022
Douglas Gregora16548e2009-08-11 05:31:07 +00006023 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6024 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006025 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006026
Douglas Gregora16548e2009-08-11 05:31:07 +00006027 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00006028 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006029 }
Mike Stump11289f42009-09-09 15:08:12 +00006030
Peter Collingbournee190dee2011-03-11 19:24:49 +00006031 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6032 E->getOperatorLoc(),
6033 E->getKind(),
6034 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006035}
Mike Stump11289f42009-09-09 15:08:12 +00006036
Douglas Gregora16548e2009-08-11 05:31:07 +00006037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006038ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006039TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006040 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006041 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006043
John McCalldadc5752010-08-24 06:29:42 +00006044 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006045 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006046 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006047
6048
Douglas Gregora16548e2009-08-11 05:31:07 +00006049 if (!getDerived().AlwaysRebuild() &&
6050 LHS.get() == E->getLHS() &&
6051 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006052 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006053
John McCallb268a282010-08-23 23:25:46 +00006054 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006055 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006056 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006057 E->getRBracketLoc());
6058}
Mike Stump11289f42009-09-09 15:08:12 +00006059
6060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006061ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006062TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006063 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006064 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006065 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006066 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006067
6068 // Transform arguments.
6069 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006070 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006071 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6072 &ArgChanged))
6073 return ExprError();
6074
Douglas Gregora16548e2009-08-11 05:31:07 +00006075 if (!getDerived().AlwaysRebuild() &&
6076 Callee.get() == E->getCallee() &&
6077 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006078 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006079
Douglas Gregora16548e2009-08-11 05:31:07 +00006080 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006081 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006082 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006083 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006084 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006085 E->getRParenLoc());
6086}
Mike Stump11289f42009-09-09 15:08:12 +00006087
6088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006089ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006090TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006091 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006092 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006093 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006094
Douglas Gregorea972d32011-02-28 21:54:11 +00006095 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006096 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006097 QualifierLoc
6098 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6099
6100 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006101 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006102 }
Mike Stump11289f42009-09-09 15:08:12 +00006103
Eli Friedman2cfcef62009-12-04 06:40:45 +00006104 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006105 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6106 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006107 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006108 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006109
John McCall16df1e52010-03-30 21:47:33 +00006110 NamedDecl *FoundDecl = E->getFoundDecl();
6111 if (FoundDecl == E->getMemberDecl()) {
6112 FoundDecl = Member;
6113 } else {
6114 FoundDecl = cast_or_null<NamedDecl>(
6115 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6116 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006117 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006118 }
6119
Douglas Gregora16548e2009-08-11 05:31:07 +00006120 if (!getDerived().AlwaysRebuild() &&
6121 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006122 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006123 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006124 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006125 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006126
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006127 // Mark it referenced in the new context regardless.
6128 // FIXME: this is a bit instantiation-specific.
6129 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00006130 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006131 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006132
John McCall6b51f282009-11-23 01:53:49 +00006133 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006134 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006135 TransArgs.setLAngleLoc(E->getLAngleLoc());
6136 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006137 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6138 E->getNumTemplateArgs(),
6139 TransArgs))
6140 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006141 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006142
Douglas Gregora16548e2009-08-11 05:31:07 +00006143 // FIXME: Bogus source location for the operator
6144 SourceLocation FakeOperatorLoc
6145 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6146
John McCall38836f02010-01-15 08:34:02 +00006147 // FIXME: to do this check properly, we will need to preserve the
6148 // first-qualifier-in-scope here, just in case we had a dependent
6149 // base (and therefore couldn't do the check) and a
6150 // nested-name-qualifier (and therefore could do the lookup).
6151 NamedDecl *FirstQualifierInScope = 0;
6152
John McCallb268a282010-08-23 23:25:46 +00006153 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006154 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006155 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006156 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006157 Member,
John McCall16df1e52010-03-30 21:47:33 +00006158 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006159 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006160 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006161 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006162}
Mike Stump11289f42009-09-09 15:08:12 +00006163
Douglas Gregora16548e2009-08-11 05:31:07 +00006164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006165ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006166TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006167 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006168 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006169 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006170
John McCalldadc5752010-08-24 06:29:42 +00006171 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006172 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006173 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006174
Douglas Gregora16548e2009-08-11 05:31:07 +00006175 if (!getDerived().AlwaysRebuild() &&
6176 LHS.get() == E->getLHS() &&
6177 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006178 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006179
Douglas Gregora16548e2009-08-11 05:31:07 +00006180 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006181 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006182}
6183
Mike Stump11289f42009-09-09 15:08:12 +00006184template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006185ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006186TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006187 CompoundAssignOperator *E) {
6188 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006189}
Mike Stump11289f42009-09-09 15:08:12 +00006190
Douglas Gregora16548e2009-08-11 05:31:07 +00006191template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006192ExprResult TreeTransform<Derived>::
6193TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6194 // Just rebuild the common and RHS expressions and see whether we
6195 // get any changes.
6196
6197 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6198 if (commonExpr.isInvalid())
6199 return ExprError();
6200
6201 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6202 if (rhs.isInvalid())
6203 return ExprError();
6204
6205 if (!getDerived().AlwaysRebuild() &&
6206 commonExpr.get() == e->getCommon() &&
6207 rhs.get() == e->getFalseExpr())
6208 return SemaRef.Owned(e);
6209
6210 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6211 e->getQuestionLoc(),
6212 0,
6213 e->getColonLoc(),
6214 rhs.get());
6215}
6216
6217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006219TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006220 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006221 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006223
John McCalldadc5752010-08-24 06:29:42 +00006224 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006225 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006227
John McCalldadc5752010-08-24 06:29:42 +00006228 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006229 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006230 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006231
Douglas Gregora16548e2009-08-11 05:31:07 +00006232 if (!getDerived().AlwaysRebuild() &&
6233 Cond.get() == E->getCond() &&
6234 LHS.get() == E->getLHS() &&
6235 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006236 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006237
John McCallb268a282010-08-23 23:25:46 +00006238 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006239 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006240 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006241 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006242 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006243}
Mike Stump11289f42009-09-09 15:08:12 +00006244
6245template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006246ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006247TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006248 // Implicit casts are eliminated during transformation, since they
6249 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006250 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006251}
Mike Stump11289f42009-09-09 15:08:12 +00006252
Douglas Gregora16548e2009-08-11 05:31:07 +00006253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006254ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006255TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006256 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6257 if (!Type)
6258 return ExprError();
6259
John McCalldadc5752010-08-24 06:29:42 +00006260 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006261 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006262 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006263 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006264
Douglas Gregora16548e2009-08-11 05:31:07 +00006265 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006266 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006267 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006268 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006269
John McCall97513962010-01-15 18:39:57 +00006270 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006271 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006272 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006273 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006274}
Mike Stump11289f42009-09-09 15:08:12 +00006275
Douglas Gregora16548e2009-08-11 05:31:07 +00006276template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006277ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006278TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006279 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6280 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6281 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006282 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006283
John McCalldadc5752010-08-24 06:29:42 +00006284 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006285 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006287
Douglas Gregora16548e2009-08-11 05:31:07 +00006288 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006289 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006290 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006291 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006292
John McCall5d7aa7f2010-01-19 22:33:45 +00006293 // Note: the expression type doesn't necessarily match the
6294 // type-as-written, but that's okay, because it should always be
6295 // derivable from the initializer.
6296
John McCalle15bbff2010-01-18 19:35:47 +00006297 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006298 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006299 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006300}
Mike Stump11289f42009-09-09 15:08:12 +00006301
Douglas Gregora16548e2009-08-11 05:31:07 +00006302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006303ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006304TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006305 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006306 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006307 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006308
Douglas Gregora16548e2009-08-11 05:31:07 +00006309 if (!getDerived().AlwaysRebuild() &&
6310 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006311 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006312
Douglas Gregora16548e2009-08-11 05:31:07 +00006313 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006314 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006315 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006316 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006317 E->getAccessorLoc(),
6318 E->getAccessor());
6319}
Mike Stump11289f42009-09-09 15:08:12 +00006320
Douglas Gregora16548e2009-08-11 05:31:07 +00006321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006322ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006323TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006324 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006325
John McCall37ad5512010-08-23 06:44:23 +00006326 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006327 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6328 Inits, &InitChanged))
6329 return ExprError();
6330
Douglas Gregora16548e2009-08-11 05:31:07 +00006331 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006332 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006333
Douglas Gregora16548e2009-08-11 05:31:07 +00006334 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006335 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006336}
Mike Stump11289f42009-09-09 15:08:12 +00006337
Douglas Gregora16548e2009-08-11 05:31:07 +00006338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006340TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006341 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregorebe10102009-08-20 07:17:43 +00006343 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006344 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006345 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006347
Douglas Gregorebe10102009-08-20 07:17:43 +00006348 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006349 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006350 bool ExprChanged = false;
6351 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6352 DEnd = E->designators_end();
6353 D != DEnd; ++D) {
6354 if (D->isFieldDesignator()) {
6355 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6356 D->getDotLoc(),
6357 D->getFieldLoc()));
6358 continue;
6359 }
Mike Stump11289f42009-09-09 15:08:12 +00006360
Douglas Gregora16548e2009-08-11 05:31:07 +00006361 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006362 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006363 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006364 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006365
6366 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006367 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006368
Douglas Gregora16548e2009-08-11 05:31:07 +00006369 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6370 ArrayExprs.push_back(Index.release());
6371 continue;
6372 }
Mike Stump11289f42009-09-09 15:08:12 +00006373
Douglas Gregora16548e2009-08-11 05:31:07 +00006374 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006375 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006376 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6377 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006378 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006379
John McCalldadc5752010-08-24 06:29:42 +00006380 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006381 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006382 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006383
6384 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006385 End.get(),
6386 D->getLBracketLoc(),
6387 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006388
Douglas Gregora16548e2009-08-11 05:31:07 +00006389 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6390 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006391
Douglas Gregora16548e2009-08-11 05:31:07 +00006392 ArrayExprs.push_back(Start.release());
6393 ArrayExprs.push_back(End.release());
6394 }
Mike Stump11289f42009-09-09 15:08:12 +00006395
Douglas Gregora16548e2009-08-11 05:31:07 +00006396 if (!getDerived().AlwaysRebuild() &&
6397 Init.get() == E->getInit() &&
6398 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006399 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006400
Douglas Gregora16548e2009-08-11 05:31:07 +00006401 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6402 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006403 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006404}
Mike Stump11289f42009-09-09 15:08:12 +00006405
Douglas Gregora16548e2009-08-11 05:31:07 +00006406template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006407ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006408TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006409 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006410 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006411
Douglas Gregor3da3c062009-10-28 00:29:27 +00006412 // FIXME: Will we ever have proper type location here? Will we actually
6413 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006414 QualType T = getDerived().TransformType(E->getType());
6415 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006416 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006417
Douglas Gregora16548e2009-08-11 05:31:07 +00006418 if (!getDerived().AlwaysRebuild() &&
6419 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006420 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006421
Douglas Gregora16548e2009-08-11 05:31:07 +00006422 return getDerived().RebuildImplicitValueInitExpr(T);
6423}
Mike Stump11289f42009-09-09 15:08:12 +00006424
Douglas Gregora16548e2009-08-11 05:31:07 +00006425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006426ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006427TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006428 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6429 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006430 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006431
John McCalldadc5752010-08-24 06:29:42 +00006432 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006433 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006434 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006435
Douglas Gregora16548e2009-08-11 05:31:07 +00006436 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006437 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006439 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006440
John McCallb268a282010-08-23 23:25:46 +00006441 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006442 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006443}
6444
6445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006446ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006447TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006448 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006449 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006450 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6451 &ArgumentChanged))
6452 return ExprError();
6453
Douglas Gregora16548e2009-08-11 05:31:07 +00006454 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6455 move_arg(Inits),
6456 E->getRParenLoc());
6457}
Mike Stump11289f42009-09-09 15:08:12 +00006458
Douglas Gregora16548e2009-08-11 05:31:07 +00006459/// \brief Transform an address-of-label expression.
6460///
6461/// By default, the transformation of an address-of-label expression always
6462/// rebuilds the expression, so that the label identifier can be resolved to
6463/// the corresponding label statement by semantic analysis.
6464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006465ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006466TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006467 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6468 E->getLabel());
6469 if (!LD)
6470 return ExprError();
6471
Douglas Gregora16548e2009-08-11 05:31:07 +00006472 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006473 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006474}
Mike Stump11289f42009-09-09 15:08:12 +00006475
6476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006477ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006478TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006479 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006480 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6481 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006482 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006483
Douglas Gregora16548e2009-08-11 05:31:07 +00006484 if (!getDerived().AlwaysRebuild() &&
6485 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006486 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006487
6488 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006489 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006490 E->getRParenLoc());
6491}
Mike Stump11289f42009-09-09 15:08:12 +00006492
Douglas Gregora16548e2009-08-11 05:31:07 +00006493template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006494ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006495TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006496 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006497 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006498 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006499
John McCalldadc5752010-08-24 06:29:42 +00006500 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006501 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006502 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006503
John McCalldadc5752010-08-24 06:29:42 +00006504 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006505 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006506 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006507
Douglas Gregora16548e2009-08-11 05:31:07 +00006508 if (!getDerived().AlwaysRebuild() &&
6509 Cond.get() == E->getCond() &&
6510 LHS.get() == E->getLHS() &&
6511 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006512 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006513
Douglas Gregora16548e2009-08-11 05:31:07 +00006514 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006515 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006516 E->getRParenLoc());
6517}
Mike Stump11289f42009-09-09 15:08:12 +00006518
Douglas Gregora16548e2009-08-11 05:31:07 +00006519template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006520ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006521TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006522 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006523}
6524
6525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006526ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006527TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006528 switch (E->getOperator()) {
6529 case OO_New:
6530 case OO_Delete:
6531 case OO_Array_New:
6532 case OO_Array_Delete:
6533 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006534 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006535
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006536 case OO_Call: {
6537 // This is a call to an object's operator().
6538 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6539
6540 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006541 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006542 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006543 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006544
6545 // FIXME: Poor location information
6546 SourceLocation FakeLParenLoc
6547 = SemaRef.PP.getLocForEndOfToken(
6548 static_cast<Expr *>(Object.get())->getLocEnd());
6549
6550 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006551 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006552 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6553 Args))
6554 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006555
John McCallb268a282010-08-23 23:25:46 +00006556 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006557 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006558 E->getLocEnd());
6559 }
6560
6561#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6562 case OO_##Name:
6563#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6564#include "clang/Basic/OperatorKinds.def"
6565 case OO_Subscript:
6566 // Handled below.
6567 break;
6568
6569 case OO_Conditional:
6570 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006571 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006572
6573 case OO_None:
6574 case NUM_OVERLOADED_OPERATORS:
6575 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006576 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006577 }
6578
John McCalldadc5752010-08-24 06:29:42 +00006579 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006580 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006581 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006582
John McCalldadc5752010-08-24 06:29:42 +00006583 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006584 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006585 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006586
John McCalldadc5752010-08-24 06:29:42 +00006587 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006588 if (E->getNumArgs() == 2) {
6589 Second = getDerived().TransformExpr(E->getArg(1));
6590 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006591 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006592 }
Mike Stump11289f42009-09-09 15:08:12 +00006593
Douglas Gregora16548e2009-08-11 05:31:07 +00006594 if (!getDerived().AlwaysRebuild() &&
6595 Callee.get() == E->getCallee() &&
6596 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006597 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006598 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006599
Douglas Gregora16548e2009-08-11 05:31:07 +00006600 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6601 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006602 Callee.get(),
6603 First.get(),
6604 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006605}
Mike Stump11289f42009-09-09 15:08:12 +00006606
Douglas Gregora16548e2009-08-11 05:31:07 +00006607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006608ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006609TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6610 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006611}
Mike Stump11289f42009-09-09 15:08:12 +00006612
Douglas Gregora16548e2009-08-11 05:31:07 +00006613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006614ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006615TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6616 // Transform the callee.
6617 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6618 if (Callee.isInvalid())
6619 return ExprError();
6620
6621 // Transform exec config.
6622 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6623 if (EC.isInvalid())
6624 return ExprError();
6625
6626 // Transform arguments.
6627 bool ArgChanged = false;
6628 ASTOwningVector<Expr*> Args(SemaRef);
6629 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6630 &ArgChanged))
6631 return ExprError();
6632
6633 if (!getDerived().AlwaysRebuild() &&
6634 Callee.get() == E->getCallee() &&
6635 !ArgChanged)
6636 return SemaRef.Owned(E);
6637
6638 // FIXME: Wrong source location information for the '('.
6639 SourceLocation FakeLParenLoc
6640 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6641 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6642 move_arg(Args),
6643 E->getRParenLoc(), EC.get());
6644}
6645
6646template<typename Derived>
6647ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006648TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006649 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6650 if (!Type)
6651 return ExprError();
6652
John McCalldadc5752010-08-24 06:29:42 +00006653 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006654 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006655 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006656 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006657
Douglas Gregora16548e2009-08-11 05:31:07 +00006658 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006659 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006660 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006661 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006662
Douglas Gregora16548e2009-08-11 05:31:07 +00006663 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006664 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006665 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6666 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6667 SourceLocation FakeRParenLoc
6668 = SemaRef.PP.getLocForEndOfToken(
6669 E->getSubExpr()->getSourceRange().getEnd());
6670 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006671 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006672 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006673 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006674 FakeRAngleLoc,
6675 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006676 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006677 FakeRParenLoc);
6678}
Mike Stump11289f42009-09-09 15:08:12 +00006679
Douglas Gregora16548e2009-08-11 05:31:07 +00006680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006681ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006682TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6683 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006684}
Mike Stump11289f42009-09-09 15:08:12 +00006685
6686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006687ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006688TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6689 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006690}
6691
Douglas Gregora16548e2009-08-11 05:31:07 +00006692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006693ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006694TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006695 CXXReinterpretCastExpr *E) {
6696 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006697}
Mike Stump11289f42009-09-09 15:08:12 +00006698
Douglas Gregora16548e2009-08-11 05:31:07 +00006699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006700ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006701TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6702 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006703}
Mike Stump11289f42009-09-09 15:08:12 +00006704
Douglas Gregora16548e2009-08-11 05:31:07 +00006705template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006706ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006707TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006708 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006709 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6710 if (!Type)
6711 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006712
John McCalldadc5752010-08-24 06:29:42 +00006713 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006714 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006715 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006717
Douglas Gregora16548e2009-08-11 05:31:07 +00006718 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006719 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006720 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006721 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006722
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006723 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006724 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006725 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006726 E->getRParenLoc());
6727}
Mike Stump11289f42009-09-09 15:08:12 +00006728
Douglas Gregora16548e2009-08-11 05:31:07 +00006729template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006730ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006731TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006732 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006733 TypeSourceInfo *TInfo
6734 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6735 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006736 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006737
Douglas Gregora16548e2009-08-11 05:31:07 +00006738 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006739 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006740 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006741
Douglas Gregor9da64192010-04-26 22:37:10 +00006742 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6743 E->getLocStart(),
6744 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006745 E->getLocEnd());
6746 }
Mike Stump11289f42009-09-09 15:08:12 +00006747
Douglas Gregora16548e2009-08-11 05:31:07 +00006748 // We don't know whether the expression is potentially evaluated until
6749 // after we perform semantic analysis, so the expression is potentially
6750 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006751 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006752 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006753
John McCalldadc5752010-08-24 06:29:42 +00006754 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006755 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006756 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006757
Douglas Gregora16548e2009-08-11 05:31:07 +00006758 if (!getDerived().AlwaysRebuild() &&
6759 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006760 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006761
Douglas Gregor9da64192010-04-26 22:37:10 +00006762 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6763 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006764 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006765 E->getLocEnd());
6766}
6767
6768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006769ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006770TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6771 if (E->isTypeOperand()) {
6772 TypeSourceInfo *TInfo
6773 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6774 if (!TInfo)
6775 return ExprError();
6776
6777 if (!getDerived().AlwaysRebuild() &&
6778 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006779 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006780
Douglas Gregor69735112011-03-06 17:40:41 +00006781 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006782 E->getLocStart(),
6783 TInfo,
6784 E->getLocEnd());
6785 }
6786
6787 // We don't know whether the expression is potentially evaluated until
6788 // after we perform semantic analysis, so the expression is potentially
6789 // potentially evaluated.
6790 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6791
6792 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6793 if (SubExpr.isInvalid())
6794 return ExprError();
6795
6796 if (!getDerived().AlwaysRebuild() &&
6797 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006798 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006799
6800 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6801 E->getLocStart(),
6802 SubExpr.get(),
6803 E->getLocEnd());
6804}
6805
6806template<typename Derived>
6807ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006808TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006809 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006810}
Mike Stump11289f42009-09-09 15:08:12 +00006811
Douglas Gregora16548e2009-08-11 05:31:07 +00006812template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006813ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006814TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006815 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006816 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006817}
Mike Stump11289f42009-09-09 15:08:12 +00006818
Douglas Gregora16548e2009-08-11 05:31:07 +00006819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006820ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006821TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006822 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith938f40b2011-06-11 17:19:42 +00006823 QualType T;
6824 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6825 T = MD->getThisType(getSema().Context);
6826 else
6827 T = getSema().Context.getPointerType(
6828 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump11289f42009-09-09 15:08:12 +00006829
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006830 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006831 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006832
Douglas Gregorb15af892010-01-07 23:12:05 +00006833 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006834}
Mike Stump11289f42009-09-09 15:08:12 +00006835
Douglas Gregora16548e2009-08-11 05:31:07 +00006836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006837ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006838TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006839 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006840 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006841 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006842
Douglas Gregora16548e2009-08-11 05:31:07 +00006843 if (!getDerived().AlwaysRebuild() &&
6844 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006845 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006846
Douglas Gregor53e191ed2011-07-06 22:04:06 +00006847 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6848 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00006849}
Mike Stump11289f42009-09-09 15:08:12 +00006850
Douglas Gregora16548e2009-08-11 05:31:07 +00006851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006852ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006853TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006854 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006855 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6856 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006857 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006858 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006859
Chandler Carruth794da4c2010-02-08 06:42:49 +00006860 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006861 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006862 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006863
Douglas Gregor033f6752009-12-23 23:03:06 +00006864 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006865}
Mike Stump11289f42009-09-09 15:08:12 +00006866
Douglas Gregora16548e2009-08-11 05:31:07 +00006867template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006868ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006869TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6870 CXXScalarValueInitExpr *E) {
6871 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6872 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006873 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006874
Douglas Gregora16548e2009-08-11 05:31:07 +00006875 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006876 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006877 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006878
Douglas Gregor2b88c112010-09-08 00:15:04 +00006879 return getDerived().RebuildCXXScalarValueInitExpr(T,
6880 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006881 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006882}
Mike Stump11289f42009-09-09 15:08:12 +00006883
Douglas Gregora16548e2009-08-11 05:31:07 +00006884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006885ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006886TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006887 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006888 TypeSourceInfo *AllocTypeInfo
6889 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6890 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006892
Douglas Gregora16548e2009-08-11 05:31:07 +00006893 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006894 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006895 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006896 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006897
Douglas Gregora16548e2009-08-11 05:31:07 +00006898 // Transform the placement arguments (if any).
6899 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006900 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006901 if (getDerived().TransformExprs(E->getPlacementArgs(),
6902 E->getNumPlacementArgs(), true,
6903 PlacementArgs, &ArgumentChanged))
6904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006905
Douglas Gregorebe10102009-08-20 07:17:43 +00006906 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006907 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006908 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6909 ConstructorArgs, &ArgumentChanged))
6910 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006911
Douglas Gregord2d9da02010-02-26 00:38:10 +00006912 // Transform constructor, new operator, and delete operator.
6913 CXXConstructorDecl *Constructor = 0;
6914 if (E->getConstructor()) {
6915 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006916 getDerived().TransformDecl(E->getLocStart(),
6917 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006918 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006919 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006920 }
6921
6922 FunctionDecl *OperatorNew = 0;
6923 if (E->getOperatorNew()) {
6924 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006925 getDerived().TransformDecl(E->getLocStart(),
6926 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006927 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006928 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006929 }
6930
6931 FunctionDecl *OperatorDelete = 0;
6932 if (E->getOperatorDelete()) {
6933 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006934 getDerived().TransformDecl(E->getLocStart(),
6935 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006936 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006937 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006938 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006939
Douglas Gregora16548e2009-08-11 05:31:07 +00006940 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006941 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006942 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006943 Constructor == E->getConstructor() &&
6944 OperatorNew == E->getOperatorNew() &&
6945 OperatorDelete == E->getOperatorDelete() &&
6946 !ArgumentChanged) {
6947 // Mark any declarations we need as referenced.
6948 // FIXME: instantiation-specific.
6949 if (Constructor)
6950 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6951 if (OperatorNew)
6952 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6953 if (OperatorDelete)
6954 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor72912fb2011-07-26 15:11:03 +00006955
6956 if (E->isArray() && Constructor &&
6957 !E->getAllocatedType()->isDependentType()) {
6958 QualType ElementType
6959 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
6960 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
6961 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
6962 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
6963 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
6964 }
6965 }
6966 }
6967
John McCallc3007a22010-10-26 07:05:15 +00006968 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006969 }
Mike Stump11289f42009-09-09 15:08:12 +00006970
Douglas Gregor0744ef62010-09-07 21:49:58 +00006971 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006972 if (!ArraySize.get()) {
6973 // If no array size was specified, but the new expression was
6974 // instantiated with an array type (e.g., "new T" where T is
6975 // instantiated with "int[4]"), extract the outer bound from the
6976 // array type as our array size. We do this with constant and
6977 // dependently-sized array types.
6978 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6979 if (!ArrayT) {
6980 // Do nothing
6981 } else if (const ConstantArrayType *ConsArrayT
6982 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006983 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006984 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6985 ConsArrayT->getSize(),
6986 SemaRef.Context.getSizeType(),
6987 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006988 AllocType = ConsArrayT->getElementType();
6989 } else if (const DependentSizedArrayType *DepArrayT
6990 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6991 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006992 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006993 AllocType = DepArrayT->getElementType();
6994 }
6995 }
6996 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006997
Douglas Gregora16548e2009-08-11 05:31:07 +00006998 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6999 E->isGlobalNew(),
7000 /*FIXME:*/E->getLocStart(),
7001 move_arg(PlacementArgs),
7002 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007003 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007004 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007005 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007006 ArraySize.get(),
Douglas Gregor3bdcff52011-06-27 16:55:54 +00007007 /*FIXME:*/E->hasInitializer()
7008 ? E->getLocStart()
7009 : SourceLocation(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007010 move_arg(ConstructorArgs),
Douglas Gregor3bdcff52011-06-27 16:55:54 +00007011 /*FIXME:*/E->hasInitializer()
7012 ? E->getLocEnd()
7013 : SourceLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007014}
Mike Stump11289f42009-09-09 15:08:12 +00007015
Douglas Gregora16548e2009-08-11 05:31:07 +00007016template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007017ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007018TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007019 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007020 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007021 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007022
Douglas Gregord2d9da02010-02-26 00:38:10 +00007023 // Transform the delete operator, if known.
7024 FunctionDecl *OperatorDelete = 0;
7025 if (E->getOperatorDelete()) {
7026 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007027 getDerived().TransformDecl(E->getLocStart(),
7028 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007029 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007030 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007031 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007032
Douglas Gregora16548e2009-08-11 05:31:07 +00007033 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007034 Operand.get() == E->getArgument() &&
7035 OperatorDelete == E->getOperatorDelete()) {
7036 // Mark any declarations we need as referenced.
7037 // FIXME: instantiation-specific.
7038 if (OperatorDelete)
7039 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007040
7041 if (!E->getArgument()->isTypeDependent()) {
7042 QualType Destroyed = SemaRef.Context.getBaseElementType(
7043 E->getDestroyedType());
7044 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7045 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7046 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7047 SemaRef.LookupDestructor(Record));
7048 }
7049 }
7050
John McCallc3007a22010-10-26 07:05:15 +00007051 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007052 }
Mike Stump11289f42009-09-09 15:08:12 +00007053
Douglas Gregora16548e2009-08-11 05:31:07 +00007054 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7055 E->isGlobalDelete(),
7056 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007057 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007058}
Mike Stump11289f42009-09-09 15:08:12 +00007059
Douglas Gregora16548e2009-08-11 05:31:07 +00007060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007061ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007062TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007063 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007064 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007065 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007066 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007067
John McCallba7bf592010-08-24 05:47:05 +00007068 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007069 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007070 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007071 E->getOperatorLoc(),
7072 E->isArrow()? tok::arrow : tok::period,
7073 ObjectTypePtr,
7074 MayBePseudoDestructor);
7075 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007076 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007077
John McCallba7bf592010-08-24 05:47:05 +00007078 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007079 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7080 if (QualifierLoc) {
7081 QualifierLoc
7082 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7083 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007084 return ExprError();
7085 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007086 CXXScopeSpec SS;
7087 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007088
Douglas Gregor678f90d2010-02-25 01:56:36 +00007089 PseudoDestructorTypeStorage Destroyed;
7090 if (E->getDestroyedTypeInfo()) {
7091 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007092 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007093 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007094 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007095 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007096 Destroyed = DestroyedTypeInfo;
7097 } else if (ObjectType->isDependentType()) {
7098 // We aren't likely to be able to resolve the identifier down to a type
7099 // now anyway, so just retain the identifier.
7100 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7101 E->getDestroyedTypeLoc());
7102 } else {
7103 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007104 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007105 *E->getDestroyedTypeIdentifier(),
7106 E->getDestroyedTypeLoc(),
7107 /*Scope=*/0,
7108 SS, ObjectTypePtr,
7109 false);
7110 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007111 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007112
Douglas Gregor678f90d2010-02-25 01:56:36 +00007113 Destroyed
7114 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7115 E->getDestroyedTypeLoc());
7116 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007117
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007118 TypeSourceInfo *ScopeTypeInfo = 0;
7119 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00007120 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007121 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007122 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007123 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007124
John McCallb268a282010-08-23 23:25:46 +00007125 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007126 E->getOperatorLoc(),
7127 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007128 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007129 ScopeTypeInfo,
7130 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007131 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007132 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007133}
Mike Stump11289f42009-09-09 15:08:12 +00007134
Douglas Gregorad8a3362009-09-04 17:36:40 +00007135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007136ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007137TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007138 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007139 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7140 Sema::LookupOrdinaryName);
7141
7142 // Transform all the decls.
7143 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7144 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007145 NamedDecl *InstD = static_cast<NamedDecl*>(
7146 getDerived().TransformDecl(Old->getNameLoc(),
7147 *I));
John McCall84d87672009-12-10 09:41:52 +00007148 if (!InstD) {
7149 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7150 // This can happen because of dependent hiding.
7151 if (isa<UsingShadowDecl>(*I))
7152 continue;
7153 else
John McCallfaf5fb42010-08-26 23:41:50 +00007154 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007155 }
John McCalle66edc12009-11-24 19:00:30 +00007156
7157 // Expand using declarations.
7158 if (isa<UsingDecl>(InstD)) {
7159 UsingDecl *UD = cast<UsingDecl>(InstD);
7160 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7161 E = UD->shadow_end(); I != E; ++I)
7162 R.addDecl(*I);
7163 continue;
7164 }
7165
7166 R.addDecl(InstD);
7167 }
7168
7169 // Resolve a kind, but don't do any further analysis. If it's
7170 // ambiguous, the callee needs to deal with it.
7171 R.resolveKind();
7172
7173 // Rebuild the nested-name qualifier, if present.
7174 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007175 if (Old->getQualifierLoc()) {
7176 NestedNameSpecifierLoc QualifierLoc
7177 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7178 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007179 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007180
Douglas Gregor0da1d432011-02-28 20:01:57 +00007181 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007182 }
7183
Douglas Gregor9262f472010-04-27 18:19:34 +00007184 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007185 CXXRecordDecl *NamingClass
7186 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7187 Old->getNameLoc(),
7188 Old->getNamingClass()));
7189 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007190 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007191
Douglas Gregorda7be082010-04-27 16:10:10 +00007192 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007193 }
7194
7195 // If we have no template arguments, it's a normal declaration name.
7196 if (!Old->hasExplicitTemplateArgs())
7197 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7198
7199 // If we have template arguments, rebuild them, then rebuild the
7200 // templateid expression.
7201 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007202 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7203 Old->getNumTemplateArgs(),
7204 TransArgs))
7205 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007206
7207 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7208 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007209}
Mike Stump11289f42009-09-09 15:08:12 +00007210
Douglas Gregora16548e2009-08-11 05:31:07 +00007211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007212ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007213TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007214 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7215 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007216 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007217
Douglas Gregora16548e2009-08-11 05:31:07 +00007218 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007219 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007220 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007221
Mike Stump11289f42009-09-09 15:08:12 +00007222 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007223 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007224 T,
7225 E->getLocEnd());
7226}
Mike Stump11289f42009-09-09 15:08:12 +00007227
Douglas Gregora16548e2009-08-11 05:31:07 +00007228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007229ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007230TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7231 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7232 if (!LhsT)
7233 return ExprError();
7234
7235 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7236 if (!RhsT)
7237 return ExprError();
7238
7239 if (!getDerived().AlwaysRebuild() &&
7240 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7241 return SemaRef.Owned(E);
7242
7243 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7244 E->getLocStart(),
7245 LhsT, RhsT,
7246 E->getLocEnd());
7247}
7248
7249template<typename Derived>
7250ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007251TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7252 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7253 if (!T)
7254 return ExprError();
7255
7256 if (!getDerived().AlwaysRebuild() &&
7257 T == E->getQueriedTypeSourceInfo())
7258 return SemaRef.Owned(E);
7259
7260 ExprResult SubExpr;
7261 {
7262 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7263 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7264 if (SubExpr.isInvalid())
7265 return ExprError();
7266
7267 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7268 return SemaRef.Owned(E);
7269 }
7270
7271 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7272 E->getLocStart(),
7273 T,
7274 SubExpr.get(),
7275 E->getLocEnd());
7276}
7277
7278template<typename Derived>
7279ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007280TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7281 ExprResult SubExpr;
7282 {
7283 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7284 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7285 if (SubExpr.isInvalid())
7286 return ExprError();
7287
7288 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7289 return SemaRef.Owned(E);
7290 }
7291
7292 return getDerived().RebuildExpressionTrait(
7293 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7294}
7295
7296template<typename Derived>
7297ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007298TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007299 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007300 NestedNameSpecifierLoc QualifierLoc
7301 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7302 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007303 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007304
John McCall31f82722010-11-12 08:19:04 +00007305 // TODO: If this is a conversion-function-id, verify that the
7306 // destination type name (if present) resolves the same way after
7307 // instantiation as it did in the local scope.
7308
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007309 DeclarationNameInfo NameInfo
7310 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7311 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007312 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007313
John McCalle66edc12009-11-24 19:00:30 +00007314 if (!E->hasExplicitTemplateArgs()) {
7315 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007316 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007317 // Note: it is sufficient to compare the Name component of NameInfo:
7318 // if name has not changed, DNLoc has not changed either.
7319 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007320 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007321
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007322 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007323 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007324 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007325 }
John McCall6b51f282009-11-23 01:53:49 +00007326
7327 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007328 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7329 E->getNumTemplateArgs(),
7330 TransArgs))
7331 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007332
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007333 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007334 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007335 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007336}
7337
7338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007340TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007341 // CXXConstructExprs are always implicit, so when we have a
7342 // 1-argument construction we just transform that argument.
7343 if (E->getNumArgs() == 1 ||
7344 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7345 return getDerived().TransformExpr(E->getArg(0));
7346
Douglas Gregora16548e2009-08-11 05:31:07 +00007347 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7348
7349 QualType T = getDerived().TransformType(E->getType());
7350 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007351 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007352
7353 CXXConstructorDecl *Constructor
7354 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007355 getDerived().TransformDecl(E->getLocStart(),
7356 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007357 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007358 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007359
Douglas Gregora16548e2009-08-11 05:31:07 +00007360 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007361 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007362 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7363 &ArgumentChanged))
7364 return ExprError();
7365
Douglas Gregora16548e2009-08-11 05:31:07 +00007366 if (!getDerived().AlwaysRebuild() &&
7367 T == E->getType() &&
7368 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007369 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007370 // Mark the constructor as referenced.
7371 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007372 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007373 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007374 }
Mike Stump11289f42009-09-09 15:08:12 +00007375
Douglas Gregordb121ba2009-12-14 16:27:04 +00007376 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7377 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007378 move_arg(Args),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00007379 E->hadMultipleCandidates(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007380 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007381 E->getConstructionKind(),
7382 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007383}
Mike Stump11289f42009-09-09 15:08:12 +00007384
Douglas Gregora16548e2009-08-11 05:31:07 +00007385/// \brief Transform a C++ temporary-binding expression.
7386///
Douglas Gregor363b1512009-12-24 18:51:59 +00007387/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7388/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007390ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007391TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007392 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007393}
Mike Stump11289f42009-09-09 15:08:12 +00007394
John McCall5d413782010-12-06 08:20:24 +00007395/// \brief Transform a C++ expression that contains cleanups that should
7396/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007397///
John McCall5d413782010-12-06 08:20:24 +00007398/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007399/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007401ExprResult
John McCall5d413782010-12-06 08:20:24 +00007402TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007403 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007404}
Mike Stump11289f42009-09-09 15:08:12 +00007405
Douglas Gregora16548e2009-08-11 05:31:07 +00007406template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007407ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007408TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007409 CXXTemporaryObjectExpr *E) {
7410 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7411 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007412 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007413
Douglas Gregora16548e2009-08-11 05:31:07 +00007414 CXXConstructorDecl *Constructor
7415 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007416 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007417 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007418 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007419 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007420
Douglas Gregora16548e2009-08-11 05:31:07 +00007421 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007422 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007423 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007424 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7425 &ArgumentChanged))
7426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007427
Douglas Gregora16548e2009-08-11 05:31:07 +00007428 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007429 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007430 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007431 !ArgumentChanged) {
7432 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007433 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007434 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007435 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007436
7437 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7438 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007439 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007440 E->getLocEnd());
7441}
Mike Stump11289f42009-09-09 15:08:12 +00007442
Douglas Gregora16548e2009-08-11 05:31:07 +00007443template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007444ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007445TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007446 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007447 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7448 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007449 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007450
Douglas Gregora16548e2009-08-11 05:31:07 +00007451 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007452 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007453 Args.reserve(E->arg_size());
7454 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7455 &ArgumentChanged))
7456 return ExprError();
7457
Douglas Gregora16548e2009-08-11 05:31:07 +00007458 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007459 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007460 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007461 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007462
Douglas Gregora16548e2009-08-11 05:31:07 +00007463 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007464 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007465 E->getLParenLoc(),
7466 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007467 E->getRParenLoc());
7468}
Mike Stump11289f42009-09-09 15:08:12 +00007469
Douglas Gregora16548e2009-08-11 05:31:07 +00007470template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007471ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007472TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007473 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007474 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007475 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007476 Expr *OldBase;
7477 QualType BaseType;
7478 QualType ObjectType;
7479 if (!E->isImplicitAccess()) {
7480 OldBase = E->getBase();
7481 Base = getDerived().TransformExpr(OldBase);
7482 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007483 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007484
John McCall2d74de92009-12-01 22:10:20 +00007485 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007486 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007487 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007488 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007489 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007490 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007491 ObjectTy,
7492 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007493 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007494 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007495
John McCallba7bf592010-08-24 05:47:05 +00007496 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007497 BaseType = ((Expr*) Base.get())->getType();
7498 } else {
7499 OldBase = 0;
7500 BaseType = getDerived().TransformType(E->getBaseType());
7501 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7502 }
Mike Stump11289f42009-09-09 15:08:12 +00007503
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007504 // Transform the first part of the nested-name-specifier that qualifies
7505 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007506 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007507 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007508 E->getFirstQualifierFoundInScope(),
7509 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007510
Douglas Gregore16af532011-02-28 18:50:33 +00007511 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007512 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007513 QualifierLoc
7514 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7515 ObjectType,
7516 FirstQualifierInScope);
7517 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007518 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007519 }
Mike Stump11289f42009-09-09 15:08:12 +00007520
John McCall31f82722010-11-12 08:19:04 +00007521 // TODO: If this is a conversion-function-id, verify that the
7522 // destination type name (if present) resolves the same way after
7523 // instantiation as it did in the local scope.
7524
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007525 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007526 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007527 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007528 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007529
John McCall2d74de92009-12-01 22:10:20 +00007530 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007531 // This is a reference to a member without an explicitly-specified
7532 // template argument list. Optimize for this common case.
7533 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007534 Base.get() == OldBase &&
7535 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007536 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007537 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007538 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007539 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007540
John McCallb268a282010-08-23 23:25:46 +00007541 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007542 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007543 E->isArrow(),
7544 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007545 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007546 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007547 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007548 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007549 }
7550
John McCall6b51f282009-11-23 01:53:49 +00007551 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007552 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7553 E->getNumTemplateArgs(),
7554 TransArgs))
7555 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007556
John McCallb268a282010-08-23 23:25:46 +00007557 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007558 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007559 E->isArrow(),
7560 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007561 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007562 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007563 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007564 &TransArgs);
7565}
7566
7567template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007568ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007569TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007570 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007571 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007572 QualType BaseType;
7573 if (!Old->isImplicitAccess()) {
7574 Base = getDerived().TransformExpr(Old->getBase());
7575 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007576 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007577 BaseType = ((Expr*) Base.get())->getType();
7578 } else {
7579 BaseType = getDerived().TransformType(Old->getBaseType());
7580 }
John McCall10eae182009-11-30 22:42:35 +00007581
Douglas Gregor0da1d432011-02-28 20:01:57 +00007582 NestedNameSpecifierLoc QualifierLoc;
7583 if (Old->getQualifierLoc()) {
7584 QualifierLoc
7585 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7586 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007587 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007588 }
7589
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007590 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007591 Sema::LookupOrdinaryName);
7592
7593 // Transform all the decls.
7594 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7595 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007596 NamedDecl *InstD = static_cast<NamedDecl*>(
7597 getDerived().TransformDecl(Old->getMemberLoc(),
7598 *I));
John McCall84d87672009-12-10 09:41:52 +00007599 if (!InstD) {
7600 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7601 // This can happen because of dependent hiding.
7602 if (isa<UsingShadowDecl>(*I))
7603 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007604 else {
7605 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007606 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007607 }
John McCall84d87672009-12-10 09:41:52 +00007608 }
John McCall10eae182009-11-30 22:42:35 +00007609
7610 // Expand using declarations.
7611 if (isa<UsingDecl>(InstD)) {
7612 UsingDecl *UD = cast<UsingDecl>(InstD);
7613 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7614 E = UD->shadow_end(); I != E; ++I)
7615 R.addDecl(*I);
7616 continue;
7617 }
7618
7619 R.addDecl(InstD);
7620 }
7621
7622 R.resolveKind();
7623
Douglas Gregor9262f472010-04-27 18:19:34 +00007624 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007625 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007626 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007627 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007628 Old->getMemberLoc(),
7629 Old->getNamingClass()));
7630 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007631 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007632
Douglas Gregorda7be082010-04-27 16:10:10 +00007633 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007634 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007635
John McCall10eae182009-11-30 22:42:35 +00007636 TemplateArgumentListInfo TransArgs;
7637 if (Old->hasExplicitTemplateArgs()) {
7638 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7639 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007640 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7641 Old->getNumTemplateArgs(),
7642 TransArgs))
7643 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007644 }
John McCall38836f02010-01-15 08:34:02 +00007645
7646 // FIXME: to do this check properly, we will need to preserve the
7647 // first-qualifier-in-scope here, just in case we had a dependent
7648 // base (and therefore couldn't do the check) and a
7649 // nested-name-qualifier (and therefore could do the lookup).
7650 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007651
John McCallb268a282010-08-23 23:25:46 +00007652 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007653 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007654 Old->getOperatorLoc(),
7655 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007656 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007657 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007658 R,
7659 (Old->hasExplicitTemplateArgs()
7660 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007661}
7662
7663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007664ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007665TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00007666 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007667 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7668 if (SubExpr.isInvalid())
7669 return ExprError();
7670
7671 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007672 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007673
7674 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7675}
7676
7677template<typename Derived>
7678ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007679TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007680 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7681 if (Pattern.isInvalid())
7682 return ExprError();
7683
7684 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7685 return SemaRef.Owned(E);
7686
Douglas Gregorb8840002011-01-14 21:20:45 +00007687 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7688 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007689}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007690
7691template<typename Derived>
7692ExprResult
7693TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7694 // If E is not value-dependent, then nothing will change when we transform it.
7695 // Note: This is an instantiation-centric view.
7696 if (!E->isValueDependent())
7697 return SemaRef.Owned(E);
7698
7699 // Note: None of the implementations of TryExpandParameterPacks can ever
7700 // produce a diagnostic when given only a single unexpanded parameter pack,
7701 // so
7702 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7703 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007704 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007705 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007706 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00007707 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007708 ShouldExpand, RetainExpansion,
7709 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007710 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007711
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007712 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007713 return SemaRef.Owned(E);
7714
7715 // We now know the length of the parameter pack, so build a new expression
7716 // that stores that length.
7717 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7718 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007719 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007720}
7721
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007722template<typename Derived>
7723ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007724TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7725 SubstNonTypeTemplateParmPackExpr *E) {
7726 // Default behavior is to do nothing with this transformation.
7727 return SemaRef.Owned(E);
7728}
7729
7730template<typename Derived>
7731ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00007732TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7733 SubstNonTypeTemplateParmExpr *E) {
7734 // Default behavior is to do nothing with this transformation.
7735 return SemaRef.Owned(E);
7736}
7737
7738template<typename Derived>
7739ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00007740TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7741 MaterializeTemporaryExpr *E) {
7742 return getDerived().TransformExpr(E->GetTemporaryExpr());
7743}
7744
7745template<typename Derived>
7746ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007747TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007748 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007749}
7750
Mike Stump11289f42009-09-09 15:08:12 +00007751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007752ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007753TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007754 TypeSourceInfo *EncodedTypeInfo
7755 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7756 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007757 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007758
Douglas Gregora16548e2009-08-11 05:31:07 +00007759 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007760 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007761 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007762
7763 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007764 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007765 E->getRParenLoc());
7766}
Mike Stump11289f42009-09-09 15:08:12 +00007767
Douglas Gregora16548e2009-08-11 05:31:07 +00007768template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00007769ExprResult TreeTransform<Derived>::
7770TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7771 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7772 if (result.isInvalid()) return ExprError();
7773 Expr *subExpr = result.take();
7774
7775 if (!getDerived().AlwaysRebuild() &&
7776 subExpr == E->getSubExpr())
7777 return SemaRef.Owned(E);
7778
7779 return SemaRef.Owned(new(SemaRef.Context)
7780 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7781}
7782
7783template<typename Derived>
7784ExprResult TreeTransform<Derived>::
7785TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7786 TypeSourceInfo *TSInfo
7787 = getDerived().TransformType(E->getTypeInfoAsWritten());
7788 if (!TSInfo)
7789 return ExprError();
7790
7791 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7792 if (Result.isInvalid())
7793 return ExprError();
7794
7795 if (!getDerived().AlwaysRebuild() &&
7796 TSInfo == E->getTypeInfoAsWritten() &&
7797 Result.get() == E->getSubExpr())
7798 return SemaRef.Owned(E);
7799
7800 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7801 E->getBridgeKeywordLoc(), TSInfo,
7802 Result.get());
7803}
7804
7805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007806ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007807TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007808 // Transform arguments.
7809 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007810 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007811 Args.reserve(E->getNumArgs());
7812 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7813 &ArgChanged))
7814 return ExprError();
7815
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007816 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7817 // Class message: transform the receiver type.
7818 TypeSourceInfo *ReceiverTypeInfo
7819 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7820 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007821 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007822
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007823 // If nothing changed, just retain the existing message send.
7824 if (!getDerived().AlwaysRebuild() &&
7825 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007826 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007827
7828 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007829 SmallVector<SourceLocation, 16> SelLocs;
7830 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007831 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7832 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007833 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007834 E->getMethodDecl(),
7835 E->getLeftLoc(),
7836 move_arg(Args),
7837 E->getRightLoc());
7838 }
7839
7840 // Instance message: transform the receiver
7841 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7842 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007843 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007844 = getDerived().TransformExpr(E->getInstanceReceiver());
7845 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007846 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007847
7848 // If nothing changed, just retain the existing message send.
7849 if (!getDerived().AlwaysRebuild() &&
7850 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007851 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007852
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007853 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007854 SmallVector<SourceLocation, 16> SelLocs;
7855 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00007856 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007857 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007858 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007859 E->getMethodDecl(),
7860 E->getLeftLoc(),
7861 move_arg(Args),
7862 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007863}
7864
Mike Stump11289f42009-09-09 15:08:12 +00007865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007866ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007867TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007868 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007869}
7870
Mike Stump11289f42009-09-09 15:08:12 +00007871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007872ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007873TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007874 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007875}
7876
Mike Stump11289f42009-09-09 15:08:12 +00007877template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007878ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007879TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007880 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007881 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007882 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007883 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007884
7885 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007886
Douglas Gregord51d90d2010-04-26 20:11:03 +00007887 // If nothing changed, just retain the existing expression.
7888 if (!getDerived().AlwaysRebuild() &&
7889 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007890 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007891
John McCallb268a282010-08-23 23:25:46 +00007892 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007893 E->getLocation(),
7894 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007895}
7896
Mike Stump11289f42009-09-09 15:08:12 +00007897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007898ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007899TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007900 // 'super' and types never change. Property never changes. Just
7901 // retain the existing expression.
7902 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007903 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007904
Douglas Gregor9faee212010-04-26 20:47:02 +00007905 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007906 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007907 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007908 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007909
Douglas Gregor9faee212010-04-26 20:47:02 +00007910 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007911
Douglas Gregor9faee212010-04-26 20:47:02 +00007912 // If nothing changed, just retain the existing expression.
7913 if (!getDerived().AlwaysRebuild() &&
7914 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007915 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007916
John McCallb7bd14f2010-12-02 01:19:52 +00007917 if (E->isExplicitProperty())
7918 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7919 E->getExplicitProperty(),
7920 E->getLocation());
7921
7922 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7923 E->getType(),
7924 E->getImplicitPropertyGetter(),
7925 E->getImplicitPropertySetter(),
7926 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007927}
7928
Mike Stump11289f42009-09-09 15:08:12 +00007929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007930ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007931TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007932 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007933 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007934 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007935 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007936
Douglas Gregord51d90d2010-04-26 20:11:03 +00007937 // If nothing changed, just retain the existing expression.
7938 if (!getDerived().AlwaysRebuild() &&
7939 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007940 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007941
John McCallb268a282010-08-23 23:25:46 +00007942 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007943 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007944}
7945
Mike Stump11289f42009-09-09 15:08:12 +00007946template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007947ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007948TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007949 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007950 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007951 SubExprs.reserve(E->getNumSubExprs());
7952 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7953 SubExprs, &ArgumentChanged))
7954 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007955
Douglas Gregora16548e2009-08-11 05:31:07 +00007956 if (!getDerived().AlwaysRebuild() &&
7957 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007958 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007959
Douglas Gregora16548e2009-08-11 05:31:07 +00007960 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7961 move_arg(SubExprs),
7962 E->getRParenLoc());
7963}
7964
Mike Stump11289f42009-09-09 15:08:12 +00007965template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007966ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007967TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007968 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007969
John McCall490112f2011-02-04 18:33:18 +00007970 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7971 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7972
7973 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00007974 // We built a new blockScopeInfo in call to ActOnBlockStart
7975 // in above, CapturesCXXThis need be set here from the block
7976 // expression.
7977 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7978
Chris Lattner01cf8db2011-07-20 06:58:45 +00007979 SmallVector<ParmVarDecl*, 4> params;
7980 SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007981
7982 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007983 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7984 oldBlock->param_begin(),
7985 oldBlock->param_size(),
7986 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007987 return true;
John McCall490112f2011-02-04 18:33:18 +00007988
7989 const FunctionType *exprFunctionType = E->getFunctionType();
7990 QualType exprResultType = exprFunctionType->getResultType();
7991 if (!exprResultType.isNull()) {
7992 if (!exprResultType->isDependentType())
7993 blockScope->ReturnType = exprResultType;
7994 else if (exprResultType != getSema().Context.DependentTy)
7995 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007996 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007997
7998 // If the return type has not been determined yet, leave it as a dependent
7999 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00008000 if (blockScope->ReturnType.isNull())
8001 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00008002
8003 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00008004 if (blockScope->ReturnType->isObjCObjectType()) {
8005 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00008006 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00008007 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00008008 return ExprError();
8009 }
John McCall3882ace2011-01-05 12:14:39 +00008010
John McCall490112f2011-02-04 18:33:18 +00008011 QualType functionType = getDerived().RebuildFunctionProtoType(
8012 blockScope->ReturnType,
8013 paramTypes.data(),
8014 paramTypes.size(),
8015 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00008016 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00008017 exprFunctionType->getExtInfo());
8018 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00008019
8020 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00008021 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00008022 blockScope->TheDecl->setParams(params);
Douglas Gregor476e3022011-01-19 21:32:01 +00008023
8024 // If the return type wasn't explicitly set, it will have been marked as a
8025 // dependent type (DependentTy); clear out the return type setting so
8026 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00008027 if (blockScope->ReturnType == getSema().Context.DependentTy)
8028 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00008029
John McCall3882ace2011-01-05 12:14:39 +00008030 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00008031 StmtResult body = getDerived().TransformStmt(E->getBody());
8032 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00008033 return ExprError();
8034
John McCall490112f2011-02-04 18:33:18 +00008035#ifndef NDEBUG
8036 // In builds with assertions, make sure that we captured everything we
8037 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008038 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8039 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8040 e = oldBlock->capture_end(); i != e; ++i) {
8041 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00008042
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008043 // Ignore parameter packs.
8044 if (isa<ParmVarDecl>(oldCapture) &&
8045 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8046 continue;
John McCall490112f2011-02-04 18:33:18 +00008047
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008048 VarDecl *newCapture =
8049 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8050 oldCapture));
8051 assert(blockScope->CaptureMap.count(newCapture));
8052 }
John McCall490112f2011-02-04 18:33:18 +00008053 }
8054#endif
8055
8056 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8057 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008058}
8059
Mike Stump11289f42009-09-09 15:08:12 +00008060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008061ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008062TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008063 ValueDecl *ND
8064 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8065 E->getDecl()));
8066 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008067 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008068
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008069 if (!getDerived().AlwaysRebuild() &&
8070 ND == E->getDecl()) {
8071 // Mark it referenced in the new context regardless.
8072 // FIXME: this is a bit instantiation-specific.
8073 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8074
John McCallc3007a22010-10-26 07:05:15 +00008075 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008076 }
8077
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008078 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00008079 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008080 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008081}
Mike Stump11289f42009-09-09 15:08:12 +00008082
Tanya Lattner55808c12011-06-04 00:47:47 +00008083template<typename Derived>
8084ExprResult
8085TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00008086 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00008087}
8088
Douglas Gregora16548e2009-08-11 05:31:07 +00008089//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008090// Type reconstruction
8091//===----------------------------------------------------------------------===//
8092
Mike Stump11289f42009-09-09 15:08:12 +00008093template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008094QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8095 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008096 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008097 getDerived().getBaseEntity());
8098}
8099
Mike Stump11289f42009-09-09 15:08:12 +00008100template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008101QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8102 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008103 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008104 getDerived().getBaseEntity());
8105}
8106
Mike Stump11289f42009-09-09 15:08:12 +00008107template<typename Derived>
8108QualType
John McCall70dd5f62009-10-30 00:06:24 +00008109TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8110 bool WrittenAsLValue,
8111 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008112 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00008113 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008114}
8115
8116template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008117QualType
John McCall70dd5f62009-10-30 00:06:24 +00008118TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8119 QualType ClassType,
8120 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008121 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00008122 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008123}
8124
8125template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008126QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00008127TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8128 ArrayType::ArraySizeModifier SizeMod,
8129 const llvm::APInt *Size,
8130 Expr *SizeExpr,
8131 unsigned IndexTypeQuals,
8132 SourceRange BracketsRange) {
8133 if (SizeExpr || !Size)
8134 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8135 IndexTypeQuals, BracketsRange,
8136 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00008137
8138 QualType Types[] = {
8139 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8140 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8141 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00008142 };
8143 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8144 QualType SizeType;
8145 for (unsigned I = 0; I != NumTypes; ++I)
8146 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8147 SizeType = Types[I];
8148 break;
8149 }
Mike Stump11289f42009-09-09 15:08:12 +00008150
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008151 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8152 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00008153 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008154 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00008155 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008156}
Mike Stump11289f42009-09-09 15:08:12 +00008157
Douglas Gregord6ff3322009-08-04 16:50:30 +00008158template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008159QualType
8160TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008161 ArrayType::ArraySizeModifier SizeMod,
8162 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00008163 unsigned IndexTypeQuals,
8164 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008165 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008166 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008167}
8168
8169template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008170QualType
Mike Stump11289f42009-09-09 15:08:12 +00008171TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008172 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00008173 unsigned IndexTypeQuals,
8174 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008175 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008176 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008177}
Mike Stump11289f42009-09-09 15:08:12 +00008178
Douglas Gregord6ff3322009-08-04 16:50:30 +00008179template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008180QualType
8181TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008182 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008183 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008184 unsigned IndexTypeQuals,
8185 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008186 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008187 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008188 IndexTypeQuals, BracketsRange);
8189}
8190
8191template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008192QualType
8193TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008194 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008195 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008196 unsigned IndexTypeQuals,
8197 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008198 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008199 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008200 IndexTypeQuals, BracketsRange);
8201}
8202
8203template<typename Derived>
8204QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00008205 unsigned NumElements,
8206 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00008207 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00008208 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008209}
Mike Stump11289f42009-09-09 15:08:12 +00008210
Douglas Gregord6ff3322009-08-04 16:50:30 +00008211template<typename Derived>
8212QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8213 unsigned NumElements,
8214 SourceLocation AttributeLoc) {
8215 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8216 NumElements, true);
8217 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008218 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8219 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00008220 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008221}
Mike Stump11289f42009-09-09 15:08:12 +00008222
Douglas Gregord6ff3322009-08-04 16:50:30 +00008223template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008224QualType
8225TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00008226 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008227 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00008228 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008229}
Mike Stump11289f42009-09-09 15:08:12 +00008230
Douglas Gregord6ff3322009-08-04 16:50:30 +00008231template<typename Derived>
8232QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00008233 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008234 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00008235 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00008236 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008237 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00008238 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00008239 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008240 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008241 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008242 getDerived().getBaseEntity(),
8243 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008244}
Mike Stump11289f42009-09-09 15:08:12 +00008245
Douglas Gregord6ff3322009-08-04 16:50:30 +00008246template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008247QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8248 return SemaRef.Context.getFunctionNoProtoType(T);
8249}
8250
8251template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008252QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8253 assert(D && "no decl found");
8254 if (D->isInvalidDecl()) return QualType();
8255
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008256 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008257 TypeDecl *Ty;
8258 if (isa<UsingDecl>(D)) {
8259 UsingDecl *Using = cast<UsingDecl>(D);
8260 assert(Using->isTypeName() &&
8261 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8262
8263 // A valid resolved using typename decl points to exactly one type decl.
8264 assert(++Using->shadow_begin() == Using->shadow_end());
8265 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008266
John McCallb96ec562009-12-04 22:46:56 +00008267 } else {
8268 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8269 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8270 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8271 }
8272
8273 return SemaRef.Context.getTypeDeclType(Ty);
8274}
8275
8276template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008277QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8278 SourceLocation Loc) {
8279 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008280}
8281
8282template<typename Derived>
8283QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8284 return SemaRef.Context.getTypeOfType(Underlying);
8285}
8286
8287template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008288QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8289 SourceLocation Loc) {
8290 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008291}
8292
8293template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00008294QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8295 UnaryTransformType::UTTKind UKind,
8296 SourceLocation Loc) {
8297 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8298}
8299
8300template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00008301QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008302 TemplateName Template,
8303 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008304 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008305 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008306}
Mike Stump11289f42009-09-09 15:08:12 +00008307
Douglas Gregor1135c352009-08-06 05:28:30 +00008308template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00008309QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8310 SourceLocation KWLoc) {
8311 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8312}
8313
8314template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008315TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008316TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008317 bool TemplateKW,
8318 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008319 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008320 Template);
8321}
8322
8323template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008324TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008325TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8326 const IdentifierInfo &Name,
8327 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008328 QualType ObjectType,
8329 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008330 UnqualifiedId TemplateName;
8331 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008332 Sema::TemplateTy Template;
8333 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008334 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008335 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008336 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008337 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008338 /*EnteringContext=*/false,
8339 Template);
John McCall31f82722010-11-12 08:19:04 +00008340 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008341}
Mike Stump11289f42009-09-09 15:08:12 +00008342
Douglas Gregora16548e2009-08-11 05:31:07 +00008343template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008344TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008345TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008346 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008347 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008348 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008349 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008350 // FIXME: Bogus location information.
8351 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8352 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008353 Sema::TemplateTy Template;
8354 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008355 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008356 SS,
8357 Name,
John McCallba7bf592010-08-24 05:47:05 +00008358 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008359 /*EnteringContext=*/false,
8360 Template);
8361 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008362}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008363
Douglas Gregor71395fa2009-11-04 00:56:37 +00008364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008365ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008366TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8367 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008368 Expr *OrigCallee,
8369 Expr *First,
8370 Expr *Second) {
8371 Expr *Callee = OrigCallee->IgnoreParenCasts();
8372 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008373
Douglas Gregora16548e2009-08-11 05:31:07 +00008374 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008375 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008376 if (!First->getType()->isOverloadableType() &&
8377 !Second->getType()->isOverloadableType())
8378 return getSema().CreateBuiltinArraySubscriptExpr(First,
8379 Callee->getLocStart(),
8380 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008381 } else if (Op == OO_Arrow) {
8382 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008383 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8384 } else if (Second == 0 || isPostIncDec) {
8385 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008386 // The argument is not of overloadable type, so try to create a
8387 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008388 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008389 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008390
John McCallb268a282010-08-23 23:25:46 +00008391 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008392 }
8393 } else {
John McCallb268a282010-08-23 23:25:46 +00008394 if (!First->getType()->isOverloadableType() &&
8395 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008396 // Neither of the arguments is an overloadable type, so try to
8397 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008398 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008399 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008400 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008401 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008402 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008403
Douglas Gregora16548e2009-08-11 05:31:07 +00008404 return move(Result);
8405 }
8406 }
Mike Stump11289f42009-09-09 15:08:12 +00008407
8408 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008409 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008410 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008411
John McCallb268a282010-08-23 23:25:46 +00008412 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008413 assert(ULE->requiresADL());
8414
8415 // FIXME: Do we have to check
8416 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008417 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008418 } else {
John McCallb268a282010-08-23 23:25:46 +00008419 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008420 }
Mike Stump11289f42009-09-09 15:08:12 +00008421
Douglas Gregora16548e2009-08-11 05:31:07 +00008422 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008423 Expr *Args[2] = { First, Second };
8424 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008425
Douglas Gregora16548e2009-08-11 05:31:07 +00008426 // Create the overloaded operator invocation for unary operators.
8427 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008428 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008429 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008430 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008431 }
Mike Stump11289f42009-09-09 15:08:12 +00008432
Douglas Gregore9d62932011-07-15 16:25:15 +00008433 if (Op == OO_Subscript) {
8434 SourceLocation LBrace;
8435 SourceLocation RBrace;
8436
8437 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8438 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8439 LBrace = SourceLocation::getFromRawEncoding(
8440 NameLoc.CXXOperatorName.BeginOpNameLoc);
8441 RBrace = SourceLocation::getFromRawEncoding(
8442 NameLoc.CXXOperatorName.EndOpNameLoc);
8443 } else {
8444 LBrace = Callee->getLocStart();
8445 RBrace = OpLoc;
8446 }
8447
8448 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8449 First, Second);
8450 }
Sebastian Redladba46e2009-10-29 20:17:01 +00008451
Douglas Gregora16548e2009-08-11 05:31:07 +00008452 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008453 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008454 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008455 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8456 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008457 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008458
Mike Stump11289f42009-09-09 15:08:12 +00008459 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008460}
Mike Stump11289f42009-09-09 15:08:12 +00008461
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008463ExprResult
John McCallb268a282010-08-23 23:25:46 +00008464TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008465 SourceLocation OperatorLoc,
8466 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008467 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008468 TypeSourceInfo *ScopeType,
8469 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008470 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008471 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008472 QualType BaseType = Base->getType();
8473 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008474 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008475 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008476 !BaseType->getAs<PointerType>()->getPointeeType()
8477 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008478 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008479 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008480 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008481 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008482 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008483 /*FIXME?*/true);
8484 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008485
Douglas Gregor678f90d2010-02-25 01:56:36 +00008486 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008487 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8488 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8489 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8490 NameInfo.setNamedTypeInfo(DestroyedType);
8491
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008492 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008493
John McCallb268a282010-08-23 23:25:46 +00008494 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008495 OperatorLoc, isArrow,
8496 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008497 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008498 /*TemplateArgs*/ 0);
8499}
8500
Douglas Gregord6ff3322009-08-04 16:50:30 +00008501} // end namespace clang
8502
8503#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H