blob: fe1e9aa9d242a21eb67e8a61eab58aec5af27e64 [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"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000024#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000025#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000027#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000030#include "clang/Sema/Ownership.h"
31#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000032#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000033#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000034#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000035#include <algorithm>
36
37namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000038using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000039
Douglas Gregord6ff3322009-08-04 16:50:30 +000040/// \brief A semantic tree transformation that allows one to transform one
41/// abstract syntax tree into another.
42///
Mike Stump11289f42009-09-09 15:08:12 +000043/// A new tree transformation is defined by creating a new subclass \c X of
44/// \c TreeTransform<X> and then overriding certain operations to provide
45/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000046/// instantiation is implemented as a tree transformation where the
47/// transformation of TemplateTypeParmType nodes involves substituting the
48/// template arguments for their corresponding template parameters; a similar
49/// transformation is performed for non-type template parameters and
50/// template template parameters.
51///
52/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000053/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000054/// override any of the transformation or rebuild operators by providing an
55/// operation with the same signature as the default implementation. The
56/// overridding function should not be virtual.
57///
58/// Semantic tree transformations are split into two stages, either of which
59/// can be replaced by a subclass. The "transform" step transforms an AST node
60/// or the parts of an AST node using the various transformation functions,
61/// then passes the pieces on to the "rebuild" step, which constructs a new AST
62/// node of the appropriate kind from the pieces. The default transformation
63/// routines recursively transform the operands to composite AST nodes (e.g.,
64/// the pointee type of a PointerType node) and, if any of those operand nodes
65/// were changed by the transformation, invokes the rebuild operation to create
66/// a new AST node.
67///
Mike Stump11289f42009-09-09 15:08:12 +000068/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000069/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
71/// TransformTemplateName(), or TransformTemplateArgument() with entirely
72/// new implementations.
73///
74/// For more fine-grained transformations, subclasses can replace any of the
75/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000076/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000078/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// parameters. Additionally, subclasses can override the \c RebuildXXX
80/// functions to control how AST nodes are rebuilt when their operands change.
81/// By default, \c TreeTransform will invoke semantic analysis to rebuild
82/// AST nodes. However, certain other tree transformations (e.g, cloning) may
83/// be able to use more efficient rebuild steps.
84///
85/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000086/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000087/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
88/// operands have not changed (\c AlwaysRebuild()), and customize the
89/// default locations and entity names used for type-checking
90/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000091template<typename Derived>
92class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000093 /// \brief Private RAII object that helps us forget and then re-remember
94 /// the template argument corresponding to a partially-substituted parameter
95 /// pack.
96 class ForgetPartiallySubstitutedPackRAII {
97 Derived &Self;
98 TemplateArgument Old;
99
100 public:
101 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
102 Old = Self.ForgetPartiallySubstitutedPack();
103 }
104
105 ~ForgetPartiallySubstitutedPackRAII() {
106 Self.RememberPartiallySubstitutedPack(Old);
107 }
108 };
109
Douglas Gregord6ff3322009-08-04 16:50:30 +0000110protected:
111 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000112
Mike Stump11289f42009-09-09 15:08:12 +0000113public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000115 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000116
Douglas Gregord6ff3322009-08-04 16:50:30 +0000117 /// \brief Retrieves a reference to the derived class.
118 Derived &getDerived() { return static_cast<Derived&>(*this); }
119
120 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000121 const Derived &getDerived() const {
122 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000123 }
124
John McCalldadc5752010-08-24 06:29:42 +0000125 static inline ExprResult Owned(Expr *E) { return E; }
126 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Retrieves a reference to the semantic analysis object used for
129 /// this tree transform.
130 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000131
Douglas Gregord6ff3322009-08-04 16:50:30 +0000132 /// \brief Whether the transformation should always rebuild AST nodes, even
133 /// if none of the children have changed.
134 ///
135 /// Subclasses may override this function to specify when the transformation
136 /// should rebuild all AST nodes.
137 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Returns the location of the entity being transformed, if that
140 /// information was not available elsewhere in the AST.
141 ///
Mike Stump11289f42009-09-09 15:08:12 +0000142 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000143 /// provide an alternative implementation that provides better location
144 /// information.
145 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000146
Douglas Gregord6ff3322009-08-04 16:50:30 +0000147 /// \brief Returns the name of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
150 /// By default, returns an empty name. Subclasses can provide an alternative
151 /// implementation with a more precise name.
152 DeclarationName getBaseEntity() { return DeclarationName(); }
153
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 /// \brief Sets the "base" location and entity when that
155 /// information is known based on another transformation.
156 ///
157 /// By default, the source location and entity are ignored. Subclasses can
158 /// override this function to provide a customized implementation.
159 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000160
Douglas Gregora16548e2009-08-11 05:31:07 +0000161 /// \brief RAII object that temporarily sets the base location and entity
162 /// used for reporting diagnostics in types.
163 class TemporaryBase {
164 TreeTransform &Self;
165 SourceLocation OldLocation;
166 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000167
Douglas Gregora16548e2009-08-11 05:31:07 +0000168 public:
169 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000170 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000171 OldLocation = Self.getDerived().getBaseLocation();
172 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000173
174 if (Location.isValid())
175 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000176 }
Mike Stump11289f42009-09-09 15:08:12 +0000177
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 ~TemporaryBase() {
179 Self.getDerived().setBase(OldLocation, OldEntity);
180 }
181 };
Mike Stump11289f42009-09-09 15:08:12 +0000182
183 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000184 /// transformed.
185 ///
186 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000187 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000188 /// not change. For example, template instantiation need not traverse
189 /// non-dependent types.
190 bool AlreadyTransformed(QualType T) {
191 return T.isNull();
192 }
193
Douglas Gregord196a582009-12-14 19:27:10 +0000194 /// \brief Determine whether the given call argument should be dropped, e.g.,
195 /// because it is a default argument.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine to
198 /// determine which kinds of call arguments get dropped. By default,
199 /// CXXDefaultArgument nodes are dropped (prior to transformation).
200 bool DropCallArgument(Expr *E) {
201 return E->isDefaultArgument();
202 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000203
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000204 /// \brief Determine whether we should expand a pack expansion with the
205 /// given set of parameter packs into separate arguments by repeatedly
206 /// transforming the pattern.
207 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000208 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000209 /// Subclasses can override this routine to provide different behavior.
210 ///
211 /// \param EllipsisLoc The location of the ellipsis that identifies the
212 /// pack expansion.
213 ///
214 /// \param PatternRange The source range that covers the entire pattern of
215 /// the pack expansion.
216 ///
217 /// \param Unexpanded The set of unexpanded parameter packs within the
218 /// pattern.
219 ///
220 /// \param NumUnexpanded The number of unexpanded parameter packs in
221 /// \p Unexpanded.
222 ///
223 /// \param ShouldExpand Will be set to \c true if the transformer should
224 /// expand the corresponding pack expansions into separate arguments. When
225 /// set, \c NumExpansions must also be set.
226 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000227 /// \param RetainExpansion Whether the caller should add an unexpanded
228 /// pack expansion after all of the expanded arguments. This is used
229 /// when extending explicitly-specified template argument packs per
230 /// C++0x [temp.arg.explicit]p9.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000233 /// the expanded form of the corresponding pack expansion. This is both an
234 /// input and an output parameter, which can be set by the caller if the
235 /// number of expansions is known a priori (e.g., due to a prior substitution)
236 /// and will be set by the callee when the number of expansions is known.
237 /// The callee must set this value when \c ShouldExpand is \c true; it may
238 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000239 ///
240 /// \returns true if an error occurred (e.g., because the parameter packs
241 /// are to be instantiated with arguments of different lengths), false
242 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
243 /// must be set.
244 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
245 SourceRange PatternRange,
246 const UnexpandedParameterPack *Unexpanded,
247 unsigned NumUnexpanded,
248 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000249 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000250 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 ShouldExpand = false;
252 return false;
253 }
254
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000255 /// \brief "Forget" about the partially-substituted pack template argument,
256 /// when performing an instantiation that must preserve the parameter pack
257 /// use.
258 ///
259 /// This routine is meant to be overridden by the template instantiator.
260 TemplateArgument ForgetPartiallySubstitutedPack() {
261 return TemplateArgument();
262 }
263
264 /// \brief "Remember" the partially-substituted pack template argument
265 /// after performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
270
Douglas Gregorf3010112011-01-07 16:43:16 +0000271 /// \brief Note to the derived class when a function parameter pack is
272 /// being expanded.
273 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
274
Douglas Gregord6ff3322009-08-04 16:50:30 +0000275 /// \brief Transforms the given type into another type.
276 ///
John McCall550e0c22009-10-21 00:40:46 +0000277 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000278 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000279 /// function. This is expensive, but we don't mind, because
280 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000281 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 ///
283 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000284 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000285
John McCall550e0c22009-10-21 00:40:46 +0000286 /// \brief Transforms the given type-with-location into a new
287 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000288 ///
John McCall550e0c22009-10-21 00:40:46 +0000289 /// By default, this routine transforms a type by delegating to the
290 /// appropriate TransformXXXType to build a new type. Subclasses
291 /// may override this function (to take over all type
292 /// transformations) or some set of the TransformXXXType functions
293 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000294 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000295
296 /// \brief Transform the given type-with-location into a new
297 /// type, collecting location information in the given builder
298 /// as necessary.
299 ///
John McCall31f82722010-11-12 08:19:04 +0000300 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000301
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000302 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000303 ///
Mike Stump11289f42009-09-09 15:08:12 +0000304 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000305 /// appropriate TransformXXXStmt function to transform a specific kind of
306 /// statement or the TransformExpr() function to transform an expression.
307 /// Subclasses may override this function to transform statements using some
308 /// other mechanism.
309 ///
310 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000311 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000312
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000313 /// \brief Transform the given expression.
314 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000315 /// By default, this routine transforms an expression by delegating to the
316 /// appropriate TransformXXXExpr function to build a new expression.
317 /// Subclasses may override this function to transform expressions using some
318 /// other mechanism.
319 ///
320 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000321 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000322
Douglas Gregora3efea12011-01-03 19:04:46 +0000323 /// \brief Transform the given list of expressions.
324 ///
325 /// This routine transforms a list of expressions by invoking
326 /// \c TransformExpr() for each subexpression. However, it also provides
327 /// support for variadic templates by expanding any pack expansions (if the
328 /// derived class permits such expansion) along the way. When pack expansions
329 /// are present, the number of outputs may not equal the number of inputs.
330 ///
331 /// \param Inputs The set of expressions to be transformed.
332 ///
333 /// \param NumInputs The number of expressions in \c Inputs.
334 ///
335 /// \param IsCall If \c true, then this transform is being performed on
336 /// function-call arguments, and any arguments that should be dropped, will
337 /// be.
338 ///
339 /// \param Outputs The transformed input expressions will be added to this
340 /// vector.
341 ///
342 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
343 /// due to transformation.
344 ///
345 /// \returns true if an error occurred, false otherwise.
346 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
347 llvm::SmallVectorImpl<Expr *> &Outputs,
348 bool *ArgChanged = 0);
349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Transform the given declaration, which is referenced from a type
351 /// or expression.
352 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000353 /// By default, acts as the identity function on declarations. Subclasses
354 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000355 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000356
357 /// \brief Transform the definition of the given declaration.
358 ///
Mike Stump11289f42009-09-09 15:08:12 +0000359 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000360 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000361 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
362 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000363 }
Mike Stump11289f42009-09-09 15:08:12 +0000364
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000365 /// \brief Transform the given declaration, which was the first part of a
366 /// nested-name-specifier in a member access expression.
367 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000368 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000369 /// identifier in a nested-name-specifier of a member access expression, e.g.,
370 /// the \c T in \c x->T::member
371 ///
372 /// By default, invokes TransformDecl() to transform the declaration.
373 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000374 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
375 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000376 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000377
Douglas Gregord6ff3322009-08-04 16:50:30 +0000378 /// \brief Transform the given nested-name-specifier.
379 ///
Mike Stump11289f42009-09-09 15:08:12 +0000380 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// nested-name-specifier. Subclasses may override this function to provide
382 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000384 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000385 QualType ObjectType = QualType(),
386 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000387
Douglas Gregor14454802011-02-25 02:25:35 +0000388 /// \brief Transform the given nested-name-specifier with source-location
389 /// information.
390 ///
391 /// By default, transforms all of the types and declarations within the
392 /// nested-name-specifier. Subclasses may override this function to provide
393 /// alternate behavior.
394 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
395 NestedNameSpecifierLoc NNS,
396 QualType ObjectType = QualType(),
397 NamedDecl *FirstQualifierInScope = 0);
398
Douglas Gregorf816bd72009-09-03 22:13:48 +0000399 /// \brief Transform the given declaration name.
400 ///
401 /// By default, transforms the types of conversion function, constructor,
402 /// and destructor names and then (if needed) rebuilds the declaration name.
403 /// Identifiers and selectors are returned unmodified. Sublcasses may
404 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000405 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000406 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000407
Douglas Gregord6ff3322009-08-04 16:50:30 +0000408 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000409 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000410 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000412 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000413 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000414 QualType ObjectType = QualType(),
415 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregord6ff3322009-08-04 16:50:30 +0000417 /// \brief Transform the given template argument.
418 ///
Mike Stump11289f42009-09-09 15:08:12 +0000419 /// By default, this operation transforms the type, expression, or
420 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000421 /// new template argument from the transformed result. Subclasses may
422 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000423 ///
424 /// Returns true if there was an error.
425 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
426 TemplateArgumentLoc &Output);
427
Douglas Gregor62e06f22010-12-20 17:31:10 +0000428 /// \brief Transform the given set of template arguments.
429 ///
430 /// By default, this operation transforms all of the template arguments
431 /// in the input set using \c TransformTemplateArgument(), and appends
432 /// the transformed arguments to the output list.
433 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000434 /// Note that this overload of \c TransformTemplateArguments() is merely
435 /// a convenience function. Subclasses that wish to override this behavior
436 /// should override the iterator-based member template version.
437 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000438 /// \param Inputs The set of template arguments to be transformed.
439 ///
440 /// \param NumInputs The number of template arguments in \p Inputs.
441 ///
442 /// \param Outputs The set of transformed template arguments output by this
443 /// routine.
444 ///
445 /// Returns true if an error occurred.
446 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
447 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000448 TemplateArgumentListInfo &Outputs) {
449 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
450 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000451
452 /// \brief Transform the given set of template arguments.
453 ///
454 /// By default, this operation transforms all of the template arguments
455 /// in the input set using \c TransformTemplateArgument(), and appends
456 /// the transformed arguments to the output list.
457 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000458 /// \param First An iterator to the first template argument.
459 ///
460 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000461 ///
462 /// \param Outputs The set of transformed template arguments output by this
463 /// routine.
464 ///
465 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000466 template<typename InputIterator>
467 bool TransformTemplateArguments(InputIterator First,
468 InputIterator Last,
469 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000470
John McCall0ad16662009-10-29 08:12:44 +0000471 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
472 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
473 TemplateArgumentLoc &ArgLoc);
474
John McCallbcd03502009-12-07 02:54:59 +0000475 /// \brief Fakes up a TypeSourceInfo for a type.
476 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
477 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000478 getDerived().getBaseLocation());
479 }
Mike Stump11289f42009-09-09 15:08:12 +0000480
John McCall550e0c22009-10-21 00:40:46 +0000481#define ABSTRACT_TYPELOC(CLASS, PARENT)
482#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000483 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000484#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000485
John McCall31f82722010-11-12 08:19:04 +0000486 QualType
487 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
488 TemplateSpecializationTypeLoc TL,
489 TemplateName Template);
490
491 QualType
492 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
493 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor5a064722011-02-28 17:23:35 +0000494 TemplateName Template);
495
496 QualType
497 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
498 DependentTemplateSpecializationTypeLoc TL,
John McCall31f82722010-11-12 08:19:04 +0000499 NestedNameSpecifier *Prefix);
500
Douglas Gregora7a795b2011-03-01 20:11:18 +0000501 QualType
502 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
503 DependentTemplateSpecializationTypeLoc TL,
504 NestedNameSpecifierLoc QualifierLoc);
505
John McCall58f10c32010-03-11 09:03:00 +0000506 /// \brief Transforms the parameters of a function type into the
507 /// given vectors.
508 ///
509 /// The result vectors should be kept in sync; null entries in the
510 /// variables vector are acceptable.
511 ///
512 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000513 bool TransformFunctionTypeParams(SourceLocation Loc,
514 ParmVarDecl **Params, unsigned NumParams,
515 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000516 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000517 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000518
519 /// \brief Transforms a single function-type parameter. Return null
520 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000521 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
522 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000523
John McCall31f82722010-11-12 08:19:04 +0000524 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000525
John McCalldadc5752010-08-24 06:29:42 +0000526 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
527 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000528
Douglas Gregorebe10102009-08-20 07:17:43 +0000529#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000530 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000531#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000532 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000533#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000534#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000535
Douglas Gregord6ff3322009-08-04 16:50:30 +0000536 /// \brief Build a new pointer type given its pointee type.
537 ///
538 /// By default, performs semantic analysis when building the pointer type.
539 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000540 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000541
542 /// \brief Build a new block pointer type given its pointee type.
543 ///
Mike Stump11289f42009-09-09 15:08:12 +0000544 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000545 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000546 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000547
John McCall70dd5f62009-10-30 00:06:24 +0000548 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549 ///
John McCall70dd5f62009-10-30 00:06:24 +0000550 /// By default, performs semantic analysis when building the
551 /// reference type. Subclasses may override this routine to provide
552 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000553 ///
John McCall70dd5f62009-10-30 00:06:24 +0000554 /// \param LValue whether the type was written with an lvalue sigil
555 /// or an rvalue sigil.
556 QualType RebuildReferenceType(QualType ReferentType,
557 bool LValue,
558 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000559
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 /// \brief Build a new member pointer type given the pointee type and the
561 /// class type it refers into.
562 ///
563 /// By default, performs semantic analysis when building the member pointer
564 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000565 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
566 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000567
Douglas Gregord6ff3322009-08-04 16:50:30 +0000568 /// \brief Build a new array type given the element type, size
569 /// modifier, size of the array (if known), size expression, and index type
570 /// qualifiers.
571 ///
572 /// By default, performs semantic analysis when building the array type.
573 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000574 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000575 QualType RebuildArrayType(QualType ElementType,
576 ArrayType::ArraySizeModifier SizeMod,
577 const llvm::APInt *Size,
578 Expr *SizeExpr,
579 unsigned IndexTypeQuals,
580 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000581
Douglas Gregord6ff3322009-08-04 16:50:30 +0000582 /// \brief Build a new constant array type given the element type, size
583 /// modifier, (known) size of the array, and index type qualifiers.
584 ///
585 /// By default, performs semantic analysis when building the array type.
586 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000587 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000588 ArrayType::ArraySizeModifier SizeMod,
589 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000592
Douglas Gregord6ff3322009-08-04 16:50:30 +0000593 /// \brief Build a new incomplete array type given the element type, size
594 /// modifier, 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 RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000600 unsigned IndexTypeQuals,
601 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000602
Mike Stump11289f42009-09-09 15:08:12 +0000603 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000604 /// size modifier, size expression, and index type qualifiers.
605 ///
606 /// By default, performs semantic analysis when building the array type.
607 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000608 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000609 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000610 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
613
Mike Stump11289f42009-09-09 15:08:12 +0000614 /// \brief Build a new dependent-sized 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 RebuildDependentSizedArrayType(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
625 /// \brief Build a new vector type given the element type and
626 /// number of elements.
627 ///
628 /// By default, performs semantic analysis when building the vector type.
629 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000630 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000631 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000632
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633 /// \brief Build a new extended vector type given the element type and
634 /// number of elements.
635 ///
636 /// By default, performs semantic analysis when building the vector type.
637 /// Subclasses may override this routine to provide different behavior.
638 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
639 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000640
641 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000642 /// given the element type and number of elements.
643 ///
644 /// By default, performs semantic analysis when building the vector type.
645 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000646 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000647 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000648 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000649
Douglas Gregord6ff3322009-08-04 16:50:30 +0000650 /// \brief Build a new function type.
651 ///
652 /// By default, performs semantic analysis when building the function type.
653 /// Subclasses may override this routine to provide different behavior.
654 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000655 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000656 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000657 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000658 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000659 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000660
John McCall550e0c22009-10-21 00:40:46 +0000661 /// \brief Build a new unprototyped function type.
662 QualType RebuildFunctionNoProtoType(QualType ResultType);
663
John McCallb96ec562009-12-04 22:46:56 +0000664 /// \brief Rebuild an unresolved typename type, given the decl that
665 /// the UnresolvedUsingTypenameDecl was transformed to.
666 QualType RebuildUnresolvedUsingType(Decl *D);
667
Douglas Gregord6ff3322009-08-04 16:50:30 +0000668 /// \brief Build a new typedef type.
669 QualType RebuildTypedefType(TypedefDecl *Typedef) {
670 return SemaRef.Context.getTypeDeclType(Typedef);
671 }
672
673 /// \brief Build a new class/struct/union type.
674 QualType RebuildRecordType(RecordDecl *Record) {
675 return SemaRef.Context.getTypeDeclType(Record);
676 }
677
678 /// \brief Build a new Enum type.
679 QualType RebuildEnumType(EnumDecl *Enum) {
680 return SemaRef.Context.getTypeDeclType(Enum);
681 }
John McCallfcc33b02009-09-05 00:15:47 +0000682
Mike Stump11289f42009-09-09 15:08:12 +0000683 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684 ///
685 /// By default, performs semantic analysis when building the typeof type.
686 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000687 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000688
Mike Stump11289f42009-09-09 15:08:12 +0000689 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 ///
691 /// By default, builds a new TypeOfType with the given underlying type.
692 QualType RebuildTypeOfType(QualType Underlying);
693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the decltype type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000698 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000699
Richard Smith30482bc2011-02-20 03:19:35 +0000700 /// \brief Build a new C++0x auto type.
701 ///
702 /// By default, builds a new AutoType with the given deduced type.
703 QualType RebuildAutoType(QualType Deduced) {
704 return SemaRef.Context.getAutoType(Deduced);
705 }
706
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 /// \brief Build a new template specialization type.
708 ///
709 /// By default, performs semantic analysis when building the template
710 /// specialization type. Subclasses may override this routine to provide
711 /// different behavior.
712 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000713 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000714 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000715
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000716 /// \brief Build a new parenthesized type.
717 ///
718 /// By default, builds a new ParenType type from the inner type.
719 /// Subclasses may override this routine to provide different behavior.
720 QualType RebuildParenType(QualType InnerType) {
721 return SemaRef.Context.getParenType(InnerType);
722 }
723
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// \brief Build a new qualified name type.
725 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000726 /// By default, builds a new ElaboratedType type from the keyword,
727 /// the nested-name-specifier and the named type.
728 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000729 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
730 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000731 NestedNameSpecifierLoc QualifierLoc,
732 QualType Named) {
733 return SemaRef.Context.getElaboratedType(Keyword,
734 QualifierLoc.getNestedNameSpecifier(),
735 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000736 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000737
738 /// \brief Build a new typename type that refers to a template-id.
739 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000740 /// By default, builds a new DependentNameType type from the
741 /// nested-name-specifier and the given type. Subclasses may override
742 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000743 QualType RebuildDependentTemplateSpecializationType(
744 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000745 NestedNameSpecifier *Qualifier,
746 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000747 const IdentifierInfo *Name,
748 SourceLocation NameLoc,
749 const TemplateArgumentListInfo &Args) {
750 // Rebuild the template name.
751 // TODO: avoid TemplateName abstraction
752 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000753 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000754 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000755
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000756 if (InstName.isNull())
757 return QualType();
758
John McCallc392f372010-06-11 00:33:02 +0000759 // If it's still dependent, make a dependent specialization.
760 if (InstName.getAsDependentTemplateName())
761 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000762 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000763
764 // Otherwise, make an elaborated type wrapping a non-dependent
765 // specialization.
766 QualType T =
767 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
768 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000769
Douglas Gregor5a064722011-02-28 17:23:35 +0000770 if (Keyword == ETK_None && Qualifier == 0)
Douglas Gregor6e068012011-02-28 00:04:36 +0000771 return T;
772
Douglas Gregor5a064722011-02-28 17:23:35 +0000773 return SemaRef.Context.getElaboratedType(Keyword, Qualifier, T);
Mike Stump11289f42009-09-09 15:08:12 +0000774 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000775
Douglas Gregora7a795b2011-03-01 20:11:18 +0000776 /// \brief Build a new typename type that refers to a template-id.
777 ///
778 /// By default, builds a new DependentNameType type from the
779 /// nested-name-specifier and the given type. Subclasses may override
780 /// this routine to provide different behavior.
781 QualType RebuildDependentTemplateSpecializationType(
782 ElaboratedTypeKeyword Keyword,
783 NestedNameSpecifierLoc QualifierLoc,
784 const IdentifierInfo *Name,
785 SourceLocation NameLoc,
786 const TemplateArgumentListInfo &Args) {
787 // Rebuild the template name.
788 // TODO: avoid TemplateName abstraction
789 TemplateName InstName
790 = getDerived().RebuildTemplateName(QualifierLoc.getNestedNameSpecifier(),
791 QualifierLoc.getSourceRange(), *Name,
792 QualType(), 0);
793
794 if (InstName.isNull())
795 return QualType();
796
797 // If it's still dependent, make a dependent specialization.
798 if (InstName.getAsDependentTemplateName())
799 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
800 QualifierLoc.getNestedNameSpecifier(),
801 Name,
802 Args);
803
804 // Otherwise, make an elaborated type wrapping a non-dependent
805 // specialization.
806 QualType T =
807 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
808 if (T.isNull()) return QualType();
809
810 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
811 return T;
812
813 return SemaRef.Context.getElaboratedType(Keyword,
814 QualifierLoc.getNestedNameSpecifier(),
815 T);
816 }
817
Douglas Gregord6ff3322009-08-04 16:50:30 +0000818 /// \brief Build a new typename type that refers to an identifier.
819 ///
820 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000821 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000823 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000824 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000825 NestedNameSpecifierLoc QualifierLoc,
826 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000827 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000828 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000829 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000830
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000831 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000832 // If the name is still dependent, just build a new dependent name type.
833 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000834 return SemaRef.Context.getDependentNameType(Keyword,
835 QualifierLoc.getNestedNameSpecifier(),
836 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000837 }
838
Abramo Bagnara6150c882010-05-11 21:36:43 +0000839 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000840 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000841 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000842
843 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
844
Abramo Bagnarad7548482010-05-19 21:37:53 +0000845 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000846 // into a non-dependent elaborated-type-specifier. Find the tag we're
847 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000848 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000849 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
850 if (!DC)
851 return QualType();
852
John McCallbf8c5192010-05-27 06:40:31 +0000853 if (SemaRef.RequireCompleteDeclContext(SS, DC))
854 return QualType();
855
Douglas Gregore677daf2010-03-31 22:19:08 +0000856 TagDecl *Tag = 0;
857 SemaRef.LookupQualifiedName(Result, DC);
858 switch (Result.getResultKind()) {
859 case LookupResult::NotFound:
860 case LookupResult::NotFoundInCurrentInstantiation:
861 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000862
Douglas Gregore677daf2010-03-31 22:19:08 +0000863 case LookupResult::Found:
864 Tag = Result.getAsSingle<TagDecl>();
865 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000866
Douglas Gregore677daf2010-03-31 22:19:08 +0000867 case LookupResult::FoundOverloaded:
868 case LookupResult::FoundUnresolvedValue:
869 llvm_unreachable("Tag lookup cannot find non-tags");
870 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000871
Douglas Gregore677daf2010-03-31 22:19:08 +0000872 case LookupResult::Ambiguous:
873 // Let the LookupResult structure handle ambiguities.
874 return QualType();
875 }
876
877 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000878 // Check where the name exists but isn't a tag type and use that to emit
879 // better diagnostics.
880 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
881 SemaRef.LookupQualifiedName(Result, DC);
882 switch (Result.getResultKind()) {
883 case LookupResult::Found:
884 case LookupResult::FoundOverloaded:
885 case LookupResult::FoundUnresolvedValue: {
886 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
887 unsigned Kind = 0;
888 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
889 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
890 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
891 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
892 break;
893 }
894 default:
895 // FIXME: Would be nice to highlight just the source range.
896 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
897 << Kind << Id << DC;
898 break;
899 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000900 return QualType();
901 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000902
Abramo Bagnarad7548482010-05-19 21:37:53 +0000903 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
904 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000905 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
906 return QualType();
907 }
908
909 // Build the elaborated-type-specifier type.
910 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000911 return SemaRef.Context.getElaboratedType(Keyword,
912 QualifierLoc.getNestedNameSpecifier(),
913 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000914 }
Mike Stump11289f42009-09-09 15:08:12 +0000915
Douglas Gregor822d0302011-01-12 17:07:58 +0000916 /// \brief Build a new pack expansion type.
917 ///
918 /// By default, builds a new PackExpansionType type from the given pattern.
919 /// Subclasses may override this routine to provide different behavior.
920 QualType RebuildPackExpansionType(QualType Pattern,
921 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000922 SourceLocation EllipsisLoc,
923 llvm::Optional<unsigned> NumExpansions) {
924 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
925 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000926 }
927
Douglas Gregor1135c352009-08-06 05:28:30 +0000928 /// \brief Build a new nested-name-specifier given the prefix and an
929 /// identifier that names the next step in the nested-name-specifier.
930 ///
931 /// By default, performs semantic analysis when building the new
932 /// nested-name-specifier. Subclasses may override this routine to provide
933 /// different behavior.
934 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
935 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000936 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000937 QualType ObjectType,
938 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000939
940 /// \brief Build a new nested-name-specifier given the prefix and the
941 /// namespace named in the next step in the nested-name-specifier.
942 ///
943 /// By default, performs semantic analysis when building the new
944 /// nested-name-specifier. Subclasses may override this routine to provide
945 /// different behavior.
946 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
947 SourceRange Range,
948 NamespaceDecl *NS);
949
950 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor7b26ff92011-02-24 02:36:08 +0000951 /// namespace alias named in the next step in the nested-name-specifier.
952 ///
953 /// By default, performs semantic analysis when building the new
954 /// nested-name-specifier. Subclasses may override this routine to provide
955 /// different behavior.
956 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
957 SourceRange Range,
958 NamespaceAliasDecl *Alias);
959
960 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor1135c352009-08-06 05:28:30 +0000961 /// type named in the next step in the nested-name-specifier.
962 ///
963 /// By default, performs semantic analysis when building the new
964 /// nested-name-specifier. Subclasses may override this routine to provide
965 /// different behavior.
966 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
967 SourceRange Range,
968 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000969 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000970
971 /// \brief Build a new template name given a nested name specifier, a flag
972 /// indicating whether the "template" keyword was provided, and the template
973 /// that the template name refers to.
974 ///
975 /// By default, builds the new template name directly. Subclasses may override
976 /// this routine to provide different behavior.
977 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
978 bool TemplateKW,
979 TemplateDecl *Template);
980
Douglas Gregor71dc5092009-08-06 06:41:21 +0000981 /// \brief Build a new template name given a nested name specifier and the
982 /// name that is referred to as a template.
983 ///
984 /// By default, performs semantic analysis to determine whether the name can
985 /// be resolved to a specific template, then builds the appropriate kind of
986 /// template name. Subclasses may override this routine to provide different
987 /// behavior.
988 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000989 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000990 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000991 QualType ObjectType,
992 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000993
Douglas Gregor71395fa2009-11-04 00:56:37 +0000994 /// \brief Build a new template name given a nested name specifier and the
995 /// overloaded operator name that is referred to as a template.
996 ///
997 /// By default, performs semantic analysis to determine whether the name can
998 /// be resolved to a specific template, then builds the appropriate kind of
999 /// template name. Subclasses may override this routine to provide different
1000 /// behavior.
1001 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
1002 OverloadedOperatorKind Operator,
1003 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001004
1005 /// \brief Build a new template name given a template template parameter pack
1006 /// and the
1007 ///
1008 /// By default, performs semantic analysis to determine whether the name can
1009 /// be resolved to a specific template, then builds the appropriate kind of
1010 /// template name. Subclasses may override this routine to provide different
1011 /// behavior.
1012 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1013 const TemplateArgument &ArgPack) {
1014 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1015 }
1016
Douglas Gregorebe10102009-08-20 07:17:43 +00001017 /// \brief Build a new compound statement.
1018 ///
1019 /// By default, performs semantic analysis to build the new statement.
1020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001021 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001022 MultiStmtArg Statements,
1023 SourceLocation RBraceLoc,
1024 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001025 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001026 IsStmtExpr);
1027 }
1028
1029 /// \brief Build a new case statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001033 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001034 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001035 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001036 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001037 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001038 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001039 ColonLoc);
1040 }
Mike Stump11289f42009-09-09 15:08:12 +00001041
Douglas Gregorebe10102009-08-20 07:17:43 +00001042 /// \brief Attach the body to a new case statement.
1043 ///
1044 /// By default, performs semantic analysis to build the new statement.
1045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001046 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001047 getSema().ActOnCaseStmtBody(S, Body);
1048 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001049 }
Mike Stump11289f42009-09-09 15:08:12 +00001050
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 /// \brief Build a new default statement.
1052 ///
1053 /// By default, performs semantic analysis to build the new statement.
1054 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001055 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001056 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001057 Stmt *SubStmt) {
1058 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 /*CurScope=*/0);
1060 }
Mike Stump11289f42009-09-09 15:08:12 +00001061
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 /// \brief Build a new label statement.
1063 ///
1064 /// By default, performs semantic analysis to build the new statement.
1065 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001066 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1067 SourceLocation ColonLoc, Stmt *SubStmt) {
1068 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001069 }
Mike Stump11289f42009-09-09 15:08:12 +00001070
Douglas Gregorebe10102009-08-20 07:17:43 +00001071 /// \brief Build a new "if" statement.
1072 ///
1073 /// By default, performs semantic analysis to build the new statement.
1074 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001075 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001076 VarDecl *CondVar, Stmt *Then,
1077 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001078 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 }
Mike Stump11289f42009-09-09 15:08:12 +00001080
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 /// \brief Start building a new switch statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001085 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001086 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001087 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001088 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001089 }
Mike Stump11289f42009-09-09 15:08:12 +00001090
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 /// \brief Attach the body to the switch statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001095 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001096 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001097 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001098 }
1099
1100 /// \brief Build a new while statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001104 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1105 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001106 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001107 }
Mike Stump11289f42009-09-09 15:08:12 +00001108
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 /// \brief Build a new do-while statement.
1110 ///
1111 /// By default, performs semantic analysis to build the new statement.
1112 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001113 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001114 SourceLocation WhileLoc, SourceLocation LParenLoc,
1115 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001116 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1117 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001118 }
1119
1120 /// \brief Build a new for statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001124 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1125 Stmt *Init, Sema::FullExprArg Cond,
1126 VarDecl *CondVar, Sema::FullExprArg Inc,
1127 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001128 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001129 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 }
Mike Stump11289f42009-09-09 15:08:12 +00001131
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 /// \brief Build a new goto statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001136 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1137 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001138 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 }
1140
1141 /// \brief Build a new indirect goto statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001145 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001146 SourceLocation StarLoc,
1147 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001148 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001149 }
Mike Stump11289f42009-09-09 15:08:12 +00001150
Douglas Gregorebe10102009-08-20 07:17:43 +00001151 /// \brief Build a new return statement.
1152 ///
1153 /// By default, performs semantic analysis to build the new statement.
1154 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001155 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001156 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001157 }
Mike Stump11289f42009-09-09 15:08:12 +00001158
Douglas Gregorebe10102009-08-20 07:17:43 +00001159 /// \brief Build a new declaration statement.
1160 ///
1161 /// By default, performs semantic analysis to build the new statement.
1162 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001163 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001164 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001165 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001166 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1167 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Anders Carlssonaaeef072010-01-24 05:50:09 +00001170 /// \brief Build a new inline asm statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001174 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001175 bool IsSimple,
1176 bool IsVolatile,
1177 unsigned NumOutputs,
1178 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001179 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001180 MultiExprArg Constraints,
1181 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001182 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001183 MultiExprArg Clobbers,
1184 SourceLocation RParenLoc,
1185 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001186 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001187 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001188 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001189 RParenLoc, MSAsm);
1190 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001191
1192 /// \brief Build a new Objective-C @try statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001196 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001197 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001198 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001199 Stmt *Finally) {
1200 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1201 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001202 }
1203
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001204 /// \brief Rebuild an Objective-C exception declaration.
1205 ///
1206 /// By default, performs semantic analysis to build the new declaration.
1207 /// Subclasses may override this routine to provide different behavior.
1208 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1209 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001210 return getSema().BuildObjCExceptionDecl(TInfo, T,
1211 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001212 ExceptionDecl->getLocation());
1213 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001214
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001215 /// \brief Build a new Objective-C @catch statement.
1216 ///
1217 /// By default, performs semantic analysis to build the new statement.
1218 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001219 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001220 SourceLocation RParenLoc,
1221 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001222 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001223 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001224 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001225 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001226
Douglas Gregor306de2f2010-04-22 23:59:56 +00001227 /// \brief Build a new Objective-C @finally 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 RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001232 Stmt *Body) {
1233 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001234 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001235
Douglas Gregor6148de72010-04-22 22:01:21 +00001236 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001237 ///
1238 /// By default, performs semantic analysis to build the new statement.
1239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001240 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001241 Expr *Operand) {
1242 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001243 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001244
Douglas Gregor6148de72010-04-22 22:01:21 +00001245 /// \brief Build a new Objective-C @synchronized statement.
1246 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001247 /// By default, performs semantic analysis to build the new statement.
1248 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001249 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001250 Expr *Object,
1251 Stmt *Body) {
1252 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1253 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001254 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001255
1256 /// \brief Build a new Objective-C fast enumeration statement.
1257 ///
1258 /// By default, performs semantic analysis to build the new statement.
1259 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001260 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001261 SourceLocation LParenLoc,
1262 Stmt *Element,
1263 Expr *Collection,
1264 SourceLocation RParenLoc,
1265 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001266 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001267 Element,
1268 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001269 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001270 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001271 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001272
Douglas Gregorebe10102009-08-20 07:17:43 +00001273 /// \brief Build a new C++ exception declaration.
1274 ///
1275 /// By default, performs semantic analysis to build the new decaration.
1276 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001277 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001278 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001279 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001280 SourceLocation Loc) {
1281 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001282 }
1283
1284 /// \brief Build a new C++ catch statement.
1285 ///
1286 /// By default, performs semantic analysis to build the new statement.
1287 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001288 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001289 VarDecl *ExceptionDecl,
1290 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001291 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1292 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001293 }
Mike Stump11289f42009-09-09 15:08:12 +00001294
Douglas Gregorebe10102009-08-20 07:17:43 +00001295 /// \brief Build a new C++ try statement.
1296 ///
1297 /// By default, performs semantic analysis to build the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001299 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001300 Stmt *TryBlock,
1301 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001302 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001303 }
Mike Stump11289f42009-09-09 15:08:12 +00001304
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 /// \brief Build a new expression that references a declaration.
1306 ///
1307 /// By default, performs semantic analysis to build the new expression.
1308 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001309 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001310 LookupResult &R,
1311 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001312 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1313 }
1314
1315
1316 /// \brief Build a new expression that references a declaration.
1317 ///
1318 /// By default, performs semantic analysis to build the new expression.
1319 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001320 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001321 ValueDecl *VD,
1322 const DeclarationNameInfo &NameInfo,
1323 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001324 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001325 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001326
1327 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001328
1329 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001333 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001336 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001338 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 }
1340
Douglas Gregorad8a3362009-09-04 17:36:40 +00001341 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001342 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001345 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001346 SourceLocation OperatorLoc,
1347 bool isArrow,
1348 CXXScopeSpec &SS,
1349 TypeSourceInfo *ScopeType,
1350 SourceLocation CCLoc,
1351 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001352 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001353
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001355 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001356 /// By default, performs semantic analysis to build the new expression.
1357 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001358 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001359 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001360 Expr *SubExpr) {
1361 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 }
Mike Stump11289f42009-09-09 15:08:12 +00001363
Douglas Gregor882211c2010-04-28 22:16:22 +00001364 /// \brief Build a new builtin offsetof expression.
1365 ///
1366 /// By default, performs semantic analysis to build the new expression.
1367 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001368 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001369 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001370 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001371 unsigned NumComponents,
1372 SourceLocation RParenLoc) {
1373 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1374 NumComponents, RParenLoc);
1375 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001376
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001378 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001379 /// By default, performs semantic analysis to build the new expression.
1380 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001381 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001382 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001384 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 }
1386
Mike Stump11289f42009-09-09 15:08:12 +00001387 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001388 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001389 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 /// By default, performs semantic analysis to build the new expression.
1391 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001392 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001394 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001395 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001396 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001397 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001398
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 return move(Result);
1400 }
Mike Stump11289f42009-09-09 15:08:12 +00001401
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001403 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001406 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001407 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001408 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001410 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1411 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 RBracketLoc);
1413 }
1414
1415 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001416 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001419 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001421 SourceLocation RParenLoc,
1422 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001423 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001424 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 }
1426
1427 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001428 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 /// By default, performs semantic analysis to build the new expression.
1430 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001431 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001432 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001433 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001434 const DeclarationNameInfo &MemberNameInfo,
1435 ValueDecl *Member,
1436 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001437 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001438 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001439 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001440 // We have a reference to an unnamed field. This is always the
1441 // base of an anonymous struct/union member access, i.e. the
1442 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001443 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001444 assert(Member->getType()->isRecordType() &&
1445 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001446
Douglas Gregorea972d32011-02-28 21:54:11 +00001447 if (getSema().PerformObjectMemberConversion(Base,
1448 QualifierLoc.getNestedNameSpecifier(),
John McCall16df1e52010-03-30 21:47:33 +00001449 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001450 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001451
John McCall7decc9e2010-11-18 06:31:45 +00001452 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001453 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001454 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001455 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001456 cast<FieldDecl>(Member)->getType(),
1457 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001458 return getSema().Owned(ME);
1459 }
Mike Stump11289f42009-09-09 15:08:12 +00001460
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001461 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001462 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001463
John McCallb268a282010-08-23 23:25:46 +00001464 getSema().DefaultFunctionArrayConversion(Base);
1465 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001466
John McCall16df1e52010-03-30 21:47:33 +00001467 // FIXME: this involves duplicating earlier analysis in a lot of
1468 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001469 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001470 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001471 R.resolveKind();
1472
John McCallb268a282010-08-23 23:25:46 +00001473 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001474 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001475 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001476 }
Mike Stump11289f42009-09-09 15:08:12 +00001477
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001479 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 /// By default, performs semantic analysis to build the new expression.
1481 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001482 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001483 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001484 Expr *LHS, Expr *RHS) {
1485 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 }
1487
1488 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001489 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 /// By default, performs semantic analysis to build the new expression.
1491 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001492 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001493 SourceLocation QuestionLoc,
1494 Expr *LHS,
1495 SourceLocation ColonLoc,
1496 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001497 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1498 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 }
1500
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001502 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 /// By default, performs semantic analysis to build the new expression.
1504 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001505 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001506 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001508 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001509 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001510 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 }
Mike Stump11289f42009-09-09 15:08:12 +00001512
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001514 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001517 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001518 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001520 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001521 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001522 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 }
Mike Stump11289f42009-09-09 15:08:12 +00001524
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 /// \brief Build a new extended vector element access 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 RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 SourceLocation OpLoc,
1531 SourceLocation AccessorLoc,
1532 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001533
John McCall10eae182009-11-30 22:42:35 +00001534 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001535 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001536 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001537 OpLoc, /*IsArrow*/ false,
1538 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001539 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001540 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 }
Mike Stump11289f42009-09-09 15:08:12 +00001542
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001544 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001547 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001549 SourceLocation RBraceLoc,
1550 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001551 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001552 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1553 if (Result.isInvalid() || ResultTy->isDependentType())
1554 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001555
Douglas Gregord3d93062009-11-09 17:16:50 +00001556 // Patch in the result type we were given, which may have been computed
1557 // when the initial InitListExpr was built.
1558 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1559 ILE->setType(ResultTy);
1560 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 }
Mike Stump11289f42009-09-09 15:08:12 +00001562
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001564 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 /// By default, performs semantic analysis to build the new expression.
1566 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001567 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 MultiExprArg ArrayExprs,
1569 SourceLocation EqualOrColonLoc,
1570 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001571 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001572 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001574 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001576 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001577
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 ArrayExprs.release();
1579 return move(Result);
1580 }
Mike Stump11289f42009-09-09 15:08:12 +00001581
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001583 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 /// By default, builds the implicit value initialization without performing
1585 /// any semantic analysis. Subclasses may override this routine to provide
1586 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001587 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1589 }
Mike Stump11289f42009-09-09 15:08:12 +00001590
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001592 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 /// By default, performs semantic analysis to build the new expression.
1594 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001595 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001596 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001597 SourceLocation RParenLoc) {
1598 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001599 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001600 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 }
1602
1603 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001604 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 /// By default, performs semantic analysis to build the new expression.
1606 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001607 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 MultiExprArg SubExprs,
1609 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001610 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001611 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 }
Mike Stump11289f42009-09-09 15:08:12 +00001613
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001615 ///
1616 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 /// rather than attempting to map the label statement itself.
1618 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001619 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001620 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001621 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 }
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001625 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// By default, performs semantic analysis to build the new expression.
1627 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001628 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001629 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001631 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 }
Mike Stump11289f42009-09-09 15:08:12 +00001633
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 /// \brief Build a new __builtin_choose_expr expression.
1635 ///
1636 /// By default, performs semantic analysis to build the new expression.
1637 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001638 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001639 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SourceLocation RParenLoc) {
1641 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001642 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 RParenLoc);
1644 }
Mike Stump11289f42009-09-09 15:08:12 +00001645
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 /// \brief Build a new overloaded operator call expression.
1647 ///
1648 /// By default, performs semantic analysis to build the new expression.
1649 /// The semantic analysis provides the behavior of template instantiation,
1650 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001651 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 /// argument-dependent lookup, etc. Subclasses may override this routine to
1653 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001654 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001656 Expr *Callee,
1657 Expr *First,
1658 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001659
1660 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 /// reinterpret_cast.
1662 ///
1663 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001664 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001666 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 Stmt::StmtClass Class,
1668 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001669 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 SourceLocation RAngleLoc,
1671 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001672 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 SourceLocation RParenLoc) {
1674 switch (Class) {
1675 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001676 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001677 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001678 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001679
1680 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001681 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001682 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001683 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001684
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001686 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001687 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001688 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001690
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001692 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001693 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001694 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001695
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 default:
1697 assert(false && "Invalid C++ named cast");
1698 break;
1699 }
Mike Stump11289f42009-09-09 15:08:12 +00001700
John McCallfaf5fb42010-08-26 23:41:50 +00001701 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001702 }
Mike Stump11289f42009-09-09 15:08:12 +00001703
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 /// \brief Build a new C++ static_cast expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001708 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001710 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 SourceLocation RAngleLoc,
1712 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001713 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001715 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001716 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001717 SourceRange(LAngleLoc, RAngleLoc),
1718 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 }
1720
1721 /// \brief Build a new C++ dynamic_cast expression.
1722 ///
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001725 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001727 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 SourceLocation RAngleLoc,
1729 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001730 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001732 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001733 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001734 SourceRange(LAngleLoc, RAngleLoc),
1735 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 }
1737
1738 /// \brief Build a new C++ reinterpret_cast expression.
1739 ///
1740 /// By default, performs semantic analysis to build the new expression.
1741 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001742 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001744 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 SourceLocation RAngleLoc,
1746 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001747 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001749 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001750 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001751 SourceRange(LAngleLoc, RAngleLoc),
1752 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 }
1754
1755 /// \brief Build a new C++ const_cast expression.
1756 ///
1757 /// By default, performs semantic analysis to build the new expression.
1758 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001759 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001761 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 SourceLocation RAngleLoc,
1763 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001764 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001766 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001767 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001768 SourceRange(LAngleLoc, RAngleLoc),
1769 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 }
Mike Stump11289f42009-09-09 15:08:12 +00001771
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 /// \brief Build a new C++ functional-style cast expression.
1773 ///
1774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001776 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1777 SourceLocation LParenLoc,
1778 Expr *Sub,
1779 SourceLocation RParenLoc) {
1780 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001781 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 RParenLoc);
1783 }
Mike Stump11289f42009-09-09 15:08:12 +00001784
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 /// \brief Build a new C++ typeid(type) expression.
1786 ///
1787 /// By default, performs semantic analysis to build the new expression.
1788 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001789 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001790 SourceLocation TypeidLoc,
1791 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001793 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001794 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 }
Mike Stump11289f42009-09-09 15:08:12 +00001796
Francois Pichet9f4f2072010-09-08 12:20:18 +00001797
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 /// \brief Build a new C++ typeid(expr) expression.
1799 ///
1800 /// By default, performs semantic analysis to build the new expression.
1801 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001802 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001803 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001804 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001806 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001807 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001808 }
1809
Francois Pichet9f4f2072010-09-08 12:20:18 +00001810 /// \brief Build a new C++ __uuidof(type) expression.
1811 ///
1812 /// By default, performs semantic analysis to build the new expression.
1813 /// Subclasses may override this routine to provide different behavior.
1814 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1815 SourceLocation TypeidLoc,
1816 TypeSourceInfo *Operand,
1817 SourceLocation RParenLoc) {
1818 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1819 RParenLoc);
1820 }
1821
1822 /// \brief Build a new C++ __uuidof(expr) expression.
1823 ///
1824 /// By default, performs semantic analysis to build the new expression.
1825 /// Subclasses may override this routine to provide different behavior.
1826 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1827 SourceLocation TypeidLoc,
1828 Expr *Operand,
1829 SourceLocation RParenLoc) {
1830 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1831 RParenLoc);
1832 }
1833
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 /// \brief Build a new C++ "this" expression.
1835 ///
1836 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001837 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001839 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001840 QualType ThisType,
1841 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001843 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1844 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001845 }
1846
1847 /// \brief Build a new C++ throw expression.
1848 ///
1849 /// By default, performs semantic analysis to build the new expression.
1850 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001851 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001852 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 }
1854
1855 /// \brief Build a new C++ default-argument expression.
1856 ///
1857 /// By default, builds a new default-argument expression, which does not
1858 /// require any semantic analysis. Subclasses may override this routine to
1859 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001860 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001861 ParmVarDecl *Param) {
1862 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1863 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 }
1865
1866 /// \brief Build a new C++ zero-initialization expression.
1867 ///
1868 /// By default, performs semantic analysis to build the new expression.
1869 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001870 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1871 SourceLocation LParenLoc,
1872 SourceLocation RParenLoc) {
1873 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001874 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001875 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 }
Mike Stump11289f42009-09-09 15:08:12 +00001877
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 /// \brief Build a new C++ "new" expression.
1879 ///
1880 /// By default, performs semantic analysis to build the new expression.
1881 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001882 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001883 bool UseGlobal,
1884 SourceLocation PlacementLParen,
1885 MultiExprArg PlacementArgs,
1886 SourceLocation PlacementRParen,
1887 SourceRange TypeIdParens,
1888 QualType AllocatedType,
1889 TypeSourceInfo *AllocatedTypeInfo,
1890 Expr *ArraySize,
1891 SourceLocation ConstructorLParen,
1892 MultiExprArg ConstructorArgs,
1893 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001894 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 PlacementLParen,
1896 move(PlacementArgs),
1897 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001898 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001899 AllocatedType,
1900 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001901 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001902 ConstructorLParen,
1903 move(ConstructorArgs),
1904 ConstructorRParen);
1905 }
Mike Stump11289f42009-09-09 15:08:12 +00001906
Douglas Gregora16548e2009-08-11 05:31:07 +00001907 /// \brief Build a new C++ "delete" expression.
1908 ///
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001911 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 bool IsGlobalDelete,
1913 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001914 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001916 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 }
Mike Stump11289f42009-09-09 15:08:12 +00001918
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 /// \brief Build a new unary type trait expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001923 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001924 SourceLocation StartLoc,
1925 TypeSourceInfo *T,
1926 SourceLocation RParenLoc) {
1927 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 }
1929
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001930 /// \brief Build a new binary type trait expression.
1931 ///
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
1934 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1935 SourceLocation StartLoc,
1936 TypeSourceInfo *LhsT,
1937 TypeSourceInfo *RhsT,
1938 SourceLocation RParenLoc) {
1939 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1940 }
1941
Mike Stump11289f42009-09-09 15:08:12 +00001942 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001947 ExprResult RebuildDependentScopeDeclRefExpr(
1948 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001949 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001950 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001952 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001953
1954 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001955 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001956 *TemplateArgs);
1957
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001958 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 }
1960
1961 /// \brief Build a new template-id expression.
1962 ///
1963 /// By default, performs semantic analysis to build the new expression.
1964 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001965 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001966 LookupResult &R,
1967 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001968 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001969 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 }
1971
1972 /// \brief Build a new object-construction expression.
1973 ///
1974 /// By default, performs semantic analysis to build the new expression.
1975 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001976 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001977 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 CXXConstructorDecl *Constructor,
1979 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001980 MultiExprArg Args,
1981 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001982 CXXConstructExpr::ConstructionKind ConstructKind,
1983 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001984 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001985 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001986 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001987 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001988
Douglas Gregordb121ba2009-12-14 16:27:04 +00001989 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001990 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001991 RequiresZeroInit, ConstructKind,
1992 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 }
1994
1995 /// \brief Build a new object-construction expression.
1996 ///
1997 /// By default, performs semantic analysis to build the new expression.
1998 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001999 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2000 SourceLocation LParenLoc,
2001 MultiExprArg Args,
2002 SourceLocation RParenLoc) {
2003 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 LParenLoc,
2005 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 RParenLoc);
2007 }
2008
2009 /// \brief Build a new object-construction expression.
2010 ///
2011 /// By default, performs semantic analysis to build the new expression.
2012 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002013 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2014 SourceLocation LParenLoc,
2015 MultiExprArg Args,
2016 SourceLocation RParenLoc) {
2017 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 LParenLoc,
2019 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 RParenLoc);
2021 }
Mike Stump11289f42009-09-09 15:08:12 +00002022
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 /// \brief Build a new member reference expression.
2024 ///
2025 /// By default, performs semantic analysis to build the new expression.
2026 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002027 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002028 QualType BaseType,
2029 bool IsArrow,
2030 SourceLocation OperatorLoc,
2031 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002032 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002033 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002034 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002036 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002037
John McCallb268a282010-08-23 23:25:46 +00002038 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002039 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002040 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002041 MemberNameInfo,
2042 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 }
2044
John McCall10eae182009-11-30 22:42:35 +00002045 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002046 ///
2047 /// By default, performs semantic analysis to build the new expression.
2048 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002049 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002050 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002051 SourceLocation OperatorLoc,
2052 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002053 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002054 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002055 LookupResult &R,
2056 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002057 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002058 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002059
John McCallb268a282010-08-23 23:25:46 +00002060 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002061 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002062 SS, FirstQualifierInScope,
2063 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002064 }
Mike Stump11289f42009-09-09 15:08:12 +00002065
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002066 /// \brief Build a new noexcept expression.
2067 ///
2068 /// By default, performs semantic analysis to build the new expression.
2069 /// Subclasses may override this routine to provide different behavior.
2070 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2071 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2072 }
2073
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002074 /// \brief Build a new expression to compute the length of a parameter pack.
2075 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2076 SourceLocation PackLoc,
2077 SourceLocation RParenLoc,
2078 unsigned Length) {
2079 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2080 OperatorLoc, Pack, PackLoc,
2081 RParenLoc, Length);
2082 }
2083
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 /// \brief Build a new Objective-C @encode expression.
2085 ///
2086 /// By default, performs semantic analysis to build the new expression.
2087 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002088 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002089 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002090 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002091 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002093 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002094
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002095 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002096 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002097 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002098 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002099 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002100 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002101 MultiExprArg Args,
2102 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002103 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2104 ReceiverTypeInfo->getType(),
2105 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002106 Sel, Method, LBracLoc, SelectorLoc,
2107 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002108 }
2109
2110 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002111 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002112 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002113 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002114 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002115 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002116 MultiExprArg Args,
2117 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002118 return SemaRef.BuildInstanceMessage(Receiver,
2119 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002120 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002121 Sel, Method, LBracLoc, SelectorLoc,
2122 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002123 }
2124
Douglas Gregord51d90d2010-04-26 20:11:03 +00002125 /// \brief Build a new Objective-C ivar reference expression.
2126 ///
2127 /// By default, performs semantic analysis to build the new expression.
2128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002129 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002130 SourceLocation IvarLoc,
2131 bool IsArrow, bool IsFreeIvar) {
2132 // FIXME: We lose track of the IsFreeIvar bit.
2133 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002134 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002135 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2136 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002138 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002139 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002140 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002141 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002142 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002143
Douglas Gregord51d90d2010-04-26 20:11:03 +00002144 if (Result.get())
2145 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002146
John McCallb268a282010-08-23 23:25:46 +00002147 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002148 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002149 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002150 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002151 /*TemplateArgs=*/0);
2152 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002153
2154 /// \brief Build a new Objective-C property reference expression.
2155 ///
2156 /// By default, performs semantic analysis to build the new expression.
2157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002158 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002159 ObjCPropertyDecl *Property,
2160 SourceLocation PropertyLoc) {
2161 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002162 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002163 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2164 Sema::LookupMemberName);
2165 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002166 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002167 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002168 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002169 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002170 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002171
Douglas Gregor9faee212010-04-26 20:47:02 +00002172 if (Result.get())
2173 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002174
John McCallb268a282010-08-23 23:25:46 +00002175 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002176 /*FIXME:*/PropertyLoc, IsArrow,
2177 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002178 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002179 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002180 /*TemplateArgs=*/0);
2181 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002182
John McCallb7bd14f2010-12-02 01:19:52 +00002183 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002184 ///
2185 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002186 /// Subclasses may override this routine to provide different behavior.
2187 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2188 ObjCMethodDecl *Getter,
2189 ObjCMethodDecl *Setter,
2190 SourceLocation PropertyLoc) {
2191 // Since these expressions can only be value-dependent, we do not
2192 // need to perform semantic analysis again.
2193 return Owned(
2194 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2195 VK_LValue, OK_ObjCProperty,
2196 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002197 }
2198
Douglas Gregord51d90d2010-04-26 20:11:03 +00002199 /// \brief Build a new Objective-C "isa" expression.
2200 ///
2201 /// By default, performs semantic analysis to build the new expression.
2202 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002203 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002204 bool IsArrow) {
2205 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002206 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002207 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2208 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002209 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002210 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002211 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002212 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002213 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002214
Douglas Gregord51d90d2010-04-26 20:11:03 +00002215 if (Result.get())
2216 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002217
John McCallb268a282010-08-23 23:25:46 +00002218 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002219 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002220 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002221 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002222 /*TemplateArgs=*/0);
2223 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002224
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 /// \brief Build a new shuffle vector expression.
2226 ///
2227 /// By default, performs semantic analysis to build the new expression.
2228 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002229 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002230 MultiExprArg SubExprs,
2231 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002233 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2235 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2236 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2237 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002238
Douglas Gregora16548e2009-08-11 05:31:07 +00002239 // Build a reference to the __builtin_shufflevector builtin
2240 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002241 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002243 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002244 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002245
2246 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 unsigned NumSubExprs = SubExprs.size();
2248 Expr **Subs = (Expr **)SubExprs.release();
2249 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2250 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002251 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002252 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002253 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002254 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002255
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002257 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002259 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002260
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002262 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002263 }
John McCall31f82722010-11-12 08:19:04 +00002264
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002265 /// \brief Build a new template argument pack expansion.
2266 ///
2267 /// By default, performs semantic analysis to build a new pack expansion
2268 /// for a template argument. Subclasses may override this routine to provide
2269 /// different behavior.
2270 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002271 SourceLocation EllipsisLoc,
2272 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002273 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002274 case TemplateArgument::Expression: {
2275 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002276 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2277 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002278 if (Result.isInvalid())
2279 return TemplateArgumentLoc();
2280
2281 return TemplateArgumentLoc(Result.get(), Result.get());
2282 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002283
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002284 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002285 return TemplateArgumentLoc(TemplateArgument(
2286 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002287 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002288 Pattern.getTemplateQualifierRange(),
2289 Pattern.getTemplateNameLoc(),
2290 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002291
2292 case TemplateArgument::Null:
2293 case TemplateArgument::Integral:
2294 case TemplateArgument::Declaration:
2295 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002296 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002297 llvm_unreachable("Pack expansion pattern has no parameter packs");
2298
2299 case TemplateArgument::Type:
2300 if (TypeSourceInfo *Expansion
2301 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002302 EllipsisLoc,
2303 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002304 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2305 Expansion);
2306 break;
2307 }
2308
2309 return TemplateArgumentLoc();
2310 }
2311
Douglas Gregor968f23a2011-01-03 19:31:53 +00002312 /// \brief Build a new expression pack expansion.
2313 ///
2314 /// By default, performs semantic analysis to build a new pack expansion
2315 /// for an expression. Subclasses may override this routine to provide
2316 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002317 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2318 llvm::Optional<unsigned> NumExpansions) {
2319 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002320 }
2321
John McCall31f82722010-11-12 08:19:04 +00002322private:
2323 QualType TransformTypeInObjectScope(QualType T,
2324 QualType ObjectType,
2325 NamedDecl *FirstQualifierInScope,
2326 NestedNameSpecifier *Prefix);
2327
2328 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2329 QualType ObjectType,
2330 NamedDecl *FirstQualifierInScope,
2331 NestedNameSpecifier *Prefix);
Douglas Gregor14454802011-02-25 02:25:35 +00002332
2333 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2334 QualType ObjectType,
2335 NamedDecl *FirstQualifierInScope,
2336 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002337};
Douglas Gregora16548e2009-08-11 05:31:07 +00002338
Douglas Gregorebe10102009-08-20 07:17:43 +00002339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002340StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002341 if (!S)
2342 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002343
Douglas Gregorebe10102009-08-20 07:17:43 +00002344 switch (S->getStmtClass()) {
2345 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002346
Douglas Gregorebe10102009-08-20 07:17:43 +00002347 // Transform individual statement nodes
2348#define STMT(Node, Parent) \
2349 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002350#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002351#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002352#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002353
Douglas Gregorebe10102009-08-20 07:17:43 +00002354 // Transform expressions by calling TransformExpr.
2355#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002356#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002357#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002358#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002359 {
John McCalldadc5752010-08-24 06:29:42 +00002360 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002361 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002362 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002363
John McCallb268a282010-08-23 23:25:46 +00002364 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002365 }
Mike Stump11289f42009-09-09 15:08:12 +00002366 }
2367
John McCallc3007a22010-10-26 07:05:15 +00002368 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002369}
Mike Stump11289f42009-09-09 15:08:12 +00002370
2371
Douglas Gregore922c772009-08-04 22:27:00 +00002372template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002373ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002374 if (!E)
2375 return SemaRef.Owned(E);
2376
2377 switch (E->getStmtClass()) {
2378 case Stmt::NoStmtClass: break;
2379#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002380#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002381#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002382 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002383#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002384 }
2385
John McCallc3007a22010-10-26 07:05:15 +00002386 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002387}
2388
2389template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002390bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2391 unsigned NumInputs,
2392 bool IsCall,
2393 llvm::SmallVectorImpl<Expr *> &Outputs,
2394 bool *ArgChanged) {
2395 for (unsigned I = 0; I != NumInputs; ++I) {
2396 // If requested, drop call arguments that need to be dropped.
2397 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2398 if (ArgChanged)
2399 *ArgChanged = true;
2400
2401 break;
2402 }
2403
Douglas Gregor968f23a2011-01-03 19:31:53 +00002404 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2405 Expr *Pattern = Expansion->getPattern();
2406
2407 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2408 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2409 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2410
2411 // Determine whether the set of unexpanded parameter packs can and should
2412 // be expanded.
2413 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002414 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002415 llvm::Optional<unsigned> OrigNumExpansions
2416 = Expansion->getNumExpansions();
2417 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002418 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2419 Pattern->getSourceRange(),
2420 Unexpanded.data(),
2421 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002422 Expand, RetainExpansion,
2423 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002424 return true;
2425
2426 if (!Expand) {
2427 // The transform has determined that we should perform a simple
2428 // transformation on the pack expansion, producing another pack
2429 // expansion.
2430 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2431 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2432 if (OutPattern.isInvalid())
2433 return true;
2434
2435 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002436 Expansion->getEllipsisLoc(),
2437 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002438 if (Out.isInvalid())
2439 return true;
2440
2441 if (ArgChanged)
2442 *ArgChanged = true;
2443 Outputs.push_back(Out.get());
2444 continue;
2445 }
2446
2447 // The transform has determined that we should perform an elementwise
2448 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002449 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002450 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2451 ExprResult Out = getDerived().TransformExpr(Pattern);
2452 if (Out.isInvalid())
2453 return true;
2454
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002455 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002456 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2457 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002458 if (Out.isInvalid())
2459 return true;
2460 }
2461
Douglas Gregor968f23a2011-01-03 19:31:53 +00002462 if (ArgChanged)
2463 *ArgChanged = true;
2464 Outputs.push_back(Out.get());
2465 }
2466
2467 continue;
2468 }
2469
Douglas Gregora3efea12011-01-03 19:04:46 +00002470 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2471 if (Result.isInvalid())
2472 return true;
2473
2474 if (Result.get() != Inputs[I] && ArgChanged)
2475 *ArgChanged = true;
2476
2477 Outputs.push_back(Result.get());
2478 }
2479
2480 return false;
2481}
2482
2483template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002484NestedNameSpecifier *
2485TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002486 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002487 QualType ObjectType,
2488 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002489 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002490
Douglas Gregorebe10102009-08-20 07:17:43 +00002491 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002492 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002493 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002494 ObjectType,
2495 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002496 if (!Prefix)
2497 return 0;
2498 }
Mike Stump11289f42009-09-09 15:08:12 +00002499
Douglas Gregor1135c352009-08-06 05:28:30 +00002500 switch (NNS->getKind()) {
2501 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002502 if (Prefix) {
2503 // The object type and qualifier-in-scope really apply to the
2504 // leftmost entity.
2505 ObjectType = QualType();
2506 FirstQualifierInScope = 0;
2507 }
2508
Mike Stump11289f42009-09-09 15:08:12 +00002509 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002510 "Identifier nested-name-specifier with no prefix or object type");
2511 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2512 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002513 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002514
2515 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002516 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002517 ObjectType,
2518 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002519
Douglas Gregor1135c352009-08-06 05:28:30 +00002520 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002521 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002522 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002523 getDerived().TransformDecl(Range.getBegin(),
2524 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002525 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002526 Prefix == NNS->getPrefix() &&
2527 NS == NNS->getAsNamespace())
2528 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002529
Douglas Gregor1135c352009-08-06 05:28:30 +00002530 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2531 }
Mike Stump11289f42009-09-09 15:08:12 +00002532
Douglas Gregor7b26ff92011-02-24 02:36:08 +00002533 case NestedNameSpecifier::NamespaceAlias: {
2534 NamespaceAliasDecl *Alias
2535 = cast_or_null<NamespaceAliasDecl>(
2536 getDerived().TransformDecl(Range.getBegin(),
2537 NNS->getAsNamespaceAlias()));
2538 if (!getDerived().AlwaysRebuild() &&
2539 Prefix == NNS->getPrefix() &&
2540 Alias == NNS->getAsNamespaceAlias())
2541 return NNS;
2542
2543 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias);
2544 }
2545
Douglas Gregor1135c352009-08-06 05:28:30 +00002546 case NestedNameSpecifier::Global:
2547 // There is no meaningful transformation that one could perform on the
2548 // global scope.
2549 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002550
Douglas Gregor1135c352009-08-06 05:28:30 +00002551 case NestedNameSpecifier::TypeSpecWithTemplate:
2552 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002553 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002554 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2555 ObjectType,
2556 FirstQualifierInScope,
2557 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002558 if (T.isNull())
2559 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002560
Douglas Gregor1135c352009-08-06 05:28:30 +00002561 if (!getDerived().AlwaysRebuild() &&
2562 Prefix == NNS->getPrefix() &&
2563 T == QualType(NNS->getAsType(), 0))
2564 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002565
2566 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2567 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002568 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002569 }
2570 }
Mike Stump11289f42009-09-09 15:08:12 +00002571
Douglas Gregor1135c352009-08-06 05:28:30 +00002572 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002573 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002574}
2575
2576template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002577NestedNameSpecifierLoc
2578TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2579 NestedNameSpecifierLoc NNS,
2580 QualType ObjectType,
2581 NamedDecl *FirstQualifierInScope) {
2582 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2583 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2584 Qualifier = Qualifier.getPrefix())
2585 Qualifiers.push_back(Qualifier);
2586
2587 CXXScopeSpec SS;
2588 while (!Qualifiers.empty()) {
2589 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2590 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2591
2592 switch (QNNS->getKind()) {
2593 case NestedNameSpecifier::Identifier:
2594 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2595 *QNNS->getAsIdentifier(),
2596 Q.getLocalBeginLoc(),
2597 Q.getLocalEndLoc(),
2598 ObjectType, false, SS,
2599 FirstQualifierInScope, false))
2600 return NestedNameSpecifierLoc();
2601
2602 break;
2603
2604 case NestedNameSpecifier::Namespace: {
2605 NamespaceDecl *NS
2606 = cast_or_null<NamespaceDecl>(
2607 getDerived().TransformDecl(
2608 Q.getLocalBeginLoc(),
2609 QNNS->getAsNamespace()));
2610 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2611 break;
2612 }
2613
2614 case NestedNameSpecifier::NamespaceAlias: {
2615 NamespaceAliasDecl *Alias
2616 = cast_or_null<NamespaceAliasDecl>(
2617 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2618 QNNS->getAsNamespaceAlias()));
2619 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2620 Q.getLocalEndLoc());
2621 break;
2622 }
2623
2624 case NestedNameSpecifier::Global:
2625 // There is no meaningful transformation that one could perform on the
2626 // global scope.
2627 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2628 break;
2629
2630 case NestedNameSpecifier::TypeSpecWithTemplate:
2631 case NestedNameSpecifier::TypeSpec: {
2632 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2633 FirstQualifierInScope, SS);
2634
2635 if (!TL)
2636 return NestedNameSpecifierLoc();
2637
2638 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2639 (SemaRef.getLangOptions().CPlusPlus0x &&
2640 TL.getType()->isEnumeralType())) {
2641 assert(!TL.getType().hasLocalQualifiers() &&
2642 "Can't get cv-qualifiers here");
2643 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2644 Q.getLocalEndLoc());
2645 break;
2646 }
2647
2648 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2649 << TL.getType() << SS.getRange();
2650 return NestedNameSpecifierLoc();
2651 }
Douglas Gregore16af532011-02-28 18:50:33 +00002652 }
Douglas Gregor14454802011-02-25 02:25:35 +00002653
Douglas Gregore16af532011-02-28 18:50:33 +00002654 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002655 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002656 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002657 }
2658
2659 // Don't rebuild the nested-name-specifier if we don't have to.
2660 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2661 !getDerived().AlwaysRebuild())
2662 return NNS;
2663
2664 // If we can re-use the source-location data from the original
2665 // nested-name-specifier, do so.
2666 if (SS.location_size() == NNS.getDataLength() &&
2667 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2668 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2669
2670 // Allocate new nested-name-specifier location information.
2671 return SS.getWithLocInContext(SemaRef.Context);
2672}
2673
2674template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002675DeclarationNameInfo
2676TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002677::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002678 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002679 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002680 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002681
2682 switch (Name.getNameKind()) {
2683 case DeclarationName::Identifier:
2684 case DeclarationName::ObjCZeroArgSelector:
2685 case DeclarationName::ObjCOneArgSelector:
2686 case DeclarationName::ObjCMultiArgSelector:
2687 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002688 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002689 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002690 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002691
Douglas Gregorf816bd72009-09-03 22:13:48 +00002692 case DeclarationName::CXXConstructorName:
2693 case DeclarationName::CXXDestructorName:
2694 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002695 TypeSourceInfo *NewTInfo;
2696 CanQualType NewCanTy;
2697 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002698 NewTInfo = getDerived().TransformType(OldTInfo);
2699 if (!NewTInfo)
2700 return DeclarationNameInfo();
2701 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002702 }
2703 else {
2704 NewTInfo = 0;
2705 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002706 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002707 if (NewT.isNull())
2708 return DeclarationNameInfo();
2709 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2710 }
Mike Stump11289f42009-09-09 15:08:12 +00002711
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002712 DeclarationName NewName
2713 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2714 NewCanTy);
2715 DeclarationNameInfo NewNameInfo(NameInfo);
2716 NewNameInfo.setName(NewName);
2717 NewNameInfo.setNamedTypeInfo(NewTInfo);
2718 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002719 }
Mike Stump11289f42009-09-09 15:08:12 +00002720 }
2721
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002722 assert(0 && "Unknown name kind.");
2723 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002724}
2725
2726template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002727TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002728TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002729 QualType ObjectType,
2730 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002731 SourceLocation Loc = getDerived().getBaseLocation();
2732
Douglas Gregor71dc5092009-08-06 06:41:21 +00002733 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002734 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002735 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002736 /*FIXME*/ SourceRange(Loc),
2737 ObjectType,
2738 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002739 if (!NNS)
2740 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002741
Douglas Gregor71dc5092009-08-06 06:41:21 +00002742 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002743 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002744 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002745 if (!TransTemplate)
2746 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002747
Douglas Gregor71dc5092009-08-06 06:41:21 +00002748 if (!getDerived().AlwaysRebuild() &&
2749 NNS == QTN->getQualifier() &&
2750 TransTemplate == Template)
2751 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002752
Douglas Gregor71dc5092009-08-06 06:41:21 +00002753 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2754 TransTemplate);
2755 }
Mike Stump11289f42009-09-09 15:08:12 +00002756
John McCalle66edc12009-11-24 19:00:30 +00002757 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002758 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002759 }
Mike Stump11289f42009-09-09 15:08:12 +00002760
Douglas Gregor71dc5092009-08-06 06:41:21 +00002761 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002762 NestedNameSpecifier *NNS = DTN->getQualifier();
2763 if (NNS) {
2764 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2765 /*FIXME:*/SourceRange(Loc),
2766 ObjectType,
2767 FirstQualifierInScope);
2768 if (!NNS) return TemplateName();
2769
2770 // These apply to the scope specifier, not the template.
2771 ObjectType = QualType();
2772 FirstQualifierInScope = 0;
2773 }
Mike Stump11289f42009-09-09 15:08:12 +00002774
Douglas Gregor71dc5092009-08-06 06:41:21 +00002775 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002776 NNS == DTN->getQualifier() &&
2777 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002778 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002779
Douglas Gregora5614c52010-09-08 23:56:00 +00002780 if (DTN->isIdentifier()) {
2781 // FIXME: Bad range
2782 SourceRange QualifierRange(getDerived().getBaseLocation());
2783 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2784 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002785 ObjectType,
2786 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002787 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002788
2789 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002790 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002791 }
Mike Stump11289f42009-09-09 15:08:12 +00002792
Douglas Gregor71dc5092009-08-06 06:41:21 +00002793 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002794 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002795 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002796 if (!TransTemplate)
2797 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002798
Douglas Gregor71dc5092009-08-06 06:41:21 +00002799 if (!getDerived().AlwaysRebuild() &&
2800 TransTemplate == Template)
2801 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002802
Douglas Gregor71dc5092009-08-06 06:41:21 +00002803 return TemplateName(TransTemplate);
2804 }
Mike Stump11289f42009-09-09 15:08:12 +00002805
Douglas Gregor5590be02011-01-15 06:45:20 +00002806 if (SubstTemplateTemplateParmPackStorage *SubstPack
2807 = Name.getAsSubstTemplateTemplateParmPack()) {
2808 TemplateTemplateParmDecl *TransParam
2809 = cast_or_null<TemplateTemplateParmDecl>(
2810 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2811 if (!TransParam)
2812 return TemplateName();
2813
2814 if (!getDerived().AlwaysRebuild() &&
2815 TransParam == SubstPack->getParameterPack())
2816 return Name;
2817
2818 return getDerived().RebuildTemplateName(TransParam,
2819 SubstPack->getArgumentPack());
2820 }
2821
John McCalle66edc12009-11-24 19:00:30 +00002822 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002823 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002824 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002825}
2826
2827template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002828void TreeTransform<Derived>::InventTemplateArgumentLoc(
2829 const TemplateArgument &Arg,
2830 TemplateArgumentLoc &Output) {
2831 SourceLocation Loc = getDerived().getBaseLocation();
2832 switch (Arg.getKind()) {
2833 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002834 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002835 break;
2836
2837 case TemplateArgument::Type:
2838 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002839 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002840
John McCall0ad16662009-10-29 08:12:44 +00002841 break;
2842
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002843 case TemplateArgument::Template:
2844 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2845 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002846
2847 case TemplateArgument::TemplateExpansion:
2848 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2849 break;
2850
John McCall0ad16662009-10-29 08:12:44 +00002851 case TemplateArgument::Expression:
2852 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2853 break;
2854
2855 case TemplateArgument::Declaration:
2856 case TemplateArgument::Integral:
2857 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002858 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002859 break;
2860 }
2861}
2862
2863template<typename Derived>
2864bool TreeTransform<Derived>::TransformTemplateArgument(
2865 const TemplateArgumentLoc &Input,
2866 TemplateArgumentLoc &Output) {
2867 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002868 switch (Arg.getKind()) {
2869 case TemplateArgument::Null:
2870 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002871 Output = Input;
2872 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002873
Douglas Gregore922c772009-08-04 22:27:00 +00002874 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002875 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002876 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002877 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002878
2879 DI = getDerived().TransformType(DI);
2880 if (!DI) return true;
2881
2882 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2883 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002884 }
Mike Stump11289f42009-09-09 15:08:12 +00002885
Douglas Gregore922c772009-08-04 22:27:00 +00002886 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002887 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002888 DeclarationName Name;
2889 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2890 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002891 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002892 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002893 if (!D) return true;
2894
John McCall0d07eb32009-10-29 18:45:58 +00002895 Expr *SourceExpr = Input.getSourceDeclExpression();
2896 if (SourceExpr) {
2897 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002898 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002899 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002900 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002901 }
2902
2903 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002904 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002905 }
Mike Stump11289f42009-09-09 15:08:12 +00002906
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002907 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002908 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002909 TemplateName Template
2910 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2911 if (Template.isNull())
2912 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002913
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002914 Output = TemplateArgumentLoc(TemplateArgument(Template),
2915 Input.getTemplateQualifierRange(),
2916 Input.getTemplateNameLoc());
2917 return false;
2918 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002919
2920 case TemplateArgument::TemplateExpansion:
2921 llvm_unreachable("Caller should expand pack expansions");
2922
Douglas Gregore922c772009-08-04 22:27:00 +00002923 case TemplateArgument::Expression: {
2924 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002925 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002926 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002927
John McCall0ad16662009-10-29 08:12:44 +00002928 Expr *InputExpr = Input.getSourceExpression();
2929 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2930
John McCalldadc5752010-08-24 06:29:42 +00002931 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002932 = getDerived().TransformExpr(InputExpr);
2933 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002934 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002935 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002936 }
Mike Stump11289f42009-09-09 15:08:12 +00002937
Douglas Gregore922c772009-08-04 22:27:00 +00002938 case TemplateArgument::Pack: {
2939 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2940 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002941 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002942 AEnd = Arg.pack_end();
2943 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002944
John McCall0ad16662009-10-29 08:12:44 +00002945 // FIXME: preserve source information here when we start
2946 // caring about parameter packs.
2947
John McCall0d07eb32009-10-29 18:45:58 +00002948 TemplateArgumentLoc InputArg;
2949 TemplateArgumentLoc OutputArg;
2950 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2951 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002952 return true;
2953
John McCall0d07eb32009-10-29 18:45:58 +00002954 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002955 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002956
2957 TemplateArgument *TransformedArgsPtr
2958 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2959 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2960 TransformedArgsPtr);
2961 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2962 TransformedArgs.size()),
2963 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002964 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002965 }
2966 }
Mike Stump11289f42009-09-09 15:08:12 +00002967
Douglas Gregore922c772009-08-04 22:27:00 +00002968 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002969 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002970}
2971
Douglas Gregorfe921a72010-12-20 23:36:19 +00002972/// \brief Iterator adaptor that invents template argument location information
2973/// for each of the template arguments in its underlying iterator.
2974template<typename Derived, typename InputIterator>
2975class TemplateArgumentLocInventIterator {
2976 TreeTransform<Derived> &Self;
2977 InputIterator Iter;
2978
2979public:
2980 typedef TemplateArgumentLoc value_type;
2981 typedef TemplateArgumentLoc reference;
2982 typedef typename std::iterator_traits<InputIterator>::difference_type
2983 difference_type;
2984 typedef std::input_iterator_tag iterator_category;
2985
2986 class pointer {
2987 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002988
Douglas Gregorfe921a72010-12-20 23:36:19 +00002989 public:
2990 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2991
2992 const TemplateArgumentLoc *operator->() const { return &Arg; }
2993 };
2994
2995 TemplateArgumentLocInventIterator() { }
2996
2997 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2998 InputIterator Iter)
2999 : Self(Self), Iter(Iter) { }
3000
3001 TemplateArgumentLocInventIterator &operator++() {
3002 ++Iter;
3003 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003004 }
3005
Douglas Gregorfe921a72010-12-20 23:36:19 +00003006 TemplateArgumentLocInventIterator operator++(int) {
3007 TemplateArgumentLocInventIterator Old(*this);
3008 ++(*this);
3009 return Old;
3010 }
3011
3012 reference operator*() const {
3013 TemplateArgumentLoc Result;
3014 Self.InventTemplateArgumentLoc(*Iter, Result);
3015 return Result;
3016 }
3017
3018 pointer operator->() const { return pointer(**this); }
3019
3020 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3021 const TemplateArgumentLocInventIterator &Y) {
3022 return X.Iter == Y.Iter;
3023 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003024
Douglas Gregorfe921a72010-12-20 23:36:19 +00003025 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3026 const TemplateArgumentLocInventIterator &Y) {
3027 return X.Iter != Y.Iter;
3028 }
3029};
3030
Douglas Gregor42cafa82010-12-20 17:42:22 +00003031template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003032template<typename InputIterator>
3033bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3034 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003035 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003036 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003037 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003038 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003039
3040 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3041 // Unpack argument packs, which we translate them into separate
3042 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003043 // FIXME: We could do much better if we could guarantee that the
3044 // TemplateArgumentLocInfo for the pack expansion would be usable for
3045 // all of the template arguments in the argument pack.
3046 typedef TemplateArgumentLocInventIterator<Derived,
3047 TemplateArgument::pack_iterator>
3048 PackLocIterator;
3049 if (TransformTemplateArguments(PackLocIterator(*this,
3050 In.getArgument().pack_begin()),
3051 PackLocIterator(*this,
3052 In.getArgument().pack_end()),
3053 Outputs))
3054 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003055
3056 continue;
3057 }
3058
3059 if (In.getArgument().isPackExpansion()) {
3060 // We have a pack expansion, for which we will be substituting into
3061 // the pattern.
3062 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003063 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003064 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003065 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3066 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003067
3068 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3069 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3070 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3071
3072 // Determine whether the set of unexpanded parameter packs can and should
3073 // be expanded.
3074 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003075 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003076 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003077 if (getDerived().TryExpandParameterPacks(Ellipsis,
3078 Pattern.getSourceRange(),
3079 Unexpanded.data(),
3080 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003081 Expand,
3082 RetainExpansion,
3083 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003084 return true;
3085
3086 if (!Expand) {
3087 // The transform has determined that we should perform a simple
3088 // transformation on the pack expansion, producing another pack
3089 // expansion.
3090 TemplateArgumentLoc OutPattern;
3091 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3092 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3093 return true;
3094
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003095 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3096 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003097 if (Out.getArgument().isNull())
3098 return true;
3099
3100 Outputs.addArgument(Out);
3101 continue;
3102 }
3103
3104 // The transform has determined that we should perform an elementwise
3105 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003106 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003107 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3108
3109 if (getDerived().TransformTemplateArgument(Pattern, Out))
3110 return true;
3111
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003112 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003113 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3114 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003115 if (Out.getArgument().isNull())
3116 return true;
3117 }
3118
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003119 Outputs.addArgument(Out);
3120 }
3121
Douglas Gregor48d24112011-01-10 20:53:55 +00003122 // If we're supposed to retain a pack expansion, do so by temporarily
3123 // forgetting the partially-substituted parameter pack.
3124 if (RetainExpansion) {
3125 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3126
3127 if (getDerived().TransformTemplateArgument(Pattern, Out))
3128 return true;
3129
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003130 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3131 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003132 if (Out.getArgument().isNull())
3133 return true;
3134
3135 Outputs.addArgument(Out);
3136 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003137
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003138 continue;
3139 }
3140
3141 // The simple case:
3142 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003143 return true;
3144
3145 Outputs.addArgument(Out);
3146 }
3147
3148 return false;
3149
3150}
3151
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152//===----------------------------------------------------------------------===//
3153// Type transformation
3154//===----------------------------------------------------------------------===//
3155
3156template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003157QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003158 if (getDerived().AlreadyTransformed(T))
3159 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003160
John McCall550e0c22009-10-21 00:40:46 +00003161 // Temporary workaround. All of these transformations should
3162 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003163 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3164 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003165
John McCall31f82722010-11-12 08:19:04 +00003166 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003167
John McCall550e0c22009-10-21 00:40:46 +00003168 if (!NewDI)
3169 return QualType();
3170
3171 return NewDI->getType();
3172}
3173
3174template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003175TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003176 if (getDerived().AlreadyTransformed(DI->getType()))
3177 return DI;
3178
3179 TypeLocBuilder TLB;
3180
3181 TypeLoc TL = DI->getTypeLoc();
3182 TLB.reserve(TL.getFullDataSize());
3183
John McCall31f82722010-11-12 08:19:04 +00003184 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003185 if (Result.isNull())
3186 return 0;
3187
John McCallbcd03502009-12-07 02:54:59 +00003188 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003189}
3190
3191template<typename Derived>
3192QualType
John McCall31f82722010-11-12 08:19:04 +00003193TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003194 switch (T.getTypeLocClass()) {
3195#define ABSTRACT_TYPELOC(CLASS, PARENT)
3196#define TYPELOC(CLASS, PARENT) \
3197 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003198 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003199#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003200 }
Mike Stump11289f42009-09-09 15:08:12 +00003201
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003202 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003203 return QualType();
3204}
3205
3206/// FIXME: By default, this routine adds type qualifiers only to types
3207/// that can have qualifiers, and silently suppresses those qualifiers
3208/// that are not permitted (e.g., qualifiers on reference or function
3209/// types). This is the right thing for template instantiation, but
3210/// probably not for other clients.
3211template<typename Derived>
3212QualType
3213TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003214 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003215 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003216
John McCall31f82722010-11-12 08:19:04 +00003217 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003218 if (Result.isNull())
3219 return QualType();
3220
3221 // Silently suppress qualifiers if the result type can't be qualified.
3222 // FIXME: this is the right thing for template instantiation, but
3223 // probably not for other clients.
3224 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003225 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003226
John McCallcb0f89a2010-06-05 06:41:15 +00003227 if (!Quals.empty()) {
3228 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3229 TLB.push<QualifiedTypeLoc>(Result);
3230 // No location information to preserve.
3231 }
John McCall550e0c22009-10-21 00:40:46 +00003232
3233 return Result;
3234}
3235
John McCall31f82722010-11-12 08:19:04 +00003236/// \brief Transforms a type that was written in a scope specifier,
3237/// given an object type, the results of unqualified lookup, and
3238/// an already-instantiated prefix.
3239///
3240/// The object type is provided iff the scope specifier qualifies the
3241/// member of a dependent member-access expression. The prefix is
3242/// provided iff the the scope specifier in which this appears has a
3243/// prefix.
3244///
3245/// This is private to TreeTransform.
3246template<typename Derived>
3247QualType
3248TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3249 QualType ObjectType,
3250 NamedDecl *UnqualLookup,
3251 NestedNameSpecifier *Prefix) {
3252 if (getDerived().AlreadyTransformed(T))
3253 return T;
3254
3255 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003256 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003257
3258 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3259 UnqualLookup, Prefix);
3260 if (!TSI) return QualType();
3261 return TSI->getType();
3262}
3263
3264template<typename Derived>
3265TypeSourceInfo *
3266TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3267 QualType ObjectType,
3268 NamedDecl *UnqualLookup,
3269 NestedNameSpecifier *Prefix) {
Douglas Gregor14454802011-02-25 02:25:35 +00003270 // TODO: in some cases, we might have some verification to do here.
John McCall31f82722010-11-12 08:19:04 +00003271 if (ObjectType.isNull())
3272 return getDerived().TransformType(TSI);
3273
3274 QualType T = TSI->getType();
3275 if (getDerived().AlreadyTransformed(T))
3276 return TSI;
3277
3278 TypeLocBuilder TLB;
3279 QualType Result;
3280
3281 if (isa<TemplateSpecializationType>(T)) {
3282 TemplateSpecializationTypeLoc TL
3283 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3284
3285 TemplateName Template =
3286 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3287 ObjectType, UnqualLookup);
3288 if (Template.isNull()) return 0;
3289
3290 Result = getDerived()
3291 .TransformTemplateSpecializationType(TLB, TL, Template);
3292 } else if (isa<DependentTemplateSpecializationType>(T)) {
3293 DependentTemplateSpecializationTypeLoc TL
3294 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3295
Douglas Gregor5a064722011-02-28 17:23:35 +00003296 TemplateName Template
3297 = SemaRef.Context.getDependentTemplateName(
3298 TL.getTypePtr()->getQualifier(),
3299 TL.getTypePtr()->getIdentifier());
3300
3301 Template = getDerived().TransformTemplateName(Template, ObjectType,
3302 UnqualLookup);
3303 if (Template.isNull())
3304 return 0;
3305
3306 Result = getDerived().TransformDependentTemplateSpecializationType(TLB, TL,
3307 Template);
John McCall31f82722010-11-12 08:19:04 +00003308 } else {
3309 // Nothing special needs to be done for these.
3310 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3311 }
3312
3313 if (Result.isNull()) return 0;
3314 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3315}
3316
Douglas Gregor14454802011-02-25 02:25:35 +00003317template<typename Derived>
3318TypeLoc
3319TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3320 QualType ObjectType,
3321 NamedDecl *UnqualLookup,
3322 CXXScopeSpec &SS) {
3323 // FIXME: Painfully copy-paste from the above!
3324
Douglas Gregor14454802011-02-25 02:25:35 +00003325 QualType T = TL.getType();
3326 if (getDerived().AlreadyTransformed(T))
3327 return TL;
3328
3329 TypeLocBuilder TLB;
3330 QualType Result;
3331
3332 if (isa<TemplateSpecializationType>(T)) {
3333 TemplateSpecializationTypeLoc SpecTL
3334 = cast<TemplateSpecializationTypeLoc>(TL);
3335
3336 TemplateName Template =
3337 getDerived().TransformTemplateName(SpecTL.getTypePtr()->getTemplateName(),
3338 ObjectType, UnqualLookup);
3339 if (Template.isNull())
3340 return TypeLoc();
3341
3342 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3343 Template);
3344 } else if (isa<DependentTemplateSpecializationType>(T)) {
3345 DependentTemplateSpecializationTypeLoc SpecTL
3346 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3347
Douglas Gregor5a064722011-02-28 17:23:35 +00003348 TemplateName Template
Douglas Gregore16af532011-02-28 18:50:33 +00003349 = getDerived().RebuildTemplateName(SS.getScopeRep(), SS.getRange(),
3350 *SpecTL.getTypePtr()->getIdentifier(),
3351 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003352 if (Template.isNull())
3353 return TypeLoc();
3354
Douglas Gregor14454802011-02-25 02:25:35 +00003355 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003356 SpecTL,
3357 Template);
Douglas Gregor14454802011-02-25 02:25:35 +00003358 } else {
3359 // Nothing special needs to be done for these.
3360 Result = getDerived().TransformType(TLB, TL);
3361 }
3362
3363 if (Result.isNull())
3364 return TypeLoc();
3365
3366 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3367}
3368
John McCall550e0c22009-10-21 00:40:46 +00003369template <class TyLoc> static inline
3370QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3371 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3372 NewT.setNameLoc(T.getNameLoc());
3373 return T.getType();
3374}
3375
John McCall550e0c22009-10-21 00:40:46 +00003376template<typename Derived>
3377QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003378 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003379 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3380 NewT.setBuiltinLoc(T.getBuiltinLoc());
3381 if (T.needsExtraLocalData())
3382 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3383 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003384}
Mike Stump11289f42009-09-09 15:08:12 +00003385
Douglas Gregord6ff3322009-08-04 16:50:30 +00003386template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003387QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003388 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003389 // FIXME: recurse?
3390 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003391}
Mike Stump11289f42009-09-09 15:08:12 +00003392
Douglas Gregord6ff3322009-08-04 16:50:30 +00003393template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003394QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003395 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003396 QualType PointeeType
3397 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003398 if (PointeeType.isNull())
3399 return QualType();
3400
3401 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003402 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003403 // A dependent pointer type 'T *' has is being transformed such
3404 // that an Objective-C class type is being replaced for 'T'. The
3405 // resulting pointer type is an ObjCObjectPointerType, not a
3406 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003407 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003408
John McCall8b07ec22010-05-15 11:32:37 +00003409 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3410 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003411 return Result;
3412 }
John McCall31f82722010-11-12 08:19:04 +00003413
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003414 if (getDerived().AlwaysRebuild() ||
3415 PointeeType != TL.getPointeeLoc().getType()) {
3416 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3417 if (Result.isNull())
3418 return QualType();
3419 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003420
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003421 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3422 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003423 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003424}
Mike Stump11289f42009-09-09 15:08:12 +00003425
3426template<typename Derived>
3427QualType
John McCall550e0c22009-10-21 00:40:46 +00003428TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003429 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003430 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003431 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3432 if (PointeeType.isNull())
3433 return QualType();
3434
3435 QualType Result = TL.getType();
3436 if (getDerived().AlwaysRebuild() ||
3437 PointeeType != TL.getPointeeLoc().getType()) {
3438 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003439 TL.getSigilLoc());
3440 if (Result.isNull())
3441 return QualType();
3442 }
3443
Douglas Gregor049211a2010-04-22 16:50:51 +00003444 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003445 NewT.setSigilLoc(TL.getSigilLoc());
3446 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003447}
3448
John McCall70dd5f62009-10-30 00:06:24 +00003449/// Transforms a reference type. Note that somewhat paradoxically we
3450/// don't care whether the type itself is an l-value type or an r-value
3451/// type; we only care if the type was *written* as an l-value type
3452/// or an r-value type.
3453template<typename Derived>
3454QualType
3455TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003456 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003457 const ReferenceType *T = TL.getTypePtr();
3458
3459 // Note that this works with the pointee-as-written.
3460 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3461 if (PointeeType.isNull())
3462 return QualType();
3463
3464 QualType Result = TL.getType();
3465 if (getDerived().AlwaysRebuild() ||
3466 PointeeType != T->getPointeeTypeAsWritten()) {
3467 Result = getDerived().RebuildReferenceType(PointeeType,
3468 T->isSpelledAsLValue(),
3469 TL.getSigilLoc());
3470 if (Result.isNull())
3471 return QualType();
3472 }
3473
3474 // r-value references can be rebuilt as l-value references.
3475 ReferenceTypeLoc NewTL;
3476 if (isa<LValueReferenceType>(Result))
3477 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3478 else
3479 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3480 NewTL.setSigilLoc(TL.getSigilLoc());
3481
3482 return Result;
3483}
3484
Mike Stump11289f42009-09-09 15:08:12 +00003485template<typename Derived>
3486QualType
John McCall550e0c22009-10-21 00:40:46 +00003487TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003488 LValueReferenceTypeLoc TL) {
3489 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003490}
3491
Mike Stump11289f42009-09-09 15:08:12 +00003492template<typename Derived>
3493QualType
John McCall550e0c22009-10-21 00:40:46 +00003494TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003495 RValueReferenceTypeLoc TL) {
3496 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003497}
Mike Stump11289f42009-09-09 15:08:12 +00003498
Douglas Gregord6ff3322009-08-04 16:50:30 +00003499template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003500QualType
John McCall550e0c22009-10-21 00:40:46 +00003501TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003502 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003503 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003504
3505 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003506 if (PointeeType.isNull())
3507 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003508
John McCall550e0c22009-10-21 00:40:46 +00003509 // TODO: preserve source information for this.
3510 QualType ClassType
3511 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003512 if (ClassType.isNull())
3513 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003514
John McCall550e0c22009-10-21 00:40:46 +00003515 QualType Result = TL.getType();
3516 if (getDerived().AlwaysRebuild() ||
3517 PointeeType != T->getPointeeType() ||
3518 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003519 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3520 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003521 if (Result.isNull())
3522 return QualType();
3523 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003524
John McCall550e0c22009-10-21 00:40:46 +00003525 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3526 NewTL.setSigilLoc(TL.getSigilLoc());
3527
3528 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003529}
3530
Mike Stump11289f42009-09-09 15:08:12 +00003531template<typename Derived>
3532QualType
John McCall550e0c22009-10-21 00:40:46 +00003533TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003534 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003535 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003536 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003537 if (ElementType.isNull())
3538 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003539
John McCall550e0c22009-10-21 00:40:46 +00003540 QualType Result = TL.getType();
3541 if (getDerived().AlwaysRebuild() ||
3542 ElementType != T->getElementType()) {
3543 Result = getDerived().RebuildConstantArrayType(ElementType,
3544 T->getSizeModifier(),
3545 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003546 T->getIndexTypeCVRQualifiers(),
3547 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003548 if (Result.isNull())
3549 return QualType();
3550 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003551
John McCall550e0c22009-10-21 00:40:46 +00003552 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3553 NewTL.setLBracketLoc(TL.getLBracketLoc());
3554 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003555
John McCall550e0c22009-10-21 00:40:46 +00003556 Expr *Size = TL.getSizeExpr();
3557 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003558 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003559 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3560 }
3561 NewTL.setSizeExpr(Size);
3562
3563 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003564}
Mike Stump11289f42009-09-09 15:08:12 +00003565
Douglas Gregord6ff3322009-08-04 16:50:30 +00003566template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003567QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003568 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003569 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003570 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003571 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003572 if (ElementType.isNull())
3573 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003574
John McCall550e0c22009-10-21 00:40:46 +00003575 QualType Result = TL.getType();
3576 if (getDerived().AlwaysRebuild() ||
3577 ElementType != T->getElementType()) {
3578 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003579 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003580 T->getIndexTypeCVRQualifiers(),
3581 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003582 if (Result.isNull())
3583 return QualType();
3584 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003585
John McCall550e0c22009-10-21 00:40:46 +00003586 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3587 NewTL.setLBracketLoc(TL.getLBracketLoc());
3588 NewTL.setRBracketLoc(TL.getRBracketLoc());
3589 NewTL.setSizeExpr(0);
3590
3591 return Result;
3592}
3593
3594template<typename Derived>
3595QualType
3596TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003597 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003598 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003599 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3600 if (ElementType.isNull())
3601 return QualType();
3602
3603 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003604 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003605
John McCalldadc5752010-08-24 06:29:42 +00003606 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003607 = getDerived().TransformExpr(T->getSizeExpr());
3608 if (SizeResult.isInvalid())
3609 return QualType();
3610
John McCallb268a282010-08-23 23:25:46 +00003611 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003612
3613 QualType Result = TL.getType();
3614 if (getDerived().AlwaysRebuild() ||
3615 ElementType != T->getElementType() ||
3616 Size != T->getSizeExpr()) {
3617 Result = getDerived().RebuildVariableArrayType(ElementType,
3618 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003619 Size,
John McCall550e0c22009-10-21 00:40:46 +00003620 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003621 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003622 if (Result.isNull())
3623 return QualType();
3624 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003625
John McCall550e0c22009-10-21 00:40:46 +00003626 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3627 NewTL.setLBracketLoc(TL.getLBracketLoc());
3628 NewTL.setRBracketLoc(TL.getRBracketLoc());
3629 NewTL.setSizeExpr(Size);
3630
3631 return Result;
3632}
3633
3634template<typename Derived>
3635QualType
3636TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003637 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003638 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003639 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3640 if (ElementType.isNull())
3641 return QualType();
3642
3643 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003644 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003645
John McCall33ddac02011-01-19 10:06:00 +00003646 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3647 Expr *origSize = TL.getSizeExpr();
3648 if (!origSize) origSize = T->getSizeExpr();
3649
3650 ExprResult sizeResult
3651 = getDerived().TransformExpr(origSize);
3652 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003653 return QualType();
3654
John McCall33ddac02011-01-19 10:06:00 +00003655 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003656
3657 QualType Result = TL.getType();
3658 if (getDerived().AlwaysRebuild() ||
3659 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003660 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003661 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3662 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003663 size,
John McCall550e0c22009-10-21 00:40:46 +00003664 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003665 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003666 if (Result.isNull())
3667 return QualType();
3668 }
John McCall550e0c22009-10-21 00:40:46 +00003669
3670 // We might have any sort of array type now, but fortunately they
3671 // all have the same location layout.
3672 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3673 NewTL.setLBracketLoc(TL.getLBracketLoc());
3674 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003675 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003676
3677 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003678}
Mike Stump11289f42009-09-09 15:08:12 +00003679
3680template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003681QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003682 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003683 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003684 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003685
3686 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003687 QualType ElementType = getDerived().TransformType(T->getElementType());
3688 if (ElementType.isNull())
3689 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003690
Douglas Gregore922c772009-08-04 22:27:00 +00003691 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003692 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003693
John McCalldadc5752010-08-24 06:29:42 +00003694 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003695 if (Size.isInvalid())
3696 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003697
John McCall550e0c22009-10-21 00:40:46 +00003698 QualType Result = TL.getType();
3699 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003700 ElementType != T->getElementType() ||
3701 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003702 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003703 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003704 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003705 if (Result.isNull())
3706 return QualType();
3707 }
John McCall550e0c22009-10-21 00:40:46 +00003708
3709 // Result might be dependent or not.
3710 if (isa<DependentSizedExtVectorType>(Result)) {
3711 DependentSizedExtVectorTypeLoc NewTL
3712 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3713 NewTL.setNameLoc(TL.getNameLoc());
3714 } else {
3715 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3716 NewTL.setNameLoc(TL.getNameLoc());
3717 }
3718
3719 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003720}
Mike Stump11289f42009-09-09 15:08:12 +00003721
3722template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003723QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003724 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003725 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003726 QualType ElementType = getDerived().TransformType(T->getElementType());
3727 if (ElementType.isNull())
3728 return QualType();
3729
John McCall550e0c22009-10-21 00:40:46 +00003730 QualType Result = TL.getType();
3731 if (getDerived().AlwaysRebuild() ||
3732 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003733 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003734 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003735 if (Result.isNull())
3736 return QualType();
3737 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003738
John McCall550e0c22009-10-21 00:40:46 +00003739 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3740 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003741
John McCall550e0c22009-10-21 00:40:46 +00003742 return Result;
3743}
3744
3745template<typename Derived>
3746QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003747 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003748 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003749 QualType ElementType = getDerived().TransformType(T->getElementType());
3750 if (ElementType.isNull())
3751 return QualType();
3752
3753 QualType Result = TL.getType();
3754 if (getDerived().AlwaysRebuild() ||
3755 ElementType != T->getElementType()) {
3756 Result = getDerived().RebuildExtVectorType(ElementType,
3757 T->getNumElements(),
3758 /*FIXME*/ SourceLocation());
3759 if (Result.isNull())
3760 return QualType();
3761 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003762
John McCall550e0c22009-10-21 00:40:46 +00003763 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3764 NewTL.setNameLoc(TL.getNameLoc());
3765
3766 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003767}
Mike Stump11289f42009-09-09 15:08:12 +00003768
3769template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003770ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003771TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3772 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003773 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003774 TypeSourceInfo *NewDI = 0;
3775
3776 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3777 // If we're substituting into a pack expansion type and we know the
3778 TypeLoc OldTL = OldDI->getTypeLoc();
3779 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3780
3781 TypeLocBuilder TLB;
3782 TypeLoc NewTL = OldDI->getTypeLoc();
3783 TLB.reserve(NewTL.getFullDataSize());
3784
3785 QualType Result = getDerived().TransformType(TLB,
3786 OldExpansionTL.getPatternLoc());
3787 if (Result.isNull())
3788 return 0;
3789
3790 Result = RebuildPackExpansionType(Result,
3791 OldExpansionTL.getPatternLoc().getSourceRange(),
3792 OldExpansionTL.getEllipsisLoc(),
3793 NumExpansions);
3794 if (Result.isNull())
3795 return 0;
3796
3797 PackExpansionTypeLoc NewExpansionTL
3798 = TLB.push<PackExpansionTypeLoc>(Result);
3799 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3800 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3801 } else
3802 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003803 if (!NewDI)
3804 return 0;
3805
3806 if (NewDI == OldDI)
3807 return OldParm;
3808 else
3809 return ParmVarDecl::Create(SemaRef.Context,
3810 OldParm->getDeclContext(),
3811 OldParm->getLocation(),
3812 OldParm->getIdentifier(),
3813 NewDI->getType(),
3814 NewDI,
3815 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003816 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003817 /* DefArg */ NULL);
3818}
3819
3820template<typename Derived>
3821bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003822 TransformFunctionTypeParams(SourceLocation Loc,
3823 ParmVarDecl **Params, unsigned NumParams,
3824 const QualType *ParamTypes,
3825 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3826 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3827 for (unsigned i = 0; i != NumParams; ++i) {
3828 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003829 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003830 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003831 if (OldParm->isParameterPack()) {
3832 // We have a function parameter pack that may need to be expanded.
3833 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003834
Douglas Gregor5499af42011-01-05 23:12:31 +00003835 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003836 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3837 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3838 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3839 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003840 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3841
Douglas Gregor5499af42011-01-05 23:12:31 +00003842 // Determine whether we should expand the parameter packs.
3843 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003844 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003845 llvm::Optional<unsigned> OrigNumExpansions
3846 = ExpansionTL.getTypePtr()->getNumExpansions();
3847 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003848 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3849 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003850 Unexpanded.data(),
3851 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003852 ShouldExpand,
3853 RetainExpansion,
3854 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003855 return true;
3856 }
3857
3858 if (ShouldExpand) {
3859 // Expand the function parameter pack into multiple, separate
3860 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003861 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003862 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003863 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3864 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003865 = getDerived().TransformFunctionTypeParam(OldParm,
3866 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003867 if (!NewParm)
3868 return true;
3869
Douglas Gregordd472162011-01-07 00:20:55 +00003870 OutParamTypes.push_back(NewParm->getType());
3871 if (PVars)
3872 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003873 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003874
3875 // If we're supposed to retain a pack expansion, do so by temporarily
3876 // forgetting the partially-substituted parameter pack.
3877 if (RetainExpansion) {
3878 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3879 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003880 = getDerived().TransformFunctionTypeParam(OldParm,
3881 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003882 if (!NewParm)
3883 return true;
3884
3885 OutParamTypes.push_back(NewParm->getType());
3886 if (PVars)
3887 PVars->push_back(NewParm);
3888 }
3889
Douglas Gregor5499af42011-01-05 23:12:31 +00003890 // We're done with the pack expansion.
3891 continue;
3892 }
3893
3894 // We'll substitute the parameter now without expanding the pack
3895 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003896 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3897 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3898 NumExpansions);
3899 } else {
3900 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3901 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003902 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003903
John McCall58f10c32010-03-11 09:03:00 +00003904 if (!NewParm)
3905 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003906
Douglas Gregordd472162011-01-07 00:20:55 +00003907 OutParamTypes.push_back(NewParm->getType());
3908 if (PVars)
3909 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003910 continue;
3911 }
John McCall58f10c32010-03-11 09:03:00 +00003912
3913 // Deal with the possibility that we don't have a parameter
3914 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003915 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003916 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003917 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003918 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003919 if (const PackExpansionType *Expansion
3920 = dyn_cast<PackExpansionType>(OldType)) {
3921 // We have a function parameter pack that may need to be expanded.
3922 QualType Pattern = Expansion->getPattern();
3923 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3924 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3925
3926 // Determine whether we should expand the parameter packs.
3927 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003928 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003929 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003930 Unexpanded.data(),
3931 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003932 ShouldExpand,
3933 RetainExpansion,
3934 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003935 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003936 }
3937
3938 if (ShouldExpand) {
3939 // Expand the function parameter pack into multiple, separate
3940 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003941 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003942 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3943 QualType NewType = getDerived().TransformType(Pattern);
3944 if (NewType.isNull())
3945 return true;
John McCall58f10c32010-03-11 09:03:00 +00003946
Douglas Gregordd472162011-01-07 00:20:55 +00003947 OutParamTypes.push_back(NewType);
3948 if (PVars)
3949 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003950 }
3951
3952 // We're done with the pack expansion.
3953 continue;
3954 }
3955
Douglas Gregor48d24112011-01-10 20:53:55 +00003956 // If we're supposed to retain a pack expansion, do so by temporarily
3957 // forgetting the partially-substituted parameter pack.
3958 if (RetainExpansion) {
3959 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3960 QualType NewType = getDerived().TransformType(Pattern);
3961 if (NewType.isNull())
3962 return true;
3963
3964 OutParamTypes.push_back(NewType);
3965 if (PVars)
3966 PVars->push_back(0);
3967 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003968
Douglas Gregor5499af42011-01-05 23:12:31 +00003969 // We'll substitute the parameter now without expanding the pack
3970 // expansion.
3971 OldType = Expansion->getPattern();
3972 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003973 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3974 NewType = getDerived().TransformType(OldType);
3975 } else {
3976 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003977 }
3978
Douglas Gregor5499af42011-01-05 23:12:31 +00003979 if (NewType.isNull())
3980 return true;
3981
3982 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003983 NewType = getSema().Context.getPackExpansionType(NewType,
3984 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003985
Douglas Gregordd472162011-01-07 00:20:55 +00003986 OutParamTypes.push_back(NewType);
3987 if (PVars)
3988 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003989 }
3990
3991 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003992 }
John McCall58f10c32010-03-11 09:03:00 +00003993
3994template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003995QualType
John McCall550e0c22009-10-21 00:40:46 +00003996TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003997 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003998 // Transform the parameters and return type.
3999 //
4000 // We instantiate in source order, with the return type first followed by
4001 // the parameters, because users tend to expect this (even if they shouldn't
4002 // rely on it!).
4003 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00004004 // When the function has a trailing return type, we instantiate the
4005 // parameters before the return type, since the return type can then refer
4006 // to the parameters themselves (via decltype, sizeof, etc.).
4007 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00004008 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00004009 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004010 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004011
Douglas Gregor7fb25412010-10-01 18:44:50 +00004012 QualType ResultType;
4013
4014 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004015 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4016 TL.getParmArray(),
4017 TL.getNumArgs(),
4018 TL.getTypePtr()->arg_type_begin(),
4019 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004020 return QualType();
4021
4022 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4023 if (ResultType.isNull())
4024 return QualType();
4025 }
4026 else {
4027 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4028 if (ResultType.isNull())
4029 return QualType();
4030
Douglas Gregordd472162011-01-07 00:20:55 +00004031 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4032 TL.getParmArray(),
4033 TL.getNumArgs(),
4034 TL.getTypePtr()->arg_type_begin(),
4035 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004036 return QualType();
4037 }
4038
John McCall550e0c22009-10-21 00:40:46 +00004039 QualType Result = TL.getType();
4040 if (getDerived().AlwaysRebuild() ||
4041 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004042 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004043 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4044 Result = getDerived().RebuildFunctionProtoType(ResultType,
4045 ParamTypes.data(),
4046 ParamTypes.size(),
4047 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004048 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004049 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004050 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004051 if (Result.isNull())
4052 return QualType();
4053 }
Mike Stump11289f42009-09-09 15:08:12 +00004054
John McCall550e0c22009-10-21 00:40:46 +00004055 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4056 NewTL.setLParenLoc(TL.getLParenLoc());
4057 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004058 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004059 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4060 NewTL.setArg(i, ParamDecls[i]);
4061
4062 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004063}
Mike Stump11289f42009-09-09 15:08:12 +00004064
Douglas Gregord6ff3322009-08-04 16:50:30 +00004065template<typename Derived>
4066QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004067 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004068 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004069 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004070 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4071 if (ResultType.isNull())
4072 return QualType();
4073
4074 QualType Result = TL.getType();
4075 if (getDerived().AlwaysRebuild() ||
4076 ResultType != T->getResultType())
4077 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4078
4079 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4080 NewTL.setLParenLoc(TL.getLParenLoc());
4081 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004082 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004083
4084 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004085}
Mike Stump11289f42009-09-09 15:08:12 +00004086
John McCallb96ec562009-12-04 22:46:56 +00004087template<typename Derived> QualType
4088TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004089 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004090 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004091 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004092 if (!D)
4093 return QualType();
4094
4095 QualType Result = TL.getType();
4096 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4097 Result = getDerived().RebuildUnresolvedUsingType(D);
4098 if (Result.isNull())
4099 return QualType();
4100 }
4101
4102 // We might get an arbitrary type spec type back. We should at
4103 // least always get a type spec type, though.
4104 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4105 NewTL.setNameLoc(TL.getNameLoc());
4106
4107 return Result;
4108}
4109
Douglas Gregord6ff3322009-08-04 16:50:30 +00004110template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004111QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004112 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004113 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004114 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004115 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4116 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004117 if (!Typedef)
4118 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004119
John McCall550e0c22009-10-21 00:40:46 +00004120 QualType Result = TL.getType();
4121 if (getDerived().AlwaysRebuild() ||
4122 Typedef != T->getDecl()) {
4123 Result = getDerived().RebuildTypedefType(Typedef);
4124 if (Result.isNull())
4125 return QualType();
4126 }
Mike Stump11289f42009-09-09 15:08:12 +00004127
John McCall550e0c22009-10-21 00:40:46 +00004128 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4129 NewTL.setNameLoc(TL.getNameLoc());
4130
4131 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004132}
Mike Stump11289f42009-09-09 15:08:12 +00004133
Douglas Gregord6ff3322009-08-04 16:50:30 +00004134template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004135QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004136 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004137 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004138 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004139
John McCalldadc5752010-08-24 06:29:42 +00004140 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004141 if (E.isInvalid())
4142 return QualType();
4143
John McCall550e0c22009-10-21 00:40:46 +00004144 QualType Result = TL.getType();
4145 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004146 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004147 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004148 if (Result.isNull())
4149 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004150 }
John McCall550e0c22009-10-21 00:40:46 +00004151 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004152
John McCall550e0c22009-10-21 00:40:46 +00004153 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004154 NewTL.setTypeofLoc(TL.getTypeofLoc());
4155 NewTL.setLParenLoc(TL.getLParenLoc());
4156 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004157
4158 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004159}
Mike Stump11289f42009-09-09 15:08:12 +00004160
4161template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004162QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004163 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004164 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4165 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4166 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004167 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004168
John McCall550e0c22009-10-21 00:40:46 +00004169 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004170 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4171 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004172 if (Result.isNull())
4173 return QualType();
4174 }
Mike Stump11289f42009-09-09 15:08:12 +00004175
John McCall550e0c22009-10-21 00:40:46 +00004176 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004177 NewTL.setTypeofLoc(TL.getTypeofLoc());
4178 NewTL.setLParenLoc(TL.getLParenLoc());
4179 NewTL.setRParenLoc(TL.getRParenLoc());
4180 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004181
4182 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004183}
Mike Stump11289f42009-09-09 15:08:12 +00004184
4185template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004186QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004187 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004188 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004189
Douglas Gregore922c772009-08-04 22:27:00 +00004190 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004191 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004192
John McCalldadc5752010-08-24 06:29:42 +00004193 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004194 if (E.isInvalid())
4195 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004196
John McCall550e0c22009-10-21 00:40:46 +00004197 QualType Result = TL.getType();
4198 if (getDerived().AlwaysRebuild() ||
4199 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004200 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004201 if (Result.isNull())
4202 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004203 }
John McCall550e0c22009-10-21 00:40:46 +00004204 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004205
John McCall550e0c22009-10-21 00:40:46 +00004206 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4207 NewTL.setNameLoc(TL.getNameLoc());
4208
4209 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004210}
4211
4212template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004213QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4214 AutoTypeLoc TL) {
4215 const AutoType *T = TL.getTypePtr();
4216 QualType OldDeduced = T->getDeducedType();
4217 QualType NewDeduced;
4218 if (!OldDeduced.isNull()) {
4219 NewDeduced = getDerived().TransformType(OldDeduced);
4220 if (NewDeduced.isNull())
4221 return QualType();
4222 }
4223
4224 QualType Result = TL.getType();
4225 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4226 Result = getDerived().RebuildAutoType(NewDeduced);
4227 if (Result.isNull())
4228 return QualType();
4229 }
4230
4231 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4232 NewTL.setNameLoc(TL.getNameLoc());
4233
4234 return Result;
4235}
4236
4237template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004238QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004239 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004240 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004241 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004242 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4243 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004244 if (!Record)
4245 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004246
John McCall550e0c22009-10-21 00:40:46 +00004247 QualType Result = TL.getType();
4248 if (getDerived().AlwaysRebuild() ||
4249 Record != T->getDecl()) {
4250 Result = getDerived().RebuildRecordType(Record);
4251 if (Result.isNull())
4252 return QualType();
4253 }
Mike Stump11289f42009-09-09 15:08:12 +00004254
John McCall550e0c22009-10-21 00:40:46 +00004255 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4256 NewTL.setNameLoc(TL.getNameLoc());
4257
4258 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004259}
Mike Stump11289f42009-09-09 15:08:12 +00004260
4261template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004262QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004263 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004264 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004265 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004266 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4267 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004268 if (!Enum)
4269 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004270
John McCall550e0c22009-10-21 00:40:46 +00004271 QualType Result = TL.getType();
4272 if (getDerived().AlwaysRebuild() ||
4273 Enum != T->getDecl()) {
4274 Result = getDerived().RebuildEnumType(Enum);
4275 if (Result.isNull())
4276 return QualType();
4277 }
Mike Stump11289f42009-09-09 15:08:12 +00004278
John McCall550e0c22009-10-21 00:40:46 +00004279 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4280 NewTL.setNameLoc(TL.getNameLoc());
4281
4282 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004283}
John McCallfcc33b02009-09-05 00:15:47 +00004284
John McCalle78aac42010-03-10 03:28:59 +00004285template<typename Derived>
4286QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4287 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004288 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004289 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4290 TL.getTypePtr()->getDecl());
4291 if (!D) return QualType();
4292
4293 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4294 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4295 return T;
4296}
4297
Douglas Gregord6ff3322009-08-04 16:50:30 +00004298template<typename Derived>
4299QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004300 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004301 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004302 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004303}
4304
Mike Stump11289f42009-09-09 15:08:12 +00004305template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004306QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004307 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004308 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004309 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004310}
4311
4312template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004313QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4314 TypeLocBuilder &TLB,
4315 SubstTemplateTypeParmPackTypeLoc TL) {
4316 return TransformTypeSpecType(TLB, TL);
4317}
4318
4319template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004320QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004321 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004322 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004323 const TemplateSpecializationType *T = TL.getTypePtr();
4324
Mike Stump11289f42009-09-09 15:08:12 +00004325 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004326 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004327 if (Template.isNull())
4328 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004329
John McCall31f82722010-11-12 08:19:04 +00004330 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4331}
4332
Douglas Gregorfe921a72010-12-20 23:36:19 +00004333namespace {
4334 /// \brief Simple iterator that traverses the template arguments in a
4335 /// container that provides a \c getArgLoc() member function.
4336 ///
4337 /// This iterator is intended to be used with the iterator form of
4338 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4339 template<typename ArgLocContainer>
4340 class TemplateArgumentLocContainerIterator {
4341 ArgLocContainer *Container;
4342 unsigned Index;
4343
4344 public:
4345 typedef TemplateArgumentLoc value_type;
4346 typedef TemplateArgumentLoc reference;
4347 typedef int difference_type;
4348 typedef std::input_iterator_tag iterator_category;
4349
4350 class pointer {
4351 TemplateArgumentLoc Arg;
4352
4353 public:
4354 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4355
4356 const TemplateArgumentLoc *operator->() const {
4357 return &Arg;
4358 }
4359 };
4360
4361
4362 TemplateArgumentLocContainerIterator() {}
4363
4364 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4365 unsigned Index)
4366 : Container(&Container), Index(Index) { }
4367
4368 TemplateArgumentLocContainerIterator &operator++() {
4369 ++Index;
4370 return *this;
4371 }
4372
4373 TemplateArgumentLocContainerIterator operator++(int) {
4374 TemplateArgumentLocContainerIterator Old(*this);
4375 ++(*this);
4376 return Old;
4377 }
4378
4379 TemplateArgumentLoc operator*() const {
4380 return Container->getArgLoc(Index);
4381 }
4382
4383 pointer operator->() const {
4384 return pointer(Container->getArgLoc(Index));
4385 }
4386
4387 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004388 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004389 return X.Container == Y.Container && X.Index == Y.Index;
4390 }
4391
4392 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004393 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004394 return !(X == Y);
4395 }
4396 };
4397}
4398
4399
John McCall31f82722010-11-12 08:19:04 +00004400template <typename Derived>
4401QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4402 TypeLocBuilder &TLB,
4403 TemplateSpecializationTypeLoc TL,
4404 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004405 TemplateArgumentListInfo NewTemplateArgs;
4406 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4407 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004408 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4409 ArgIterator;
4410 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4411 ArgIterator(TL, TL.getNumArgs()),
4412 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004413 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004414
John McCall0ad16662009-10-29 08:12:44 +00004415 // FIXME: maybe don't rebuild if all the template arguments are the same.
4416
4417 QualType Result =
4418 getDerived().RebuildTemplateSpecializationType(Template,
4419 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004420 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004421
4422 if (!Result.isNull()) {
4423 TemplateSpecializationTypeLoc NewTL
4424 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4425 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4426 NewTL.setLAngleLoc(TL.getLAngleLoc());
4427 NewTL.setRAngleLoc(TL.getRAngleLoc());
4428 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4429 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004430 }
Mike Stump11289f42009-09-09 15:08:12 +00004431
John McCall0ad16662009-10-29 08:12:44 +00004432 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004433}
Mike Stump11289f42009-09-09 15:08:12 +00004434
Douglas Gregor5a064722011-02-28 17:23:35 +00004435template <typename Derived>
4436QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4437 TypeLocBuilder &TLB,
4438 DependentTemplateSpecializationTypeLoc TL,
4439 TemplateName Template) {
4440 TemplateArgumentListInfo NewTemplateArgs;
4441 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4442 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4443 typedef TemplateArgumentLocContainerIterator<
4444 DependentTemplateSpecializationTypeLoc> ArgIterator;
4445 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4446 ArgIterator(TL, TL.getNumArgs()),
4447 NewTemplateArgs))
4448 return QualType();
4449
4450 // FIXME: maybe don't rebuild if all the template arguments are the same.
4451
4452 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4453 QualType Result
4454 = getSema().Context.getDependentTemplateSpecializationType(
4455 TL.getTypePtr()->getKeyword(),
4456 DTN->getQualifier(),
4457 DTN->getIdentifier(),
4458 NewTemplateArgs);
4459
4460 DependentTemplateSpecializationTypeLoc NewTL
4461 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4462 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004463
4464 // FIXME: Poor nested-name-specifier source-location information.
4465 CXXScopeSpec SS;
4466 SS.MakeTrivial(SemaRef.Context,
4467 DTN->getQualifier(), TL.getQualifierLoc().getSourceRange());
4468 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004469 NewTL.setNameLoc(TL.getNameLoc());
4470 NewTL.setLAngleLoc(TL.getLAngleLoc());
4471 NewTL.setRAngleLoc(TL.getRAngleLoc());
4472 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4473 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4474 return Result;
4475 }
4476
4477 QualType Result
4478 = getDerived().RebuildTemplateSpecializationType(Template,
4479 TL.getNameLoc(),
4480 NewTemplateArgs);
4481
4482 if (!Result.isNull()) {
4483 /// FIXME: Wrap this in an elaborated-type-specifier?
4484 TemplateSpecializationTypeLoc NewTL
4485 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4486 NewTL.setTemplateNameLoc(TL.getNameLoc());
4487 NewTL.setLAngleLoc(TL.getLAngleLoc());
4488 NewTL.setRAngleLoc(TL.getRAngleLoc());
4489 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4490 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4491 }
4492
4493 return Result;
4494}
4495
Mike Stump11289f42009-09-09 15:08:12 +00004496template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004497QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004498TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004499 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004500 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004501
Douglas Gregor844cb502011-03-01 18:12:44 +00004502 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004503 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004504 if (TL.getQualifierLoc()) {
4505 QualifierLoc
4506 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4507 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004508 return QualType();
4509 }
Mike Stump11289f42009-09-09 15:08:12 +00004510
John McCall31f82722010-11-12 08:19:04 +00004511 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4512 if (NamedT.isNull())
4513 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004514
John McCall550e0c22009-10-21 00:40:46 +00004515 QualType Result = TL.getType();
4516 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004517 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004518 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004519 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004520 T->getKeyword(),
4521 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004522 if (Result.isNull())
4523 return QualType();
4524 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004525
Abramo Bagnara6150c882010-05-11 21:36:43 +00004526 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004527 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004528 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004529 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004530}
Mike Stump11289f42009-09-09 15:08:12 +00004531
4532template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004533QualType TreeTransform<Derived>::TransformAttributedType(
4534 TypeLocBuilder &TLB,
4535 AttributedTypeLoc TL) {
4536 const AttributedType *oldType = TL.getTypePtr();
4537 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4538 if (modifiedType.isNull())
4539 return QualType();
4540
4541 QualType result = TL.getType();
4542
4543 // FIXME: dependent operand expressions?
4544 if (getDerived().AlwaysRebuild() ||
4545 modifiedType != oldType->getModifiedType()) {
4546 // TODO: this is really lame; we should really be rebuilding the
4547 // equivalent type from first principles.
4548 QualType equivalentType
4549 = getDerived().TransformType(oldType->getEquivalentType());
4550 if (equivalentType.isNull())
4551 return QualType();
4552 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4553 modifiedType,
4554 equivalentType);
4555 }
4556
4557 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4558 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4559 if (TL.hasAttrOperand())
4560 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4561 if (TL.hasAttrExprOperand())
4562 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4563 else if (TL.hasAttrEnumOperand())
4564 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4565
4566 return result;
4567}
4568
4569template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004570QualType
4571TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4572 ParenTypeLoc TL) {
4573 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4574 if (Inner.isNull())
4575 return QualType();
4576
4577 QualType Result = TL.getType();
4578 if (getDerived().AlwaysRebuild() ||
4579 Inner != TL.getInnerLoc().getType()) {
4580 Result = getDerived().RebuildParenType(Inner);
4581 if (Result.isNull())
4582 return QualType();
4583 }
4584
4585 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4586 NewTL.setLParenLoc(TL.getLParenLoc());
4587 NewTL.setRParenLoc(TL.getRParenLoc());
4588 return Result;
4589}
4590
4591template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004592QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004593 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004594 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004595
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004596 NestedNameSpecifierLoc QualifierLoc
4597 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4598 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004599 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004600
John McCallc392f372010-06-11 00:33:02 +00004601 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004602 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004603 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004604 QualifierLoc,
4605 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004606 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004607 if (Result.isNull())
4608 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004609
Abramo Bagnarad7548482010-05-19 21:37:53 +00004610 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4611 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004612 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4613
Abramo Bagnarad7548482010-05-19 21:37:53 +00004614 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4615 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004616 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004617 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004618 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4619 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004620 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004621 NewTL.setNameLoc(TL.getNameLoc());
4622 }
John McCall550e0c22009-10-21 00:40:46 +00004623 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004624}
Mike Stump11289f42009-09-09 15:08:12 +00004625
Douglas Gregord6ff3322009-08-04 16:50:30 +00004626template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004627QualType TreeTransform<Derived>::
4628 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004629 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004630 NestedNameSpecifierLoc QualifierLoc;
4631 if (TL.getQualifierLoc()) {
4632 QualifierLoc
4633 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4634 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004635 return QualType();
4636 }
4637
John McCall31f82722010-11-12 08:19:04 +00004638 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004639 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004640}
4641
4642template<typename Derived>
4643QualType TreeTransform<Derived>::
4644 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4645 DependentTemplateSpecializationTypeLoc TL,
4646 NestedNameSpecifier *NNS) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004647 // FIXME: This routine needs to go away.
John McCall424cec92011-01-19 06:33:43 +00004648 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004649
John McCallc392f372010-06-11 00:33:02 +00004650 TemplateArgumentListInfo NewTemplateArgs;
4651 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4652 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor14454802011-02-25 02:25:35 +00004653
4654 // FIXME: Nested-name-specifier source location info!
Douglas Gregorfe921a72010-12-20 23:36:19 +00004655 typedef TemplateArgumentLocContainerIterator<
4656 DependentTemplateSpecializationTypeLoc> ArgIterator;
4657 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4658 ArgIterator(TL, TL.getNumArgs()),
4659 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004660 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004661
Douglas Gregora5614c52010-09-08 23:56:00 +00004662 QualType Result
4663 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4664 NNS,
Douglas Gregora7a795b2011-03-01 20:11:18 +00004665 TL.getQualifierLoc().getSourceRange(),
Douglas Gregora5614c52010-09-08 23:56:00 +00004666 T->getIdentifier(),
4667 TL.getNameLoc(),
4668 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004669 if (Result.isNull())
4670 return QualType();
4671
4672 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4673 QualType NamedT = ElabT->getNamedType();
4674
4675 // Copy information relevant to the template specialization.
4676 TemplateSpecializationTypeLoc NamedTL
4677 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4678 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4679 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4680 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4681 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4682
4683 // Copy information relevant to the elaborated type.
4684 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4685 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004686
4687 // FIXME: DependentTemplateSpecializationType needs better source-location
4688 // info.
4689 NestedNameSpecifierLocBuilder Builder;
Douglas Gregora7a795b2011-03-01 20:11:18 +00004690 Builder.MakeTrivial(SemaRef.Context,
4691 NNS, TL.getQualifierLoc().getSourceRange());
Douglas Gregor844cb502011-03-01 18:12:44 +00004692 NewTL.setQualifierLoc(Builder.getWithLocInContext(SemaRef.Context));
John McCallc392f372010-06-11 00:33:02 +00004693 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004694 TypeLoc NewTL(Result, TL.getOpaqueData());
4695 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004696 }
4697 return Result;
4698}
4699
4700template<typename Derived>
Douglas Gregora7a795b2011-03-01 20:11:18 +00004701QualType TreeTransform<Derived>::
4702TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4703 DependentTemplateSpecializationTypeLoc TL,
4704 NestedNameSpecifierLoc QualifierLoc) {
4705 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4706
4707 TemplateArgumentListInfo NewTemplateArgs;
4708 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4709 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4710
4711 typedef TemplateArgumentLocContainerIterator<
4712 DependentTemplateSpecializationTypeLoc> ArgIterator;
4713 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4714 ArgIterator(TL, TL.getNumArgs()),
4715 NewTemplateArgs))
4716 return QualType();
4717
4718 QualType Result
4719 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4720 QualifierLoc,
4721 T->getIdentifier(),
4722 TL.getNameLoc(),
4723 NewTemplateArgs);
4724 if (Result.isNull())
4725 return QualType();
4726
4727 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4728 QualType NamedT = ElabT->getNamedType();
4729
4730 // Copy information relevant to the template specialization.
4731 TemplateSpecializationTypeLoc NamedTL
4732 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4733 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4734 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4735 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4736 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4737
4738 // Copy information relevant to the elaborated type.
4739 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4740 NewTL.setKeywordLoc(TL.getKeywordLoc());
4741 NewTL.setQualifierLoc(QualifierLoc);
4742 } else {
4743 TypeLoc NewTL(Result, TL.getOpaqueData());
4744 TLB.pushFullCopy(NewTL);
4745 }
4746 return Result;
4747}
4748
4749template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004750QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4751 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004752 QualType Pattern
4753 = getDerived().TransformType(TLB, TL.getPatternLoc());
4754 if (Pattern.isNull())
4755 return QualType();
4756
4757 QualType Result = TL.getType();
4758 if (getDerived().AlwaysRebuild() ||
4759 Pattern != TL.getPatternLoc().getType()) {
4760 Result = getDerived().RebuildPackExpansionType(Pattern,
4761 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004762 TL.getEllipsisLoc(),
4763 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004764 if (Result.isNull())
4765 return QualType();
4766 }
4767
4768 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4769 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4770 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004771}
4772
4773template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004774QualType
4775TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004776 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004777 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004778 TLB.pushFullCopy(TL);
4779 return TL.getType();
4780}
4781
4782template<typename Derived>
4783QualType
4784TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004785 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004786 // ObjCObjectType is never dependent.
4787 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004788 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004789}
Mike Stump11289f42009-09-09 15:08:12 +00004790
4791template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004792QualType
4793TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004794 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004795 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004796 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004797 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004798}
4799
Douglas Gregord6ff3322009-08-04 16:50:30 +00004800//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004801// Statement transformation
4802//===----------------------------------------------------------------------===//
4803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004804StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004805TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004806 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004807}
4808
4809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004810StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004811TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4812 return getDerived().TransformCompoundStmt(S, false);
4813}
4814
4815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004816StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004817TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004818 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004819 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004820 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004821 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004822 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4823 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004824 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004825 if (Result.isInvalid()) {
4826 // Immediately fail if this was a DeclStmt, since it's very
4827 // likely that this will cause problems for future statements.
4828 if (isa<DeclStmt>(*B))
4829 return StmtError();
4830
4831 // Otherwise, just keep processing substatements and fail later.
4832 SubStmtInvalid = true;
4833 continue;
4834 }
Mike Stump11289f42009-09-09 15:08:12 +00004835
Douglas Gregorebe10102009-08-20 07:17:43 +00004836 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4837 Statements.push_back(Result.takeAs<Stmt>());
4838 }
Mike Stump11289f42009-09-09 15:08:12 +00004839
John McCall1ababa62010-08-27 19:56:05 +00004840 if (SubStmtInvalid)
4841 return StmtError();
4842
Douglas Gregorebe10102009-08-20 07:17:43 +00004843 if (!getDerived().AlwaysRebuild() &&
4844 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004845 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004846
4847 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4848 move_arg(Statements),
4849 S->getRBracLoc(),
4850 IsStmtExpr);
4851}
Mike Stump11289f42009-09-09 15:08:12 +00004852
Douglas Gregorebe10102009-08-20 07:17:43 +00004853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004854StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004855TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004856 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004857 {
4858 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004859 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004860
Eli Friedman06577382009-11-19 03:14:00 +00004861 // Transform the left-hand case value.
4862 LHS = getDerived().TransformExpr(S->getLHS());
4863 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004864 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004865
Eli Friedman06577382009-11-19 03:14:00 +00004866 // Transform the right-hand case value (for the GNU case-range extension).
4867 RHS = getDerived().TransformExpr(S->getRHS());
4868 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004869 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004870 }
Mike Stump11289f42009-09-09 15:08:12 +00004871
Douglas Gregorebe10102009-08-20 07:17:43 +00004872 // Build the case statement.
4873 // Case statements are always rebuilt so that they will attached to their
4874 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004875 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004876 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004877 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004878 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004879 S->getColonLoc());
4880 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004881 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004882
Douglas Gregorebe10102009-08-20 07:17:43 +00004883 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004884 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004885 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004886 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004887
Douglas Gregorebe10102009-08-20 07:17:43 +00004888 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004889 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004890}
4891
4892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004893StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004894TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004895 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004896 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004897 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004898 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004899
Douglas Gregorebe10102009-08-20 07:17:43 +00004900 // Default statements are always rebuilt
4901 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004902 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004903}
Mike Stump11289f42009-09-09 15:08:12 +00004904
Douglas Gregorebe10102009-08-20 07:17:43 +00004905template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004906StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004907TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004908 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004909 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004910 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004911
Chris Lattnercab02a62011-02-17 20:34:02 +00004912 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4913 S->getDecl());
4914 if (!LD)
4915 return StmtError();
4916
4917
Douglas Gregorebe10102009-08-20 07:17:43 +00004918 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004919 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004920 cast<LabelDecl>(LD), SourceLocation(),
4921 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004922}
Mike Stump11289f42009-09-09 15:08:12 +00004923
Douglas Gregorebe10102009-08-20 07:17:43 +00004924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004925StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004926TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004927 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004928 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004929 VarDecl *ConditionVar = 0;
4930 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004931 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004932 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004933 getDerived().TransformDefinition(
4934 S->getConditionVariable()->getLocation(),
4935 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004936 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004937 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004938 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004939 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004940
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004941 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004942 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004943
4944 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004945 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004946 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4947 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004948 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004949 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004950
John McCallb268a282010-08-23 23:25:46 +00004951 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004952 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004953 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004954
John McCallb268a282010-08-23 23:25:46 +00004955 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4956 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004957 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004958
Douglas Gregorebe10102009-08-20 07:17:43 +00004959 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004960 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004961 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004962 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004963
Douglas Gregorebe10102009-08-20 07:17:43 +00004964 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004965 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004966 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004967 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004968
Douglas Gregorebe10102009-08-20 07:17:43 +00004969 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004970 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004971 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004972 Then.get() == S->getThen() &&
4973 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004974 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004975
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004976 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004977 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004978 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004979}
4980
4981template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004982StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004983TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004984 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004985 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004986 VarDecl *ConditionVar = 0;
4987 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004988 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004989 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004990 getDerived().TransformDefinition(
4991 S->getConditionVariable()->getLocation(),
4992 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004993 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004994 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004995 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004996 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004997
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004998 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004999 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005000 }
Mike Stump11289f42009-09-09 15:08:12 +00005001
Douglas Gregorebe10102009-08-20 07:17:43 +00005002 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005003 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005004 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005005 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005006 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005007 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005008
Douglas Gregorebe10102009-08-20 07:17:43 +00005009 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005010 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005011 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005012 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregorebe10102009-08-20 07:17:43 +00005014 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005015 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5016 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005017}
Mike Stump11289f42009-09-09 15:08:12 +00005018
Douglas Gregorebe10102009-08-20 07:17:43 +00005019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005020StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005021TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005022 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005023 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005024 VarDecl *ConditionVar = 0;
5025 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005026 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005027 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005028 getDerived().TransformDefinition(
5029 S->getConditionVariable()->getLocation(),
5030 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005031 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005032 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005033 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005034 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005035
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005036 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005037 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005038
5039 if (S->getCond()) {
5040 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005041 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5042 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005043 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005044 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005045 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005046 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005047 }
Mike Stump11289f42009-09-09 15:08:12 +00005048
John McCallb268a282010-08-23 23:25:46 +00005049 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5050 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005051 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005052
Douglas Gregorebe10102009-08-20 07:17:43 +00005053 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005054 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005055 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005056 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005057
Douglas Gregorebe10102009-08-20 07:17:43 +00005058 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005059 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005060 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005061 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005062 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005063
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005064 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005065 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005066}
Mike Stump11289f42009-09-09 15:08:12 +00005067
Douglas Gregorebe10102009-08-20 07:17:43 +00005068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005069StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005070TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005071 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005072 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005073 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005074 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005075
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005076 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005077 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005078 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005079 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005080
Douglas Gregorebe10102009-08-20 07:17:43 +00005081 if (!getDerived().AlwaysRebuild() &&
5082 Cond.get() == S->getCond() &&
5083 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005084 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005085
John McCallb268a282010-08-23 23:25:46 +00005086 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5087 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005088 S->getRParenLoc());
5089}
Mike Stump11289f42009-09-09 15:08:12 +00005090
Douglas Gregorebe10102009-08-20 07:17:43 +00005091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005092StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005093TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005094 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005095 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005096 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005097 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005098
Douglas Gregorebe10102009-08-20 07:17:43 +00005099 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005100 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005101 VarDecl *ConditionVar = 0;
5102 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005103 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005104 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005105 getDerived().TransformDefinition(
5106 S->getConditionVariable()->getLocation(),
5107 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005108 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005109 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005110 } else {
5111 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005112
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005113 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005114 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005115
5116 if (S->getCond()) {
5117 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005118 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5119 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005120 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005121 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005122
John McCallb268a282010-08-23 23:25:46 +00005123 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005124 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005125 }
Mike Stump11289f42009-09-09 15:08:12 +00005126
John McCallb268a282010-08-23 23:25:46 +00005127 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5128 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005129 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005130
Douglas Gregorebe10102009-08-20 07:17:43 +00005131 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005132 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005133 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005134 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005135
John McCallb268a282010-08-23 23:25:46 +00005136 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5137 if (S->getInc() && !FullInc.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() &&
5146 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005147 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005148 Inc.get() == S->getInc() &&
5149 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005150 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005151
Douglas Gregorebe10102009-08-20 07:17:43 +00005152 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005153 Init.get(), FullCond, ConditionVar,
5154 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005155}
5156
5157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005158StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005159TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005160 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5161 S->getLabel());
5162 if (!LD)
5163 return StmtError();
5164
Douglas Gregorebe10102009-08-20 07:17:43 +00005165 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005166 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005167 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005168}
5169
5170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005171StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005172TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005173 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005174 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005175 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005176
Douglas Gregorebe10102009-08-20 07:17:43 +00005177 if (!getDerived().AlwaysRebuild() &&
5178 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005179 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005180
5181 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005182 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005183}
5184
5185template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005186StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005187TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005188 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005189}
Mike Stump11289f42009-09-09 15:08:12 +00005190
Douglas Gregorebe10102009-08-20 07:17:43 +00005191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005192StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005193TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005194 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005195}
Mike Stump11289f42009-09-09 15:08:12 +00005196
Douglas Gregorebe10102009-08-20 07:17:43 +00005197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005198StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005199TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005200 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005201 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005202 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005203
Mike Stump11289f42009-09-09 15:08:12 +00005204 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005205 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005206 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005207}
Mike Stump11289f42009-09-09 15:08:12 +00005208
Douglas Gregorebe10102009-08-20 07:17:43 +00005209template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005210StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005211TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005212 bool DeclChanged = false;
5213 llvm::SmallVector<Decl *, 4> Decls;
5214 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5215 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005216 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5217 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005218 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005219 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregorebe10102009-08-20 07:17:43 +00005221 if (Transformed != *D)
5222 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005223
Douglas Gregorebe10102009-08-20 07:17:43 +00005224 Decls.push_back(Transformed);
5225 }
Mike Stump11289f42009-09-09 15:08:12 +00005226
Douglas Gregorebe10102009-08-20 07:17:43 +00005227 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005228 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005229
5230 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005231 S->getStartLoc(), S->getEndLoc());
5232}
Mike Stump11289f42009-09-09 15:08:12 +00005233
Douglas Gregorebe10102009-08-20 07:17:43 +00005234template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005235StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005236TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005237
John McCall37ad5512010-08-23 06:44:23 +00005238 ASTOwningVector<Expr*> Constraints(getSema());
5239 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005240 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005241
John McCalldadc5752010-08-24 06:29:42 +00005242 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005243 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005244
5245 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005246
Anders Carlssonaaeef072010-01-24 05:50:09 +00005247 // Go through the outputs.
5248 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005249 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005250
Anders Carlssonaaeef072010-01-24 05:50:09 +00005251 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005252 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005253
Anders Carlssonaaeef072010-01-24 05:50:09 +00005254 // Transform the output expr.
5255 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005256 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005257 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005258 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005259
Anders Carlssonaaeef072010-01-24 05:50:09 +00005260 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005261
John McCallb268a282010-08-23 23:25:46 +00005262 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005263 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005264
Anders Carlssonaaeef072010-01-24 05:50:09 +00005265 // Go through the inputs.
5266 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005267 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005268
Anders Carlssonaaeef072010-01-24 05:50:09 +00005269 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005270 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005271
Anders Carlssonaaeef072010-01-24 05:50:09 +00005272 // Transform the input expr.
5273 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005274 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005275 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005276 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005277
Anders Carlssonaaeef072010-01-24 05:50:09 +00005278 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005279
John McCallb268a282010-08-23 23:25:46 +00005280 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005281 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005282
Anders Carlssonaaeef072010-01-24 05:50:09 +00005283 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005284 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005285
5286 // Go through the clobbers.
5287 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005288 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005289
5290 // No need to transform the asm string literal.
5291 AsmString = SemaRef.Owned(S->getAsmString());
5292
5293 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5294 S->isSimple(),
5295 S->isVolatile(),
5296 S->getNumOutputs(),
5297 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005298 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005299 move_arg(Constraints),
5300 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005301 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005302 move_arg(Clobbers),
5303 S->getRParenLoc(),
5304 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005305}
5306
5307
5308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005309StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005310TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005311 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005312 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005313 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005314 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005315
Douglas Gregor96c79492010-04-23 22:50:49 +00005316 // Transform the @catch statements (if present).
5317 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005318 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005319 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005320 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005321 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005322 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005323 if (Catch.get() != S->getCatchStmt(I))
5324 AnyCatchChanged = true;
5325 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005326 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005327
Douglas Gregor306de2f2010-04-22 23:59:56 +00005328 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005329 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005330 if (S->getFinallyStmt()) {
5331 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5332 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005333 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005334 }
5335
5336 // If nothing changed, just retain this statement.
5337 if (!getDerived().AlwaysRebuild() &&
5338 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005339 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005340 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005341 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005342
Douglas Gregor306de2f2010-04-22 23:59:56 +00005343 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005344 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5345 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005346}
Mike Stump11289f42009-09-09 15:08:12 +00005347
Douglas Gregorebe10102009-08-20 07:17:43 +00005348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005349StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005350TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005351 // Transform the @catch parameter, if there is one.
5352 VarDecl *Var = 0;
5353 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5354 TypeSourceInfo *TSInfo = 0;
5355 if (FromVar->getTypeSourceInfo()) {
5356 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5357 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005358 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005359 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005360
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005361 QualType T;
5362 if (TSInfo)
5363 T = TSInfo->getType();
5364 else {
5365 T = getDerived().TransformType(FromVar->getType());
5366 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005367 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005368 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005369
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005370 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5371 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005372 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005373 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005374
John McCalldadc5752010-08-24 06:29:42 +00005375 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005376 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005377 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005378
5379 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005380 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005381 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005382}
Mike Stump11289f42009-09-09 15:08:12 +00005383
Douglas Gregorebe10102009-08-20 07:17:43 +00005384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005385StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005386TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005387 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005388 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005389 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005390 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005391
Douglas Gregor306de2f2010-04-22 23:59:56 +00005392 // If nothing changed, just retain this statement.
5393 if (!getDerived().AlwaysRebuild() &&
5394 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005395 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005396
5397 // Build a new statement.
5398 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005399 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005400}
Mike Stump11289f42009-09-09 15:08:12 +00005401
Douglas Gregorebe10102009-08-20 07:17:43 +00005402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005403StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005404TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005405 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005406 if (S->getThrowExpr()) {
5407 Operand = getDerived().TransformExpr(S->getThrowExpr());
5408 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005409 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005410 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005411
Douglas Gregor2900c162010-04-22 21:44:01 +00005412 if (!getDerived().AlwaysRebuild() &&
5413 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005414 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005415
John McCallb268a282010-08-23 23:25:46 +00005416 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005417}
Mike Stump11289f42009-09-09 15:08:12 +00005418
Douglas Gregorebe10102009-08-20 07:17:43 +00005419template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005420StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005421TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005422 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005423 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005424 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005425 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005426 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005427
Douglas Gregor6148de72010-04-22 22:01:21 +00005428 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005429 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005430 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005431 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005432
Douglas Gregor6148de72010-04-22 22:01:21 +00005433 // If nothing change, just retain the current statement.
5434 if (!getDerived().AlwaysRebuild() &&
5435 Object.get() == S->getSynchExpr() &&
5436 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005437 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005438
5439 // Build a new statement.
5440 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005441 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005442}
5443
5444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005445StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005446TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005447 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005448 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005449 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005450 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005451 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005452
Douglas Gregorf68a5082010-04-22 23:10:45 +00005453 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005454 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005455 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005456 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005457
Douglas Gregorf68a5082010-04-22 23:10:45 +00005458 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005459 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005460 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005461 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005462
Douglas Gregorf68a5082010-04-22 23:10:45 +00005463 // If nothing changed, just retain this statement.
5464 if (!getDerived().AlwaysRebuild() &&
5465 Element.get() == S->getElement() &&
5466 Collection.get() == S->getCollection() &&
5467 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005468 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005469
Douglas Gregorf68a5082010-04-22 23:10:45 +00005470 // Build a new statement.
5471 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5472 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005473 Element.get(),
5474 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005475 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005476 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005477}
5478
5479
5480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005481StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005482TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5483 // Transform the exception declaration, if any.
5484 VarDecl *Var = 0;
5485 if (S->getExceptionDecl()) {
5486 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005487 TypeSourceInfo *T = getDerived().TransformType(
5488 ExceptionDecl->getTypeSourceInfo());
5489 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005490 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005491
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005492 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005493 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005494 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005495 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005496 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005497 }
Mike Stump11289f42009-09-09 15:08:12 +00005498
Douglas Gregorebe10102009-08-20 07:17:43 +00005499 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005500 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005501 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005502 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005503
Douglas Gregorebe10102009-08-20 07:17:43 +00005504 if (!getDerived().AlwaysRebuild() &&
5505 !Var &&
5506 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005507 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005508
5509 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5510 Var,
John McCallb268a282010-08-23 23:25:46 +00005511 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005512}
Mike Stump11289f42009-09-09 15:08:12 +00005513
Douglas Gregorebe10102009-08-20 07:17:43 +00005514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005515StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005516TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5517 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005518 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005519 = getDerived().TransformCompoundStmt(S->getTryBlock());
5520 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005521 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005522
Douglas Gregorebe10102009-08-20 07:17:43 +00005523 // Transform the handlers.
5524 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005525 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005526 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005527 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005528 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5529 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005530 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005531
Douglas Gregorebe10102009-08-20 07:17:43 +00005532 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5533 Handlers.push_back(Handler.takeAs<Stmt>());
5534 }
Mike Stump11289f42009-09-09 15:08:12 +00005535
Douglas Gregorebe10102009-08-20 07:17:43 +00005536 if (!getDerived().AlwaysRebuild() &&
5537 TryBlock.get() == S->getTryBlock() &&
5538 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005539 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005540
John McCallb268a282010-08-23 23:25:46 +00005541 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005542 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005543}
Mike Stump11289f42009-09-09 15:08:12 +00005544
Douglas Gregorebe10102009-08-20 07:17:43 +00005545//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005546// Expression transformation
5547//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005549ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005550TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005551 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005552}
Mike Stump11289f42009-09-09 15:08:12 +00005553
5554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005555ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005556TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005557 NestedNameSpecifierLoc QualifierLoc;
5558 if (E->getQualifierLoc()) {
5559 QualifierLoc
5560 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5561 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005562 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005563 }
John McCallce546572009-12-08 09:08:17 +00005564
5565 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005566 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5567 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005568 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005569 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005570
John McCall815039a2010-08-17 21:27:17 +00005571 DeclarationNameInfo NameInfo = E->getNameInfo();
5572 if (NameInfo.getName()) {
5573 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5574 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005575 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005576 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005577
5578 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005579 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005580 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005581 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005582 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005583
5584 // Mark it referenced in the new context regardless.
5585 // FIXME: this is a bit instantiation-specific.
5586 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5587
John McCallc3007a22010-10-26 07:05:15 +00005588 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005589 }
John McCallce546572009-12-08 09:08:17 +00005590
5591 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005592 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005593 TemplateArgs = &TransArgs;
5594 TransArgs.setLAngleLoc(E->getLAngleLoc());
5595 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005596 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5597 E->getNumTemplateArgs(),
5598 TransArgs))
5599 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005600 }
5601
Douglas Gregorea972d32011-02-28 21:54:11 +00005602 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5603 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005604}
Mike Stump11289f42009-09-09 15:08:12 +00005605
Douglas Gregora16548e2009-08-11 05:31:07 +00005606template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005607ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005608TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005609 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005610}
Mike Stump11289f42009-09-09 15:08:12 +00005611
Douglas Gregora16548e2009-08-11 05:31:07 +00005612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005613ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005614TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005615 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005616}
Mike Stump11289f42009-09-09 15:08:12 +00005617
Douglas Gregora16548e2009-08-11 05:31:07 +00005618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005619ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005620TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005621 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005622}
Mike Stump11289f42009-09-09 15:08:12 +00005623
Douglas Gregora16548e2009-08-11 05:31:07 +00005624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005625ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005626TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005627 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005628}
Mike Stump11289f42009-09-09 15:08:12 +00005629
Douglas Gregora16548e2009-08-11 05:31:07 +00005630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005631ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005632TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005633 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005634}
5635
5636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005637ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005638TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005639 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005640 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005641 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005642
Douglas Gregora16548e2009-08-11 05:31:07 +00005643 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005644 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005645
John McCallb268a282010-08-23 23:25:46 +00005646 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005647 E->getRParen());
5648}
5649
Mike Stump11289f42009-09-09 15:08:12 +00005650template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005651ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005652TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005653 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005654 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005658 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005659
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5661 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005662 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005663}
Mike Stump11289f42009-09-09 15:08:12 +00005664
Douglas Gregora16548e2009-08-11 05:31:07 +00005665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005666ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005667TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5668 // Transform the type.
5669 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5670 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005671 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005672
Douglas Gregor882211c2010-04-28 22:16:22 +00005673 // Transform all of the components into components similar to what the
5674 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005675 // FIXME: It would be slightly more efficient in the non-dependent case to
5676 // just map FieldDecls, rather than requiring the rebuilder to look for
5677 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005678 // template code that we don't care.
5679 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005680 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005681 typedef OffsetOfExpr::OffsetOfNode Node;
5682 llvm::SmallVector<Component, 4> Components;
5683 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5684 const Node &ON = E->getComponent(I);
5685 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005686 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005687 Comp.LocStart = ON.getRange().getBegin();
5688 Comp.LocEnd = ON.getRange().getEnd();
5689 switch (ON.getKind()) {
5690 case Node::Array: {
5691 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005692 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005693 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005694 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005695
Douglas Gregor882211c2010-04-28 22:16:22 +00005696 ExprChanged = ExprChanged || Index.get() != FromIndex;
5697 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005698 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005699 break;
5700 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005701
Douglas Gregor882211c2010-04-28 22:16:22 +00005702 case Node::Field:
5703 case Node::Identifier:
5704 Comp.isBrackets = false;
5705 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005706 if (!Comp.U.IdentInfo)
5707 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005708
Douglas Gregor882211c2010-04-28 22:16:22 +00005709 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005710
Douglas Gregord1702062010-04-29 00:18:15 +00005711 case Node::Base:
5712 // Will be recomputed during the rebuild.
5713 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005714 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005715
Douglas Gregor882211c2010-04-28 22:16:22 +00005716 Components.push_back(Comp);
5717 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005718
Douglas Gregor882211c2010-04-28 22:16:22 +00005719 // If nothing changed, retain the existing expression.
5720 if (!getDerived().AlwaysRebuild() &&
5721 Type == E->getTypeSourceInfo() &&
5722 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005723 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005724
Douglas Gregor882211c2010-04-28 22:16:22 +00005725 // Build a new offsetof expression.
5726 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5727 Components.data(), Components.size(),
5728 E->getRParenLoc());
5729}
5730
5731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005732ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005733TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5734 assert(getDerived().AlreadyTransformed(E->getType()) &&
5735 "opaque value expression requires transformation");
5736 return SemaRef.Owned(E);
5737}
5738
5739template<typename Derived>
5740ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005741TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005742 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005743 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005744
John McCallbcd03502009-12-07 02:54:59 +00005745 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005746 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005748
John McCall4c98fd82009-11-04 07:28:41 +00005749 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005750 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005751
John McCall4c98fd82009-11-04 07:28:41 +00005752 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005753 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005754 E->getSourceRange());
5755 }
Mike Stump11289f42009-09-09 15:08:12 +00005756
John McCalldadc5752010-08-24 06:29:42 +00005757 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005758 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005759 // C++0x [expr.sizeof]p1:
5760 // The operand is either an expression, which is an unevaluated operand
5761 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005762 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005763
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5765 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005766 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005767
Douglas Gregora16548e2009-08-11 05:31:07 +00005768 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005769 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005770 }
Mike Stump11289f42009-09-09 15:08:12 +00005771
John McCallb268a282010-08-23 23:25:46 +00005772 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 E->isSizeOf(),
5774 E->getSourceRange());
5775}
Mike Stump11289f42009-09-09 15:08:12 +00005776
Douglas Gregora16548e2009-08-11 05:31:07 +00005777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005778ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005779TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005780 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005781 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005782 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005783
John McCalldadc5752010-08-24 06:29:42 +00005784 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005785 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005786 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005787
5788
Douglas Gregora16548e2009-08-11 05:31:07 +00005789 if (!getDerived().AlwaysRebuild() &&
5790 LHS.get() == E->getLHS() &&
5791 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005792 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005793
John McCallb268a282010-08-23 23:25:46 +00005794 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005795 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005796 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005797 E->getRBracketLoc());
5798}
Mike Stump11289f42009-09-09 15:08:12 +00005799
5800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005801ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005802TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005803 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005804 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005805 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005806 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005807
5808 // Transform arguments.
5809 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005810 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005811 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5812 &ArgChanged))
5813 return ExprError();
5814
Douglas Gregora16548e2009-08-11 05:31:07 +00005815 if (!getDerived().AlwaysRebuild() &&
5816 Callee.get() == E->getCallee() &&
5817 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005818 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005819
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005821 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005822 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005823 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005824 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005825 E->getRParenLoc());
5826}
Mike Stump11289f42009-09-09 15:08:12 +00005827
5828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005829ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005830TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005831 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005832 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005833 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005834
Douglas Gregorea972d32011-02-28 21:54:11 +00005835 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005836 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005837 QualifierLoc
5838 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5839
5840 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005841 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005842 }
Mike Stump11289f42009-09-09 15:08:12 +00005843
Eli Friedman2cfcef62009-12-04 06:40:45 +00005844 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005845 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5846 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005847 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005849
John McCall16df1e52010-03-30 21:47:33 +00005850 NamedDecl *FoundDecl = E->getFoundDecl();
5851 if (FoundDecl == E->getMemberDecl()) {
5852 FoundDecl = Member;
5853 } else {
5854 FoundDecl = cast_or_null<NamedDecl>(
5855 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5856 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005857 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005858 }
5859
Douglas Gregora16548e2009-08-11 05:31:07 +00005860 if (!getDerived().AlwaysRebuild() &&
5861 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005862 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005863 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005864 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005865 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005866
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005867 // Mark it referenced in the new context regardless.
5868 // FIXME: this is a bit instantiation-specific.
5869 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005870 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005871 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005872
John McCall6b51f282009-11-23 01:53:49 +00005873 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005874 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005875 TransArgs.setLAngleLoc(E->getLAngleLoc());
5876 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005877 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5878 E->getNumTemplateArgs(),
5879 TransArgs))
5880 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005881 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005882
Douglas Gregora16548e2009-08-11 05:31:07 +00005883 // FIXME: Bogus source location for the operator
5884 SourceLocation FakeOperatorLoc
5885 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5886
John McCall38836f02010-01-15 08:34:02 +00005887 // FIXME: to do this check properly, we will need to preserve the
5888 // first-qualifier-in-scope here, just in case we had a dependent
5889 // base (and therefore couldn't do the check) and a
5890 // nested-name-qualifier (and therefore could do the lookup).
5891 NamedDecl *FirstQualifierInScope = 0;
5892
John McCallb268a282010-08-23 23:25:46 +00005893 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005894 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005895 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005896 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005897 Member,
John McCall16df1e52010-03-30 21:47:33 +00005898 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005899 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005900 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005901 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005902}
Mike Stump11289f42009-09-09 15:08:12 +00005903
Douglas Gregora16548e2009-08-11 05:31:07 +00005904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005906TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005907 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005908 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005909 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005910
John McCalldadc5752010-08-24 06:29:42 +00005911 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005912 if (RHS.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() &&
5916 LHS.get() == E->getLHS() &&
5917 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005918 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005919
Douglas Gregora16548e2009-08-11 05:31:07 +00005920 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005921 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005922}
5923
Mike Stump11289f42009-09-09 15:08:12 +00005924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005925ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005926TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005927 CompoundAssignOperator *E) {
5928 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005929}
Mike Stump11289f42009-09-09 15:08:12 +00005930
Douglas Gregora16548e2009-08-11 05:31:07 +00005931template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005932ExprResult TreeTransform<Derived>::
5933TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5934 // Just rebuild the common and RHS expressions and see whether we
5935 // get any changes.
5936
5937 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5938 if (commonExpr.isInvalid())
5939 return ExprError();
5940
5941 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5942 if (rhs.isInvalid())
5943 return ExprError();
5944
5945 if (!getDerived().AlwaysRebuild() &&
5946 commonExpr.get() == e->getCommon() &&
5947 rhs.get() == e->getFalseExpr())
5948 return SemaRef.Owned(e);
5949
5950 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5951 e->getQuestionLoc(),
5952 0,
5953 e->getColonLoc(),
5954 rhs.get());
5955}
5956
5957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005958ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005959TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005960 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005961 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005962 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005963
John McCalldadc5752010-08-24 06:29:42 +00005964 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005965 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005966 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005967
John McCalldadc5752010-08-24 06:29:42 +00005968 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005969 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005971
Douglas Gregora16548e2009-08-11 05:31:07 +00005972 if (!getDerived().AlwaysRebuild() &&
5973 Cond.get() == E->getCond() &&
5974 LHS.get() == E->getLHS() &&
5975 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005976 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005977
John McCallb268a282010-08-23 23:25:46 +00005978 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005979 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005980 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005981 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005982 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005983}
Mike Stump11289f42009-09-09 15:08:12 +00005984
5985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005986ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005987TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005988 // Implicit casts are eliminated during transformation, since they
5989 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005990 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005991}
Mike Stump11289f42009-09-09 15:08:12 +00005992
Douglas Gregora16548e2009-08-11 05:31:07 +00005993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005994ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005995TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005996 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5997 if (!Type)
5998 return ExprError();
5999
John McCalldadc5752010-08-24 06:29:42 +00006000 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006001 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006002 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006003 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006004
Douglas Gregora16548e2009-08-11 05:31:07 +00006005 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006006 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006007 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006008 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006009
John McCall97513962010-01-15 18:39:57 +00006010 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006011 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006013 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006014}
Mike Stump11289f42009-09-09 15:08:12 +00006015
Douglas Gregora16548e2009-08-11 05:31:07 +00006016template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006017ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006018TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006019 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6020 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6021 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006022 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006023
John McCalldadc5752010-08-24 06:29:42 +00006024 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006025 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006026 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006027
Douglas Gregora16548e2009-08-11 05:31:07 +00006028 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006029 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006030 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006031 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006032
John McCall5d7aa7f2010-01-19 22:33:45 +00006033 // Note: the expression type doesn't necessarily match the
6034 // type-as-written, but that's okay, because it should always be
6035 // derivable from the initializer.
6036
John McCalle15bbff2010-01-18 19:35:47 +00006037 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006038 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006039 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006040}
Mike Stump11289f42009-09-09 15:08:12 +00006041
Douglas Gregora16548e2009-08-11 05:31:07 +00006042template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006043ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006044TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006045 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006046 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006047 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006048
Douglas Gregora16548e2009-08-11 05:31:07 +00006049 if (!getDerived().AlwaysRebuild() &&
6050 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006051 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006052
Douglas Gregora16548e2009-08-11 05:31:07 +00006053 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006054 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006055 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006056 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006057 E->getAccessorLoc(),
6058 E->getAccessor());
6059}
Mike Stump11289f42009-09-09 15:08:12 +00006060
Douglas Gregora16548e2009-08-11 05:31:07 +00006061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006062ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006063TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006064 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006065
John McCall37ad5512010-08-23 06:44:23 +00006066 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006067 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6068 Inits, &InitChanged))
6069 return ExprError();
6070
Douglas Gregora16548e2009-08-11 05:31:07 +00006071 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006072 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006073
Douglas Gregora16548e2009-08-11 05:31:07 +00006074 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006075 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006076}
Mike Stump11289f42009-09-09 15:08:12 +00006077
Douglas Gregora16548e2009-08-11 05:31:07 +00006078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006079ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006080TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006081 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006082
Douglas Gregorebe10102009-08-20 07:17:43 +00006083 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006084 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006085 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006086 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006087
Douglas Gregorebe10102009-08-20 07:17:43 +00006088 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006089 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006090 bool ExprChanged = false;
6091 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6092 DEnd = E->designators_end();
6093 D != DEnd; ++D) {
6094 if (D->isFieldDesignator()) {
6095 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6096 D->getDotLoc(),
6097 D->getFieldLoc()));
6098 continue;
6099 }
Mike Stump11289f42009-09-09 15:08:12 +00006100
Douglas Gregora16548e2009-08-11 05:31:07 +00006101 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006102 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006103 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006105
6106 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006107 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006108
Douglas Gregora16548e2009-08-11 05:31:07 +00006109 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6110 ArrayExprs.push_back(Index.release());
6111 continue;
6112 }
Mike Stump11289f42009-09-09 15:08:12 +00006113
Douglas Gregora16548e2009-08-11 05:31:07 +00006114 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006115 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006116 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6117 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006118 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006119
John McCalldadc5752010-08-24 06:29:42 +00006120 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006121 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006122 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006123
6124 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006125 End.get(),
6126 D->getLBracketLoc(),
6127 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006128
Douglas Gregora16548e2009-08-11 05:31:07 +00006129 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6130 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006131
Douglas Gregora16548e2009-08-11 05:31:07 +00006132 ArrayExprs.push_back(Start.release());
6133 ArrayExprs.push_back(End.release());
6134 }
Mike Stump11289f42009-09-09 15:08:12 +00006135
Douglas Gregora16548e2009-08-11 05:31:07 +00006136 if (!getDerived().AlwaysRebuild() &&
6137 Init.get() == E->getInit() &&
6138 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006139 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006140
Douglas Gregora16548e2009-08-11 05:31:07 +00006141 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6142 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006143 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006144}
Mike Stump11289f42009-09-09 15:08:12 +00006145
Douglas Gregora16548e2009-08-11 05:31:07 +00006146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006147ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006148TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006149 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006150 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006151
Douglas Gregor3da3c062009-10-28 00:29:27 +00006152 // FIXME: Will we ever have proper type location here? Will we actually
6153 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006154 QualType T = getDerived().TransformType(E->getType());
6155 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006156 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006157
Douglas Gregora16548e2009-08-11 05:31:07 +00006158 if (!getDerived().AlwaysRebuild() &&
6159 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006160 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006161
Douglas Gregora16548e2009-08-11 05:31:07 +00006162 return getDerived().RebuildImplicitValueInitExpr(T);
6163}
Mike Stump11289f42009-09-09 15:08:12 +00006164
Douglas Gregora16548e2009-08-11 05:31:07 +00006165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006167TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006168 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6169 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006170 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006171
John McCalldadc5752010-08-24 06:29:42 +00006172 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006173 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006174 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006175
Douglas Gregora16548e2009-08-11 05:31:07 +00006176 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006177 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006178 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006179 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006180
John McCallb268a282010-08-23 23:25:46 +00006181 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006182 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006183}
6184
6185template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006186ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006187TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006188 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006189 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006190 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6191 &ArgumentChanged))
6192 return ExprError();
6193
Douglas Gregora16548e2009-08-11 05:31:07 +00006194 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6195 move_arg(Inits),
6196 E->getRParenLoc());
6197}
Mike Stump11289f42009-09-09 15:08:12 +00006198
Douglas Gregora16548e2009-08-11 05:31:07 +00006199/// \brief Transform an address-of-label expression.
6200///
6201/// By default, the transformation of an address-of-label expression always
6202/// rebuilds the expression, so that the label identifier can be resolved to
6203/// the corresponding label statement by semantic analysis.
6204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006205ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006206TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006207 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6208 E->getLabel());
6209 if (!LD)
6210 return ExprError();
6211
Douglas Gregora16548e2009-08-11 05:31:07 +00006212 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006213 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006214}
Mike Stump11289f42009-09-09 15:08:12 +00006215
6216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006217ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006218TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006219 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006220 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6221 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006223
Douglas Gregora16548e2009-08-11 05:31:07 +00006224 if (!getDerived().AlwaysRebuild() &&
6225 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006226 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006227
6228 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006229 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006230 E->getRParenLoc());
6231}
Mike Stump11289f42009-09-09 15:08:12 +00006232
Douglas Gregora16548e2009-08-11 05:31:07 +00006233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006235TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006236 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006237 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006239
John McCalldadc5752010-08-24 06:29:42 +00006240 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006241 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006242 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006243
John McCalldadc5752010-08-24 06:29:42 +00006244 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006245 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006246 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006247
Douglas Gregora16548e2009-08-11 05:31:07 +00006248 if (!getDerived().AlwaysRebuild() &&
6249 Cond.get() == E->getCond() &&
6250 LHS.get() == E->getLHS() &&
6251 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006252 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006253
Douglas Gregora16548e2009-08-11 05:31:07 +00006254 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006255 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006256 E->getRParenLoc());
6257}
Mike Stump11289f42009-09-09 15:08:12 +00006258
Douglas Gregora16548e2009-08-11 05:31:07 +00006259template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006260ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006261TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006262 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006263}
6264
6265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006266ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006267TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006268 switch (E->getOperator()) {
6269 case OO_New:
6270 case OO_Delete:
6271 case OO_Array_New:
6272 case OO_Array_Delete:
6273 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006274 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006275
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006276 case OO_Call: {
6277 // This is a call to an object's operator().
6278 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6279
6280 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006281 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006282 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006283 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006284
6285 // FIXME: Poor location information
6286 SourceLocation FakeLParenLoc
6287 = SemaRef.PP.getLocForEndOfToken(
6288 static_cast<Expr *>(Object.get())->getLocEnd());
6289
6290 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006291 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006292 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6293 Args))
6294 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006295
John McCallb268a282010-08-23 23:25:46 +00006296 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006297 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006298 E->getLocEnd());
6299 }
6300
6301#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6302 case OO_##Name:
6303#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6304#include "clang/Basic/OperatorKinds.def"
6305 case OO_Subscript:
6306 // Handled below.
6307 break;
6308
6309 case OO_Conditional:
6310 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006311 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006312
6313 case OO_None:
6314 case NUM_OVERLOADED_OPERATORS:
6315 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006316 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006317 }
6318
John McCalldadc5752010-08-24 06:29:42 +00006319 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006320 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006321 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006322
John McCalldadc5752010-08-24 06:29:42 +00006323 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006324 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006325 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006326
John McCalldadc5752010-08-24 06:29:42 +00006327 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006328 if (E->getNumArgs() == 2) {
6329 Second = getDerived().TransformExpr(E->getArg(1));
6330 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006331 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006332 }
Mike Stump11289f42009-09-09 15:08:12 +00006333
Douglas Gregora16548e2009-08-11 05:31:07 +00006334 if (!getDerived().AlwaysRebuild() &&
6335 Callee.get() == E->getCallee() &&
6336 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006337 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006338 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006339
Douglas Gregora16548e2009-08-11 05:31:07 +00006340 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6341 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006342 Callee.get(),
6343 First.get(),
6344 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006345}
Mike Stump11289f42009-09-09 15:08:12 +00006346
Douglas Gregora16548e2009-08-11 05:31:07 +00006347template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006348ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006349TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6350 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006351}
Mike Stump11289f42009-09-09 15:08:12 +00006352
Douglas Gregora16548e2009-08-11 05:31:07 +00006353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006354ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006355TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6356 // Transform the callee.
6357 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6358 if (Callee.isInvalid())
6359 return ExprError();
6360
6361 // Transform exec config.
6362 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6363 if (EC.isInvalid())
6364 return ExprError();
6365
6366 // Transform arguments.
6367 bool ArgChanged = false;
6368 ASTOwningVector<Expr*> Args(SemaRef);
6369 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6370 &ArgChanged))
6371 return ExprError();
6372
6373 if (!getDerived().AlwaysRebuild() &&
6374 Callee.get() == E->getCallee() &&
6375 !ArgChanged)
6376 return SemaRef.Owned(E);
6377
6378 // FIXME: Wrong source location information for the '('.
6379 SourceLocation FakeLParenLoc
6380 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6381 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6382 move_arg(Args),
6383 E->getRParenLoc(), EC.get());
6384}
6385
6386template<typename Derived>
6387ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006388TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006389 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6390 if (!Type)
6391 return ExprError();
6392
John McCalldadc5752010-08-24 06:29:42 +00006393 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006394 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006395 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006396 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006397
Douglas Gregora16548e2009-08-11 05:31:07 +00006398 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006399 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006400 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006401 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006402
Douglas Gregora16548e2009-08-11 05:31:07 +00006403 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006404 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006405 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6406 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6407 SourceLocation FakeRParenLoc
6408 = SemaRef.PP.getLocForEndOfToken(
6409 E->getSubExpr()->getSourceRange().getEnd());
6410 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006411 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006412 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006413 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006414 FakeRAngleLoc,
6415 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006416 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006417 FakeRParenLoc);
6418}
Mike Stump11289f42009-09-09 15:08:12 +00006419
Douglas Gregora16548e2009-08-11 05:31:07 +00006420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006422TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6423 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006424}
Mike Stump11289f42009-09-09 15:08:12 +00006425
6426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006427ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006428TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6429 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006430}
6431
Douglas Gregora16548e2009-08-11 05:31:07 +00006432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006433ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006434TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006435 CXXReinterpretCastExpr *E) {
6436 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006437}
Mike Stump11289f42009-09-09 15:08:12 +00006438
Douglas Gregora16548e2009-08-11 05:31:07 +00006439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006440ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006441TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6442 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006443}
Mike Stump11289f42009-09-09 15:08:12 +00006444
Douglas Gregora16548e2009-08-11 05:31:07 +00006445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006446ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006447TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006448 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006449 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6450 if (!Type)
6451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006452
John McCalldadc5752010-08-24 06:29:42 +00006453 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006454 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006455 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006456 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006457
Douglas Gregora16548e2009-08-11 05:31:07 +00006458 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006459 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006460 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006461 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006462
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006463 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006464 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006465 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006466 E->getRParenLoc());
6467}
Mike Stump11289f42009-09-09 15:08:12 +00006468
Douglas Gregora16548e2009-08-11 05:31:07 +00006469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006471TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006472 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006473 TypeSourceInfo *TInfo
6474 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6475 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006476 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006477
Douglas Gregora16548e2009-08-11 05:31:07 +00006478 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006479 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006480 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006481
Douglas Gregor9da64192010-04-26 22:37:10 +00006482 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6483 E->getLocStart(),
6484 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006485 E->getLocEnd());
6486 }
Mike Stump11289f42009-09-09 15:08:12 +00006487
Douglas Gregora16548e2009-08-11 05:31:07 +00006488 // We don't know whether the expression is potentially evaluated until
6489 // after we perform semantic analysis, so the expression is potentially
6490 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006491 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006492 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006493
John McCalldadc5752010-08-24 06:29:42 +00006494 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006495 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006496 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006497
Douglas Gregora16548e2009-08-11 05:31:07 +00006498 if (!getDerived().AlwaysRebuild() &&
6499 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006500 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006501
Douglas Gregor9da64192010-04-26 22:37:10 +00006502 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6503 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006504 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006505 E->getLocEnd());
6506}
6507
6508template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006509ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006510TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6511 if (E->isTypeOperand()) {
6512 TypeSourceInfo *TInfo
6513 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6514 if (!TInfo)
6515 return ExprError();
6516
6517 if (!getDerived().AlwaysRebuild() &&
6518 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006519 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006520
6521 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6522 E->getLocStart(),
6523 TInfo,
6524 E->getLocEnd());
6525 }
6526
6527 // We don't know whether the expression is potentially evaluated until
6528 // after we perform semantic analysis, so the expression is potentially
6529 // potentially evaluated.
6530 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6531
6532 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6533 if (SubExpr.isInvalid())
6534 return ExprError();
6535
6536 if (!getDerived().AlwaysRebuild() &&
6537 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006538 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006539
6540 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6541 E->getLocStart(),
6542 SubExpr.get(),
6543 E->getLocEnd());
6544}
6545
6546template<typename Derived>
6547ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006548TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006549 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006550}
Mike Stump11289f42009-09-09 15:08:12 +00006551
Douglas Gregora16548e2009-08-11 05:31:07 +00006552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006553ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006554TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006555 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006556 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006557}
Mike Stump11289f42009-09-09 15:08:12 +00006558
Douglas Gregora16548e2009-08-11 05:31:07 +00006559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006561TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006562 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6563 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6564 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006565
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006566 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006567 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006568
Douglas Gregorb15af892010-01-07 23:12:05 +00006569 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006570}
Mike Stump11289f42009-09-09 15:08:12 +00006571
Douglas Gregora16548e2009-08-11 05:31:07 +00006572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006573ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006574TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006575 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006576 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006577 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006578
Douglas Gregora16548e2009-08-11 05:31:07 +00006579 if (!getDerived().AlwaysRebuild() &&
6580 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006581 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006582
John McCallb268a282010-08-23 23:25:46 +00006583 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006584}
Mike Stump11289f42009-09-09 15:08:12 +00006585
Douglas Gregora16548e2009-08-11 05:31:07 +00006586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006587ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006588TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006589 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006590 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6591 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006592 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006593 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006594
Chandler Carruth794da4c2010-02-08 06:42:49 +00006595 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006596 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006597 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006598
Douglas Gregor033f6752009-12-23 23:03:06 +00006599 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006600}
Mike Stump11289f42009-09-09 15:08:12 +00006601
Douglas Gregora16548e2009-08-11 05:31:07 +00006602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006603ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006604TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6605 CXXScalarValueInitExpr *E) {
6606 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6607 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006608 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006609
Douglas Gregora16548e2009-08-11 05:31:07 +00006610 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006611 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006612 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006613
Douglas Gregor2b88c112010-09-08 00:15:04 +00006614 return getDerived().RebuildCXXScalarValueInitExpr(T,
6615 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006616 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006617}
Mike Stump11289f42009-09-09 15:08:12 +00006618
Douglas Gregora16548e2009-08-11 05:31:07 +00006619template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006620ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006621TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006622 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006623 TypeSourceInfo *AllocTypeInfo
6624 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6625 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006626 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006627
Douglas Gregora16548e2009-08-11 05:31:07 +00006628 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006629 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006630 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006631 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006632
Douglas Gregora16548e2009-08-11 05:31:07 +00006633 // Transform the placement arguments (if any).
6634 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006635 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006636 if (getDerived().TransformExprs(E->getPlacementArgs(),
6637 E->getNumPlacementArgs(), true,
6638 PlacementArgs, &ArgumentChanged))
6639 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006640
Douglas Gregorebe10102009-08-20 07:17:43 +00006641 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006642 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006643 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6644 ConstructorArgs, &ArgumentChanged))
6645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006646
Douglas Gregord2d9da02010-02-26 00:38:10 +00006647 // Transform constructor, new operator, and delete operator.
6648 CXXConstructorDecl *Constructor = 0;
6649 if (E->getConstructor()) {
6650 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006651 getDerived().TransformDecl(E->getLocStart(),
6652 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006653 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006654 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006655 }
6656
6657 FunctionDecl *OperatorNew = 0;
6658 if (E->getOperatorNew()) {
6659 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006660 getDerived().TransformDecl(E->getLocStart(),
6661 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006662 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006663 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006664 }
6665
6666 FunctionDecl *OperatorDelete = 0;
6667 if (E->getOperatorDelete()) {
6668 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006669 getDerived().TransformDecl(E->getLocStart(),
6670 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006671 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006672 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006673 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006674
Douglas Gregora16548e2009-08-11 05:31:07 +00006675 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006676 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006677 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006678 Constructor == E->getConstructor() &&
6679 OperatorNew == E->getOperatorNew() &&
6680 OperatorDelete == E->getOperatorDelete() &&
6681 !ArgumentChanged) {
6682 // Mark any declarations we need as referenced.
6683 // FIXME: instantiation-specific.
6684 if (Constructor)
6685 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6686 if (OperatorNew)
6687 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6688 if (OperatorDelete)
6689 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006690 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006691 }
Mike Stump11289f42009-09-09 15:08:12 +00006692
Douglas Gregor0744ef62010-09-07 21:49:58 +00006693 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006694 if (!ArraySize.get()) {
6695 // If no array size was specified, but the new expression was
6696 // instantiated with an array type (e.g., "new T" where T is
6697 // instantiated with "int[4]"), extract the outer bound from the
6698 // array type as our array size. We do this with constant and
6699 // dependently-sized array types.
6700 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6701 if (!ArrayT) {
6702 // Do nothing
6703 } else if (const ConstantArrayType *ConsArrayT
6704 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006705 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006706 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6707 ConsArrayT->getSize(),
6708 SemaRef.Context.getSizeType(),
6709 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006710 AllocType = ConsArrayT->getElementType();
6711 } else if (const DependentSizedArrayType *DepArrayT
6712 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6713 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006714 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006715 AllocType = DepArrayT->getElementType();
6716 }
6717 }
6718 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006719
Douglas Gregora16548e2009-08-11 05:31:07 +00006720 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6721 E->isGlobalNew(),
6722 /*FIXME:*/E->getLocStart(),
6723 move_arg(PlacementArgs),
6724 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006725 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006726 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006727 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006728 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006729 /*FIXME:*/E->getLocStart(),
6730 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006731 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006732}
Mike Stump11289f42009-09-09 15:08:12 +00006733
Douglas Gregora16548e2009-08-11 05:31:07 +00006734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006736TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006737 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006738 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006739 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006740
Douglas Gregord2d9da02010-02-26 00:38:10 +00006741 // Transform the delete operator, if known.
6742 FunctionDecl *OperatorDelete = 0;
6743 if (E->getOperatorDelete()) {
6744 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006745 getDerived().TransformDecl(E->getLocStart(),
6746 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006747 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006748 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006749 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006750
Douglas Gregora16548e2009-08-11 05:31:07 +00006751 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006752 Operand.get() == E->getArgument() &&
6753 OperatorDelete == E->getOperatorDelete()) {
6754 // Mark any declarations we need as referenced.
6755 // FIXME: instantiation-specific.
6756 if (OperatorDelete)
6757 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006758
6759 if (!E->getArgument()->isTypeDependent()) {
6760 QualType Destroyed = SemaRef.Context.getBaseElementType(
6761 E->getDestroyedType());
6762 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6763 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6764 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6765 SemaRef.LookupDestructor(Record));
6766 }
6767 }
6768
John McCallc3007a22010-10-26 07:05:15 +00006769 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006770 }
Mike Stump11289f42009-09-09 15:08:12 +00006771
Douglas Gregora16548e2009-08-11 05:31:07 +00006772 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6773 E->isGlobalDelete(),
6774 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006775 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006776}
Mike Stump11289f42009-09-09 15:08:12 +00006777
Douglas Gregora16548e2009-08-11 05:31:07 +00006778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006779ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006780TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006781 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006782 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006783 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006784 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006785
John McCallba7bf592010-08-24 05:47:05 +00006786 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006787 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006788 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006789 E->getOperatorLoc(),
6790 E->isArrow()? tok::arrow : tok::period,
6791 ObjectTypePtr,
6792 MayBePseudoDestructor);
6793 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006794 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006795
John McCallba7bf592010-08-24 05:47:05 +00006796 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006797 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6798 if (QualifierLoc) {
6799 QualifierLoc
6800 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6801 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006802 return ExprError();
6803 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006804 CXXScopeSpec SS;
6805 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006806
Douglas Gregor678f90d2010-02-25 01:56:36 +00006807 PseudoDestructorTypeStorage Destroyed;
6808 if (E->getDestroyedTypeInfo()) {
6809 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006810 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006811 ObjectType, 0,
6812 QualifierLoc.getNestedNameSpecifier());
Douglas Gregor678f90d2010-02-25 01:56:36 +00006813 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006814 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006815 Destroyed = DestroyedTypeInfo;
6816 } else if (ObjectType->isDependentType()) {
6817 // We aren't likely to be able to resolve the identifier down to a type
6818 // now anyway, so just retain the identifier.
6819 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6820 E->getDestroyedTypeLoc());
6821 } else {
6822 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006823 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006824 *E->getDestroyedTypeIdentifier(),
6825 E->getDestroyedTypeLoc(),
6826 /*Scope=*/0,
6827 SS, ObjectTypePtr,
6828 false);
6829 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006830 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006831
Douglas Gregor678f90d2010-02-25 01:56:36 +00006832 Destroyed
6833 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6834 E->getDestroyedTypeLoc());
6835 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006836
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006837 TypeSourceInfo *ScopeTypeInfo = 0;
6838 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006839 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006840 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006841 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006842 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006843
John McCallb268a282010-08-23 23:25:46 +00006844 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006845 E->getOperatorLoc(),
6846 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006847 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006848 ScopeTypeInfo,
6849 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006850 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006851 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006852}
Mike Stump11289f42009-09-09 15:08:12 +00006853
Douglas Gregorad8a3362009-09-04 17:36:40 +00006854template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006855ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006856TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006857 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006858 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6859
6860 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6861 Sema::LookupOrdinaryName);
6862
6863 // Transform all the decls.
6864 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6865 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006866 NamedDecl *InstD = static_cast<NamedDecl*>(
6867 getDerived().TransformDecl(Old->getNameLoc(),
6868 *I));
John McCall84d87672009-12-10 09:41:52 +00006869 if (!InstD) {
6870 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6871 // This can happen because of dependent hiding.
6872 if (isa<UsingShadowDecl>(*I))
6873 continue;
6874 else
John McCallfaf5fb42010-08-26 23:41:50 +00006875 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006876 }
John McCalle66edc12009-11-24 19:00:30 +00006877
6878 // Expand using declarations.
6879 if (isa<UsingDecl>(InstD)) {
6880 UsingDecl *UD = cast<UsingDecl>(InstD);
6881 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6882 E = UD->shadow_end(); I != E; ++I)
6883 R.addDecl(*I);
6884 continue;
6885 }
6886
6887 R.addDecl(InstD);
6888 }
6889
6890 // Resolve a kind, but don't do any further analysis. If it's
6891 // ambiguous, the callee needs to deal with it.
6892 R.resolveKind();
6893
6894 // Rebuild the nested-name qualifier, if present.
6895 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006896 if (Old->getQualifierLoc()) {
6897 NestedNameSpecifierLoc QualifierLoc
6898 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6899 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006900 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006901
Douglas Gregor0da1d432011-02-28 20:01:57 +00006902 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006903 }
6904
Douglas Gregor9262f472010-04-27 18:19:34 +00006905 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006906 CXXRecordDecl *NamingClass
6907 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6908 Old->getNameLoc(),
6909 Old->getNamingClass()));
6910 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006911 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006912
Douglas Gregorda7be082010-04-27 16:10:10 +00006913 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006914 }
6915
6916 // If we have no template arguments, it's a normal declaration name.
6917 if (!Old->hasExplicitTemplateArgs())
6918 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6919
6920 // If we have template arguments, rebuild them, then rebuild the
6921 // templateid expression.
6922 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006923 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6924 Old->getNumTemplateArgs(),
6925 TransArgs))
6926 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006927
6928 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6929 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006930}
Mike Stump11289f42009-09-09 15:08:12 +00006931
Douglas Gregora16548e2009-08-11 05:31:07 +00006932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006933ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006934TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006935 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6936 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006938
Douglas Gregora16548e2009-08-11 05:31:07 +00006939 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006940 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006941 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006942
Mike Stump11289f42009-09-09 15:08:12 +00006943 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006944 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006945 T,
6946 E->getLocEnd());
6947}
Mike Stump11289f42009-09-09 15:08:12 +00006948
Douglas Gregora16548e2009-08-11 05:31:07 +00006949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006950ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006951TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6952 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6953 if (!LhsT)
6954 return ExprError();
6955
6956 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6957 if (!RhsT)
6958 return ExprError();
6959
6960 if (!getDerived().AlwaysRebuild() &&
6961 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6962 return SemaRef.Owned(E);
6963
6964 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6965 E->getLocStart(),
6966 LhsT, RhsT,
6967 E->getLocEnd());
6968}
6969
6970template<typename Derived>
6971ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006972TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006973 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006974 NestedNameSpecifierLoc QualifierLoc
6975 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6976 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006977 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006978
John McCall31f82722010-11-12 08:19:04 +00006979 // TODO: If this is a conversion-function-id, verify that the
6980 // destination type name (if present) resolves the same way after
6981 // instantiation as it did in the local scope.
6982
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006983 DeclarationNameInfo NameInfo
6984 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6985 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006986 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006987
John McCalle66edc12009-11-24 19:00:30 +00006988 if (!E->hasExplicitTemplateArgs()) {
6989 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006990 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006991 // Note: it is sufficient to compare the Name component of NameInfo:
6992 // if name has not changed, DNLoc has not changed either.
6993 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006994 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006995
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006996 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006997 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006998 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006999 }
John McCall6b51f282009-11-23 01:53:49 +00007000
7001 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007002 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7003 E->getNumTemplateArgs(),
7004 TransArgs))
7005 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007006
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007007 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007008 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007009 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007010}
7011
7012template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007013ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007014TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007015 // CXXConstructExprs are always implicit, so when we have a
7016 // 1-argument construction we just transform that argument.
7017 if (E->getNumArgs() == 1 ||
7018 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7019 return getDerived().TransformExpr(E->getArg(0));
7020
Douglas Gregora16548e2009-08-11 05:31:07 +00007021 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7022
7023 QualType T = getDerived().TransformType(E->getType());
7024 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007025 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007026
7027 CXXConstructorDecl *Constructor
7028 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007029 getDerived().TransformDecl(E->getLocStart(),
7030 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007031 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007032 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007033
Douglas Gregora16548e2009-08-11 05:31:07 +00007034 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007035 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007036 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7037 &ArgumentChanged))
7038 return ExprError();
7039
Douglas Gregora16548e2009-08-11 05:31:07 +00007040 if (!getDerived().AlwaysRebuild() &&
7041 T == E->getType() &&
7042 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007043 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007044 // Mark the constructor as referenced.
7045 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007046 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007047 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007048 }
Mike Stump11289f42009-09-09 15:08:12 +00007049
Douglas Gregordb121ba2009-12-14 16:27:04 +00007050 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7051 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007052 move_arg(Args),
7053 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007054 E->getConstructionKind(),
7055 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007056}
Mike Stump11289f42009-09-09 15:08:12 +00007057
Douglas Gregora16548e2009-08-11 05:31:07 +00007058/// \brief Transform a C++ temporary-binding expression.
7059///
Douglas Gregor363b1512009-12-24 18:51:59 +00007060/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7061/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007062template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007063ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007064TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007065 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007066}
Mike Stump11289f42009-09-09 15:08:12 +00007067
John McCall5d413782010-12-06 08:20:24 +00007068/// \brief Transform a C++ expression that contains cleanups that should
7069/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007070///
John McCall5d413782010-12-06 08:20:24 +00007071/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007072/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007073template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007074ExprResult
John McCall5d413782010-12-06 08:20:24 +00007075TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007076 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007077}
Mike Stump11289f42009-09-09 15:08:12 +00007078
Douglas Gregora16548e2009-08-11 05:31:07 +00007079template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007080ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007081TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007082 CXXTemporaryObjectExpr *E) {
7083 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7084 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007085 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007086
Douglas Gregora16548e2009-08-11 05:31:07 +00007087 CXXConstructorDecl *Constructor
7088 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007089 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007090 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007091 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007092 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007093
Douglas Gregora16548e2009-08-11 05:31:07 +00007094 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007095 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007096 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007097 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7098 &ArgumentChanged))
7099 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007100
Douglas Gregora16548e2009-08-11 05:31:07 +00007101 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007102 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007103 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007104 !ArgumentChanged) {
7105 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007106 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007107 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007108 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007109
7110 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7111 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007112 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007113 E->getLocEnd());
7114}
Mike Stump11289f42009-09-09 15:08:12 +00007115
Douglas Gregora16548e2009-08-11 05:31:07 +00007116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007117ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007118TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007119 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007120 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7121 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007122 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007123
Douglas Gregora16548e2009-08-11 05:31:07 +00007124 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007125 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007126 Args.reserve(E->arg_size());
7127 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7128 &ArgumentChanged))
7129 return ExprError();
7130
Douglas Gregora16548e2009-08-11 05:31:07 +00007131 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007132 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007133 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007134 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007135
Douglas Gregora16548e2009-08-11 05:31:07 +00007136 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007137 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007138 E->getLParenLoc(),
7139 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007140 E->getRParenLoc());
7141}
Mike Stump11289f42009-09-09 15:08:12 +00007142
Douglas Gregora16548e2009-08-11 05:31:07 +00007143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007144ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007145TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007146 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007147 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007148 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007149 Expr *OldBase;
7150 QualType BaseType;
7151 QualType ObjectType;
7152 if (!E->isImplicitAccess()) {
7153 OldBase = E->getBase();
7154 Base = getDerived().TransformExpr(OldBase);
7155 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007156 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007157
John McCall2d74de92009-12-01 22:10:20 +00007158 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007159 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007160 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007161 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007162 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007163 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007164 ObjectTy,
7165 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007166 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007167 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007168
John McCallba7bf592010-08-24 05:47:05 +00007169 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007170 BaseType = ((Expr*) Base.get())->getType();
7171 } else {
7172 OldBase = 0;
7173 BaseType = getDerived().TransformType(E->getBaseType());
7174 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7175 }
Mike Stump11289f42009-09-09 15:08:12 +00007176
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007177 // Transform the first part of the nested-name-specifier that qualifies
7178 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007179 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007180 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007181 E->getFirstQualifierFoundInScope(),
7182 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007183
Douglas Gregore16af532011-02-28 18:50:33 +00007184 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007185 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007186 QualifierLoc
7187 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7188 ObjectType,
7189 FirstQualifierInScope);
7190 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007191 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007192 }
Mike Stump11289f42009-09-09 15:08:12 +00007193
John McCall31f82722010-11-12 08:19:04 +00007194 // TODO: If this is a conversion-function-id, verify that the
7195 // destination type name (if present) resolves the same way after
7196 // instantiation as it did in the local scope.
7197
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007198 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007199 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007200 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007201 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007202
John McCall2d74de92009-12-01 22:10:20 +00007203 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007204 // This is a reference to a member without an explicitly-specified
7205 // template argument list. Optimize for this common case.
7206 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007207 Base.get() == OldBase &&
7208 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007209 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007210 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007211 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007212 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007213
John McCallb268a282010-08-23 23:25:46 +00007214 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007215 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007216 E->isArrow(),
7217 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007218 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007219 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007220 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007221 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007222 }
7223
John McCall6b51f282009-11-23 01:53:49 +00007224 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007225 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7226 E->getNumTemplateArgs(),
7227 TransArgs))
7228 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007229
John McCallb268a282010-08-23 23:25:46 +00007230 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007231 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007232 E->isArrow(),
7233 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007234 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007235 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007236 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007237 &TransArgs);
7238}
7239
7240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007241ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007242TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007243 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007244 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007245 QualType BaseType;
7246 if (!Old->isImplicitAccess()) {
7247 Base = getDerived().TransformExpr(Old->getBase());
7248 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007249 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007250 BaseType = ((Expr*) Base.get())->getType();
7251 } else {
7252 BaseType = getDerived().TransformType(Old->getBaseType());
7253 }
John McCall10eae182009-11-30 22:42:35 +00007254
Douglas Gregor0da1d432011-02-28 20:01:57 +00007255 NestedNameSpecifierLoc QualifierLoc;
7256 if (Old->getQualifierLoc()) {
7257 QualifierLoc
7258 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7259 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007260 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007261 }
7262
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007263 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007264 Sema::LookupOrdinaryName);
7265
7266 // Transform all the decls.
7267 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7268 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007269 NamedDecl *InstD = static_cast<NamedDecl*>(
7270 getDerived().TransformDecl(Old->getMemberLoc(),
7271 *I));
John McCall84d87672009-12-10 09:41:52 +00007272 if (!InstD) {
7273 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7274 // This can happen because of dependent hiding.
7275 if (isa<UsingShadowDecl>(*I))
7276 continue;
7277 else
John McCallfaf5fb42010-08-26 23:41:50 +00007278 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007279 }
John McCall10eae182009-11-30 22:42:35 +00007280
7281 // Expand using declarations.
7282 if (isa<UsingDecl>(InstD)) {
7283 UsingDecl *UD = cast<UsingDecl>(InstD);
7284 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7285 E = UD->shadow_end(); I != E; ++I)
7286 R.addDecl(*I);
7287 continue;
7288 }
7289
7290 R.addDecl(InstD);
7291 }
7292
7293 R.resolveKind();
7294
Douglas Gregor9262f472010-04-27 18:19:34 +00007295 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007296 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007297 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007298 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007299 Old->getMemberLoc(),
7300 Old->getNamingClass()));
7301 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007302 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007303
Douglas Gregorda7be082010-04-27 16:10:10 +00007304 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007305 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007306
John McCall10eae182009-11-30 22:42:35 +00007307 TemplateArgumentListInfo TransArgs;
7308 if (Old->hasExplicitTemplateArgs()) {
7309 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7310 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007311 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7312 Old->getNumTemplateArgs(),
7313 TransArgs))
7314 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007315 }
John McCall38836f02010-01-15 08:34:02 +00007316
7317 // FIXME: to do this check properly, we will need to preserve the
7318 // first-qualifier-in-scope here, just in case we had a dependent
7319 // base (and therefore couldn't do the check) and a
7320 // nested-name-qualifier (and therefore could do the lookup).
7321 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007322
John McCallb268a282010-08-23 23:25:46 +00007323 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007324 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007325 Old->getOperatorLoc(),
7326 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007327 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007328 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007329 R,
7330 (Old->hasExplicitTemplateArgs()
7331 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007332}
7333
7334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007335ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007336TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7337 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7338 if (SubExpr.isInvalid())
7339 return ExprError();
7340
7341 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007342 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007343
7344 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7345}
7346
7347template<typename Derived>
7348ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007349TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007350 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7351 if (Pattern.isInvalid())
7352 return ExprError();
7353
7354 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7355 return SemaRef.Owned(E);
7356
Douglas Gregorb8840002011-01-14 21:20:45 +00007357 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7358 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007359}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007360
7361template<typename Derived>
7362ExprResult
7363TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7364 // If E is not value-dependent, then nothing will change when we transform it.
7365 // Note: This is an instantiation-centric view.
7366 if (!E->isValueDependent())
7367 return SemaRef.Owned(E);
7368
7369 // Note: None of the implementations of TryExpandParameterPacks can ever
7370 // produce a diagnostic when given only a single unexpanded parameter pack,
7371 // so
7372 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7373 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007374 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007375 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007376 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7377 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007378 ShouldExpand, RetainExpansion,
7379 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007380 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007381
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007382 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007383 return SemaRef.Owned(E);
7384
7385 // We now know the length of the parameter pack, so build a new expression
7386 // that stores that length.
7387 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7388 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007389 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007390}
7391
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007392template<typename Derived>
7393ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007394TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7395 SubstNonTypeTemplateParmPackExpr *E) {
7396 // Default behavior is to do nothing with this transformation.
7397 return SemaRef.Owned(E);
7398}
7399
7400template<typename Derived>
7401ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007402TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007403 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007404}
7405
Mike Stump11289f42009-09-09 15:08:12 +00007406template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007407ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007408TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007409 TypeSourceInfo *EncodedTypeInfo
7410 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7411 if (!EncodedTypeInfo)
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 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007415 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007416 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007417
7418 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007419 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007420 E->getRParenLoc());
7421}
Mike Stump11289f42009-09-09 15:08:12 +00007422
Douglas Gregora16548e2009-08-11 05:31:07 +00007423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007424ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007425TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007426 // Transform arguments.
7427 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007428 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007429 Args.reserve(E->getNumArgs());
7430 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7431 &ArgChanged))
7432 return ExprError();
7433
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007434 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7435 // Class message: transform the receiver type.
7436 TypeSourceInfo *ReceiverTypeInfo
7437 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7438 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007439 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007440
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007441 // If nothing changed, just retain the existing message send.
7442 if (!getDerived().AlwaysRebuild() &&
7443 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007444 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007445
7446 // Build a new class message send.
7447 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7448 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007449 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007450 E->getMethodDecl(),
7451 E->getLeftLoc(),
7452 move_arg(Args),
7453 E->getRightLoc());
7454 }
7455
7456 // Instance message: transform the receiver
7457 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7458 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007459 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007460 = getDerived().TransformExpr(E->getInstanceReceiver());
7461 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007462 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007463
7464 // If nothing changed, just retain the existing message send.
7465 if (!getDerived().AlwaysRebuild() &&
7466 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007467 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007468
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007469 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007470 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007471 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007472 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007473 E->getMethodDecl(),
7474 E->getLeftLoc(),
7475 move_arg(Args),
7476 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007477}
7478
Mike Stump11289f42009-09-09 15:08:12 +00007479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007480ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007481TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007482 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007483}
7484
Mike Stump11289f42009-09-09 15:08:12 +00007485template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007486ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007487TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007488 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007489}
7490
Mike Stump11289f42009-09-09 15:08:12 +00007491template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007492ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007493TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007494 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007495 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007496 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007497 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007498
7499 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007500
Douglas Gregord51d90d2010-04-26 20:11:03 +00007501 // If nothing changed, just retain the existing expression.
7502 if (!getDerived().AlwaysRebuild() &&
7503 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007504 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007505
John McCallb268a282010-08-23 23:25:46 +00007506 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007507 E->getLocation(),
7508 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007509}
7510
Mike Stump11289f42009-09-09 15:08:12 +00007511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007512ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007513TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007514 // 'super' and types never change. Property never changes. Just
7515 // retain the existing expression.
7516 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007517 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007518
Douglas Gregor9faee212010-04-26 20:47:02 +00007519 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007520 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007521 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007522 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007523
Douglas Gregor9faee212010-04-26 20:47:02 +00007524 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007525
Douglas Gregor9faee212010-04-26 20:47:02 +00007526 // If nothing changed, just retain the existing expression.
7527 if (!getDerived().AlwaysRebuild() &&
7528 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007529 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007530
John McCallb7bd14f2010-12-02 01:19:52 +00007531 if (E->isExplicitProperty())
7532 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7533 E->getExplicitProperty(),
7534 E->getLocation());
7535
7536 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7537 E->getType(),
7538 E->getImplicitPropertyGetter(),
7539 E->getImplicitPropertySetter(),
7540 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007541}
7542
Mike Stump11289f42009-09-09 15:08:12 +00007543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007544ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007545TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007546 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007547 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007548 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007549 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007550
Douglas Gregord51d90d2010-04-26 20:11:03 +00007551 // If nothing changed, just retain the existing expression.
7552 if (!getDerived().AlwaysRebuild() &&
7553 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007554 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007555
John McCallb268a282010-08-23 23:25:46 +00007556 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007557 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007558}
7559
Mike Stump11289f42009-09-09 15:08:12 +00007560template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007561ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007562TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007563 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007564 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007565 SubExprs.reserve(E->getNumSubExprs());
7566 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7567 SubExprs, &ArgumentChanged))
7568 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007569
Douglas Gregora16548e2009-08-11 05:31:07 +00007570 if (!getDerived().AlwaysRebuild() &&
7571 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007572 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007573
Douglas Gregora16548e2009-08-11 05:31:07 +00007574 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7575 move_arg(SubExprs),
7576 E->getRParenLoc());
7577}
7578
Mike Stump11289f42009-09-09 15:08:12 +00007579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007580ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007581TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007582 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007583
John McCall490112f2011-02-04 18:33:18 +00007584 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7585 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7586
7587 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7588 llvm::SmallVector<ParmVarDecl*, 4> params;
7589 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007590
7591 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007592 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7593 oldBlock->param_begin(),
7594 oldBlock->param_size(),
7595 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007596 return true;
John McCall490112f2011-02-04 18:33:18 +00007597
7598 const FunctionType *exprFunctionType = E->getFunctionType();
7599 QualType exprResultType = exprFunctionType->getResultType();
7600 if (!exprResultType.isNull()) {
7601 if (!exprResultType->isDependentType())
7602 blockScope->ReturnType = exprResultType;
7603 else if (exprResultType != getSema().Context.DependentTy)
7604 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007605 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007606
7607 // If the return type has not been determined yet, leave it as a dependent
7608 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007609 if (blockScope->ReturnType.isNull())
7610 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007611
7612 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007613 if (blockScope->ReturnType->isObjCObjectType()) {
7614 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007615 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007616 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007617 return ExprError();
7618 }
John McCall3882ace2011-01-05 12:14:39 +00007619
John McCall490112f2011-02-04 18:33:18 +00007620 QualType functionType = getDerived().RebuildFunctionProtoType(
7621 blockScope->ReturnType,
7622 paramTypes.data(),
7623 paramTypes.size(),
7624 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007625 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007626 exprFunctionType->getExtInfo());
7627 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007628
7629 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007630 if (!params.empty())
7631 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007632
7633 // If the return type wasn't explicitly set, it will have been marked as a
7634 // dependent type (DependentTy); clear out the return type setting so
7635 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007636 if (blockScope->ReturnType == getSema().Context.DependentTy)
7637 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007638
John McCall3882ace2011-01-05 12:14:39 +00007639 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007640 StmtResult body = getDerived().TransformStmt(E->getBody());
7641 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007642 return ExprError();
7643
John McCall490112f2011-02-04 18:33:18 +00007644#ifndef NDEBUG
7645 // In builds with assertions, make sure that we captured everything we
7646 // captured before.
7647
7648 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7649
7650 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7651 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007652 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007653
7654 // Ignore parameter packs.
7655 if (isa<ParmVarDecl>(oldCapture) &&
7656 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7657 continue;
7658
7659 VarDecl *newCapture =
7660 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7661 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007662 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007663 }
7664#endif
7665
7666 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7667 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007668}
7669
Mike Stump11289f42009-09-09 15:08:12 +00007670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007671ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007672TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007673 ValueDecl *ND
7674 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7675 E->getDecl()));
7676 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007677 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007678
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007679 if (!getDerived().AlwaysRebuild() &&
7680 ND == E->getDecl()) {
7681 // Mark it referenced in the new context regardless.
7682 // FIXME: this is a bit instantiation-specific.
7683 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7684
John McCallc3007a22010-10-26 07:05:15 +00007685 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007686 }
7687
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007688 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007689 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007690 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007691}
Mike Stump11289f42009-09-09 15:08:12 +00007692
Douglas Gregora16548e2009-08-11 05:31:07 +00007693//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007694// Type reconstruction
7695//===----------------------------------------------------------------------===//
7696
Mike Stump11289f42009-09-09 15:08:12 +00007697template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007698QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7699 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007700 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007701 getDerived().getBaseEntity());
7702}
7703
Mike Stump11289f42009-09-09 15:08:12 +00007704template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007705QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7706 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007707 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007708 getDerived().getBaseEntity());
7709}
7710
Mike Stump11289f42009-09-09 15:08:12 +00007711template<typename Derived>
7712QualType
John McCall70dd5f62009-10-30 00:06:24 +00007713TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7714 bool WrittenAsLValue,
7715 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007716 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007717 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007718}
7719
7720template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007721QualType
John McCall70dd5f62009-10-30 00:06:24 +00007722TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7723 QualType ClassType,
7724 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007725 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007726 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007727}
7728
7729template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007730QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007731TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7732 ArrayType::ArraySizeModifier SizeMod,
7733 const llvm::APInt *Size,
7734 Expr *SizeExpr,
7735 unsigned IndexTypeQuals,
7736 SourceRange BracketsRange) {
7737 if (SizeExpr || !Size)
7738 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7739 IndexTypeQuals, BracketsRange,
7740 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007741
7742 QualType Types[] = {
7743 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7744 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7745 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007746 };
7747 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7748 QualType SizeType;
7749 for (unsigned I = 0; I != NumTypes; ++I)
7750 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7751 SizeType = Types[I];
7752 break;
7753 }
Mike Stump11289f42009-09-09 15:08:12 +00007754
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007755 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7756 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007757 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007758 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007759 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007760}
Mike Stump11289f42009-09-09 15:08:12 +00007761
Douglas Gregord6ff3322009-08-04 16:50:30 +00007762template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007763QualType
7764TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007765 ArrayType::ArraySizeModifier SizeMod,
7766 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007767 unsigned IndexTypeQuals,
7768 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007769 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007770 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007771}
7772
7773template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007774QualType
Mike Stump11289f42009-09-09 15:08:12 +00007775TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007776 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007777 unsigned IndexTypeQuals,
7778 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007779 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007780 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007781}
Mike Stump11289f42009-09-09 15:08:12 +00007782
Douglas Gregord6ff3322009-08-04 16:50:30 +00007783template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007784QualType
7785TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007786 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007787 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007788 unsigned IndexTypeQuals,
7789 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007790 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007791 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007792 IndexTypeQuals, BracketsRange);
7793}
7794
7795template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007796QualType
7797TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007798 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007799 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007800 unsigned IndexTypeQuals,
7801 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007802 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007803 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007804 IndexTypeQuals, BracketsRange);
7805}
7806
7807template<typename Derived>
7808QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007809 unsigned NumElements,
7810 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007811 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007812 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007813}
Mike Stump11289f42009-09-09 15:08:12 +00007814
Douglas Gregord6ff3322009-08-04 16:50:30 +00007815template<typename Derived>
7816QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7817 unsigned NumElements,
7818 SourceLocation AttributeLoc) {
7819 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7820 NumElements, true);
7821 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007822 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7823 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007824 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007825}
Mike Stump11289f42009-09-09 15:08:12 +00007826
Douglas Gregord6ff3322009-08-04 16:50:30 +00007827template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007828QualType
7829TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007830 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007831 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007832 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007833}
Mike Stump11289f42009-09-09 15:08:12 +00007834
Douglas Gregord6ff3322009-08-04 16:50:30 +00007835template<typename Derived>
7836QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007837 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007838 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007839 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007840 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007841 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007842 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007843 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007844 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007845 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007846 getDerived().getBaseEntity(),
7847 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007848}
Mike Stump11289f42009-09-09 15:08:12 +00007849
Douglas Gregord6ff3322009-08-04 16:50:30 +00007850template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007851QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7852 return SemaRef.Context.getFunctionNoProtoType(T);
7853}
7854
7855template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007856QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7857 assert(D && "no decl found");
7858 if (D->isInvalidDecl()) return QualType();
7859
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007860 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007861 TypeDecl *Ty;
7862 if (isa<UsingDecl>(D)) {
7863 UsingDecl *Using = cast<UsingDecl>(D);
7864 assert(Using->isTypeName() &&
7865 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7866
7867 // A valid resolved using typename decl points to exactly one type decl.
7868 assert(++Using->shadow_begin() == Using->shadow_end());
7869 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007870
John McCallb96ec562009-12-04 22:46:56 +00007871 } else {
7872 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7873 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7874 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7875 }
7876
7877 return SemaRef.Context.getTypeDeclType(Ty);
7878}
7879
7880template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007881QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7882 SourceLocation Loc) {
7883 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007884}
7885
7886template<typename Derived>
7887QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7888 return SemaRef.Context.getTypeOfType(Underlying);
7889}
7890
7891template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007892QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7893 SourceLocation Loc) {
7894 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007895}
7896
7897template<typename Derived>
7898QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007899 TemplateName Template,
7900 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007901 const TemplateArgumentListInfo &TemplateArgs) {
7902 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007903}
Mike Stump11289f42009-09-09 15:08:12 +00007904
Douglas Gregor1135c352009-08-06 05:28:30 +00007905template<typename Derived>
7906NestedNameSpecifier *
7907TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7908 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007909 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007910 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007911 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007912 CXXScopeSpec SS;
7913 // FIXME: The source location information is all wrong.
Douglas Gregor869ad452011-02-24 17:54:50 +00007914 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
Douglas Gregor90c99722011-02-24 00:17:56 +00007915 if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(),
7916 /*FIXME:*/Range.getEnd(),
7917 ObjectType, false,
7918 SS, FirstQualifierInScope,
7919 false))
7920 return 0;
7921
7922 return SS.getScopeRep();
Douglas Gregor1135c352009-08-06 05:28:30 +00007923}
7924
7925template<typename Derived>
7926NestedNameSpecifier *
7927TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7928 SourceRange Range,
7929 NamespaceDecl *NS) {
7930 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7931}
7932
7933template<typename Derived>
7934NestedNameSpecifier *
7935TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7936 SourceRange Range,
Douglas Gregor7b26ff92011-02-24 02:36:08 +00007937 NamespaceAliasDecl *Alias) {
7938 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias);
7939}
7940
7941template<typename Derived>
7942NestedNameSpecifier *
7943TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7944 SourceRange Range,
Douglas Gregor1135c352009-08-06 05:28:30 +00007945 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007946 QualType T) {
7947 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007948 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007949 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007950 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7951 T.getTypePtr());
7952 }
Mike Stump11289f42009-09-09 15:08:12 +00007953
Douglas Gregor1135c352009-08-06 05:28:30 +00007954 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7955 return 0;
7956}
Mike Stump11289f42009-09-09 15:08:12 +00007957
Douglas Gregor71dc5092009-08-06 06:41:21 +00007958template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007959TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007960TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7961 bool TemplateKW,
7962 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007963 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007964 Template);
7965}
7966
7967template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007968TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007969TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007970 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007971 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007972 QualType ObjectType,
7973 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007974 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007975 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007976 UnqualifiedId Name;
7977 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007978 Sema::TemplateTy Template;
7979 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7980 /*FIXME:*/getDerived().getBaseLocation(),
7981 SS,
7982 Name,
John McCallba7bf592010-08-24 05:47:05 +00007983 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007984 /*EnteringContext=*/false,
7985 Template);
John McCall31f82722010-11-12 08:19:04 +00007986 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007987}
Mike Stump11289f42009-09-09 15:08:12 +00007988
Douglas Gregora16548e2009-08-11 05:31:07 +00007989template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007990TemplateName
7991TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7992 OverloadedOperatorKind Operator,
7993 QualType ObjectType) {
7994 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007995 SS.MakeTrivial(SemaRef.Context, Qualifier, SourceRange(getDerived().getBaseLocation()));
Douglas Gregor71395fa2009-11-04 00:56:37 +00007996 UnqualifiedId Name;
7997 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7998 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7999 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008000 Sema::TemplateTy Template;
8001 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008002 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008003 SS,
8004 Name,
John McCallba7bf592010-08-24 05:47:05 +00008005 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008006 /*EnteringContext=*/false,
8007 Template);
8008 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008009}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008010
Douglas Gregor71395fa2009-11-04 00:56:37 +00008011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008012ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008013TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8014 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008015 Expr *OrigCallee,
8016 Expr *First,
8017 Expr *Second) {
8018 Expr *Callee = OrigCallee->IgnoreParenCasts();
8019 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008020
Douglas Gregora16548e2009-08-11 05:31:07 +00008021 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008022 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008023 if (!First->getType()->isOverloadableType() &&
8024 !Second->getType()->isOverloadableType())
8025 return getSema().CreateBuiltinArraySubscriptExpr(First,
8026 Callee->getLocStart(),
8027 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008028 } else if (Op == OO_Arrow) {
8029 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008030 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8031 } else if (Second == 0 || isPostIncDec) {
8032 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008033 // The argument is not of overloadable type, so try to create a
8034 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008035 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008036 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008037
John McCallb268a282010-08-23 23:25:46 +00008038 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008039 }
8040 } else {
John McCallb268a282010-08-23 23:25:46 +00008041 if (!First->getType()->isOverloadableType() &&
8042 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008043 // Neither of the arguments is an overloadable type, so try to
8044 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008045 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008046 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008047 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008048 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008049 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008050
Douglas Gregora16548e2009-08-11 05:31:07 +00008051 return move(Result);
8052 }
8053 }
Mike Stump11289f42009-09-09 15:08:12 +00008054
8055 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008056 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008057 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008058
John McCallb268a282010-08-23 23:25:46 +00008059 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008060 assert(ULE->requiresADL());
8061
8062 // FIXME: Do we have to check
8063 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008064 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008065 } else {
John McCallb268a282010-08-23 23:25:46 +00008066 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008067 }
Mike Stump11289f42009-09-09 15:08:12 +00008068
Douglas Gregora16548e2009-08-11 05:31:07 +00008069 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008070 Expr *Args[2] = { First, Second };
8071 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008072
Douglas Gregora16548e2009-08-11 05:31:07 +00008073 // Create the overloaded operator invocation for unary operators.
8074 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008075 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008076 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008077 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008078 }
Mike Stump11289f42009-09-09 15:08:12 +00008079
Sebastian Redladba46e2009-10-29 20:17:01 +00008080 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00008081 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00008082 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008083 First,
8084 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00008085
Douglas Gregora16548e2009-08-11 05:31:07 +00008086 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008087 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008088 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008089 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8090 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008091 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008092
Mike Stump11289f42009-09-09 15:08:12 +00008093 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008094}
Mike Stump11289f42009-09-09 15:08:12 +00008095
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008097ExprResult
John McCallb268a282010-08-23 23:25:46 +00008098TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008099 SourceLocation OperatorLoc,
8100 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008101 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008102 TypeSourceInfo *ScopeType,
8103 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008104 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008105 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008106 QualType BaseType = Base->getType();
8107 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008108 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008109 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008110 !BaseType->getAs<PointerType>()->getPointeeType()
8111 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008112 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008113 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008114 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008115 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008116 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008117 /*FIXME?*/true);
8118 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008119
Douglas Gregor678f90d2010-02-25 01:56:36 +00008120 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008121 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8122 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8123 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8124 NameInfo.setNamedTypeInfo(DestroyedType);
8125
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008126 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008127
John McCallb268a282010-08-23 23:25:46 +00008128 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008129 OperatorLoc, isArrow,
8130 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008131 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008132 /*TemplateArgs*/ 0);
8133}
8134
Douglas Gregord6ff3322009-08-04 16:50:30 +00008135} // end namespace clang
8136
8137#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H