blob: f11f1ef0524e4170a5ef538c7ab7dd5d7da135a3 [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 Gregor9db53502011-03-02 18:07:45 +0000417 /// \brief Transform the given template name.
418 ///
419 /// \param SS The nested-name-specifier that qualifies the template
420 /// name. This nested-name-specifier must already have been transformed.
421 ///
422 /// \param Name The template name to transform.
423 ///
424 /// \param NameLoc The source location of the template name.
425 ///
426 /// \param ObjectType If we're translating a template name within a member
427 /// access expression, this is the type of the object whose member template
428 /// is being referenced.
429 ///
430 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
431 /// also refers to a name within the current (lexical) scope, this is the
432 /// declaration it refers to.
433 ///
434 /// By default, transforms the template name by transforming the declarations
435 /// and nested-name-specifiers that occur within the template name.
436 /// Subclasses may override this function to provide alternate behavior.
437 TemplateName TransformTemplateName(CXXScopeSpec &SS,
438 TemplateName Name,
439 SourceLocation NameLoc,
440 QualType ObjectType = QualType(),
441 NamedDecl *FirstQualifierInScope = 0);
442
Douglas Gregord6ff3322009-08-04 16:50:30 +0000443 /// \brief Transform the given template argument.
444 ///
Mike Stump11289f42009-09-09 15:08:12 +0000445 /// By default, this operation transforms the type, expression, or
446 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000447 /// new template argument from the transformed result. Subclasses may
448 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000449 ///
450 /// Returns true if there was an error.
451 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
452 TemplateArgumentLoc &Output);
453
Douglas Gregor62e06f22010-12-20 17:31:10 +0000454 /// \brief Transform the given set of template arguments.
455 ///
456 /// By default, this operation transforms all of the template arguments
457 /// in the input set using \c TransformTemplateArgument(), and appends
458 /// the transformed arguments to the output list.
459 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000460 /// Note that this overload of \c TransformTemplateArguments() is merely
461 /// a convenience function. Subclasses that wish to override this behavior
462 /// should override the iterator-based member template version.
463 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000464 /// \param Inputs The set of template arguments to be transformed.
465 ///
466 /// \param NumInputs The number of template arguments in \p Inputs.
467 ///
468 /// \param Outputs The set of transformed template arguments output by this
469 /// routine.
470 ///
471 /// Returns true if an error occurred.
472 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
473 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000474 TemplateArgumentListInfo &Outputs) {
475 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
476 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000477
478 /// \brief Transform the given set of template arguments.
479 ///
480 /// By default, this operation transforms all of the template arguments
481 /// in the input set using \c TransformTemplateArgument(), and appends
482 /// the transformed arguments to the output list.
483 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000484 /// \param First An iterator to the first template argument.
485 ///
486 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000487 ///
488 /// \param Outputs The set of transformed template arguments output by this
489 /// routine.
490 ///
491 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000492 template<typename InputIterator>
493 bool TransformTemplateArguments(InputIterator First,
494 InputIterator Last,
495 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000496
John McCall0ad16662009-10-29 08:12:44 +0000497 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
498 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
499 TemplateArgumentLoc &ArgLoc);
500
John McCallbcd03502009-12-07 02:54:59 +0000501 /// \brief Fakes up a TypeSourceInfo for a type.
502 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
503 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000504 getDerived().getBaseLocation());
505 }
Mike Stump11289f42009-09-09 15:08:12 +0000506
John McCall550e0c22009-10-21 00:40:46 +0000507#define ABSTRACT_TYPELOC(CLASS, PARENT)
508#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000509 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000510#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000511
John McCall31f82722010-11-12 08:19:04 +0000512 QualType
513 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
514 TemplateSpecializationTypeLoc TL,
515 TemplateName Template);
516
517 QualType
518 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
519 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor5a064722011-02-28 17:23:35 +0000520 TemplateName Template);
521
522 QualType
523 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
524 DependentTemplateSpecializationTypeLoc TL,
John McCall31f82722010-11-12 08:19:04 +0000525 NestedNameSpecifier *Prefix);
526
Douglas Gregora7a795b2011-03-01 20:11:18 +0000527 QualType
528 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
529 DependentTemplateSpecializationTypeLoc TL,
530 NestedNameSpecifierLoc QualifierLoc);
531
John McCall58f10c32010-03-11 09:03:00 +0000532 /// \brief Transforms the parameters of a function type into the
533 /// given vectors.
534 ///
535 /// The result vectors should be kept in sync; null entries in the
536 /// variables vector are acceptable.
537 ///
538 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000539 bool TransformFunctionTypeParams(SourceLocation Loc,
540 ParmVarDecl **Params, unsigned NumParams,
541 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000542 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000543 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000544
545 /// \brief Transforms a single function-type parameter. Return null
546 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000547 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
548 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000549
John McCall31f82722010-11-12 08:19:04 +0000550 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000551
John McCalldadc5752010-08-24 06:29:42 +0000552 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
553 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000554
Douglas Gregorebe10102009-08-20 07:17:43 +0000555#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000556 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000557#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000558 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000559#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000560#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000561
Douglas Gregord6ff3322009-08-04 16:50:30 +0000562 /// \brief Build a new pointer type given its pointee type.
563 ///
564 /// By default, performs semantic analysis when building the pointer type.
565 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000566 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000567
568 /// \brief Build a new block pointer type given its pointee type.
569 ///
Mike Stump11289f42009-09-09 15:08:12 +0000570 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000572 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000573
John McCall70dd5f62009-10-30 00:06:24 +0000574 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000575 ///
John McCall70dd5f62009-10-30 00:06:24 +0000576 /// By default, performs semantic analysis when building the
577 /// reference type. Subclasses may override this routine to provide
578 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000579 ///
John McCall70dd5f62009-10-30 00:06:24 +0000580 /// \param LValue whether the type was written with an lvalue sigil
581 /// or an rvalue sigil.
582 QualType RebuildReferenceType(QualType ReferentType,
583 bool LValue,
584 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000585
Douglas Gregord6ff3322009-08-04 16:50:30 +0000586 /// \brief Build a new member pointer type given the pointee type and the
587 /// class type it refers into.
588 ///
589 /// By default, performs semantic analysis when building the member pointer
590 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000591 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
592 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000593
Douglas Gregord6ff3322009-08-04 16:50:30 +0000594 /// \brief Build a new array type given the element type, size
595 /// modifier, size of the array (if known), size expression, and index type
596 /// qualifiers.
597 ///
598 /// By default, performs semantic analysis when building the array type.
599 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000600 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000601 QualType RebuildArrayType(QualType ElementType,
602 ArrayType::ArraySizeModifier SizeMod,
603 const llvm::APInt *Size,
604 Expr *SizeExpr,
605 unsigned IndexTypeQuals,
606 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000607
Douglas Gregord6ff3322009-08-04 16:50:30 +0000608 /// \brief Build a new constant array type given the element type, size
609 /// modifier, (known) size of the array, and index type qualifiers.
610 ///
611 /// By default, performs semantic analysis when building the array type.
612 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000613 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000614 ArrayType::ArraySizeModifier SizeMod,
615 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000616 unsigned IndexTypeQuals,
617 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000618
Douglas Gregord6ff3322009-08-04 16:50:30 +0000619 /// \brief Build a new incomplete array type given the element type, size
620 /// modifier, and index type qualifiers.
621 ///
622 /// By default, performs semantic analysis when building the array type.
623 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000624 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000625 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000626 unsigned IndexTypeQuals,
627 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000628
Mike Stump11289f42009-09-09 15:08:12 +0000629 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000630 /// size modifier, size expression, and index type qualifiers.
631 ///
632 /// By default, performs semantic analysis when building the array type.
633 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000634 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000635 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000636 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000637 unsigned IndexTypeQuals,
638 SourceRange BracketsRange);
639
Mike Stump11289f42009-09-09 15:08:12 +0000640 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000641 /// size modifier, size expression, and index type qualifiers.
642 ///
643 /// By default, performs semantic analysis when building the array type.
644 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000645 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000646 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000647 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000648 unsigned IndexTypeQuals,
649 SourceRange BracketsRange);
650
651 /// \brief Build a new vector type given the element type and
652 /// number of elements.
653 ///
654 /// By default, performs semantic analysis when building the vector type.
655 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000656 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000657 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000658
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 /// \brief Build a new extended vector type given the element type and
660 /// number of elements.
661 ///
662 /// By default, performs semantic analysis when building the vector type.
663 /// Subclasses may override this routine to provide different behavior.
664 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
665 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000666
667 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000668 /// given the element type and number of elements.
669 ///
670 /// By default, performs semantic analysis when building the vector type.
671 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000672 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000673 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000675
Douglas Gregord6ff3322009-08-04 16:50:30 +0000676 /// \brief Build a new function type.
677 ///
678 /// By default, performs semantic analysis when building the function type.
679 /// Subclasses may override this routine to provide different behavior.
680 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000681 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000682 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000683 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000684 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000685 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000686
John McCall550e0c22009-10-21 00:40:46 +0000687 /// \brief Build a new unprototyped function type.
688 QualType RebuildFunctionNoProtoType(QualType ResultType);
689
John McCallb96ec562009-12-04 22:46:56 +0000690 /// \brief Rebuild an unresolved typename type, given the decl that
691 /// the UnresolvedUsingTypenameDecl was transformed to.
692 QualType RebuildUnresolvedUsingType(Decl *D);
693
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694 /// \brief Build a new typedef type.
695 QualType RebuildTypedefType(TypedefDecl *Typedef) {
696 return SemaRef.Context.getTypeDeclType(Typedef);
697 }
698
699 /// \brief Build a new class/struct/union type.
700 QualType RebuildRecordType(RecordDecl *Record) {
701 return SemaRef.Context.getTypeDeclType(Record);
702 }
703
704 /// \brief Build a new Enum type.
705 QualType RebuildEnumType(EnumDecl *Enum) {
706 return SemaRef.Context.getTypeDeclType(Enum);
707 }
John McCallfcc33b02009-09-05 00:15:47 +0000708
Mike Stump11289f42009-09-09 15:08:12 +0000709 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000710 ///
711 /// By default, performs semantic analysis when building the typeof type.
712 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000713 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714
Mike Stump11289f42009-09-09 15:08:12 +0000715 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000716 ///
717 /// By default, builds a new TypeOfType with the given underlying type.
718 QualType RebuildTypeOfType(QualType Underlying);
719
Mike Stump11289f42009-09-09 15:08:12 +0000720 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 ///
722 /// By default, performs semantic analysis when building the decltype type.
723 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000724 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000725
Richard Smith30482bc2011-02-20 03:19:35 +0000726 /// \brief Build a new C++0x auto type.
727 ///
728 /// By default, builds a new AutoType with the given deduced type.
729 QualType RebuildAutoType(QualType Deduced) {
730 return SemaRef.Context.getAutoType(Deduced);
731 }
732
Douglas Gregord6ff3322009-08-04 16:50:30 +0000733 /// \brief Build a new template specialization type.
734 ///
735 /// By default, performs semantic analysis when building the template
736 /// specialization type. Subclasses may override this routine to provide
737 /// different behavior.
738 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000739 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000740 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000741
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000742 /// \brief Build a new parenthesized type.
743 ///
744 /// By default, builds a new ParenType type from the inner type.
745 /// Subclasses may override this routine to provide different behavior.
746 QualType RebuildParenType(QualType InnerType) {
747 return SemaRef.Context.getParenType(InnerType);
748 }
749
Douglas Gregord6ff3322009-08-04 16:50:30 +0000750 /// \brief Build a new qualified name type.
751 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000752 /// By default, builds a new ElaboratedType type from the keyword,
753 /// the nested-name-specifier and the named type.
754 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000755 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
756 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000757 NestedNameSpecifierLoc QualifierLoc,
758 QualType Named) {
759 return SemaRef.Context.getElaboratedType(Keyword,
760 QualifierLoc.getNestedNameSpecifier(),
761 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000762 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763
764 /// \brief Build a new typename type that refers to a template-id.
765 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000766 /// By default, builds a new DependentNameType type from the
767 /// nested-name-specifier and the given type. Subclasses may override
768 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000769 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000770 ElaboratedTypeKeyword Keyword,
771 NestedNameSpecifierLoc QualifierLoc,
772 const IdentifierInfo *Name,
773 SourceLocation NameLoc,
774 const TemplateArgumentListInfo &Args) {
775 // Rebuild the template name.
776 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000777 CXXScopeSpec SS;
778 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000779 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000780 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000781
782 if (InstName.isNull())
783 return QualType();
784
785 // If it's still dependent, make a dependent specialization.
786 if (InstName.getAsDependentTemplateName())
787 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
788 QualifierLoc.getNestedNameSpecifier(),
789 Name,
790 Args);
791
792 // Otherwise, make an elaborated type wrapping a non-dependent
793 // specialization.
794 QualType T =
795 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
796 if (T.isNull()) return QualType();
797
798 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
799 return T;
800
801 return SemaRef.Context.getElaboratedType(Keyword,
802 QualifierLoc.getNestedNameSpecifier(),
803 T);
804 }
805
Douglas Gregord6ff3322009-08-04 16:50:30 +0000806 /// \brief Build a new typename type that refers to an identifier.
807 ///
808 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000809 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000810 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000811 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000812 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000813 NestedNameSpecifierLoc QualifierLoc,
814 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000815 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000816 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000817 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000818
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000819 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000820 // If the name is still dependent, just build a new dependent name type.
821 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000822 return SemaRef.Context.getDependentNameType(Keyword,
823 QualifierLoc.getNestedNameSpecifier(),
824 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000825 }
826
Abramo Bagnara6150c882010-05-11 21:36:43 +0000827 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000828 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000829 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000830
831 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
832
Abramo Bagnarad7548482010-05-19 21:37:53 +0000833 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000834 // into a non-dependent elaborated-type-specifier. Find the tag we're
835 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000836 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000837 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
838 if (!DC)
839 return QualType();
840
John McCallbf8c5192010-05-27 06:40:31 +0000841 if (SemaRef.RequireCompleteDeclContext(SS, DC))
842 return QualType();
843
Douglas Gregore677daf2010-03-31 22:19:08 +0000844 TagDecl *Tag = 0;
845 SemaRef.LookupQualifiedName(Result, DC);
846 switch (Result.getResultKind()) {
847 case LookupResult::NotFound:
848 case LookupResult::NotFoundInCurrentInstantiation:
849 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000850
Douglas Gregore677daf2010-03-31 22:19:08 +0000851 case LookupResult::Found:
852 Tag = Result.getAsSingle<TagDecl>();
853 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000854
Douglas Gregore677daf2010-03-31 22:19:08 +0000855 case LookupResult::FoundOverloaded:
856 case LookupResult::FoundUnresolvedValue:
857 llvm_unreachable("Tag lookup cannot find non-tags");
858 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000859
Douglas Gregore677daf2010-03-31 22:19:08 +0000860 case LookupResult::Ambiguous:
861 // Let the LookupResult structure handle ambiguities.
862 return QualType();
863 }
864
865 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000866 // Check where the name exists but isn't a tag type and use that to emit
867 // better diagnostics.
868 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
869 SemaRef.LookupQualifiedName(Result, DC);
870 switch (Result.getResultKind()) {
871 case LookupResult::Found:
872 case LookupResult::FoundOverloaded:
873 case LookupResult::FoundUnresolvedValue: {
874 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
875 unsigned Kind = 0;
876 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
877 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
878 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
879 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
880 break;
881 }
882 default:
883 // FIXME: Would be nice to highlight just the source range.
884 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
885 << Kind << Id << DC;
886 break;
887 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000888 return QualType();
889 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000890
Abramo Bagnarad7548482010-05-19 21:37:53 +0000891 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
892 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000893 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
894 return QualType();
895 }
896
897 // Build the elaborated-type-specifier type.
898 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000899 return SemaRef.Context.getElaboratedType(Keyword,
900 QualifierLoc.getNestedNameSpecifier(),
901 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000902 }
Mike Stump11289f42009-09-09 15:08:12 +0000903
Douglas Gregor822d0302011-01-12 17:07:58 +0000904 /// \brief Build a new pack expansion type.
905 ///
906 /// By default, builds a new PackExpansionType type from the given pattern.
907 /// Subclasses may override this routine to provide different behavior.
908 QualType RebuildPackExpansionType(QualType Pattern,
909 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000910 SourceLocation EllipsisLoc,
911 llvm::Optional<unsigned> NumExpansions) {
912 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
913 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000914 }
915
Douglas Gregor1135c352009-08-06 05:28:30 +0000916 /// \brief Build a new nested-name-specifier given the prefix and an
917 /// identifier that names the next step in the nested-name-specifier.
918 ///
919 /// By default, performs semantic analysis when building the new
920 /// nested-name-specifier. Subclasses may override this routine to provide
921 /// different behavior.
922 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
923 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000924 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000925 QualType ObjectType,
926 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000927
928 /// \brief Build a new nested-name-specifier given the prefix and the
929 /// namespace named in 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,
936 NamespaceDecl *NS);
937
938 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor7b26ff92011-02-24 02:36:08 +0000939 /// namespace alias named in the next step in the nested-name-specifier.
940 ///
941 /// By default, performs semantic analysis when building the new
942 /// nested-name-specifier. Subclasses may override this routine to provide
943 /// different behavior.
944 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
945 SourceRange Range,
946 NamespaceAliasDecl *Alias);
947
948 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor1135c352009-08-06 05:28:30 +0000949 /// type named in the next step in the nested-name-specifier.
950 ///
951 /// By default, performs semantic analysis when building the new
952 /// nested-name-specifier. Subclasses may override this routine to provide
953 /// different behavior.
954 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
955 SourceRange Range,
956 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000957 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000958
959 /// \brief Build a new template name given a nested name specifier, a flag
960 /// indicating whether the "template" keyword was provided, and the template
961 /// that the template name refers to.
962 ///
963 /// By default, builds the new template name directly. Subclasses may override
964 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000965 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000966 bool TemplateKW,
967 TemplateDecl *Template);
968
Douglas Gregor71dc5092009-08-06 06:41:21 +0000969 /// \brief Build a new template name given a nested name specifier and the
970 /// name that is referred to as a template.
971 ///
972 /// By default, performs semantic analysis to determine whether the name can
973 /// be resolved to a specific template, then builds the appropriate kind of
974 /// template name. Subclasses may override this routine to provide different
975 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000976 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
977 const IdentifierInfo &Name,
978 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000979 QualType ObjectType,
980 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000981
Douglas Gregor71395fa2009-11-04 00:56:37 +0000982 /// \brief Build a new template name given a nested name specifier and the
983 /// overloaded operator name that is referred to as a template.
984 ///
985 /// By default, performs semantic analysis to determine whether the name can
986 /// be resolved to a specific template, then builds the appropriate kind of
987 /// template name. Subclasses may override this routine to provide different
988 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000989 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000990 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000991 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000992 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000993
994 /// \brief Build a new template name given a template template parameter pack
995 /// and the
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(TemplateTemplateParmDecl *Param,
1002 const TemplateArgument &ArgPack) {
1003 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1004 }
1005
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 /// \brief Build a new compound statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001010 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001011 MultiStmtArg Statements,
1012 SourceLocation RBraceLoc,
1013 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001014 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001015 IsStmtExpr);
1016 }
1017
1018 /// \brief Build a new case statement.
1019 ///
1020 /// By default, performs semantic analysis to build the new statement.
1021 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001022 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001023 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001024 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001025 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001026 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001027 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001028 ColonLoc);
1029 }
Mike Stump11289f42009-09-09 15:08:12 +00001030
Douglas Gregorebe10102009-08-20 07:17:43 +00001031 /// \brief Attach the body to a new case statement.
1032 ///
1033 /// By default, performs semantic analysis to build the new statement.
1034 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001035 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001036 getSema().ActOnCaseStmtBody(S, Body);
1037 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001038 }
Mike Stump11289f42009-09-09 15:08:12 +00001039
Douglas Gregorebe10102009-08-20 07:17:43 +00001040 /// \brief Build a new default statement.
1041 ///
1042 /// By default, performs semantic analysis to build the new statement.
1043 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001044 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001045 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001046 Stmt *SubStmt) {
1047 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001048 /*CurScope=*/0);
1049 }
Mike Stump11289f42009-09-09 15:08:12 +00001050
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 /// \brief Build a new label statement.
1052 ///
1053 /// By default, performs semantic analysis to build the new statement.
1054 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001055 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1056 SourceLocation ColonLoc, Stmt *SubStmt) {
1057 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001058 }
Mike Stump11289f42009-09-09 15:08:12 +00001059
Douglas Gregorebe10102009-08-20 07:17:43 +00001060 /// \brief Build a new "if" statement.
1061 ///
1062 /// By default, performs semantic analysis to build the new statement.
1063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001064 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001065 VarDecl *CondVar, Stmt *Then,
1066 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001067 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 }
Mike Stump11289f42009-09-09 15:08:12 +00001069
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 /// \brief Start building a new switch statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001074 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001075 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001076 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001077 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001078 }
Mike Stump11289f42009-09-09 15:08:12 +00001079
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 /// \brief Attach the body to the switch statement.
1081 ///
1082 /// By default, performs semantic analysis to build the new statement.
1083 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001084 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001085 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001086 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 }
1088
1089 /// \brief Build a new while statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001093 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1094 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001095 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001096 }
Mike Stump11289f42009-09-09 15:08:12 +00001097
Douglas Gregorebe10102009-08-20 07:17:43 +00001098 /// \brief Build a new do-while statement.
1099 ///
1100 /// By default, performs semantic analysis to build the new statement.
1101 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001102 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001103 SourceLocation WhileLoc, SourceLocation LParenLoc,
1104 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001105 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1106 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001107 }
1108
1109 /// \brief Build a new for statement.
1110 ///
1111 /// By default, performs semantic analysis to build the new statement.
1112 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001113 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1114 Stmt *Init, Sema::FullExprArg Cond,
1115 VarDecl *CondVar, Sema::FullExprArg Inc,
1116 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001117 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001118 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 /// \brief Build a new goto statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001125 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1126 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001127 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001128 }
1129
1130 /// \brief Build a new indirect goto statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001134 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001135 SourceLocation StarLoc,
1136 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001137 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001138 }
Mike Stump11289f42009-09-09 15:08:12 +00001139
Douglas Gregorebe10102009-08-20 07:17:43 +00001140 /// \brief Build a new return statement.
1141 ///
1142 /// By default, performs semantic analysis to build the new statement.
1143 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001144 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001145 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001146 }
Mike Stump11289f42009-09-09 15:08:12 +00001147
Douglas Gregorebe10102009-08-20 07:17:43 +00001148 /// \brief Build a new declaration statement.
1149 ///
1150 /// By default, performs semantic analysis to build the new statement.
1151 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001152 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001153 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001154 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001155 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1156 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001157 }
Mike Stump11289f42009-09-09 15:08:12 +00001158
Anders Carlssonaaeef072010-01-24 05:50:09 +00001159 /// \brief Build a new inline asm 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 RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001164 bool IsSimple,
1165 bool IsVolatile,
1166 unsigned NumOutputs,
1167 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001168 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001169 MultiExprArg Constraints,
1170 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001171 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001172 MultiExprArg Clobbers,
1173 SourceLocation RParenLoc,
1174 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001175 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001176 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001177 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001178 RParenLoc, MSAsm);
1179 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001180
1181 /// \brief Build a new Objective-C @try statement.
1182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001185 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001186 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001187 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001188 Stmt *Finally) {
1189 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1190 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001191 }
1192
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001193 /// \brief Rebuild an Objective-C exception declaration.
1194 ///
1195 /// By default, performs semantic analysis to build the new declaration.
1196 /// Subclasses may override this routine to provide different behavior.
1197 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1198 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001199 return getSema().BuildObjCExceptionDecl(TInfo, T,
1200 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001201 ExceptionDecl->getLocation());
1202 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001203
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001204 /// \brief Build a new Objective-C @catch statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001208 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001209 SourceLocation RParenLoc,
1210 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001211 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001212 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001213 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001214 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001215
Douglas Gregor306de2f2010-04-22 23:59:56 +00001216 /// \brief Build a new Objective-C @finally statement.
1217 ///
1218 /// By default, performs semantic analysis to build the new statement.
1219 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001220 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001221 Stmt *Body) {
1222 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001223 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001224
Douglas Gregor6148de72010-04-22 22:01:21 +00001225 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001229 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001230 Expr *Operand) {
1231 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001232 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001233
Douglas Gregor6148de72010-04-22 22:01:21 +00001234 /// \brief Build a new Objective-C @synchronized statement.
1235 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001236 /// By default, performs semantic analysis to build the new statement.
1237 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001238 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001239 Expr *Object,
1240 Stmt *Body) {
1241 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1242 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001243 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001244
1245 /// \brief Build a new Objective-C fast enumeration statement.
1246 ///
1247 /// 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 RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001250 SourceLocation LParenLoc,
1251 Stmt *Element,
1252 Expr *Collection,
1253 SourceLocation RParenLoc,
1254 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001255 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001256 Element,
1257 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001258 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001259 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001260 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001261
Douglas Gregorebe10102009-08-20 07:17:43 +00001262 /// \brief Build a new C++ exception declaration.
1263 ///
1264 /// By default, performs semantic analysis to build the new decaration.
1265 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001266 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001267 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001268 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001269 SourceLocation Loc) {
1270 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001271 }
1272
1273 /// \brief Build a new C++ catch statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001277 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001278 VarDecl *ExceptionDecl,
1279 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001280 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1281 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001282 }
Mike Stump11289f42009-09-09 15:08:12 +00001283
Douglas Gregorebe10102009-08-20 07:17:43 +00001284 /// \brief Build a new C++ try 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 RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001289 Stmt *TryBlock,
1290 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001291 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001292 }
Mike Stump11289f42009-09-09 15:08:12 +00001293
Douglas Gregora16548e2009-08-11 05:31:07 +00001294 /// \brief Build a new expression that references a declaration.
1295 ///
1296 /// By default, performs semantic analysis to build the new expression.
1297 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001298 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001299 LookupResult &R,
1300 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001301 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1302 }
1303
1304
1305 /// \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.
Douglas Gregorea972d32011-02-28 21:54:11 +00001309 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001310 ValueDecl *VD,
1311 const DeclarationNameInfo &NameInfo,
1312 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001313 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001314 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001315
1316 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001317
1318 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 }
Mike Stump11289f42009-09-09 15:08:12 +00001320
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001322 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 /// By default, performs semantic analysis to build the new expression.
1324 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001325 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001327 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 }
1329
Douglas Gregorad8a3362009-09-04 17:36:40 +00001330 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001331 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001334 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001335 SourceLocation OperatorLoc,
1336 bool isArrow,
1337 CXXScopeSpec &SS,
1338 TypeSourceInfo *ScopeType,
1339 SourceLocation CCLoc,
1340 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001341 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001342
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001344 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001345 /// By default, performs semantic analysis to build the new expression.
1346 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001347 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001348 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001349 Expr *SubExpr) {
1350 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 }
Mike Stump11289f42009-09-09 15:08:12 +00001352
Douglas Gregor882211c2010-04-28 22:16:22 +00001353 /// \brief Build a new builtin offsetof expression.
1354 ///
1355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001357 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001358 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001359 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001360 unsigned NumComponents,
1361 SourceLocation RParenLoc) {
1362 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1363 NumComponents, RParenLoc);
1364 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001365
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001367 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 /// By default, performs semantic analysis to build the new expression.
1369 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001370 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001371 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001373 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 }
1375
Mike Stump11289f42009-09-09 15:08:12 +00001376 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 /// 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(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001383 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001384 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001386 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001387
Douglas Gregora16548e2009-08-11 05:31:07 +00001388 return move(Result);
1389 }
Mike Stump11289f42009-09-09 15:08:12 +00001390
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001392 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 /// By default, performs semantic analysis to build the new expression.
1394 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001395 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001396 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001397 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001399 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1400 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 RBracketLoc);
1402 }
1403
1404 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001405 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 /// By default, performs semantic analysis to build the new expression.
1407 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001408 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001410 SourceLocation RParenLoc,
1411 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001412 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001413 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001414 }
1415
1416 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001417 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 /// By default, performs semantic analysis to build the new expression.
1419 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001420 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001421 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001422 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001423 const DeclarationNameInfo &MemberNameInfo,
1424 ValueDecl *Member,
1425 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001426 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001427 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001428 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001429 // We have a reference to an unnamed field. This is always the
1430 // base of an anonymous struct/union member access, i.e. the
1431 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001432 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001433 assert(Member->getType()->isRecordType() &&
1434 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001435
Douglas Gregorea972d32011-02-28 21:54:11 +00001436 if (getSema().PerformObjectMemberConversion(Base,
1437 QualifierLoc.getNestedNameSpecifier(),
John McCall16df1e52010-03-30 21:47:33 +00001438 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001439 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001440
John McCall7decc9e2010-11-18 06:31:45 +00001441 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001442 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001443 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001444 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001445 cast<FieldDecl>(Member)->getType(),
1446 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001447 return getSema().Owned(ME);
1448 }
Mike Stump11289f42009-09-09 15:08:12 +00001449
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001450 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001451 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001452
John McCallb268a282010-08-23 23:25:46 +00001453 getSema().DefaultFunctionArrayConversion(Base);
1454 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001455
John McCall16df1e52010-03-30 21:47:33 +00001456 // FIXME: this involves duplicating earlier analysis in a lot of
1457 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001458 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001459 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001460 R.resolveKind();
1461
John McCallb268a282010-08-23 23:25:46 +00001462 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001463 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001464 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 }
Mike Stump11289f42009-09-09 15:08:12 +00001466
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001468 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 /// By default, performs semantic analysis to build the new expression.
1470 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001471 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001472 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001473 Expr *LHS, Expr *RHS) {
1474 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 }
1476
1477 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001478 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 /// By default, performs semantic analysis to build the new expression.
1480 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001481 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001482 SourceLocation QuestionLoc,
1483 Expr *LHS,
1484 SourceLocation ColonLoc,
1485 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001486 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1487 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001488 }
1489
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001491 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 /// By default, performs semantic analysis to build the new expression.
1493 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001494 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001495 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001497 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001498 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001499 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 }
Mike Stump11289f42009-09-09 15:08:12 +00001501
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001503 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001506 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001507 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001509 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001510 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001511 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 }
Mike Stump11289f42009-09-09 15:08:12 +00001513
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001515 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 /// By default, performs semantic analysis to build the new expression.
1517 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001518 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 SourceLocation OpLoc,
1520 SourceLocation AccessorLoc,
1521 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001522
John McCall10eae182009-11-30 22:42:35 +00001523 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001524 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001525 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001526 OpLoc, /*IsArrow*/ false,
1527 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001528 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001529 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 }
Mike Stump11289f42009-09-09 15:08:12 +00001531
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001533 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 /// By default, performs semantic analysis to build the new expression.
1535 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001536 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001538 SourceLocation RBraceLoc,
1539 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001540 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001541 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1542 if (Result.isInvalid() || ResultTy->isDependentType())
1543 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001544
Douglas Gregord3d93062009-11-09 17:16:50 +00001545 // Patch in the result type we were given, which may have been computed
1546 // when the initial InitListExpr was built.
1547 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1548 ILE->setType(ResultTy);
1549 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 }
Mike Stump11289f42009-09-09 15:08:12 +00001551
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001553 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 /// By default, performs semantic analysis to build the new expression.
1555 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001556 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 MultiExprArg ArrayExprs,
1558 SourceLocation EqualOrColonLoc,
1559 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001560 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001561 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001563 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001565 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001566
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 ArrayExprs.release();
1568 return move(Result);
1569 }
Mike Stump11289f42009-09-09 15:08:12 +00001570
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001572 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 /// By default, builds the implicit value initialization without performing
1574 /// any semantic analysis. Subclasses may override this routine to provide
1575 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001576 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1578 }
Mike Stump11289f42009-09-09 15:08:12 +00001579
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001581 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001584 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001585 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001586 SourceLocation RParenLoc) {
1587 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001588 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001589 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 }
1591
1592 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001593 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001596 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 MultiExprArg SubExprs,
1598 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001599 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001600 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 }
Mike Stump11289f42009-09-09 15:08:12 +00001602
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001604 ///
1605 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 /// rather than attempting to map the label statement itself.
1607 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001608 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001609 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001610 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 }
Mike Stump11289f42009-09-09 15:08:12 +00001612
Douglas Gregora16548e2009-08-11 05:31:07 +00001613 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001614 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 /// By default, performs semantic analysis to build the new expression.
1616 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001617 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001618 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001620 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 }
Mike Stump11289f42009-09-09 15:08:12 +00001622
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 /// \brief Build a new __builtin_choose_expr expression.
1624 ///
1625 /// By default, performs semantic analysis to build the new expression.
1626 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001627 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001628 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 SourceLocation RParenLoc) {
1630 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001631 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 RParenLoc);
1633 }
Mike Stump11289f42009-09-09 15:08:12 +00001634
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// \brief Build a new overloaded operator call expression.
1636 ///
1637 /// By default, performs semantic analysis to build the new expression.
1638 /// The semantic analysis provides the behavior of template instantiation,
1639 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001640 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 /// argument-dependent lookup, etc. Subclasses may override this routine to
1642 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001643 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001645 Expr *Callee,
1646 Expr *First,
1647 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001648
1649 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 /// reinterpret_cast.
1651 ///
1652 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001653 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001655 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 Stmt::StmtClass Class,
1657 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001658 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 SourceLocation RAngleLoc,
1660 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001661 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001662 SourceLocation RParenLoc) {
1663 switch (Class) {
1664 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001665 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001666 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001667 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001668
1669 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001670 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001671 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001672 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001673
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001675 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001676 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001677 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001679
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001681 return getDerived().RebuildCXXConstCastExpr(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 default:
1686 assert(false && "Invalid C++ named cast");
1687 break;
1688 }
Mike Stump11289f42009-09-09 15:08:12 +00001689
John McCallfaf5fb42010-08-26 23:41:50 +00001690 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 }
Mike Stump11289f42009-09-09 15:08:12 +00001692
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 /// \brief Build a new C++ static_cast expression.
1694 ///
1695 /// By default, performs semantic analysis to build the new expression.
1696 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001697 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001699 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001700 SourceLocation RAngleLoc,
1701 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001702 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001704 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001705 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001706 SourceRange(LAngleLoc, RAngleLoc),
1707 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 }
1709
1710 /// \brief Build a new C++ dynamic_cast expression.
1711 ///
1712 /// By default, performs semantic analysis to build the new expression.
1713 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001714 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001716 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 SourceLocation RAngleLoc,
1718 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001719 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001721 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001722 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001723 SourceRange(LAngleLoc, RAngleLoc),
1724 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 }
1726
1727 /// \brief Build a new C++ reinterpret_cast expression.
1728 ///
1729 /// By default, performs semantic analysis to build the new expression.
1730 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001731 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001733 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001734 SourceLocation RAngleLoc,
1735 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001736 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001738 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001739 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001740 SourceRange(LAngleLoc, RAngleLoc),
1741 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 }
1743
1744 /// \brief Build a new C++ const_cast expression.
1745 ///
1746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001748 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001750 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 SourceLocation RAngleLoc,
1752 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001753 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001755 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001756 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001757 SourceRange(LAngleLoc, RAngleLoc),
1758 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 }
Mike Stump11289f42009-09-09 15:08:12 +00001760
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 /// \brief Build a new C++ functional-style cast expression.
1762 ///
1763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001765 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1766 SourceLocation LParenLoc,
1767 Expr *Sub,
1768 SourceLocation RParenLoc) {
1769 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001770 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 RParenLoc);
1772 }
Mike Stump11289f42009-09-09 15:08:12 +00001773
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 /// \brief Build a new C++ typeid(type) expression.
1775 ///
1776 /// By default, performs semantic analysis to build the new expression.
1777 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001778 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001779 SourceLocation TypeidLoc,
1780 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001782 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001783 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001784 }
Mike Stump11289f42009-09-09 15:08:12 +00001785
Francois Pichet9f4f2072010-09-08 12:20:18 +00001786
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 /// \brief Build a new C++ typeid(expr) expression.
1788 ///
1789 /// By default, performs semantic analysis to build the new expression.
1790 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001791 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001792 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001793 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001795 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001796 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001797 }
1798
Francois Pichet9f4f2072010-09-08 12:20:18 +00001799 /// \brief Build a new C++ __uuidof(type) expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
1803 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1804 SourceLocation TypeidLoc,
1805 TypeSourceInfo *Operand,
1806 SourceLocation RParenLoc) {
1807 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1808 RParenLoc);
1809 }
1810
1811 /// \brief Build a new C++ __uuidof(expr) expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
1815 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1816 SourceLocation TypeidLoc,
1817 Expr *Operand,
1818 SourceLocation RParenLoc) {
1819 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1820 RParenLoc);
1821 }
1822
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 /// \brief Build a new C++ "this" expression.
1824 ///
1825 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001826 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001828 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001829 QualType ThisType,
1830 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001832 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1833 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 }
1835
1836 /// \brief Build a new C++ throw expression.
1837 ///
1838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001840 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001841 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 }
1843
1844 /// \brief Build a new C++ default-argument expression.
1845 ///
1846 /// By default, builds a new default-argument expression, which does not
1847 /// require any semantic analysis. Subclasses may override this routine to
1848 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001849 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001850 ParmVarDecl *Param) {
1851 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1852 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 }
1854
1855 /// \brief Build a new C++ zero-initialization expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001859 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1860 SourceLocation LParenLoc,
1861 SourceLocation RParenLoc) {
1862 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001863 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001864 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 }
Mike Stump11289f42009-09-09 15:08:12 +00001866
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 /// \brief Build a new C++ "new" expression.
1868 ///
1869 /// By default, performs semantic analysis to build the new expression.
1870 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001871 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001872 bool UseGlobal,
1873 SourceLocation PlacementLParen,
1874 MultiExprArg PlacementArgs,
1875 SourceLocation PlacementRParen,
1876 SourceRange TypeIdParens,
1877 QualType AllocatedType,
1878 TypeSourceInfo *AllocatedTypeInfo,
1879 Expr *ArraySize,
1880 SourceLocation ConstructorLParen,
1881 MultiExprArg ConstructorArgs,
1882 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001883 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001884 PlacementLParen,
1885 move(PlacementArgs),
1886 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001887 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001888 AllocatedType,
1889 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001890 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 ConstructorLParen,
1892 move(ConstructorArgs),
1893 ConstructorRParen);
1894 }
Mike Stump11289f42009-09-09 15:08:12 +00001895
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 /// \brief Build a new C++ "delete" expression.
1897 ///
1898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001900 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 bool IsGlobalDelete,
1902 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001903 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001905 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 }
Mike Stump11289f42009-09-09 15:08:12 +00001907
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 /// \brief Build a new unary type trait expression.
1909 ///
1910 /// By default, performs semantic analysis to build the new expression.
1911 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001912 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001913 SourceLocation StartLoc,
1914 TypeSourceInfo *T,
1915 SourceLocation RParenLoc) {
1916 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 }
1918
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001919 /// \brief Build a new binary 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.
1923 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1924 SourceLocation StartLoc,
1925 TypeSourceInfo *LhsT,
1926 TypeSourceInfo *RhsT,
1927 SourceLocation RParenLoc) {
1928 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1929 }
1930
Mike Stump11289f42009-09-09 15:08:12 +00001931 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 /// expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001936 ExprResult RebuildDependentScopeDeclRefExpr(
1937 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001938 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001939 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001941 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001942
1943 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001944 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001945 *TemplateArgs);
1946
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001947 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 }
1949
1950 /// \brief Build a new template-id expression.
1951 ///
1952 /// By default, performs semantic analysis to build the new expression.
1953 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001954 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001955 LookupResult &R,
1956 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001957 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001958 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 }
1960
1961 /// \brief Build a new object-construction 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 RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001966 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 CXXConstructorDecl *Constructor,
1968 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001969 MultiExprArg Args,
1970 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001971 CXXConstructExpr::ConstructionKind ConstructKind,
1972 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001973 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001974 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001975 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001976 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001977
Douglas Gregordb121ba2009-12-14 16:27:04 +00001978 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001979 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001980 RequiresZeroInit, ConstructKind,
1981 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001982 }
1983
1984 /// \brief Build a new object-construction expression.
1985 ///
1986 /// By default, performs semantic analysis to build the new expression.
1987 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001988 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1989 SourceLocation LParenLoc,
1990 MultiExprArg Args,
1991 SourceLocation RParenLoc) {
1992 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 LParenLoc,
1994 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 RParenLoc);
1996 }
1997
1998 /// \brief Build a new object-construction expression.
1999 ///
2000 /// By default, performs semantic analysis to build the new expression.
2001 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002002 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2003 SourceLocation LParenLoc,
2004 MultiExprArg Args,
2005 SourceLocation RParenLoc) {
2006 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 LParenLoc,
2008 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 RParenLoc);
2010 }
Mike Stump11289f42009-09-09 15:08:12 +00002011
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 /// \brief Build a new member reference expression.
2013 ///
2014 /// By default, performs semantic analysis to build the new expression.
2015 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002016 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002017 QualType BaseType,
2018 bool IsArrow,
2019 SourceLocation OperatorLoc,
2020 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002021 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002022 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002023 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002025 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002026
John McCallb268a282010-08-23 23:25:46 +00002027 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002028 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002029 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002030 MemberNameInfo,
2031 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 }
2033
John McCall10eae182009-11-30 22:42:35 +00002034 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002035 ///
2036 /// By default, performs semantic analysis to build the new expression.
2037 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002038 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002039 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002040 SourceLocation OperatorLoc,
2041 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002042 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002043 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002044 LookupResult &R,
2045 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002046 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002047 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002048
John McCallb268a282010-08-23 23:25:46 +00002049 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002050 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002051 SS, FirstQualifierInScope,
2052 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002053 }
Mike Stump11289f42009-09-09 15:08:12 +00002054
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002055 /// \brief Build a new noexcept expression.
2056 ///
2057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
2059 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2060 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2061 }
2062
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002063 /// \brief Build a new expression to compute the length of a parameter pack.
2064 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2065 SourceLocation PackLoc,
2066 SourceLocation RParenLoc,
2067 unsigned Length) {
2068 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2069 OperatorLoc, Pack, PackLoc,
2070 RParenLoc, Length);
2071 }
2072
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 /// \brief Build a new Objective-C @encode expression.
2074 ///
2075 /// By default, performs semantic analysis to build the new expression.
2076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002077 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002078 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002080 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002082 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002083
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002084 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002085 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002086 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002087 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002088 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002089 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002090 MultiExprArg Args,
2091 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002092 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2093 ReceiverTypeInfo->getType(),
2094 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002095 Sel, Method, LBracLoc, SelectorLoc,
2096 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002097 }
2098
2099 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002100 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002101 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002102 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002103 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002104 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002105 MultiExprArg Args,
2106 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002107 return SemaRef.BuildInstanceMessage(Receiver,
2108 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002109 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002110 Sel, Method, LBracLoc, SelectorLoc,
2111 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002112 }
2113
Douglas Gregord51d90d2010-04-26 20:11:03 +00002114 /// \brief Build a new Objective-C ivar reference expression.
2115 ///
2116 /// By default, performs semantic analysis to build the new expression.
2117 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002118 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002119 SourceLocation IvarLoc,
2120 bool IsArrow, bool IsFreeIvar) {
2121 // FIXME: We lose track of the IsFreeIvar bit.
2122 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002123 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002124 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2125 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002126 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002127 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002128 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002129 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002130 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002131 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002132
Douglas Gregord51d90d2010-04-26 20:11:03 +00002133 if (Result.get())
2134 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002135
John McCallb268a282010-08-23 23:25:46 +00002136 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002137 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002138 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002139 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002140 /*TemplateArgs=*/0);
2141 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002142
2143 /// \brief Build a new Objective-C property reference expression.
2144 ///
2145 /// By default, performs semantic analysis to build the new expression.
2146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002147 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002148 ObjCPropertyDecl *Property,
2149 SourceLocation PropertyLoc) {
2150 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002151 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002152 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2153 Sema::LookupMemberName);
2154 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002155 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002156 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002157 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002158 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002159 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002160
Douglas Gregor9faee212010-04-26 20:47:02 +00002161 if (Result.get())
2162 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002163
John McCallb268a282010-08-23 23:25:46 +00002164 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002165 /*FIXME:*/PropertyLoc, IsArrow,
2166 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002167 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002168 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002169 /*TemplateArgs=*/0);
2170 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002171
John McCallb7bd14f2010-12-02 01:19:52 +00002172 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002173 ///
2174 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002175 /// Subclasses may override this routine to provide different behavior.
2176 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2177 ObjCMethodDecl *Getter,
2178 ObjCMethodDecl *Setter,
2179 SourceLocation PropertyLoc) {
2180 // Since these expressions can only be value-dependent, we do not
2181 // need to perform semantic analysis again.
2182 return Owned(
2183 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2184 VK_LValue, OK_ObjCProperty,
2185 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002186 }
2187
Douglas Gregord51d90d2010-04-26 20:11:03 +00002188 /// \brief Build a new Objective-C "isa" expression.
2189 ///
2190 /// By default, performs semantic analysis to build the new expression.
2191 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002192 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002193 bool IsArrow) {
2194 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002195 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002196 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2197 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002198 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002199 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002200 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002201 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002202 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002203
Douglas Gregord51d90d2010-04-26 20:11:03 +00002204 if (Result.get())
2205 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002206
John McCallb268a282010-08-23 23:25:46 +00002207 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002208 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002209 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002210 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002211 /*TemplateArgs=*/0);
2212 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002213
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 /// \brief Build a new shuffle vector expression.
2215 ///
2216 /// By default, performs semantic analysis to build the new expression.
2217 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002218 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002219 MultiExprArg SubExprs,
2220 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002222 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2224 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2225 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2226 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002227
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 // Build a reference to the __builtin_shufflevector builtin
2229 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002230 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002232 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002234
2235 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 unsigned NumSubExprs = SubExprs.size();
2237 Expr **Subs = (Expr **)SubExprs.release();
2238 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2239 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002240 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002241 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002243 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002244
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002246 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002248 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002249
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002251 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 }
John McCall31f82722010-11-12 08:19:04 +00002253
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002254 /// \brief Build a new template argument pack expansion.
2255 ///
2256 /// By default, performs semantic analysis to build a new pack expansion
2257 /// for a template argument. Subclasses may override this routine to provide
2258 /// different behavior.
2259 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002260 SourceLocation EllipsisLoc,
2261 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002262 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002263 case TemplateArgument::Expression: {
2264 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002265 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2266 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002267 if (Result.isInvalid())
2268 return TemplateArgumentLoc();
2269
2270 return TemplateArgumentLoc(Result.get(), Result.get());
2271 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002272
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002273 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002274 return TemplateArgumentLoc(TemplateArgument(
2275 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002276 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002277 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002278 Pattern.getTemplateNameLoc(),
2279 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002280
2281 case TemplateArgument::Null:
2282 case TemplateArgument::Integral:
2283 case TemplateArgument::Declaration:
2284 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002285 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002286 llvm_unreachable("Pack expansion pattern has no parameter packs");
2287
2288 case TemplateArgument::Type:
2289 if (TypeSourceInfo *Expansion
2290 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002291 EllipsisLoc,
2292 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002293 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2294 Expansion);
2295 break;
2296 }
2297
2298 return TemplateArgumentLoc();
2299 }
2300
Douglas Gregor968f23a2011-01-03 19:31:53 +00002301 /// \brief Build a new expression pack expansion.
2302 ///
2303 /// By default, performs semantic analysis to build a new pack expansion
2304 /// for an expression. Subclasses may override this routine to provide
2305 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002306 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2307 llvm::Optional<unsigned> NumExpansions) {
2308 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002309 }
2310
John McCall31f82722010-11-12 08:19:04 +00002311private:
2312 QualType TransformTypeInObjectScope(QualType T,
2313 QualType ObjectType,
2314 NamedDecl *FirstQualifierInScope,
2315 NestedNameSpecifier *Prefix);
2316
2317 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2318 QualType ObjectType,
2319 NamedDecl *FirstQualifierInScope,
2320 NestedNameSpecifier *Prefix);
Douglas Gregor14454802011-02-25 02:25:35 +00002321
2322 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2323 QualType ObjectType,
2324 NamedDecl *FirstQualifierInScope,
2325 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002326};
Douglas Gregora16548e2009-08-11 05:31:07 +00002327
Douglas Gregorebe10102009-08-20 07:17:43 +00002328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002329StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002330 if (!S)
2331 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002332
Douglas Gregorebe10102009-08-20 07:17:43 +00002333 switch (S->getStmtClass()) {
2334 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002335
Douglas Gregorebe10102009-08-20 07:17:43 +00002336 // Transform individual statement nodes
2337#define STMT(Node, Parent) \
2338 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002339#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002340#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002341#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002342
Douglas Gregorebe10102009-08-20 07:17:43 +00002343 // Transform expressions by calling TransformExpr.
2344#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002345#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002346#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002347#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002348 {
John McCalldadc5752010-08-24 06:29:42 +00002349 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002350 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002351 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002352
John McCallb268a282010-08-23 23:25:46 +00002353 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002354 }
Mike Stump11289f42009-09-09 15:08:12 +00002355 }
2356
John McCallc3007a22010-10-26 07:05:15 +00002357 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002358}
Mike Stump11289f42009-09-09 15:08:12 +00002359
2360
Douglas Gregore922c772009-08-04 22:27:00 +00002361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002362ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 if (!E)
2364 return SemaRef.Owned(E);
2365
2366 switch (E->getStmtClass()) {
2367 case Stmt::NoStmtClass: break;
2368#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002369#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002370#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002371 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002372#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002373 }
2374
John McCallc3007a22010-10-26 07:05:15 +00002375 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002376}
2377
2378template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002379bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2380 unsigned NumInputs,
2381 bool IsCall,
2382 llvm::SmallVectorImpl<Expr *> &Outputs,
2383 bool *ArgChanged) {
2384 for (unsigned I = 0; I != NumInputs; ++I) {
2385 // If requested, drop call arguments that need to be dropped.
2386 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2387 if (ArgChanged)
2388 *ArgChanged = true;
2389
2390 break;
2391 }
2392
Douglas Gregor968f23a2011-01-03 19:31:53 +00002393 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2394 Expr *Pattern = Expansion->getPattern();
2395
2396 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2397 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2398 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2399
2400 // Determine whether the set of unexpanded parameter packs can and should
2401 // be expanded.
2402 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002403 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002404 llvm::Optional<unsigned> OrigNumExpansions
2405 = Expansion->getNumExpansions();
2406 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002407 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2408 Pattern->getSourceRange(),
2409 Unexpanded.data(),
2410 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002411 Expand, RetainExpansion,
2412 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002413 return true;
2414
2415 if (!Expand) {
2416 // The transform has determined that we should perform a simple
2417 // transformation on the pack expansion, producing another pack
2418 // expansion.
2419 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2420 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2421 if (OutPattern.isInvalid())
2422 return true;
2423
2424 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002425 Expansion->getEllipsisLoc(),
2426 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002427 if (Out.isInvalid())
2428 return true;
2429
2430 if (ArgChanged)
2431 *ArgChanged = true;
2432 Outputs.push_back(Out.get());
2433 continue;
2434 }
2435
2436 // The transform has determined that we should perform an elementwise
2437 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002438 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002439 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2440 ExprResult Out = getDerived().TransformExpr(Pattern);
2441 if (Out.isInvalid())
2442 return true;
2443
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002444 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002445 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2446 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002447 if (Out.isInvalid())
2448 return true;
2449 }
2450
Douglas Gregor968f23a2011-01-03 19:31:53 +00002451 if (ArgChanged)
2452 *ArgChanged = true;
2453 Outputs.push_back(Out.get());
2454 }
2455
2456 continue;
2457 }
2458
Douglas Gregora3efea12011-01-03 19:04:46 +00002459 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2460 if (Result.isInvalid())
2461 return true;
2462
2463 if (Result.get() != Inputs[I] && ArgChanged)
2464 *ArgChanged = true;
2465
2466 Outputs.push_back(Result.get());
2467 }
2468
2469 return false;
2470}
2471
2472template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002473NestedNameSpecifier *
2474TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002475 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002476 QualType ObjectType,
2477 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002478 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002479
Douglas Gregorebe10102009-08-20 07:17:43 +00002480 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002481 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002482 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002483 ObjectType,
2484 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002485 if (!Prefix)
2486 return 0;
2487 }
Mike Stump11289f42009-09-09 15:08:12 +00002488
Douglas Gregor1135c352009-08-06 05:28:30 +00002489 switch (NNS->getKind()) {
2490 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002491 if (Prefix) {
2492 // The object type and qualifier-in-scope really apply to the
2493 // leftmost entity.
2494 ObjectType = QualType();
2495 FirstQualifierInScope = 0;
2496 }
2497
Mike Stump11289f42009-09-09 15:08:12 +00002498 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002499 "Identifier nested-name-specifier with no prefix or object type");
2500 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2501 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002502 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002503
2504 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002505 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002506 ObjectType,
2507 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002508
Douglas Gregor1135c352009-08-06 05:28:30 +00002509 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002510 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002511 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002512 getDerived().TransformDecl(Range.getBegin(),
2513 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002514 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002515 Prefix == NNS->getPrefix() &&
2516 NS == NNS->getAsNamespace())
2517 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002518
Douglas Gregor1135c352009-08-06 05:28:30 +00002519 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2520 }
Mike Stump11289f42009-09-09 15:08:12 +00002521
Douglas Gregor7b26ff92011-02-24 02:36:08 +00002522 case NestedNameSpecifier::NamespaceAlias: {
2523 NamespaceAliasDecl *Alias
2524 = cast_or_null<NamespaceAliasDecl>(
2525 getDerived().TransformDecl(Range.getBegin(),
2526 NNS->getAsNamespaceAlias()));
2527 if (!getDerived().AlwaysRebuild() &&
2528 Prefix == NNS->getPrefix() &&
2529 Alias == NNS->getAsNamespaceAlias())
2530 return NNS;
2531
2532 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias);
2533 }
2534
Douglas Gregor1135c352009-08-06 05:28:30 +00002535 case NestedNameSpecifier::Global:
2536 // There is no meaningful transformation that one could perform on the
2537 // global scope.
2538 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002539
Douglas Gregor1135c352009-08-06 05:28:30 +00002540 case NestedNameSpecifier::TypeSpecWithTemplate:
2541 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002542 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002543 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2544 ObjectType,
2545 FirstQualifierInScope,
2546 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002547 if (T.isNull())
2548 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002549
Douglas Gregor1135c352009-08-06 05:28:30 +00002550 if (!getDerived().AlwaysRebuild() &&
2551 Prefix == NNS->getPrefix() &&
2552 T == QualType(NNS->getAsType(), 0))
2553 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002554
2555 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2556 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002557 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002558 }
2559 }
Mike Stump11289f42009-09-09 15:08:12 +00002560
Douglas Gregor1135c352009-08-06 05:28:30 +00002561 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002562 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002563}
2564
2565template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002566NestedNameSpecifierLoc
2567TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2568 NestedNameSpecifierLoc NNS,
2569 QualType ObjectType,
2570 NamedDecl *FirstQualifierInScope) {
2571 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2572 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2573 Qualifier = Qualifier.getPrefix())
2574 Qualifiers.push_back(Qualifier);
2575
2576 CXXScopeSpec SS;
2577 while (!Qualifiers.empty()) {
2578 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2579 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2580
2581 switch (QNNS->getKind()) {
2582 case NestedNameSpecifier::Identifier:
2583 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2584 *QNNS->getAsIdentifier(),
2585 Q.getLocalBeginLoc(),
2586 Q.getLocalEndLoc(),
2587 ObjectType, false, SS,
2588 FirstQualifierInScope, false))
2589 return NestedNameSpecifierLoc();
2590
2591 break;
2592
2593 case NestedNameSpecifier::Namespace: {
2594 NamespaceDecl *NS
2595 = cast_or_null<NamespaceDecl>(
2596 getDerived().TransformDecl(
2597 Q.getLocalBeginLoc(),
2598 QNNS->getAsNamespace()));
2599 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2600 break;
2601 }
2602
2603 case NestedNameSpecifier::NamespaceAlias: {
2604 NamespaceAliasDecl *Alias
2605 = cast_or_null<NamespaceAliasDecl>(
2606 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2607 QNNS->getAsNamespaceAlias()));
2608 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2609 Q.getLocalEndLoc());
2610 break;
2611 }
2612
2613 case NestedNameSpecifier::Global:
2614 // There is no meaningful transformation that one could perform on the
2615 // global scope.
2616 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2617 break;
2618
2619 case NestedNameSpecifier::TypeSpecWithTemplate:
2620 case NestedNameSpecifier::TypeSpec: {
2621 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2622 FirstQualifierInScope, SS);
2623
2624 if (!TL)
2625 return NestedNameSpecifierLoc();
2626
2627 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2628 (SemaRef.getLangOptions().CPlusPlus0x &&
2629 TL.getType()->isEnumeralType())) {
2630 assert(!TL.getType().hasLocalQualifiers() &&
2631 "Can't get cv-qualifiers here");
2632 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2633 Q.getLocalEndLoc());
2634 break;
2635 }
2636
2637 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2638 << TL.getType() << SS.getRange();
2639 return NestedNameSpecifierLoc();
2640 }
Douglas Gregore16af532011-02-28 18:50:33 +00002641 }
Douglas Gregor14454802011-02-25 02:25:35 +00002642
Douglas Gregore16af532011-02-28 18:50:33 +00002643 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002644 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002645 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002646 }
2647
2648 // Don't rebuild the nested-name-specifier if we don't have to.
2649 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2650 !getDerived().AlwaysRebuild())
2651 return NNS;
2652
2653 // If we can re-use the source-location data from the original
2654 // nested-name-specifier, do so.
2655 if (SS.location_size() == NNS.getDataLength() &&
2656 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2657 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2658
2659 // Allocate new nested-name-specifier location information.
2660 return SS.getWithLocInContext(SemaRef.Context);
2661}
2662
2663template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002664DeclarationNameInfo
2665TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002666::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002667 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002668 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002669 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002670
2671 switch (Name.getNameKind()) {
2672 case DeclarationName::Identifier:
2673 case DeclarationName::ObjCZeroArgSelector:
2674 case DeclarationName::ObjCOneArgSelector:
2675 case DeclarationName::ObjCMultiArgSelector:
2676 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002677 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002678 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002679 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002680
Douglas Gregorf816bd72009-09-03 22:13:48 +00002681 case DeclarationName::CXXConstructorName:
2682 case DeclarationName::CXXDestructorName:
2683 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002684 TypeSourceInfo *NewTInfo;
2685 CanQualType NewCanTy;
2686 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002687 NewTInfo = getDerived().TransformType(OldTInfo);
2688 if (!NewTInfo)
2689 return DeclarationNameInfo();
2690 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002691 }
2692 else {
2693 NewTInfo = 0;
2694 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002695 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002696 if (NewT.isNull())
2697 return DeclarationNameInfo();
2698 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2699 }
Mike Stump11289f42009-09-09 15:08:12 +00002700
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002701 DeclarationName NewName
2702 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2703 NewCanTy);
2704 DeclarationNameInfo NewNameInfo(NameInfo);
2705 NewNameInfo.setName(NewName);
2706 NewNameInfo.setNamedTypeInfo(NewTInfo);
2707 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002708 }
Mike Stump11289f42009-09-09 15:08:12 +00002709 }
2710
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002711 assert(0 && "Unknown name kind.");
2712 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002713}
2714
2715template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002716TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002717TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002718 QualType ObjectType,
2719 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00002720 // FIXME: This routine needs to go away.
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002721 SourceLocation Loc = getDerived().getBaseLocation();
2722
Douglas Gregor71dc5092009-08-06 06:41:21 +00002723 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002724 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002725 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002726 /*FIXME*/ SourceRange(Loc),
2727 ObjectType,
2728 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002729 if (!NNS)
2730 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002731
Douglas Gregor71dc5092009-08-06 06:41:21 +00002732 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002733 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002734 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002735 if (!TransTemplate)
2736 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002737
Douglas Gregor71dc5092009-08-06 06:41:21 +00002738 if (!getDerived().AlwaysRebuild() &&
2739 NNS == QTN->getQualifier() &&
2740 TransTemplate == Template)
2741 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002742
Douglas Gregor9db53502011-03-02 18:07:45 +00002743 CXXScopeSpec SS;
2744 SS.MakeTrivial(SemaRef.Context, NNS, Loc);
2745 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
Douglas Gregor71dc5092009-08-06 06:41:21 +00002746 TransTemplate);
2747 }
Mike Stump11289f42009-09-09 15:08:12 +00002748
John McCalle66edc12009-11-24 19:00:30 +00002749 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002750 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002751 }
Mike Stump11289f42009-09-09 15:08:12 +00002752
Douglas Gregor71dc5092009-08-06 06:41:21 +00002753 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002754 NestedNameSpecifier *NNS = DTN->getQualifier();
2755 if (NNS) {
2756 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2757 /*FIXME:*/SourceRange(Loc),
2758 ObjectType,
2759 FirstQualifierInScope);
2760 if (!NNS) return TemplateName();
2761
2762 // These apply to the scope specifier, not the template.
2763 ObjectType = QualType();
2764 FirstQualifierInScope = 0;
2765 }
Mike Stump11289f42009-09-09 15:08:12 +00002766
Douglas Gregor71dc5092009-08-06 06:41:21 +00002767 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002768 NNS == DTN->getQualifier() &&
2769 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002770 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002771
Douglas Gregor9db53502011-03-02 18:07:45 +00002772 // FIXME: Bad source-location information all around.
2773 CXXScopeSpec SS;
2774 SS.MakeTrivial(SemaRef.Context, NNS, getDerived().getBaseLocation());
Douglas Gregora5614c52010-09-08 23:56:00 +00002775 if (DTN->isIdentifier()) {
Douglas Gregor9db53502011-03-02 18:07:45 +00002776 return getDerived().RebuildTemplateName(SS,
2777 *DTN->getIdentifier(),
2778 getDerived().getBaseLocation(),
John McCall31f82722010-11-12 08:19:04 +00002779 ObjectType,
2780 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002781 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002782
Douglas Gregor9db53502011-03-02 18:07:45 +00002783 return getDerived().RebuildTemplateName(SS, DTN->getOperator(),
2784 getDerived().getBaseLocation(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002785 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002786 }
Mike Stump11289f42009-09-09 15:08:12 +00002787
Douglas Gregor71dc5092009-08-06 06:41:21 +00002788 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002789 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002790 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002791 if (!TransTemplate)
2792 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002793
Douglas Gregor71dc5092009-08-06 06:41:21 +00002794 if (!getDerived().AlwaysRebuild() &&
2795 TransTemplate == Template)
2796 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002797
Douglas Gregor71dc5092009-08-06 06:41:21 +00002798 return TemplateName(TransTemplate);
2799 }
Mike Stump11289f42009-09-09 15:08:12 +00002800
Douglas Gregor5590be02011-01-15 06:45:20 +00002801 if (SubstTemplateTemplateParmPackStorage *SubstPack
2802 = Name.getAsSubstTemplateTemplateParmPack()) {
2803 TemplateTemplateParmDecl *TransParam
2804 = cast_or_null<TemplateTemplateParmDecl>(
2805 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2806 if (!TransParam)
2807 return TemplateName();
2808
2809 if (!getDerived().AlwaysRebuild() &&
2810 TransParam == SubstPack->getParameterPack())
2811 return Name;
2812
2813 return getDerived().RebuildTemplateName(TransParam,
2814 SubstPack->getArgumentPack());
2815 }
2816
John McCalle66edc12009-11-24 19:00:30 +00002817 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002818 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002819 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002820}
2821
2822template<typename Derived>
Douglas Gregor9db53502011-03-02 18:07:45 +00002823TemplateName
2824TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2825 TemplateName Name,
2826 SourceLocation NameLoc,
2827 QualType ObjectType,
2828 NamedDecl *FirstQualifierInScope) {
2829 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2830 TemplateDecl *Template = QTN->getTemplateDecl();
2831 assert(Template && "qualified template name must refer to a template");
2832
2833 TemplateDecl *TransTemplate
2834 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2835 Template));
2836 if (!TransTemplate)
2837 return TemplateName();
2838
2839 if (!getDerived().AlwaysRebuild() &&
2840 SS.getScopeRep() == QTN->getQualifier() &&
2841 TransTemplate == Template)
2842 return Name;
2843
2844 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2845 TransTemplate);
2846 }
2847
2848 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2849 if (SS.getScopeRep()) {
2850 // These apply to the scope specifier, not the template.
2851 ObjectType = QualType();
2852 FirstQualifierInScope = 0;
2853 }
2854
2855 if (!getDerived().AlwaysRebuild() &&
2856 SS.getScopeRep() == DTN->getQualifier() &&
2857 ObjectType.isNull())
2858 return Name;
2859
2860 if (DTN->isIdentifier()) {
2861 return getDerived().RebuildTemplateName(SS,
2862 *DTN->getIdentifier(),
2863 NameLoc,
2864 ObjectType,
2865 FirstQualifierInScope);
2866 }
2867
2868 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2869 ObjectType);
2870 }
2871
2872 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2873 TemplateDecl *TransTemplate
2874 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2875 Template));
2876 if (!TransTemplate)
2877 return TemplateName();
2878
2879 if (!getDerived().AlwaysRebuild() &&
2880 TransTemplate == Template)
2881 return Name;
2882
2883 return TemplateName(TransTemplate);
2884 }
2885
2886 if (SubstTemplateTemplateParmPackStorage *SubstPack
2887 = Name.getAsSubstTemplateTemplateParmPack()) {
2888 TemplateTemplateParmDecl *TransParam
2889 = cast_or_null<TemplateTemplateParmDecl>(
2890 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2891 if (!TransParam)
2892 return TemplateName();
2893
2894 if (!getDerived().AlwaysRebuild() &&
2895 TransParam == SubstPack->getParameterPack())
2896 return Name;
2897
2898 return getDerived().RebuildTemplateName(TransParam,
2899 SubstPack->getArgumentPack());
2900 }
2901
2902 // These should be getting filtered out before they reach the AST.
2903 llvm_unreachable("overloaded function decl survived to here");
2904 return TemplateName();
2905}
2906
2907template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002908void TreeTransform<Derived>::InventTemplateArgumentLoc(
2909 const TemplateArgument &Arg,
2910 TemplateArgumentLoc &Output) {
2911 SourceLocation Loc = getDerived().getBaseLocation();
2912 switch (Arg.getKind()) {
2913 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002914 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002915 break;
2916
2917 case TemplateArgument::Type:
2918 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002919 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002920
John McCall0ad16662009-10-29 08:12:44 +00002921 break;
2922
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002923 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002924 case TemplateArgument::TemplateExpansion: {
2925 NestedNameSpecifierLocBuilder Builder;
2926 TemplateName Template = Arg.getAsTemplate();
2927 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2928 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2929 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2930 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2931
2932 if (Arg.getKind() == TemplateArgument::Template)
2933 Output = TemplateArgumentLoc(Arg,
2934 Builder.getWithLocInContext(SemaRef.Context),
2935 Loc);
2936 else
2937 Output = TemplateArgumentLoc(Arg,
2938 Builder.getWithLocInContext(SemaRef.Context),
2939 Loc, Loc);
2940
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002941 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002942 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002943
John McCall0ad16662009-10-29 08:12:44 +00002944 case TemplateArgument::Expression:
2945 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2946 break;
2947
2948 case TemplateArgument::Declaration:
2949 case TemplateArgument::Integral:
2950 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002951 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002952 break;
2953 }
2954}
2955
2956template<typename Derived>
2957bool TreeTransform<Derived>::TransformTemplateArgument(
2958 const TemplateArgumentLoc &Input,
2959 TemplateArgumentLoc &Output) {
2960 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002961 switch (Arg.getKind()) {
2962 case TemplateArgument::Null:
2963 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002964 Output = Input;
2965 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002966
Douglas Gregore922c772009-08-04 22:27:00 +00002967 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002968 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002969 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002970 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002971
2972 DI = getDerived().TransformType(DI);
2973 if (!DI) return true;
2974
2975 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2976 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002977 }
Mike Stump11289f42009-09-09 15:08:12 +00002978
Douglas Gregore922c772009-08-04 22:27:00 +00002979 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002980 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002981 DeclarationName Name;
2982 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2983 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002984 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002985 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002986 if (!D) return true;
2987
John McCall0d07eb32009-10-29 18:45:58 +00002988 Expr *SourceExpr = Input.getSourceDeclExpression();
2989 if (SourceExpr) {
2990 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002991 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002992 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002993 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002994 }
2995
2996 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002997 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002998 }
Mike Stump11289f42009-09-09 15:08:12 +00002999
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003000 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003001 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3002 if (QualifierLoc) {
3003 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3004 if (!QualifierLoc)
3005 return true;
3006 }
3007
Alexis Hunta8136cc2010-05-05 15:23:54 +00003008 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003009 TemplateName Template
3010 = getDerived().TransformTemplateName(Arg.getAsTemplate());
3011 if (Template.isNull())
3012 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003013
Douglas Gregor9d802122011-03-02 17:09:35 +00003014 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003015 Input.getTemplateNameLoc());
3016 return false;
3017 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003018
3019 case TemplateArgument::TemplateExpansion:
3020 llvm_unreachable("Caller should expand pack expansions");
3021
Douglas Gregore922c772009-08-04 22:27:00 +00003022 case TemplateArgument::Expression: {
3023 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00003024 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00003025 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003026
John McCall0ad16662009-10-29 08:12:44 +00003027 Expr *InputExpr = Input.getSourceExpression();
3028 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3029
John McCalldadc5752010-08-24 06:29:42 +00003030 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00003031 = getDerived().TransformExpr(InputExpr);
3032 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003033 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003034 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003035 }
Mike Stump11289f42009-09-09 15:08:12 +00003036
Douglas Gregore922c772009-08-04 22:27:00 +00003037 case TemplateArgument::Pack: {
3038 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
3039 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00003040 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00003041 AEnd = Arg.pack_end();
3042 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00003043
John McCall0ad16662009-10-29 08:12:44 +00003044 // FIXME: preserve source information here when we start
3045 // caring about parameter packs.
3046
John McCall0d07eb32009-10-29 18:45:58 +00003047 TemplateArgumentLoc InputArg;
3048 TemplateArgumentLoc OutputArg;
3049 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3050 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00003051 return true;
3052
John McCall0d07eb32009-10-29 18:45:58 +00003053 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00003054 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00003055
3056 TemplateArgument *TransformedArgsPtr
3057 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3058 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3059 TransformedArgsPtr);
3060 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3061 TransformedArgs.size()),
3062 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003063 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003064 }
3065 }
Mike Stump11289f42009-09-09 15:08:12 +00003066
Douglas Gregore922c772009-08-04 22:27:00 +00003067 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003068 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003069}
3070
Douglas Gregorfe921a72010-12-20 23:36:19 +00003071/// \brief Iterator adaptor that invents template argument location information
3072/// for each of the template arguments in its underlying iterator.
3073template<typename Derived, typename InputIterator>
3074class TemplateArgumentLocInventIterator {
3075 TreeTransform<Derived> &Self;
3076 InputIterator Iter;
3077
3078public:
3079 typedef TemplateArgumentLoc value_type;
3080 typedef TemplateArgumentLoc reference;
3081 typedef typename std::iterator_traits<InputIterator>::difference_type
3082 difference_type;
3083 typedef std::input_iterator_tag iterator_category;
3084
3085 class pointer {
3086 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003087
Douglas Gregorfe921a72010-12-20 23:36:19 +00003088 public:
3089 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3090
3091 const TemplateArgumentLoc *operator->() const { return &Arg; }
3092 };
3093
3094 TemplateArgumentLocInventIterator() { }
3095
3096 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3097 InputIterator Iter)
3098 : Self(Self), Iter(Iter) { }
3099
3100 TemplateArgumentLocInventIterator &operator++() {
3101 ++Iter;
3102 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003103 }
3104
Douglas Gregorfe921a72010-12-20 23:36:19 +00003105 TemplateArgumentLocInventIterator operator++(int) {
3106 TemplateArgumentLocInventIterator Old(*this);
3107 ++(*this);
3108 return Old;
3109 }
3110
3111 reference operator*() const {
3112 TemplateArgumentLoc Result;
3113 Self.InventTemplateArgumentLoc(*Iter, Result);
3114 return Result;
3115 }
3116
3117 pointer operator->() const { return pointer(**this); }
3118
3119 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3120 const TemplateArgumentLocInventIterator &Y) {
3121 return X.Iter == Y.Iter;
3122 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003123
Douglas Gregorfe921a72010-12-20 23:36:19 +00003124 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3125 const TemplateArgumentLocInventIterator &Y) {
3126 return X.Iter != Y.Iter;
3127 }
3128};
3129
Douglas Gregor42cafa82010-12-20 17:42:22 +00003130template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003131template<typename InputIterator>
3132bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3133 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003134 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003135 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003136 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003137 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003138
3139 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3140 // Unpack argument packs, which we translate them into separate
3141 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003142 // FIXME: We could do much better if we could guarantee that the
3143 // TemplateArgumentLocInfo for the pack expansion would be usable for
3144 // all of the template arguments in the argument pack.
3145 typedef TemplateArgumentLocInventIterator<Derived,
3146 TemplateArgument::pack_iterator>
3147 PackLocIterator;
3148 if (TransformTemplateArguments(PackLocIterator(*this,
3149 In.getArgument().pack_begin()),
3150 PackLocIterator(*this,
3151 In.getArgument().pack_end()),
3152 Outputs))
3153 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003154
3155 continue;
3156 }
3157
3158 if (In.getArgument().isPackExpansion()) {
3159 // We have a pack expansion, for which we will be substituting into
3160 // the pattern.
3161 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003162 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003163 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003164 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3165 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003166
3167 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3168 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3169 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3170
3171 // Determine whether the set of unexpanded parameter packs can and should
3172 // be expanded.
3173 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003174 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003175 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003176 if (getDerived().TryExpandParameterPacks(Ellipsis,
3177 Pattern.getSourceRange(),
3178 Unexpanded.data(),
3179 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003180 Expand,
3181 RetainExpansion,
3182 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003183 return true;
3184
3185 if (!Expand) {
3186 // The transform has determined that we should perform a simple
3187 // transformation on the pack expansion, producing another pack
3188 // expansion.
3189 TemplateArgumentLoc OutPattern;
3190 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3191 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3192 return true;
3193
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003194 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3195 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003196 if (Out.getArgument().isNull())
3197 return true;
3198
3199 Outputs.addArgument(Out);
3200 continue;
3201 }
3202
3203 // The transform has determined that we should perform an elementwise
3204 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003205 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003206 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3207
3208 if (getDerived().TransformTemplateArgument(Pattern, Out))
3209 return true;
3210
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003211 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003212 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3213 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003214 if (Out.getArgument().isNull())
3215 return true;
3216 }
3217
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003218 Outputs.addArgument(Out);
3219 }
3220
Douglas Gregor48d24112011-01-10 20:53:55 +00003221 // If we're supposed to retain a pack expansion, do so by temporarily
3222 // forgetting the partially-substituted parameter pack.
3223 if (RetainExpansion) {
3224 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3225
3226 if (getDerived().TransformTemplateArgument(Pattern, Out))
3227 return true;
3228
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003229 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3230 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003231 if (Out.getArgument().isNull())
3232 return true;
3233
3234 Outputs.addArgument(Out);
3235 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003236
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003237 continue;
3238 }
3239
3240 // The simple case:
3241 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003242 return true;
3243
3244 Outputs.addArgument(Out);
3245 }
3246
3247 return false;
3248
3249}
3250
Douglas Gregord6ff3322009-08-04 16:50:30 +00003251//===----------------------------------------------------------------------===//
3252// Type transformation
3253//===----------------------------------------------------------------------===//
3254
3255template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003256QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003257 if (getDerived().AlreadyTransformed(T))
3258 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003259
John McCall550e0c22009-10-21 00:40:46 +00003260 // Temporary workaround. All of these transformations should
3261 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003262 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3263 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003264
John McCall31f82722010-11-12 08:19:04 +00003265 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003266
John McCall550e0c22009-10-21 00:40:46 +00003267 if (!NewDI)
3268 return QualType();
3269
3270 return NewDI->getType();
3271}
3272
3273template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003274TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003275 if (getDerived().AlreadyTransformed(DI->getType()))
3276 return DI;
3277
3278 TypeLocBuilder TLB;
3279
3280 TypeLoc TL = DI->getTypeLoc();
3281 TLB.reserve(TL.getFullDataSize());
3282
John McCall31f82722010-11-12 08:19:04 +00003283 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003284 if (Result.isNull())
3285 return 0;
3286
John McCallbcd03502009-12-07 02:54:59 +00003287 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003288}
3289
3290template<typename Derived>
3291QualType
John McCall31f82722010-11-12 08:19:04 +00003292TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003293 switch (T.getTypeLocClass()) {
3294#define ABSTRACT_TYPELOC(CLASS, PARENT)
3295#define TYPELOC(CLASS, PARENT) \
3296 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003297 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003298#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003299 }
Mike Stump11289f42009-09-09 15:08:12 +00003300
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003301 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003302 return QualType();
3303}
3304
3305/// FIXME: By default, this routine adds type qualifiers only to types
3306/// that can have qualifiers, and silently suppresses those qualifiers
3307/// that are not permitted (e.g., qualifiers on reference or function
3308/// types). This is the right thing for template instantiation, but
3309/// probably not for other clients.
3310template<typename Derived>
3311QualType
3312TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003313 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003314 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003315
John McCall31f82722010-11-12 08:19:04 +00003316 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003317 if (Result.isNull())
3318 return QualType();
3319
3320 // Silently suppress qualifiers if the result type can't be qualified.
3321 // FIXME: this is the right thing for template instantiation, but
3322 // probably not for other clients.
3323 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003324 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003325
John McCallcb0f89a2010-06-05 06:41:15 +00003326 if (!Quals.empty()) {
3327 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3328 TLB.push<QualifiedTypeLoc>(Result);
3329 // No location information to preserve.
3330 }
John McCall550e0c22009-10-21 00:40:46 +00003331
3332 return Result;
3333}
3334
John McCall31f82722010-11-12 08:19:04 +00003335/// \brief Transforms a type that was written in a scope specifier,
3336/// given an object type, the results of unqualified lookup, and
3337/// an already-instantiated prefix.
3338///
3339/// The object type is provided iff the scope specifier qualifies the
3340/// member of a dependent member-access expression. The prefix is
3341/// provided iff the the scope specifier in which this appears has a
3342/// prefix.
3343///
3344/// This is private to TreeTransform.
3345template<typename Derived>
3346QualType
3347TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3348 QualType ObjectType,
3349 NamedDecl *UnqualLookup,
3350 NestedNameSpecifier *Prefix) {
3351 if (getDerived().AlreadyTransformed(T))
3352 return T;
3353
3354 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003355 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003356
3357 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3358 UnqualLookup, Prefix);
3359 if (!TSI) return QualType();
3360 return TSI->getType();
3361}
3362
3363template<typename Derived>
3364TypeSourceInfo *
3365TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3366 QualType ObjectType,
3367 NamedDecl *UnqualLookup,
3368 NestedNameSpecifier *Prefix) {
Douglas Gregor14454802011-02-25 02:25:35 +00003369 // TODO: in some cases, we might have some verification to do here.
John McCall31f82722010-11-12 08:19:04 +00003370 if (ObjectType.isNull())
3371 return getDerived().TransformType(TSI);
3372
3373 QualType T = TSI->getType();
3374 if (getDerived().AlreadyTransformed(T))
3375 return TSI;
3376
3377 TypeLocBuilder TLB;
3378 QualType Result;
3379
3380 if (isa<TemplateSpecializationType>(T)) {
3381 TemplateSpecializationTypeLoc TL
3382 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3383
3384 TemplateName Template =
3385 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3386 ObjectType, UnqualLookup);
3387 if (Template.isNull()) return 0;
3388
3389 Result = getDerived()
3390 .TransformTemplateSpecializationType(TLB, TL, Template);
3391 } else if (isa<DependentTemplateSpecializationType>(T)) {
3392 DependentTemplateSpecializationTypeLoc TL
3393 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3394
Douglas Gregor5a064722011-02-28 17:23:35 +00003395 TemplateName Template
3396 = SemaRef.Context.getDependentTemplateName(
3397 TL.getTypePtr()->getQualifier(),
3398 TL.getTypePtr()->getIdentifier());
3399
3400 Template = getDerived().TransformTemplateName(Template, ObjectType,
3401 UnqualLookup);
3402 if (Template.isNull())
3403 return 0;
3404
3405 Result = getDerived().TransformDependentTemplateSpecializationType(TLB, TL,
3406 Template);
John McCall31f82722010-11-12 08:19:04 +00003407 } else {
3408 // Nothing special needs to be done for these.
3409 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3410 }
3411
3412 if (Result.isNull()) return 0;
3413 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3414}
3415
Douglas Gregor14454802011-02-25 02:25:35 +00003416template<typename Derived>
3417TypeLoc
3418TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3419 QualType ObjectType,
3420 NamedDecl *UnqualLookup,
3421 CXXScopeSpec &SS) {
3422 // FIXME: Painfully copy-paste from the above!
3423
Douglas Gregor14454802011-02-25 02:25:35 +00003424 QualType T = TL.getType();
3425 if (getDerived().AlreadyTransformed(T))
3426 return TL;
3427
3428 TypeLocBuilder TLB;
3429 QualType Result;
3430
3431 if (isa<TemplateSpecializationType>(T)) {
3432 TemplateSpecializationTypeLoc SpecTL
3433 = cast<TemplateSpecializationTypeLoc>(TL);
3434
3435 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003436 getDerived().TransformTemplateName(SS,
3437 SpecTL.getTypePtr()->getTemplateName(),
3438 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003439 ObjectType, UnqualLookup);
3440 if (Template.isNull())
3441 return TypeLoc();
3442
3443 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3444 Template);
3445 } else if (isa<DependentTemplateSpecializationType>(T)) {
3446 DependentTemplateSpecializationTypeLoc SpecTL
3447 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3448
Douglas Gregor5a064722011-02-28 17:23:35 +00003449 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003450 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003451 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003452 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003453 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003454 if (Template.isNull())
3455 return TypeLoc();
3456
Douglas Gregor14454802011-02-25 02:25:35 +00003457 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003458 SpecTL,
3459 Template);
Douglas Gregor14454802011-02-25 02:25:35 +00003460 } else {
3461 // Nothing special needs to be done for these.
3462 Result = getDerived().TransformType(TLB, TL);
3463 }
3464
3465 if (Result.isNull())
3466 return TypeLoc();
3467
3468 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3469}
3470
John McCall550e0c22009-10-21 00:40:46 +00003471template <class TyLoc> static inline
3472QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3473 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3474 NewT.setNameLoc(T.getNameLoc());
3475 return T.getType();
3476}
3477
John McCall550e0c22009-10-21 00:40:46 +00003478template<typename Derived>
3479QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003480 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003481 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3482 NewT.setBuiltinLoc(T.getBuiltinLoc());
3483 if (T.needsExtraLocalData())
3484 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3485 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003486}
Mike Stump11289f42009-09-09 15:08:12 +00003487
Douglas Gregord6ff3322009-08-04 16:50:30 +00003488template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003489QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003490 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003491 // FIXME: recurse?
3492 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003493}
Mike Stump11289f42009-09-09 15:08:12 +00003494
Douglas Gregord6ff3322009-08-04 16:50:30 +00003495template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003496QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003497 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003498 QualType PointeeType
3499 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003500 if (PointeeType.isNull())
3501 return QualType();
3502
3503 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003504 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003505 // A dependent pointer type 'T *' has is being transformed such
3506 // that an Objective-C class type is being replaced for 'T'. The
3507 // resulting pointer type is an ObjCObjectPointerType, not a
3508 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003509 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003510
John McCall8b07ec22010-05-15 11:32:37 +00003511 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3512 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003513 return Result;
3514 }
John McCall31f82722010-11-12 08:19:04 +00003515
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003516 if (getDerived().AlwaysRebuild() ||
3517 PointeeType != TL.getPointeeLoc().getType()) {
3518 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3519 if (Result.isNull())
3520 return QualType();
3521 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003522
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003523 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3524 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003525 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003526}
Mike Stump11289f42009-09-09 15:08:12 +00003527
3528template<typename Derived>
3529QualType
John McCall550e0c22009-10-21 00:40:46 +00003530TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003531 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003532 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003533 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3534 if (PointeeType.isNull())
3535 return QualType();
3536
3537 QualType Result = TL.getType();
3538 if (getDerived().AlwaysRebuild() ||
3539 PointeeType != TL.getPointeeLoc().getType()) {
3540 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003541 TL.getSigilLoc());
3542 if (Result.isNull())
3543 return QualType();
3544 }
3545
Douglas Gregor049211a2010-04-22 16:50:51 +00003546 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003547 NewT.setSigilLoc(TL.getSigilLoc());
3548 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003549}
3550
John McCall70dd5f62009-10-30 00:06:24 +00003551/// Transforms a reference type. Note that somewhat paradoxically we
3552/// don't care whether the type itself is an l-value type or an r-value
3553/// type; we only care if the type was *written* as an l-value type
3554/// or an r-value type.
3555template<typename Derived>
3556QualType
3557TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003558 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003559 const ReferenceType *T = TL.getTypePtr();
3560
3561 // Note that this works with the pointee-as-written.
3562 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3563 if (PointeeType.isNull())
3564 return QualType();
3565
3566 QualType Result = TL.getType();
3567 if (getDerived().AlwaysRebuild() ||
3568 PointeeType != T->getPointeeTypeAsWritten()) {
3569 Result = getDerived().RebuildReferenceType(PointeeType,
3570 T->isSpelledAsLValue(),
3571 TL.getSigilLoc());
3572 if (Result.isNull())
3573 return QualType();
3574 }
3575
3576 // r-value references can be rebuilt as l-value references.
3577 ReferenceTypeLoc NewTL;
3578 if (isa<LValueReferenceType>(Result))
3579 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3580 else
3581 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3582 NewTL.setSigilLoc(TL.getSigilLoc());
3583
3584 return Result;
3585}
3586
Mike Stump11289f42009-09-09 15:08:12 +00003587template<typename Derived>
3588QualType
John McCall550e0c22009-10-21 00:40:46 +00003589TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003590 LValueReferenceTypeLoc TL) {
3591 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003592}
3593
Mike Stump11289f42009-09-09 15:08:12 +00003594template<typename Derived>
3595QualType
John McCall550e0c22009-10-21 00:40:46 +00003596TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003597 RValueReferenceTypeLoc TL) {
3598 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003599}
Mike Stump11289f42009-09-09 15:08:12 +00003600
Douglas Gregord6ff3322009-08-04 16:50:30 +00003601template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003602QualType
John McCall550e0c22009-10-21 00:40:46 +00003603TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003604 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003605 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003606
3607 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003608 if (PointeeType.isNull())
3609 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003610
John McCall550e0c22009-10-21 00:40:46 +00003611 // TODO: preserve source information for this.
3612 QualType ClassType
3613 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003614 if (ClassType.isNull())
3615 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003616
John McCall550e0c22009-10-21 00:40:46 +00003617 QualType Result = TL.getType();
3618 if (getDerived().AlwaysRebuild() ||
3619 PointeeType != T->getPointeeType() ||
3620 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003621 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3622 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003623 if (Result.isNull())
3624 return QualType();
3625 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003626
John McCall550e0c22009-10-21 00:40:46 +00003627 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3628 NewTL.setSigilLoc(TL.getSigilLoc());
3629
3630 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003631}
3632
Mike Stump11289f42009-09-09 15:08:12 +00003633template<typename Derived>
3634QualType
John McCall550e0c22009-10-21 00:40:46 +00003635TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003636 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003637 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003638 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003639 if (ElementType.isNull())
3640 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003641
John McCall550e0c22009-10-21 00:40:46 +00003642 QualType Result = TL.getType();
3643 if (getDerived().AlwaysRebuild() ||
3644 ElementType != T->getElementType()) {
3645 Result = getDerived().RebuildConstantArrayType(ElementType,
3646 T->getSizeModifier(),
3647 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003648 T->getIndexTypeCVRQualifiers(),
3649 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003650 if (Result.isNull())
3651 return QualType();
3652 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003653
John McCall550e0c22009-10-21 00:40:46 +00003654 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3655 NewTL.setLBracketLoc(TL.getLBracketLoc());
3656 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003657
John McCall550e0c22009-10-21 00:40:46 +00003658 Expr *Size = TL.getSizeExpr();
3659 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003660 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003661 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3662 }
3663 NewTL.setSizeExpr(Size);
3664
3665 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003666}
Mike Stump11289f42009-09-09 15:08:12 +00003667
Douglas Gregord6ff3322009-08-04 16:50:30 +00003668template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003669QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003670 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003671 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003672 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003673 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003674 if (ElementType.isNull())
3675 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003676
John McCall550e0c22009-10-21 00:40:46 +00003677 QualType Result = TL.getType();
3678 if (getDerived().AlwaysRebuild() ||
3679 ElementType != T->getElementType()) {
3680 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003681 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003682 T->getIndexTypeCVRQualifiers(),
3683 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003684 if (Result.isNull())
3685 return QualType();
3686 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003687
John McCall550e0c22009-10-21 00:40:46 +00003688 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3689 NewTL.setLBracketLoc(TL.getLBracketLoc());
3690 NewTL.setRBracketLoc(TL.getRBracketLoc());
3691 NewTL.setSizeExpr(0);
3692
3693 return Result;
3694}
3695
3696template<typename Derived>
3697QualType
3698TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003699 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003700 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003701 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3702 if (ElementType.isNull())
3703 return QualType();
3704
3705 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003706 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003707
John McCalldadc5752010-08-24 06:29:42 +00003708 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003709 = getDerived().TransformExpr(T->getSizeExpr());
3710 if (SizeResult.isInvalid())
3711 return QualType();
3712
John McCallb268a282010-08-23 23:25:46 +00003713 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003714
3715 QualType Result = TL.getType();
3716 if (getDerived().AlwaysRebuild() ||
3717 ElementType != T->getElementType() ||
3718 Size != T->getSizeExpr()) {
3719 Result = getDerived().RebuildVariableArrayType(ElementType,
3720 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003721 Size,
John McCall550e0c22009-10-21 00:40:46 +00003722 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003723 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003724 if (Result.isNull())
3725 return QualType();
3726 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003727
John McCall550e0c22009-10-21 00:40:46 +00003728 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3729 NewTL.setLBracketLoc(TL.getLBracketLoc());
3730 NewTL.setRBracketLoc(TL.getRBracketLoc());
3731 NewTL.setSizeExpr(Size);
3732
3733 return Result;
3734}
3735
3736template<typename Derived>
3737QualType
3738TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003739 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003740 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003741 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3742 if (ElementType.isNull())
3743 return QualType();
3744
3745 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003746 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003747
John McCall33ddac02011-01-19 10:06:00 +00003748 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3749 Expr *origSize = TL.getSizeExpr();
3750 if (!origSize) origSize = T->getSizeExpr();
3751
3752 ExprResult sizeResult
3753 = getDerived().TransformExpr(origSize);
3754 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003755 return QualType();
3756
John McCall33ddac02011-01-19 10:06:00 +00003757 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003758
3759 QualType Result = TL.getType();
3760 if (getDerived().AlwaysRebuild() ||
3761 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003762 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003763 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3764 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003765 size,
John McCall550e0c22009-10-21 00:40:46 +00003766 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003767 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003768 if (Result.isNull())
3769 return QualType();
3770 }
John McCall550e0c22009-10-21 00:40:46 +00003771
3772 // We might have any sort of array type now, but fortunately they
3773 // all have the same location layout.
3774 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3775 NewTL.setLBracketLoc(TL.getLBracketLoc());
3776 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003777 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003778
3779 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003780}
Mike Stump11289f42009-09-09 15:08:12 +00003781
3782template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003783QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003784 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003785 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003786 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003787
3788 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003789 QualType ElementType = getDerived().TransformType(T->getElementType());
3790 if (ElementType.isNull())
3791 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003792
Douglas Gregore922c772009-08-04 22:27:00 +00003793 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003794 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003795
John McCalldadc5752010-08-24 06:29:42 +00003796 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003797 if (Size.isInvalid())
3798 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003799
John McCall550e0c22009-10-21 00:40:46 +00003800 QualType Result = TL.getType();
3801 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003802 ElementType != T->getElementType() ||
3803 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003804 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003805 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003806 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003807 if (Result.isNull())
3808 return QualType();
3809 }
John McCall550e0c22009-10-21 00:40:46 +00003810
3811 // Result might be dependent or not.
3812 if (isa<DependentSizedExtVectorType>(Result)) {
3813 DependentSizedExtVectorTypeLoc NewTL
3814 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3815 NewTL.setNameLoc(TL.getNameLoc());
3816 } else {
3817 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3818 NewTL.setNameLoc(TL.getNameLoc());
3819 }
3820
3821 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003822}
Mike Stump11289f42009-09-09 15:08:12 +00003823
3824template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003825QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003826 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003827 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003828 QualType ElementType = getDerived().TransformType(T->getElementType());
3829 if (ElementType.isNull())
3830 return QualType();
3831
John McCall550e0c22009-10-21 00:40:46 +00003832 QualType Result = TL.getType();
3833 if (getDerived().AlwaysRebuild() ||
3834 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003835 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003836 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003837 if (Result.isNull())
3838 return QualType();
3839 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003840
John McCall550e0c22009-10-21 00:40:46 +00003841 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3842 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003843
John McCall550e0c22009-10-21 00:40:46 +00003844 return Result;
3845}
3846
3847template<typename Derived>
3848QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003849 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003850 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003851 QualType ElementType = getDerived().TransformType(T->getElementType());
3852 if (ElementType.isNull())
3853 return QualType();
3854
3855 QualType Result = TL.getType();
3856 if (getDerived().AlwaysRebuild() ||
3857 ElementType != T->getElementType()) {
3858 Result = getDerived().RebuildExtVectorType(ElementType,
3859 T->getNumElements(),
3860 /*FIXME*/ SourceLocation());
3861 if (Result.isNull())
3862 return QualType();
3863 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003864
John McCall550e0c22009-10-21 00:40:46 +00003865 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3866 NewTL.setNameLoc(TL.getNameLoc());
3867
3868 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003869}
Mike Stump11289f42009-09-09 15:08:12 +00003870
3871template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003872ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003873TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3874 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003875 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003876 TypeSourceInfo *NewDI = 0;
3877
3878 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3879 // If we're substituting into a pack expansion type and we know the
3880 TypeLoc OldTL = OldDI->getTypeLoc();
3881 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3882
3883 TypeLocBuilder TLB;
3884 TypeLoc NewTL = OldDI->getTypeLoc();
3885 TLB.reserve(NewTL.getFullDataSize());
3886
3887 QualType Result = getDerived().TransformType(TLB,
3888 OldExpansionTL.getPatternLoc());
3889 if (Result.isNull())
3890 return 0;
3891
3892 Result = RebuildPackExpansionType(Result,
3893 OldExpansionTL.getPatternLoc().getSourceRange(),
3894 OldExpansionTL.getEllipsisLoc(),
3895 NumExpansions);
3896 if (Result.isNull())
3897 return 0;
3898
3899 PackExpansionTypeLoc NewExpansionTL
3900 = TLB.push<PackExpansionTypeLoc>(Result);
3901 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3902 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3903 } else
3904 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003905 if (!NewDI)
3906 return 0;
3907
3908 if (NewDI == OldDI)
3909 return OldParm;
3910 else
3911 return ParmVarDecl::Create(SemaRef.Context,
3912 OldParm->getDeclContext(),
3913 OldParm->getLocation(),
3914 OldParm->getIdentifier(),
3915 NewDI->getType(),
3916 NewDI,
3917 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003918 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003919 /* DefArg */ NULL);
3920}
3921
3922template<typename Derived>
3923bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003924 TransformFunctionTypeParams(SourceLocation Loc,
3925 ParmVarDecl **Params, unsigned NumParams,
3926 const QualType *ParamTypes,
3927 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3928 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3929 for (unsigned i = 0; i != NumParams; ++i) {
3930 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003931 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003932 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003933 if (OldParm->isParameterPack()) {
3934 // We have a function parameter pack that may need to be expanded.
3935 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003936
Douglas Gregor5499af42011-01-05 23:12:31 +00003937 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003938 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3939 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3940 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3941 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003942 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3943
Douglas Gregor5499af42011-01-05 23:12:31 +00003944 // Determine whether we should expand the parameter packs.
3945 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003946 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003947 llvm::Optional<unsigned> OrigNumExpansions
3948 = ExpansionTL.getTypePtr()->getNumExpansions();
3949 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003950 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3951 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003952 Unexpanded.data(),
3953 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003954 ShouldExpand,
3955 RetainExpansion,
3956 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003957 return true;
3958 }
3959
3960 if (ShouldExpand) {
3961 // Expand the function parameter pack into multiple, separate
3962 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003963 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003964 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003965 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3966 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003967 = getDerived().TransformFunctionTypeParam(OldParm,
3968 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003969 if (!NewParm)
3970 return true;
3971
Douglas Gregordd472162011-01-07 00:20:55 +00003972 OutParamTypes.push_back(NewParm->getType());
3973 if (PVars)
3974 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003975 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003976
3977 // If we're supposed to retain a pack expansion, do so by temporarily
3978 // forgetting the partially-substituted parameter pack.
3979 if (RetainExpansion) {
3980 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3981 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003982 = getDerived().TransformFunctionTypeParam(OldParm,
3983 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003984 if (!NewParm)
3985 return true;
3986
3987 OutParamTypes.push_back(NewParm->getType());
3988 if (PVars)
3989 PVars->push_back(NewParm);
3990 }
3991
Douglas Gregor5499af42011-01-05 23:12:31 +00003992 // We're done with the pack expansion.
3993 continue;
3994 }
3995
3996 // We'll substitute the parameter now without expanding the pack
3997 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003998 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3999 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4000 NumExpansions);
4001 } else {
4002 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4003 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00004004 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004005
John McCall58f10c32010-03-11 09:03:00 +00004006 if (!NewParm)
4007 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004008
Douglas Gregordd472162011-01-07 00:20:55 +00004009 OutParamTypes.push_back(NewParm->getType());
4010 if (PVars)
4011 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004012 continue;
4013 }
John McCall58f10c32010-03-11 09:03:00 +00004014
4015 // Deal with the possibility that we don't have a parameter
4016 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004017 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004018 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004019 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004020 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00004021 if (const PackExpansionType *Expansion
4022 = dyn_cast<PackExpansionType>(OldType)) {
4023 // We have a function parameter pack that may need to be expanded.
4024 QualType Pattern = Expansion->getPattern();
4025 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4026 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4027
4028 // Determine whether we should expand the parameter packs.
4029 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004030 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004031 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00004032 Unexpanded.data(),
4033 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004034 ShouldExpand,
4035 RetainExpansion,
4036 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004037 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004038 }
4039
4040 if (ShouldExpand) {
4041 // Expand the function parameter pack into multiple, separate
4042 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004043 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004044 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4045 QualType NewType = getDerived().TransformType(Pattern);
4046 if (NewType.isNull())
4047 return true;
John McCall58f10c32010-03-11 09:03:00 +00004048
Douglas Gregordd472162011-01-07 00:20:55 +00004049 OutParamTypes.push_back(NewType);
4050 if (PVars)
4051 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004052 }
4053
4054 // We're done with the pack expansion.
4055 continue;
4056 }
4057
Douglas Gregor48d24112011-01-10 20:53:55 +00004058 // If we're supposed to retain a pack expansion, do so by temporarily
4059 // forgetting the partially-substituted parameter pack.
4060 if (RetainExpansion) {
4061 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4062 QualType NewType = getDerived().TransformType(Pattern);
4063 if (NewType.isNull())
4064 return true;
4065
4066 OutParamTypes.push_back(NewType);
4067 if (PVars)
4068 PVars->push_back(0);
4069 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004070
Douglas Gregor5499af42011-01-05 23:12:31 +00004071 // We'll substitute the parameter now without expanding the pack
4072 // expansion.
4073 OldType = Expansion->getPattern();
4074 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004075 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4076 NewType = getDerived().TransformType(OldType);
4077 } else {
4078 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004079 }
4080
Douglas Gregor5499af42011-01-05 23:12:31 +00004081 if (NewType.isNull())
4082 return true;
4083
4084 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004085 NewType = getSema().Context.getPackExpansionType(NewType,
4086 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00004087
Douglas Gregordd472162011-01-07 00:20:55 +00004088 OutParamTypes.push_back(NewType);
4089 if (PVars)
4090 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004091 }
4092
4093 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00004094 }
John McCall58f10c32010-03-11 09:03:00 +00004095
4096template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004097QualType
John McCall550e0c22009-10-21 00:40:46 +00004098TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004099 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004100 // Transform the parameters and return type.
4101 //
4102 // We instantiate in source order, with the return type first followed by
4103 // the parameters, because users tend to expect this (even if they shouldn't
4104 // rely on it!).
4105 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00004106 // When the function has a trailing return type, we instantiate the
4107 // parameters before the return type, since the return type can then refer
4108 // to the parameters themselves (via decltype, sizeof, etc.).
4109 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00004110 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00004111 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004112 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004113
Douglas Gregor7fb25412010-10-01 18:44:50 +00004114 QualType ResultType;
4115
4116 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004117 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4118 TL.getParmArray(),
4119 TL.getNumArgs(),
4120 TL.getTypePtr()->arg_type_begin(),
4121 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004122 return QualType();
4123
4124 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4125 if (ResultType.isNull())
4126 return QualType();
4127 }
4128 else {
4129 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4130 if (ResultType.isNull())
4131 return QualType();
4132
Douglas Gregordd472162011-01-07 00:20:55 +00004133 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4134 TL.getParmArray(),
4135 TL.getNumArgs(),
4136 TL.getTypePtr()->arg_type_begin(),
4137 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004138 return QualType();
4139 }
4140
John McCall550e0c22009-10-21 00:40:46 +00004141 QualType Result = TL.getType();
4142 if (getDerived().AlwaysRebuild() ||
4143 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004144 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004145 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4146 Result = getDerived().RebuildFunctionProtoType(ResultType,
4147 ParamTypes.data(),
4148 ParamTypes.size(),
4149 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004150 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004151 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004152 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004153 if (Result.isNull())
4154 return QualType();
4155 }
Mike Stump11289f42009-09-09 15:08:12 +00004156
John McCall550e0c22009-10-21 00:40:46 +00004157 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4158 NewTL.setLParenLoc(TL.getLParenLoc());
4159 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004160 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004161 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4162 NewTL.setArg(i, ParamDecls[i]);
4163
4164 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004165}
Mike Stump11289f42009-09-09 15:08:12 +00004166
Douglas Gregord6ff3322009-08-04 16:50:30 +00004167template<typename Derived>
4168QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004169 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004170 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004171 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004172 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4173 if (ResultType.isNull())
4174 return QualType();
4175
4176 QualType Result = TL.getType();
4177 if (getDerived().AlwaysRebuild() ||
4178 ResultType != T->getResultType())
4179 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4180
4181 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4182 NewTL.setLParenLoc(TL.getLParenLoc());
4183 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004184 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004185
4186 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004187}
Mike Stump11289f42009-09-09 15:08:12 +00004188
John McCallb96ec562009-12-04 22:46:56 +00004189template<typename Derived> QualType
4190TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004191 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004192 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004193 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004194 if (!D)
4195 return QualType();
4196
4197 QualType Result = TL.getType();
4198 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4199 Result = getDerived().RebuildUnresolvedUsingType(D);
4200 if (Result.isNull())
4201 return QualType();
4202 }
4203
4204 // We might get an arbitrary type spec type back. We should at
4205 // least always get a type spec type, though.
4206 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4207 NewTL.setNameLoc(TL.getNameLoc());
4208
4209 return Result;
4210}
4211
Douglas Gregord6ff3322009-08-04 16:50:30 +00004212template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004213QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004214 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004215 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004216 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004217 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4218 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004219 if (!Typedef)
4220 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004221
John McCall550e0c22009-10-21 00:40:46 +00004222 QualType Result = TL.getType();
4223 if (getDerived().AlwaysRebuild() ||
4224 Typedef != T->getDecl()) {
4225 Result = getDerived().RebuildTypedefType(Typedef);
4226 if (Result.isNull())
4227 return QualType();
4228 }
Mike Stump11289f42009-09-09 15:08:12 +00004229
John McCall550e0c22009-10-21 00:40:46 +00004230 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4231 NewTL.setNameLoc(TL.getNameLoc());
4232
4233 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004234}
Mike Stump11289f42009-09-09 15:08:12 +00004235
Douglas Gregord6ff3322009-08-04 16:50:30 +00004236template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004237QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004238 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004239 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004240 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004241
John McCalldadc5752010-08-24 06:29:42 +00004242 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004243 if (E.isInvalid())
4244 return QualType();
4245
John McCall550e0c22009-10-21 00:40:46 +00004246 QualType Result = TL.getType();
4247 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004248 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004249 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004250 if (Result.isNull())
4251 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004252 }
John McCall550e0c22009-10-21 00:40:46 +00004253 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004254
John McCall550e0c22009-10-21 00:40:46 +00004255 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004256 NewTL.setTypeofLoc(TL.getTypeofLoc());
4257 NewTL.setLParenLoc(TL.getLParenLoc());
4258 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004259
4260 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004261}
Mike Stump11289f42009-09-09 15:08:12 +00004262
4263template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004264QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004265 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004266 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4267 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4268 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004269 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004270
John McCall550e0c22009-10-21 00:40:46 +00004271 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004272 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4273 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004274 if (Result.isNull())
4275 return QualType();
4276 }
Mike Stump11289f42009-09-09 15:08:12 +00004277
John McCall550e0c22009-10-21 00:40:46 +00004278 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004279 NewTL.setTypeofLoc(TL.getTypeofLoc());
4280 NewTL.setLParenLoc(TL.getLParenLoc());
4281 NewTL.setRParenLoc(TL.getRParenLoc());
4282 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004283
4284 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004285}
Mike Stump11289f42009-09-09 15:08:12 +00004286
4287template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004288QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004289 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004290 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004291
Douglas Gregore922c772009-08-04 22:27:00 +00004292 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004293 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004294
John McCalldadc5752010-08-24 06:29:42 +00004295 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004296 if (E.isInvalid())
4297 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004298
John McCall550e0c22009-10-21 00:40:46 +00004299 QualType Result = TL.getType();
4300 if (getDerived().AlwaysRebuild() ||
4301 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004302 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004303 if (Result.isNull())
4304 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004305 }
John McCall550e0c22009-10-21 00:40:46 +00004306 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004307
John McCall550e0c22009-10-21 00:40:46 +00004308 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4309 NewTL.setNameLoc(TL.getNameLoc());
4310
4311 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004312}
4313
4314template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004315QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4316 AutoTypeLoc TL) {
4317 const AutoType *T = TL.getTypePtr();
4318 QualType OldDeduced = T->getDeducedType();
4319 QualType NewDeduced;
4320 if (!OldDeduced.isNull()) {
4321 NewDeduced = getDerived().TransformType(OldDeduced);
4322 if (NewDeduced.isNull())
4323 return QualType();
4324 }
4325
4326 QualType Result = TL.getType();
4327 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4328 Result = getDerived().RebuildAutoType(NewDeduced);
4329 if (Result.isNull())
4330 return QualType();
4331 }
4332
4333 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4334 NewTL.setNameLoc(TL.getNameLoc());
4335
4336 return Result;
4337}
4338
4339template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004340QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004341 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004342 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004343 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004344 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4345 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004346 if (!Record)
4347 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004348
John McCall550e0c22009-10-21 00:40:46 +00004349 QualType Result = TL.getType();
4350 if (getDerived().AlwaysRebuild() ||
4351 Record != T->getDecl()) {
4352 Result = getDerived().RebuildRecordType(Record);
4353 if (Result.isNull())
4354 return QualType();
4355 }
Mike Stump11289f42009-09-09 15:08:12 +00004356
John McCall550e0c22009-10-21 00:40:46 +00004357 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4358 NewTL.setNameLoc(TL.getNameLoc());
4359
4360 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004361}
Mike Stump11289f42009-09-09 15:08:12 +00004362
4363template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004364QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004365 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004366 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004367 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004368 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4369 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004370 if (!Enum)
4371 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004372
John McCall550e0c22009-10-21 00:40:46 +00004373 QualType Result = TL.getType();
4374 if (getDerived().AlwaysRebuild() ||
4375 Enum != T->getDecl()) {
4376 Result = getDerived().RebuildEnumType(Enum);
4377 if (Result.isNull())
4378 return QualType();
4379 }
Mike Stump11289f42009-09-09 15:08:12 +00004380
John McCall550e0c22009-10-21 00:40:46 +00004381 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4382 NewTL.setNameLoc(TL.getNameLoc());
4383
4384 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004385}
John McCallfcc33b02009-09-05 00:15:47 +00004386
John McCalle78aac42010-03-10 03:28:59 +00004387template<typename Derived>
4388QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4389 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004390 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004391 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4392 TL.getTypePtr()->getDecl());
4393 if (!D) return QualType();
4394
4395 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4396 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4397 return T;
4398}
4399
Douglas Gregord6ff3322009-08-04 16:50:30 +00004400template<typename Derived>
4401QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004402 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004403 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004404 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004405}
4406
Mike Stump11289f42009-09-09 15:08:12 +00004407template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004408QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004409 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004410 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004411 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004412}
4413
4414template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004415QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4416 TypeLocBuilder &TLB,
4417 SubstTemplateTypeParmPackTypeLoc TL) {
4418 return TransformTypeSpecType(TLB, TL);
4419}
4420
4421template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004422QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004423 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004424 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004425 const TemplateSpecializationType *T = TL.getTypePtr();
4426
Mike Stump11289f42009-09-09 15:08:12 +00004427 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004428 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004429 if (Template.isNull())
4430 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004431
John McCall31f82722010-11-12 08:19:04 +00004432 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4433}
4434
Douglas Gregorfe921a72010-12-20 23:36:19 +00004435namespace {
4436 /// \brief Simple iterator that traverses the template arguments in a
4437 /// container that provides a \c getArgLoc() member function.
4438 ///
4439 /// This iterator is intended to be used with the iterator form of
4440 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4441 template<typename ArgLocContainer>
4442 class TemplateArgumentLocContainerIterator {
4443 ArgLocContainer *Container;
4444 unsigned Index;
4445
4446 public:
4447 typedef TemplateArgumentLoc value_type;
4448 typedef TemplateArgumentLoc reference;
4449 typedef int difference_type;
4450 typedef std::input_iterator_tag iterator_category;
4451
4452 class pointer {
4453 TemplateArgumentLoc Arg;
4454
4455 public:
4456 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4457
4458 const TemplateArgumentLoc *operator->() const {
4459 return &Arg;
4460 }
4461 };
4462
4463
4464 TemplateArgumentLocContainerIterator() {}
4465
4466 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4467 unsigned Index)
4468 : Container(&Container), Index(Index) { }
4469
4470 TemplateArgumentLocContainerIterator &operator++() {
4471 ++Index;
4472 return *this;
4473 }
4474
4475 TemplateArgumentLocContainerIterator operator++(int) {
4476 TemplateArgumentLocContainerIterator Old(*this);
4477 ++(*this);
4478 return Old;
4479 }
4480
4481 TemplateArgumentLoc operator*() const {
4482 return Container->getArgLoc(Index);
4483 }
4484
4485 pointer operator->() const {
4486 return pointer(Container->getArgLoc(Index));
4487 }
4488
4489 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004490 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004491 return X.Container == Y.Container && X.Index == Y.Index;
4492 }
4493
4494 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004495 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004496 return !(X == Y);
4497 }
4498 };
4499}
4500
4501
John McCall31f82722010-11-12 08:19:04 +00004502template <typename Derived>
4503QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4504 TypeLocBuilder &TLB,
4505 TemplateSpecializationTypeLoc TL,
4506 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004507 TemplateArgumentListInfo NewTemplateArgs;
4508 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4509 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004510 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4511 ArgIterator;
4512 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4513 ArgIterator(TL, TL.getNumArgs()),
4514 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004515 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004516
John McCall0ad16662009-10-29 08:12:44 +00004517 // FIXME: maybe don't rebuild if all the template arguments are the same.
4518
4519 QualType Result =
4520 getDerived().RebuildTemplateSpecializationType(Template,
4521 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004522 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004523
4524 if (!Result.isNull()) {
4525 TemplateSpecializationTypeLoc NewTL
4526 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4527 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4528 NewTL.setLAngleLoc(TL.getLAngleLoc());
4529 NewTL.setRAngleLoc(TL.getRAngleLoc());
4530 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4531 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004532 }
Mike Stump11289f42009-09-09 15:08:12 +00004533
John McCall0ad16662009-10-29 08:12:44 +00004534 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004535}
Mike Stump11289f42009-09-09 15:08:12 +00004536
Douglas Gregor5a064722011-02-28 17:23:35 +00004537template <typename Derived>
4538QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4539 TypeLocBuilder &TLB,
4540 DependentTemplateSpecializationTypeLoc TL,
4541 TemplateName Template) {
4542 TemplateArgumentListInfo NewTemplateArgs;
4543 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4544 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4545 typedef TemplateArgumentLocContainerIterator<
4546 DependentTemplateSpecializationTypeLoc> ArgIterator;
4547 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4548 ArgIterator(TL, TL.getNumArgs()),
4549 NewTemplateArgs))
4550 return QualType();
4551
4552 // FIXME: maybe don't rebuild if all the template arguments are the same.
4553
4554 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4555 QualType Result
4556 = getSema().Context.getDependentTemplateSpecializationType(
4557 TL.getTypePtr()->getKeyword(),
4558 DTN->getQualifier(),
4559 DTN->getIdentifier(),
4560 NewTemplateArgs);
4561
4562 DependentTemplateSpecializationTypeLoc NewTL
4563 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4564 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004565
4566 // FIXME: Poor nested-name-specifier source-location information.
4567 CXXScopeSpec SS;
4568 SS.MakeTrivial(SemaRef.Context,
4569 DTN->getQualifier(), TL.getQualifierLoc().getSourceRange());
4570 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004571 NewTL.setNameLoc(TL.getNameLoc());
4572 NewTL.setLAngleLoc(TL.getLAngleLoc());
4573 NewTL.setRAngleLoc(TL.getRAngleLoc());
4574 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4575 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4576 return Result;
4577 }
4578
4579 QualType Result
4580 = getDerived().RebuildTemplateSpecializationType(Template,
4581 TL.getNameLoc(),
4582 NewTemplateArgs);
4583
4584 if (!Result.isNull()) {
4585 /// FIXME: Wrap this in an elaborated-type-specifier?
4586 TemplateSpecializationTypeLoc NewTL
4587 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4588 NewTL.setTemplateNameLoc(TL.getNameLoc());
4589 NewTL.setLAngleLoc(TL.getLAngleLoc());
4590 NewTL.setRAngleLoc(TL.getRAngleLoc());
4591 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4592 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4593 }
4594
4595 return Result;
4596}
4597
Mike Stump11289f42009-09-09 15:08:12 +00004598template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004599QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004600TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004601 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004602 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004603
Douglas Gregor844cb502011-03-01 18:12:44 +00004604 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004605 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004606 if (TL.getQualifierLoc()) {
4607 QualifierLoc
4608 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4609 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004610 return QualType();
4611 }
Mike Stump11289f42009-09-09 15:08:12 +00004612
John McCall31f82722010-11-12 08:19:04 +00004613 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4614 if (NamedT.isNull())
4615 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004616
John McCall550e0c22009-10-21 00:40:46 +00004617 QualType Result = TL.getType();
4618 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004619 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004620 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004621 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004622 T->getKeyword(),
4623 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004624 if (Result.isNull())
4625 return QualType();
4626 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004627
Abramo Bagnara6150c882010-05-11 21:36:43 +00004628 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004629 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004630 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004631 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004632}
Mike Stump11289f42009-09-09 15:08:12 +00004633
4634template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004635QualType TreeTransform<Derived>::TransformAttributedType(
4636 TypeLocBuilder &TLB,
4637 AttributedTypeLoc TL) {
4638 const AttributedType *oldType = TL.getTypePtr();
4639 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4640 if (modifiedType.isNull())
4641 return QualType();
4642
4643 QualType result = TL.getType();
4644
4645 // FIXME: dependent operand expressions?
4646 if (getDerived().AlwaysRebuild() ||
4647 modifiedType != oldType->getModifiedType()) {
4648 // TODO: this is really lame; we should really be rebuilding the
4649 // equivalent type from first principles.
4650 QualType equivalentType
4651 = getDerived().TransformType(oldType->getEquivalentType());
4652 if (equivalentType.isNull())
4653 return QualType();
4654 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4655 modifiedType,
4656 equivalentType);
4657 }
4658
4659 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4660 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4661 if (TL.hasAttrOperand())
4662 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4663 if (TL.hasAttrExprOperand())
4664 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4665 else if (TL.hasAttrEnumOperand())
4666 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4667
4668 return result;
4669}
4670
4671template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004672QualType
4673TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4674 ParenTypeLoc TL) {
4675 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4676 if (Inner.isNull())
4677 return QualType();
4678
4679 QualType Result = TL.getType();
4680 if (getDerived().AlwaysRebuild() ||
4681 Inner != TL.getInnerLoc().getType()) {
4682 Result = getDerived().RebuildParenType(Inner);
4683 if (Result.isNull())
4684 return QualType();
4685 }
4686
4687 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4688 NewTL.setLParenLoc(TL.getLParenLoc());
4689 NewTL.setRParenLoc(TL.getRParenLoc());
4690 return Result;
4691}
4692
4693template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004694QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004695 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004696 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004697
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004698 NestedNameSpecifierLoc QualifierLoc
4699 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4700 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004701 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004702
John McCallc392f372010-06-11 00:33:02 +00004703 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004704 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004705 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004706 QualifierLoc,
4707 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004708 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004709 if (Result.isNull())
4710 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004711
Abramo Bagnarad7548482010-05-19 21:37:53 +00004712 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4713 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004714 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4715
Abramo Bagnarad7548482010-05-19 21:37:53 +00004716 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4717 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004718 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004719 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004720 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4721 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004722 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004723 NewTL.setNameLoc(TL.getNameLoc());
4724 }
John McCall550e0c22009-10-21 00:40:46 +00004725 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004726}
Mike Stump11289f42009-09-09 15:08:12 +00004727
Douglas Gregord6ff3322009-08-04 16:50:30 +00004728template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004729QualType TreeTransform<Derived>::
4730 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004731 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004732 NestedNameSpecifierLoc QualifierLoc;
4733 if (TL.getQualifierLoc()) {
4734 QualifierLoc
4735 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4736 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004737 return QualType();
4738 }
4739
John McCall31f82722010-11-12 08:19:04 +00004740 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004741 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004742}
4743
4744template<typename Derived>
4745QualType TreeTransform<Derived>::
4746 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4747 DependentTemplateSpecializationTypeLoc TL,
4748 NestedNameSpecifier *NNS) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004749 // FIXME: This routine needs to go away.
John McCall424cec92011-01-19 06:33:43 +00004750 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004751
John McCallc392f372010-06-11 00:33:02 +00004752 TemplateArgumentListInfo NewTemplateArgs;
4753 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4754 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor14454802011-02-25 02:25:35 +00004755
4756 // FIXME: Nested-name-specifier source location info!
Douglas Gregorfe921a72010-12-20 23:36:19 +00004757 typedef TemplateArgumentLocContainerIterator<
4758 DependentTemplateSpecializationTypeLoc> ArgIterator;
4759 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4760 ArgIterator(TL, TL.getNumArgs()),
4761 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004762 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004763
Douglas Gregor9db53502011-03-02 18:07:45 +00004764 CXXScopeSpec SS;
4765 SS.MakeTrivial(SemaRef.Context, NNS,
4766 TL.getQualifierLoc().getSourceRange());
Douglas Gregora5614c52010-09-08 23:56:00 +00004767 QualType Result
4768 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
Douglas Gregor9db53502011-03-02 18:07:45 +00004769 SS.getWithLocInContext(SemaRef.Context),
Douglas Gregora5614c52010-09-08 23:56:00 +00004770 T->getIdentifier(),
4771 TL.getNameLoc(),
4772 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004773 if (Result.isNull())
4774 return QualType();
4775
4776 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4777 QualType NamedT = ElabT->getNamedType();
4778
4779 // Copy information relevant to the template specialization.
4780 TemplateSpecializationTypeLoc NamedTL
4781 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4782 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4783 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4784 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4785 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4786
4787 // Copy information relevant to the elaborated type.
4788 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4789 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004790
4791 // FIXME: DependentTemplateSpecializationType needs better source-location
4792 // info.
4793 NestedNameSpecifierLocBuilder Builder;
Douglas Gregora7a795b2011-03-01 20:11:18 +00004794 Builder.MakeTrivial(SemaRef.Context,
4795 NNS, TL.getQualifierLoc().getSourceRange());
Douglas Gregor844cb502011-03-01 18:12:44 +00004796 NewTL.setQualifierLoc(Builder.getWithLocInContext(SemaRef.Context));
John McCallc392f372010-06-11 00:33:02 +00004797 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004798 TypeLoc NewTL(Result, TL.getOpaqueData());
4799 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004800 }
4801 return Result;
4802}
4803
4804template<typename Derived>
Douglas Gregora7a795b2011-03-01 20:11:18 +00004805QualType TreeTransform<Derived>::
4806TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4807 DependentTemplateSpecializationTypeLoc TL,
4808 NestedNameSpecifierLoc QualifierLoc) {
4809 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4810
4811 TemplateArgumentListInfo NewTemplateArgs;
4812 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4813 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4814
4815 typedef TemplateArgumentLocContainerIterator<
4816 DependentTemplateSpecializationTypeLoc> ArgIterator;
4817 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4818 ArgIterator(TL, TL.getNumArgs()),
4819 NewTemplateArgs))
4820 return QualType();
4821
4822 QualType Result
4823 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4824 QualifierLoc,
4825 T->getIdentifier(),
4826 TL.getNameLoc(),
4827 NewTemplateArgs);
4828 if (Result.isNull())
4829 return QualType();
4830
4831 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4832 QualType NamedT = ElabT->getNamedType();
4833
4834 // Copy information relevant to the template specialization.
4835 TemplateSpecializationTypeLoc NamedTL
4836 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4837 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4838 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4839 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4840 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4841
4842 // Copy information relevant to the elaborated type.
4843 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4844 NewTL.setKeywordLoc(TL.getKeywordLoc());
4845 NewTL.setQualifierLoc(QualifierLoc);
4846 } else {
4847 TypeLoc NewTL(Result, TL.getOpaqueData());
4848 TLB.pushFullCopy(NewTL);
4849 }
4850 return Result;
4851}
4852
4853template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004854QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4855 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004856 QualType Pattern
4857 = getDerived().TransformType(TLB, TL.getPatternLoc());
4858 if (Pattern.isNull())
4859 return QualType();
4860
4861 QualType Result = TL.getType();
4862 if (getDerived().AlwaysRebuild() ||
4863 Pattern != TL.getPatternLoc().getType()) {
4864 Result = getDerived().RebuildPackExpansionType(Pattern,
4865 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004866 TL.getEllipsisLoc(),
4867 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004868 if (Result.isNull())
4869 return QualType();
4870 }
4871
4872 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4873 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4874 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004875}
4876
4877template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004878QualType
4879TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004880 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004881 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004882 TLB.pushFullCopy(TL);
4883 return TL.getType();
4884}
4885
4886template<typename Derived>
4887QualType
4888TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004889 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004890 // ObjCObjectType is never dependent.
4891 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004892 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004893}
Mike Stump11289f42009-09-09 15:08:12 +00004894
4895template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004896QualType
4897TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004898 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004899 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004900 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004901 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004902}
4903
Douglas Gregord6ff3322009-08-04 16:50:30 +00004904//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004905// Statement transformation
4906//===----------------------------------------------------------------------===//
4907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004908StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004909TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004910 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004911}
4912
4913template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004914StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004915TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4916 return getDerived().TransformCompoundStmt(S, false);
4917}
4918
4919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004920StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004921TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004922 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004923 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004924 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004925 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004926 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4927 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004928 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004929 if (Result.isInvalid()) {
4930 // Immediately fail if this was a DeclStmt, since it's very
4931 // likely that this will cause problems for future statements.
4932 if (isa<DeclStmt>(*B))
4933 return StmtError();
4934
4935 // Otherwise, just keep processing substatements and fail later.
4936 SubStmtInvalid = true;
4937 continue;
4938 }
Mike Stump11289f42009-09-09 15:08:12 +00004939
Douglas Gregorebe10102009-08-20 07:17:43 +00004940 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4941 Statements.push_back(Result.takeAs<Stmt>());
4942 }
Mike Stump11289f42009-09-09 15:08:12 +00004943
John McCall1ababa62010-08-27 19:56:05 +00004944 if (SubStmtInvalid)
4945 return StmtError();
4946
Douglas Gregorebe10102009-08-20 07:17:43 +00004947 if (!getDerived().AlwaysRebuild() &&
4948 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004949 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004950
4951 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4952 move_arg(Statements),
4953 S->getRBracLoc(),
4954 IsStmtExpr);
4955}
Mike Stump11289f42009-09-09 15:08:12 +00004956
Douglas Gregorebe10102009-08-20 07:17:43 +00004957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004958StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004959TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004960 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004961 {
4962 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004963 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004964
Eli Friedman06577382009-11-19 03:14:00 +00004965 // Transform the left-hand case value.
4966 LHS = getDerived().TransformExpr(S->getLHS());
4967 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004968 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004969
Eli Friedman06577382009-11-19 03:14:00 +00004970 // Transform the right-hand case value (for the GNU case-range extension).
4971 RHS = getDerived().TransformExpr(S->getRHS());
4972 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004973 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004974 }
Mike Stump11289f42009-09-09 15:08:12 +00004975
Douglas Gregorebe10102009-08-20 07:17:43 +00004976 // Build the case statement.
4977 // Case statements are always rebuilt so that they will attached to their
4978 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004979 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004980 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004981 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004982 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004983 S->getColonLoc());
4984 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004985 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004986
Douglas Gregorebe10102009-08-20 07:17:43 +00004987 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004988 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004989 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004990 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004991
Douglas Gregorebe10102009-08-20 07:17:43 +00004992 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004993 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004994}
4995
4996template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004997StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004998TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004999 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005000 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005001 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005002 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005003
Douglas Gregorebe10102009-08-20 07:17:43 +00005004 // Default statements are always rebuilt
5005 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005006 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005007}
Mike Stump11289f42009-09-09 15:08:12 +00005008
Douglas Gregorebe10102009-08-20 07:17:43 +00005009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005010StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005011TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005012 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005013 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005014 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005015
Chris Lattnercab02a62011-02-17 20:34:02 +00005016 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5017 S->getDecl());
5018 if (!LD)
5019 return StmtError();
5020
5021
Douglas Gregorebe10102009-08-20 07:17:43 +00005022 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005023 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005024 cast<LabelDecl>(LD), SourceLocation(),
5025 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005026}
Mike Stump11289f42009-09-09 15:08:12 +00005027
Douglas Gregorebe10102009-08-20 07:17:43 +00005028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005029StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005030TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005031 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005032 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005033 VarDecl *ConditionVar = 0;
5034 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005035 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005036 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005037 getDerived().TransformDefinition(
5038 S->getConditionVariable()->getLocation(),
5039 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005040 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005041 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005042 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005043 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005044
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005045 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005046 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005047
5048 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005049 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005050 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5051 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005052 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005053 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005054
John McCallb268a282010-08-23 23:25:46 +00005055 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005056 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005057 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005058
John McCallb268a282010-08-23 23:25:46 +00005059 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5060 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005061 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005062
Douglas Gregorebe10102009-08-20 07:17:43 +00005063 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005064 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005065 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005066 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005067
Douglas Gregorebe10102009-08-20 07:17:43 +00005068 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005069 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005070 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005071 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005072
Douglas Gregorebe10102009-08-20 07:17:43 +00005073 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005074 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005075 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005076 Then.get() == S->getThen() &&
5077 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005078 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005079
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005080 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005081 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005082 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005083}
5084
5085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005086StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005087TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005088 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005089 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005090 VarDecl *ConditionVar = 0;
5091 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005092 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005093 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005094 getDerived().TransformDefinition(
5095 S->getConditionVariable()->getLocation(),
5096 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005097 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005098 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005099 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005100 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005101
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005102 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005103 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005104 }
Mike Stump11289f42009-09-09 15:08:12 +00005105
Douglas Gregorebe10102009-08-20 07:17:43 +00005106 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005107 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005108 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005109 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005110 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005111 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005112
Douglas Gregorebe10102009-08-20 07:17:43 +00005113 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005114 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005115 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005116 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005117
Douglas Gregorebe10102009-08-20 07:17:43 +00005118 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005119 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5120 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005121}
Mike Stump11289f42009-09-09 15:08:12 +00005122
Douglas Gregorebe10102009-08-20 07:17:43 +00005123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005124StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005125TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005126 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005127 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005128 VarDecl *ConditionVar = 0;
5129 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005130 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005131 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005132 getDerived().TransformDefinition(
5133 S->getConditionVariable()->getLocation(),
5134 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005135 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005136 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005137 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005138 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005139
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005140 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005141 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005142
5143 if (S->getCond()) {
5144 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005145 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5146 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005147 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005148 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005149 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005150 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005151 }
Mike Stump11289f42009-09-09 15:08:12 +00005152
John McCallb268a282010-08-23 23:25:46 +00005153 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5154 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005155 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005156
Douglas Gregorebe10102009-08-20 07:17:43 +00005157 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005158 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005159 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005160 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005161
Douglas Gregorebe10102009-08-20 07:17:43 +00005162 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005163 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005164 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005165 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005166 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005167
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005168 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005169 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005170}
Mike Stump11289f42009-09-09 15:08:12 +00005171
Douglas Gregorebe10102009-08-20 07:17:43 +00005172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005173StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005174TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005175 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005176 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005177 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005178 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005179
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005180 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005181 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005182 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005183 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005184
Douglas Gregorebe10102009-08-20 07:17:43 +00005185 if (!getDerived().AlwaysRebuild() &&
5186 Cond.get() == S->getCond() &&
5187 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005188 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005189
John McCallb268a282010-08-23 23:25:46 +00005190 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5191 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005192 S->getRParenLoc());
5193}
Mike Stump11289f42009-09-09 15:08:12 +00005194
Douglas Gregorebe10102009-08-20 07:17:43 +00005195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005196StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005197TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005198 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005199 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005200 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005201 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005202
Douglas Gregorebe10102009-08-20 07:17:43 +00005203 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005204 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005205 VarDecl *ConditionVar = 0;
5206 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005207 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005208 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005209 getDerived().TransformDefinition(
5210 S->getConditionVariable()->getLocation(),
5211 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005212 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005213 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005214 } else {
5215 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005216
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005217 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005218 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005219
5220 if (S->getCond()) {
5221 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005222 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5223 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005224 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005225 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005226
John McCallb268a282010-08-23 23:25:46 +00005227 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005228 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005229 }
Mike Stump11289f42009-09-09 15:08:12 +00005230
John McCallb268a282010-08-23 23:25:46 +00005231 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5232 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005233 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005234
Douglas Gregorebe10102009-08-20 07:17:43 +00005235 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005236 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005237 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005238 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005239
John McCallb268a282010-08-23 23:25:46 +00005240 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5241 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005242 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005243
Douglas Gregorebe10102009-08-20 07:17:43 +00005244 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005245 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005246 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005247 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005248
Douglas Gregorebe10102009-08-20 07:17:43 +00005249 if (!getDerived().AlwaysRebuild() &&
5250 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005251 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005252 Inc.get() == S->getInc() &&
5253 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005254 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005255
Douglas Gregorebe10102009-08-20 07:17:43 +00005256 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005257 Init.get(), FullCond, ConditionVar,
5258 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005259}
5260
5261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005262StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005263TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005264 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5265 S->getLabel());
5266 if (!LD)
5267 return StmtError();
5268
Douglas Gregorebe10102009-08-20 07:17:43 +00005269 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005270 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005271 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005272}
5273
5274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005275StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005276TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005277 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005278 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005279 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005280
Douglas Gregorebe10102009-08-20 07:17:43 +00005281 if (!getDerived().AlwaysRebuild() &&
5282 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005283 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005284
5285 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005286 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005287}
5288
5289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005290StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005291TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005292 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005293}
Mike Stump11289f42009-09-09 15:08:12 +00005294
Douglas Gregorebe10102009-08-20 07:17:43 +00005295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005296StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005297TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005298 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005299}
Mike Stump11289f42009-09-09 15:08:12 +00005300
Douglas Gregorebe10102009-08-20 07:17:43 +00005301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005302StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005303TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005304 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005305 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005306 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005307
Mike Stump11289f42009-09-09 15:08:12 +00005308 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005309 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005310 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005311}
Mike Stump11289f42009-09-09 15:08:12 +00005312
Douglas Gregorebe10102009-08-20 07:17:43 +00005313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005314StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005315TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005316 bool DeclChanged = false;
5317 llvm::SmallVector<Decl *, 4> Decls;
5318 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5319 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005320 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5321 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005322 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005323 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005324
Douglas Gregorebe10102009-08-20 07:17:43 +00005325 if (Transformed != *D)
5326 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005327
Douglas Gregorebe10102009-08-20 07:17:43 +00005328 Decls.push_back(Transformed);
5329 }
Mike Stump11289f42009-09-09 15:08:12 +00005330
Douglas Gregorebe10102009-08-20 07:17:43 +00005331 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005332 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005333
5334 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005335 S->getStartLoc(), S->getEndLoc());
5336}
Mike Stump11289f42009-09-09 15:08:12 +00005337
Douglas Gregorebe10102009-08-20 07:17:43 +00005338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005339StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005340TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005341
John McCall37ad5512010-08-23 06:44:23 +00005342 ASTOwningVector<Expr*> Constraints(getSema());
5343 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005344 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005345
John McCalldadc5752010-08-24 06:29:42 +00005346 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005347 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005348
5349 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005350
Anders Carlssonaaeef072010-01-24 05:50:09 +00005351 // Go through the outputs.
5352 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005353 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005354
Anders Carlssonaaeef072010-01-24 05:50:09 +00005355 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005356 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005357
Anders Carlssonaaeef072010-01-24 05:50:09 +00005358 // Transform the output expr.
5359 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005360 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005361 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005362 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005363
Anders Carlssonaaeef072010-01-24 05:50:09 +00005364 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005365
John McCallb268a282010-08-23 23:25:46 +00005366 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005367 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005368
Anders Carlssonaaeef072010-01-24 05:50:09 +00005369 // Go through the inputs.
5370 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005371 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005372
Anders Carlssonaaeef072010-01-24 05:50:09 +00005373 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005374 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005375
Anders Carlssonaaeef072010-01-24 05:50:09 +00005376 // Transform the input expr.
5377 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005378 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005379 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005380 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005381
Anders Carlssonaaeef072010-01-24 05:50:09 +00005382 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005383
John McCallb268a282010-08-23 23:25:46 +00005384 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005385 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005386
Anders Carlssonaaeef072010-01-24 05:50:09 +00005387 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005388 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005389
5390 // Go through the clobbers.
5391 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005392 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005393
5394 // No need to transform the asm string literal.
5395 AsmString = SemaRef.Owned(S->getAsmString());
5396
5397 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5398 S->isSimple(),
5399 S->isVolatile(),
5400 S->getNumOutputs(),
5401 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005402 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005403 move_arg(Constraints),
5404 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005405 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005406 move_arg(Clobbers),
5407 S->getRParenLoc(),
5408 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005409}
5410
5411
5412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005413StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005414TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005415 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005416 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005417 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005418 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005419
Douglas Gregor96c79492010-04-23 22:50:49 +00005420 // Transform the @catch statements (if present).
5421 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005422 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005423 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005424 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005425 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005426 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005427 if (Catch.get() != S->getCatchStmt(I))
5428 AnyCatchChanged = true;
5429 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005430 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005431
Douglas Gregor306de2f2010-04-22 23:59:56 +00005432 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005433 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005434 if (S->getFinallyStmt()) {
5435 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5436 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005437 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005438 }
5439
5440 // If nothing changed, just retain this statement.
5441 if (!getDerived().AlwaysRebuild() &&
5442 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005443 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005444 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005445 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005446
Douglas Gregor306de2f2010-04-22 23:59:56 +00005447 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005448 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5449 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005450}
Mike Stump11289f42009-09-09 15:08:12 +00005451
Douglas Gregorebe10102009-08-20 07:17:43 +00005452template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005453StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005454TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005455 // Transform the @catch parameter, if there is one.
5456 VarDecl *Var = 0;
5457 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5458 TypeSourceInfo *TSInfo = 0;
5459 if (FromVar->getTypeSourceInfo()) {
5460 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5461 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005462 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005463 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005464
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005465 QualType T;
5466 if (TSInfo)
5467 T = TSInfo->getType();
5468 else {
5469 T = getDerived().TransformType(FromVar->getType());
5470 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005471 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005472 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005473
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005474 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5475 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005476 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005477 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005478
John McCalldadc5752010-08-24 06:29:42 +00005479 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005480 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005481 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005482
5483 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005484 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005485 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005486}
Mike Stump11289f42009-09-09 15:08:12 +00005487
Douglas Gregorebe10102009-08-20 07:17:43 +00005488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005489StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005490TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005491 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005492 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005493 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005494 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005495
Douglas Gregor306de2f2010-04-22 23:59:56 +00005496 // If nothing changed, just retain this statement.
5497 if (!getDerived().AlwaysRebuild() &&
5498 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005499 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005500
5501 // Build a new statement.
5502 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005503 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005504}
Mike Stump11289f42009-09-09 15:08:12 +00005505
Douglas Gregorebe10102009-08-20 07:17:43 +00005506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005507StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005508TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005509 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005510 if (S->getThrowExpr()) {
5511 Operand = getDerived().TransformExpr(S->getThrowExpr());
5512 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005513 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005514 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005515
Douglas Gregor2900c162010-04-22 21:44:01 +00005516 if (!getDerived().AlwaysRebuild() &&
5517 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005518 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005519
John McCallb268a282010-08-23 23:25:46 +00005520 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005521}
Mike Stump11289f42009-09-09 15:08:12 +00005522
Douglas Gregorebe10102009-08-20 07:17:43 +00005523template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005524StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005525TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005526 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005527 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005528 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005529 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005530 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005531
Douglas Gregor6148de72010-04-22 22:01:21 +00005532 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005533 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005534 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005535 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005536
Douglas Gregor6148de72010-04-22 22:01:21 +00005537 // If nothing change, just retain the current statement.
5538 if (!getDerived().AlwaysRebuild() &&
5539 Object.get() == S->getSynchExpr() &&
5540 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005541 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005542
5543 // Build a new statement.
5544 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005545 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005546}
5547
5548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005549StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005550TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005551 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005552 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005553 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005554 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005555 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005556
Douglas Gregorf68a5082010-04-22 23:10:45 +00005557 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005558 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005559 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005560 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005561
Douglas Gregorf68a5082010-04-22 23:10:45 +00005562 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005563 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005564 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005565 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005566
Douglas Gregorf68a5082010-04-22 23:10:45 +00005567 // If nothing changed, just retain this statement.
5568 if (!getDerived().AlwaysRebuild() &&
5569 Element.get() == S->getElement() &&
5570 Collection.get() == S->getCollection() &&
5571 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005572 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005573
Douglas Gregorf68a5082010-04-22 23:10:45 +00005574 // Build a new statement.
5575 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5576 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005577 Element.get(),
5578 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005579 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005580 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005581}
5582
5583
5584template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005585StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005586TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5587 // Transform the exception declaration, if any.
5588 VarDecl *Var = 0;
5589 if (S->getExceptionDecl()) {
5590 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005591 TypeSourceInfo *T = getDerived().TransformType(
5592 ExceptionDecl->getTypeSourceInfo());
5593 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005594 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005595
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005596 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005597 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005598 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005599 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005600 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005601 }
Mike Stump11289f42009-09-09 15:08:12 +00005602
Douglas Gregorebe10102009-08-20 07:17:43 +00005603 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005604 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005605 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005606 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005607
Douglas Gregorebe10102009-08-20 07:17:43 +00005608 if (!getDerived().AlwaysRebuild() &&
5609 !Var &&
5610 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005611 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005612
5613 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5614 Var,
John McCallb268a282010-08-23 23:25:46 +00005615 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005616}
Mike Stump11289f42009-09-09 15:08:12 +00005617
Douglas Gregorebe10102009-08-20 07:17:43 +00005618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005619StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005620TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5621 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005622 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005623 = getDerived().TransformCompoundStmt(S->getTryBlock());
5624 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005625 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005626
Douglas Gregorebe10102009-08-20 07:17:43 +00005627 // Transform the handlers.
5628 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005629 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005630 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005631 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005632 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5633 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005634 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005635
Douglas Gregorebe10102009-08-20 07:17:43 +00005636 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5637 Handlers.push_back(Handler.takeAs<Stmt>());
5638 }
Mike Stump11289f42009-09-09 15:08:12 +00005639
Douglas Gregorebe10102009-08-20 07:17:43 +00005640 if (!getDerived().AlwaysRebuild() &&
5641 TryBlock.get() == S->getTryBlock() &&
5642 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005643 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005644
John McCallb268a282010-08-23 23:25:46 +00005645 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005646 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005647}
Mike Stump11289f42009-09-09 15:08:12 +00005648
Douglas Gregorebe10102009-08-20 07:17:43 +00005649//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005650// Expression transformation
5651//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005654TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005655 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005656}
Mike Stump11289f42009-09-09 15:08:12 +00005657
5658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005659ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005660TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005661 NestedNameSpecifierLoc QualifierLoc;
5662 if (E->getQualifierLoc()) {
5663 QualifierLoc
5664 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5665 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005666 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005667 }
John McCallce546572009-12-08 09:08:17 +00005668
5669 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005670 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5671 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005672 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005673 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005674
John McCall815039a2010-08-17 21:27:17 +00005675 DeclarationNameInfo NameInfo = E->getNameInfo();
5676 if (NameInfo.getName()) {
5677 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5678 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005679 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005680 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005681
5682 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005683 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005684 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005685 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005686 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005687
5688 // Mark it referenced in the new context regardless.
5689 // FIXME: this is a bit instantiation-specific.
5690 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5691
John McCallc3007a22010-10-26 07:05:15 +00005692 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005693 }
John McCallce546572009-12-08 09:08:17 +00005694
5695 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005696 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005697 TemplateArgs = &TransArgs;
5698 TransArgs.setLAngleLoc(E->getLAngleLoc());
5699 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005700 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5701 E->getNumTemplateArgs(),
5702 TransArgs))
5703 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005704 }
5705
Douglas Gregorea972d32011-02-28 21:54:11 +00005706 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5707 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005708}
Mike Stump11289f42009-09-09 15:08:12 +00005709
Douglas Gregora16548e2009-08-11 05:31:07 +00005710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005711ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005712TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005713 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005714}
Mike Stump11289f42009-09-09 15:08:12 +00005715
Douglas Gregora16548e2009-08-11 05:31:07 +00005716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005717ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005718TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005719 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005720}
Mike Stump11289f42009-09-09 15:08:12 +00005721
Douglas Gregora16548e2009-08-11 05:31:07 +00005722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005723ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005724TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005725 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005726}
Mike Stump11289f42009-09-09 15:08:12 +00005727
Douglas Gregora16548e2009-08-11 05:31:07 +00005728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005729ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005730TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005731 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005732}
Mike Stump11289f42009-09-09 15:08:12 +00005733
Douglas Gregora16548e2009-08-11 05:31:07 +00005734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005736TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005737 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005738}
5739
5740template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005741ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005742TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005743 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005744 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005745 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005746
Douglas Gregora16548e2009-08-11 05:31:07 +00005747 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005748 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005749
John McCallb268a282010-08-23 23:25:46 +00005750 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005751 E->getRParen());
5752}
5753
Mike Stump11289f42009-09-09 15:08:12 +00005754template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005755ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005756TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005757 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005758 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005759 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005760
Douglas Gregora16548e2009-08-11 05:31:07 +00005761 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005762 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005763
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5765 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005766 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005767}
Mike Stump11289f42009-09-09 15:08:12 +00005768
Douglas Gregora16548e2009-08-11 05:31:07 +00005769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005770ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005771TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5772 // Transform the type.
5773 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5774 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005775 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005776
Douglas Gregor882211c2010-04-28 22:16:22 +00005777 // Transform all of the components into components similar to what the
5778 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005779 // FIXME: It would be slightly more efficient in the non-dependent case to
5780 // just map FieldDecls, rather than requiring the rebuilder to look for
5781 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005782 // template code that we don't care.
5783 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005784 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005785 typedef OffsetOfExpr::OffsetOfNode Node;
5786 llvm::SmallVector<Component, 4> Components;
5787 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5788 const Node &ON = E->getComponent(I);
5789 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005790 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005791 Comp.LocStart = ON.getRange().getBegin();
5792 Comp.LocEnd = ON.getRange().getEnd();
5793 switch (ON.getKind()) {
5794 case Node::Array: {
5795 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005796 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005797 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005798 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005799
Douglas Gregor882211c2010-04-28 22:16:22 +00005800 ExprChanged = ExprChanged || Index.get() != FromIndex;
5801 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005802 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005803 break;
5804 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005805
Douglas Gregor882211c2010-04-28 22:16:22 +00005806 case Node::Field:
5807 case Node::Identifier:
5808 Comp.isBrackets = false;
5809 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005810 if (!Comp.U.IdentInfo)
5811 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005812
Douglas Gregor882211c2010-04-28 22:16:22 +00005813 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005814
Douglas Gregord1702062010-04-29 00:18:15 +00005815 case Node::Base:
5816 // Will be recomputed during the rebuild.
5817 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005818 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005819
Douglas Gregor882211c2010-04-28 22:16:22 +00005820 Components.push_back(Comp);
5821 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005822
Douglas Gregor882211c2010-04-28 22:16:22 +00005823 // If nothing changed, retain the existing expression.
5824 if (!getDerived().AlwaysRebuild() &&
5825 Type == E->getTypeSourceInfo() &&
5826 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005827 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005828
Douglas Gregor882211c2010-04-28 22:16:22 +00005829 // Build a new offsetof expression.
5830 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5831 Components.data(), Components.size(),
5832 E->getRParenLoc());
5833}
5834
5835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005836ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005837TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5838 assert(getDerived().AlreadyTransformed(E->getType()) &&
5839 "opaque value expression requires transformation");
5840 return SemaRef.Owned(E);
5841}
5842
5843template<typename Derived>
5844ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005845TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005846 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005847 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005848
John McCallbcd03502009-12-07 02:54:59 +00005849 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005850 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005851 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005852
John McCall4c98fd82009-11-04 07:28:41 +00005853 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005854 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005855
John McCall4c98fd82009-11-04 07:28:41 +00005856 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005857 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005858 E->getSourceRange());
5859 }
Mike Stump11289f42009-09-09 15:08:12 +00005860
John McCalldadc5752010-08-24 06:29:42 +00005861 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005862 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005863 // C++0x [expr.sizeof]p1:
5864 // The operand is either an expression, which is an unevaluated operand
5865 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005866 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005867
Douglas Gregora16548e2009-08-11 05:31:07 +00005868 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5869 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005871
Douglas Gregora16548e2009-08-11 05:31:07 +00005872 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005873 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005874 }
Mike Stump11289f42009-09-09 15:08:12 +00005875
John McCallb268a282010-08-23 23:25:46 +00005876 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005877 E->isSizeOf(),
5878 E->getSourceRange());
5879}
Mike Stump11289f42009-09-09 15:08:12 +00005880
Douglas Gregora16548e2009-08-11 05:31:07 +00005881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005882ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005883TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005884 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005885 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005886 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005887
John McCalldadc5752010-08-24 06:29:42 +00005888 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005890 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005891
5892
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 if (!getDerived().AlwaysRebuild() &&
5894 LHS.get() == E->getLHS() &&
5895 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005896 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005897
John McCallb268a282010-08-23 23:25:46 +00005898 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005899 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005900 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005901 E->getRBracketLoc());
5902}
Mike Stump11289f42009-09-09 15:08:12 +00005903
5904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005906TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005907 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005908 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005909 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005910 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005911
5912 // Transform arguments.
5913 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005914 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005915 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5916 &ArgChanged))
5917 return ExprError();
5918
Douglas Gregora16548e2009-08-11 05:31:07 +00005919 if (!getDerived().AlwaysRebuild() &&
5920 Callee.get() == E->getCallee() &&
5921 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005922 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005923
Douglas Gregora16548e2009-08-11 05:31:07 +00005924 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005925 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005926 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005927 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005928 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005929 E->getRParenLoc());
5930}
Mike Stump11289f42009-09-09 15:08:12 +00005931
5932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005933ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005934TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005935 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005936 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005938
Douglas Gregorea972d32011-02-28 21:54:11 +00005939 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005940 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005941 QualifierLoc
5942 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5943
5944 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005945 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005946 }
Mike Stump11289f42009-09-09 15:08:12 +00005947
Eli Friedman2cfcef62009-12-04 06:40:45 +00005948 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005949 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5950 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005951 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005952 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005953
John McCall16df1e52010-03-30 21:47:33 +00005954 NamedDecl *FoundDecl = E->getFoundDecl();
5955 if (FoundDecl == E->getMemberDecl()) {
5956 FoundDecl = Member;
5957 } else {
5958 FoundDecl = cast_or_null<NamedDecl>(
5959 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5960 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005961 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005962 }
5963
Douglas Gregora16548e2009-08-11 05:31:07 +00005964 if (!getDerived().AlwaysRebuild() &&
5965 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005966 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005967 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005968 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005969 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005970
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005971 // Mark it referenced in the new context regardless.
5972 // FIXME: this is a bit instantiation-specific.
5973 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005974 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005975 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005976
John McCall6b51f282009-11-23 01:53:49 +00005977 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005978 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005979 TransArgs.setLAngleLoc(E->getLAngleLoc());
5980 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005981 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5982 E->getNumTemplateArgs(),
5983 TransArgs))
5984 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005985 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005986
Douglas Gregora16548e2009-08-11 05:31:07 +00005987 // FIXME: Bogus source location for the operator
5988 SourceLocation FakeOperatorLoc
5989 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5990
John McCall38836f02010-01-15 08:34:02 +00005991 // FIXME: to do this check properly, we will need to preserve the
5992 // first-qualifier-in-scope here, just in case we had a dependent
5993 // base (and therefore couldn't do the check) and a
5994 // nested-name-qualifier (and therefore could do the lookup).
5995 NamedDecl *FirstQualifierInScope = 0;
5996
John McCallb268a282010-08-23 23:25:46 +00005997 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005998 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005999 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006000 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006001 Member,
John McCall16df1e52010-03-30 21:47:33 +00006002 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006003 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006004 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006005 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006006}
Mike Stump11289f42009-09-09 15:08:12 +00006007
Douglas Gregora16548e2009-08-11 05:31:07 +00006008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006009ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006010TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006011 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006013 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006014
John McCalldadc5752010-08-24 06:29:42 +00006015 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006016 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006017 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006018
Douglas Gregora16548e2009-08-11 05:31:07 +00006019 if (!getDerived().AlwaysRebuild() &&
6020 LHS.get() == E->getLHS() &&
6021 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006022 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006023
Douglas Gregora16548e2009-08-11 05:31:07 +00006024 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006025 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006026}
6027
Mike Stump11289f42009-09-09 15:08:12 +00006028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006029ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006030TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006031 CompoundAssignOperator *E) {
6032 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006033}
Mike Stump11289f42009-09-09 15:08:12 +00006034
Douglas Gregora16548e2009-08-11 05:31:07 +00006035template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006036ExprResult TreeTransform<Derived>::
6037TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6038 // Just rebuild the common and RHS expressions and see whether we
6039 // get any changes.
6040
6041 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6042 if (commonExpr.isInvalid())
6043 return ExprError();
6044
6045 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6046 if (rhs.isInvalid())
6047 return ExprError();
6048
6049 if (!getDerived().AlwaysRebuild() &&
6050 commonExpr.get() == e->getCommon() &&
6051 rhs.get() == e->getFalseExpr())
6052 return SemaRef.Owned(e);
6053
6054 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6055 e->getQuestionLoc(),
6056 0,
6057 e->getColonLoc(),
6058 rhs.get());
6059}
6060
6061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006062ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006063TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006064 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006065 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006066 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006067
John McCalldadc5752010-08-24 06:29:42 +00006068 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006069 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006070 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006071
John McCalldadc5752010-08-24 06:29:42 +00006072 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006073 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006074 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006075
Douglas Gregora16548e2009-08-11 05:31:07 +00006076 if (!getDerived().AlwaysRebuild() &&
6077 Cond.get() == E->getCond() &&
6078 LHS.get() == E->getLHS() &&
6079 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006080 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006081
John McCallb268a282010-08-23 23:25:46 +00006082 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006083 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006084 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006085 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006086 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006087}
Mike Stump11289f42009-09-09 15:08:12 +00006088
6089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006091TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006092 // Implicit casts are eliminated during transformation, since they
6093 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006094 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006095}
Mike Stump11289f42009-09-09 15:08:12 +00006096
Douglas Gregora16548e2009-08-11 05:31:07 +00006097template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006098ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006099TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006100 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6101 if (!Type)
6102 return ExprError();
6103
John McCalldadc5752010-08-24 06:29:42 +00006104 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006105 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006106 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006107 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006108
Douglas Gregora16548e2009-08-11 05:31:07 +00006109 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006110 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006111 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006112 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006113
John McCall97513962010-01-15 18:39:57 +00006114 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006115 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006116 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006117 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006118}
Mike Stump11289f42009-09-09 15:08:12 +00006119
Douglas Gregora16548e2009-08-11 05:31:07 +00006120template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006121ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006122TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006123 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6124 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6125 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006126 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006127
John McCalldadc5752010-08-24 06:29:42 +00006128 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006129 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006131
Douglas Gregora16548e2009-08-11 05:31:07 +00006132 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006133 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006134 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006135 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006136
John McCall5d7aa7f2010-01-19 22:33:45 +00006137 // Note: the expression type doesn't necessarily match the
6138 // type-as-written, but that's okay, because it should always be
6139 // derivable from the initializer.
6140
John McCalle15bbff2010-01-18 19:35:47 +00006141 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006142 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006143 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
John McCall47f29ea2009-12-08 09:21:05 +00006148TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006149 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006150 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006151 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006152
Douglas Gregora16548e2009-08-11 05:31:07 +00006153 if (!getDerived().AlwaysRebuild() &&
6154 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006155 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006156
Douglas Gregora16548e2009-08-11 05:31:07 +00006157 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006158 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006159 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006160 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006161 E->getAccessorLoc(),
6162 E->getAccessor());
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>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006168 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006169
John McCall37ad5512010-08-23 06:44:23 +00006170 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006171 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6172 Inits, &InitChanged))
6173 return ExprError();
6174
Douglas Gregora16548e2009-08-11 05:31:07 +00006175 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006176 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006177
Douglas Gregora16548e2009-08-11 05:31:07 +00006178 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006179 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006180}
Mike Stump11289f42009-09-09 15:08:12 +00006181
Douglas Gregora16548e2009-08-11 05:31:07 +00006182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006183ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006184TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006185 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006186
Douglas Gregorebe10102009-08-20 07:17:43 +00006187 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006188 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006189 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006190 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006191
Douglas Gregorebe10102009-08-20 07:17:43 +00006192 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006193 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006194 bool ExprChanged = false;
6195 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6196 DEnd = E->designators_end();
6197 D != DEnd; ++D) {
6198 if (D->isFieldDesignator()) {
6199 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6200 D->getDotLoc(),
6201 D->getFieldLoc()));
6202 continue;
6203 }
Mike Stump11289f42009-09-09 15:08:12 +00006204
Douglas Gregora16548e2009-08-11 05:31:07 +00006205 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006206 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006207 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006208 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006209
6210 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006211 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006212
Douglas Gregora16548e2009-08-11 05:31:07 +00006213 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6214 ArrayExprs.push_back(Index.release());
6215 continue;
6216 }
Mike Stump11289f42009-09-09 15:08:12 +00006217
Douglas Gregora16548e2009-08-11 05:31:07 +00006218 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006219 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006220 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6221 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006223
John McCalldadc5752010-08-24 06:29:42 +00006224 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006225 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006227
6228 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006229 End.get(),
6230 D->getLBracketLoc(),
6231 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006232
Douglas Gregora16548e2009-08-11 05:31:07 +00006233 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6234 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006235
Douglas Gregora16548e2009-08-11 05:31:07 +00006236 ArrayExprs.push_back(Start.release());
6237 ArrayExprs.push_back(End.release());
6238 }
Mike Stump11289f42009-09-09 15:08:12 +00006239
Douglas Gregora16548e2009-08-11 05:31:07 +00006240 if (!getDerived().AlwaysRebuild() &&
6241 Init.get() == E->getInit() &&
6242 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006243 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006244
Douglas Gregora16548e2009-08-11 05:31:07 +00006245 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6246 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006247 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006248}
Mike Stump11289f42009-09-09 15:08:12 +00006249
Douglas Gregora16548e2009-08-11 05:31:07 +00006250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006251ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006252TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006253 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006254 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006255
Douglas Gregor3da3c062009-10-28 00:29:27 +00006256 // FIXME: Will we ever have proper type location here? Will we actually
6257 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006258 QualType T = getDerived().TransformType(E->getType());
6259 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006260 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006261
Douglas Gregora16548e2009-08-11 05:31:07 +00006262 if (!getDerived().AlwaysRebuild() &&
6263 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006264 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006265
Douglas Gregora16548e2009-08-11 05:31:07 +00006266 return getDerived().RebuildImplicitValueInitExpr(T);
6267}
Mike Stump11289f42009-09-09 15:08:12 +00006268
Douglas Gregora16548e2009-08-11 05:31:07 +00006269template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006270ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006271TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006272 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6273 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006274 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006275
John McCalldadc5752010-08-24 06:29:42 +00006276 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006277 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006278 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006279
Douglas Gregora16548e2009-08-11 05:31:07 +00006280 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006281 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006282 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006283 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006284
John McCallb268a282010-08-23 23:25:46 +00006285 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006286 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006287}
6288
6289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006290ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006291TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006292 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006293 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006294 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6295 &ArgumentChanged))
6296 return ExprError();
6297
Douglas Gregora16548e2009-08-11 05:31:07 +00006298 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6299 move_arg(Inits),
6300 E->getRParenLoc());
6301}
Mike Stump11289f42009-09-09 15:08:12 +00006302
Douglas Gregora16548e2009-08-11 05:31:07 +00006303/// \brief Transform an address-of-label expression.
6304///
6305/// By default, the transformation of an address-of-label expression always
6306/// rebuilds the expression, so that the label identifier can be resolved to
6307/// the corresponding label statement by semantic analysis.
6308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006309ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006310TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006311 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6312 E->getLabel());
6313 if (!LD)
6314 return ExprError();
6315
Douglas Gregora16548e2009-08-11 05:31:07 +00006316 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006317 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006318}
Mike Stump11289f42009-09-09 15:08:12 +00006319
6320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006321ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006322TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006323 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006324 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6325 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006326 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006327
Douglas Gregora16548e2009-08-11 05:31:07 +00006328 if (!getDerived().AlwaysRebuild() &&
6329 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006330 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006331
6332 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006333 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006334 E->getRParenLoc());
6335}
Mike Stump11289f42009-09-09 15:08:12 +00006336
Douglas Gregora16548e2009-08-11 05:31:07 +00006337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006338ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006339TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006340 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006341 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006342 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006343
John McCalldadc5752010-08-24 06:29:42 +00006344 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006345 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006347
John McCalldadc5752010-08-24 06:29:42 +00006348 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006349 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006350 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006351
Douglas Gregora16548e2009-08-11 05:31:07 +00006352 if (!getDerived().AlwaysRebuild() &&
6353 Cond.get() == E->getCond() &&
6354 LHS.get() == E->getLHS() &&
6355 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006356 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006357
Douglas Gregora16548e2009-08-11 05:31:07 +00006358 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006359 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006360 E->getRParenLoc());
6361}
Mike Stump11289f42009-09-09 15:08:12 +00006362
Douglas Gregora16548e2009-08-11 05:31:07 +00006363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006364ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006365TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006366 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006367}
6368
6369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006370ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006371TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006372 switch (E->getOperator()) {
6373 case OO_New:
6374 case OO_Delete:
6375 case OO_Array_New:
6376 case OO_Array_Delete:
6377 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006378 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006379
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006380 case OO_Call: {
6381 // This is a call to an object's operator().
6382 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6383
6384 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006385 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006386 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006387 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006388
6389 // FIXME: Poor location information
6390 SourceLocation FakeLParenLoc
6391 = SemaRef.PP.getLocForEndOfToken(
6392 static_cast<Expr *>(Object.get())->getLocEnd());
6393
6394 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006395 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006396 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6397 Args))
6398 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006399
John McCallb268a282010-08-23 23:25:46 +00006400 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006401 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006402 E->getLocEnd());
6403 }
6404
6405#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6406 case OO_##Name:
6407#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6408#include "clang/Basic/OperatorKinds.def"
6409 case OO_Subscript:
6410 // Handled below.
6411 break;
6412
6413 case OO_Conditional:
6414 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006415 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006416
6417 case OO_None:
6418 case NUM_OVERLOADED_OPERATORS:
6419 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006420 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006421 }
6422
John McCalldadc5752010-08-24 06:29:42 +00006423 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006424 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006425 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006426
John McCalldadc5752010-08-24 06:29:42 +00006427 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006428 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006429 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006430
John McCalldadc5752010-08-24 06:29:42 +00006431 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006432 if (E->getNumArgs() == 2) {
6433 Second = getDerived().TransformExpr(E->getArg(1));
6434 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006435 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006436 }
Mike Stump11289f42009-09-09 15:08:12 +00006437
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 if (!getDerived().AlwaysRebuild() &&
6439 Callee.get() == E->getCallee() &&
6440 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006441 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006442 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006443
Douglas Gregora16548e2009-08-11 05:31:07 +00006444 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6445 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006446 Callee.get(),
6447 First.get(),
6448 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006449}
Mike Stump11289f42009-09-09 15:08:12 +00006450
Douglas Gregora16548e2009-08-11 05:31:07 +00006451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006452ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006453TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6454 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006455}
Mike Stump11289f42009-09-09 15:08:12 +00006456
Douglas Gregora16548e2009-08-11 05:31:07 +00006457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006458ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006459TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6460 // Transform the callee.
6461 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6462 if (Callee.isInvalid())
6463 return ExprError();
6464
6465 // Transform exec config.
6466 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6467 if (EC.isInvalid())
6468 return ExprError();
6469
6470 // Transform arguments.
6471 bool ArgChanged = false;
6472 ASTOwningVector<Expr*> Args(SemaRef);
6473 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6474 &ArgChanged))
6475 return ExprError();
6476
6477 if (!getDerived().AlwaysRebuild() &&
6478 Callee.get() == E->getCallee() &&
6479 !ArgChanged)
6480 return SemaRef.Owned(E);
6481
6482 // FIXME: Wrong source location information for the '('.
6483 SourceLocation FakeLParenLoc
6484 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6485 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6486 move_arg(Args),
6487 E->getRParenLoc(), EC.get());
6488}
6489
6490template<typename Derived>
6491ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006492TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006493 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6494 if (!Type)
6495 return ExprError();
6496
John McCalldadc5752010-08-24 06:29:42 +00006497 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006498 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006499 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006500 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006501
Douglas Gregora16548e2009-08-11 05:31:07 +00006502 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006503 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006504 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006505 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006506
Douglas Gregora16548e2009-08-11 05:31:07 +00006507 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006508 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006509 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6510 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6511 SourceLocation FakeRParenLoc
6512 = SemaRef.PP.getLocForEndOfToken(
6513 E->getSubExpr()->getSourceRange().getEnd());
6514 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006515 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006516 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006517 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006518 FakeRAngleLoc,
6519 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006520 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006521 FakeRParenLoc);
6522}
Mike Stump11289f42009-09-09 15:08:12 +00006523
Douglas Gregora16548e2009-08-11 05:31:07 +00006524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006525ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006526TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6527 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006528}
Mike Stump11289f42009-09-09 15:08:12 +00006529
6530template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006531ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006532TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6533 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006534}
6535
Douglas Gregora16548e2009-08-11 05:31:07 +00006536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006537ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006538TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006539 CXXReinterpretCastExpr *E) {
6540 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006541}
Mike Stump11289f42009-09-09 15:08:12 +00006542
Douglas Gregora16548e2009-08-11 05:31:07 +00006543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006544ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006545TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6546 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006547}
Mike Stump11289f42009-09-09 15:08:12 +00006548
Douglas Gregora16548e2009-08-11 05:31:07 +00006549template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006550ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006551TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006552 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006553 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6554 if (!Type)
6555 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006556
John McCalldadc5752010-08-24 06:29:42 +00006557 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006558 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006559 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006560 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006561
Douglas Gregora16548e2009-08-11 05:31:07 +00006562 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006563 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006564 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006565 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006566
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006567 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006568 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006569 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006570 E->getRParenLoc());
6571}
Mike Stump11289f42009-09-09 15:08:12 +00006572
Douglas Gregora16548e2009-08-11 05:31:07 +00006573template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006574ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006575TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006576 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006577 TypeSourceInfo *TInfo
6578 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6579 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006580 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006581
Douglas Gregora16548e2009-08-11 05:31:07 +00006582 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006583 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006584 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006585
Douglas Gregor9da64192010-04-26 22:37:10 +00006586 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6587 E->getLocStart(),
6588 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006589 E->getLocEnd());
6590 }
Mike Stump11289f42009-09-09 15:08:12 +00006591
Douglas Gregora16548e2009-08-11 05:31:07 +00006592 // We don't know whether the expression is potentially evaluated until
6593 // after we perform semantic analysis, so the expression is potentially
6594 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006595 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006596 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006597
John McCalldadc5752010-08-24 06:29:42 +00006598 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006599 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006601
Douglas Gregora16548e2009-08-11 05:31:07 +00006602 if (!getDerived().AlwaysRebuild() &&
6603 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006604 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006605
Douglas Gregor9da64192010-04-26 22:37:10 +00006606 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6607 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006608 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006609 E->getLocEnd());
6610}
6611
6612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006613ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006614TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6615 if (E->isTypeOperand()) {
6616 TypeSourceInfo *TInfo
6617 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6618 if (!TInfo)
6619 return ExprError();
6620
6621 if (!getDerived().AlwaysRebuild() &&
6622 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006623 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006624
6625 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6626 E->getLocStart(),
6627 TInfo,
6628 E->getLocEnd());
6629 }
6630
6631 // We don't know whether the expression is potentially evaluated until
6632 // after we perform semantic analysis, so the expression is potentially
6633 // potentially evaluated.
6634 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6635
6636 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6637 if (SubExpr.isInvalid())
6638 return ExprError();
6639
6640 if (!getDerived().AlwaysRebuild() &&
6641 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006642 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006643
6644 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6645 E->getLocStart(),
6646 SubExpr.get(),
6647 E->getLocEnd());
6648}
6649
6650template<typename Derived>
6651ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006652TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006653 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006654}
Mike Stump11289f42009-09-09 15:08:12 +00006655
Douglas Gregora16548e2009-08-11 05:31:07 +00006656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006657ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006658TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006659 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006660 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006661}
Mike Stump11289f42009-09-09 15:08:12 +00006662
Douglas Gregora16548e2009-08-11 05:31:07 +00006663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006665TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006666 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6667 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6668 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006669
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006670 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006671 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006672
Douglas Gregorb15af892010-01-07 23:12:05 +00006673 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006674}
Mike Stump11289f42009-09-09 15:08:12 +00006675
Douglas Gregora16548e2009-08-11 05:31:07 +00006676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006677ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006678TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006679 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006680 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006681 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006682
Douglas Gregora16548e2009-08-11 05:31:07 +00006683 if (!getDerived().AlwaysRebuild() &&
6684 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006685 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006686
John McCallb268a282010-08-23 23:25:46 +00006687 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006688}
Mike Stump11289f42009-09-09 15:08:12 +00006689
Douglas Gregora16548e2009-08-11 05:31:07 +00006690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006691ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006692TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006693 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006694 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6695 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006696 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006697 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006698
Chandler Carruth794da4c2010-02-08 06:42:49 +00006699 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006700 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006701 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006702
Douglas Gregor033f6752009-12-23 23:03:06 +00006703 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006704}
Mike Stump11289f42009-09-09 15:08:12 +00006705
Douglas Gregora16548e2009-08-11 05:31:07 +00006706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006707ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006708TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6709 CXXScalarValueInitExpr *E) {
6710 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6711 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006712 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006713
Douglas Gregora16548e2009-08-11 05:31:07 +00006714 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006715 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006716 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006717
Douglas Gregor2b88c112010-09-08 00:15:04 +00006718 return getDerived().RebuildCXXScalarValueInitExpr(T,
6719 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006720 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006721}
Mike Stump11289f42009-09-09 15:08:12 +00006722
Douglas Gregora16548e2009-08-11 05:31:07 +00006723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006724ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006725TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006726 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006727 TypeSourceInfo *AllocTypeInfo
6728 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6729 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006730 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006731
Douglas Gregora16548e2009-08-11 05:31:07 +00006732 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006733 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006734 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006735 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006736
Douglas Gregora16548e2009-08-11 05:31:07 +00006737 // Transform the placement arguments (if any).
6738 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006739 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006740 if (getDerived().TransformExprs(E->getPlacementArgs(),
6741 E->getNumPlacementArgs(), true,
6742 PlacementArgs, &ArgumentChanged))
6743 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006744
Douglas Gregorebe10102009-08-20 07:17:43 +00006745 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006746 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006747 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6748 ConstructorArgs, &ArgumentChanged))
6749 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006750
Douglas Gregord2d9da02010-02-26 00:38:10 +00006751 // Transform constructor, new operator, and delete operator.
6752 CXXConstructorDecl *Constructor = 0;
6753 if (E->getConstructor()) {
6754 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006755 getDerived().TransformDecl(E->getLocStart(),
6756 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006757 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006758 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006759 }
6760
6761 FunctionDecl *OperatorNew = 0;
6762 if (E->getOperatorNew()) {
6763 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006764 getDerived().TransformDecl(E->getLocStart(),
6765 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006766 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006767 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006768 }
6769
6770 FunctionDecl *OperatorDelete = 0;
6771 if (E->getOperatorDelete()) {
6772 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006773 getDerived().TransformDecl(E->getLocStart(),
6774 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006775 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006776 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006777 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006778
Douglas Gregora16548e2009-08-11 05:31:07 +00006779 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006780 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006781 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006782 Constructor == E->getConstructor() &&
6783 OperatorNew == E->getOperatorNew() &&
6784 OperatorDelete == E->getOperatorDelete() &&
6785 !ArgumentChanged) {
6786 // Mark any declarations we need as referenced.
6787 // FIXME: instantiation-specific.
6788 if (Constructor)
6789 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6790 if (OperatorNew)
6791 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6792 if (OperatorDelete)
6793 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006794 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006795 }
Mike Stump11289f42009-09-09 15:08:12 +00006796
Douglas Gregor0744ef62010-09-07 21:49:58 +00006797 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006798 if (!ArraySize.get()) {
6799 // If no array size was specified, but the new expression was
6800 // instantiated with an array type (e.g., "new T" where T is
6801 // instantiated with "int[4]"), extract the outer bound from the
6802 // array type as our array size. We do this with constant and
6803 // dependently-sized array types.
6804 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6805 if (!ArrayT) {
6806 // Do nothing
6807 } else if (const ConstantArrayType *ConsArrayT
6808 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006809 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006810 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6811 ConsArrayT->getSize(),
6812 SemaRef.Context.getSizeType(),
6813 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006814 AllocType = ConsArrayT->getElementType();
6815 } else if (const DependentSizedArrayType *DepArrayT
6816 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6817 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006818 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006819 AllocType = DepArrayT->getElementType();
6820 }
6821 }
6822 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006823
Douglas Gregora16548e2009-08-11 05:31:07 +00006824 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6825 E->isGlobalNew(),
6826 /*FIXME:*/E->getLocStart(),
6827 move_arg(PlacementArgs),
6828 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006829 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006830 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006831 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006832 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006833 /*FIXME:*/E->getLocStart(),
6834 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006835 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006836}
Mike Stump11289f42009-09-09 15:08:12 +00006837
Douglas Gregora16548e2009-08-11 05:31:07 +00006838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006839ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006840TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006841 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006842 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006843 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006844
Douglas Gregord2d9da02010-02-26 00:38:10 +00006845 // Transform the delete operator, if known.
6846 FunctionDecl *OperatorDelete = 0;
6847 if (E->getOperatorDelete()) {
6848 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006849 getDerived().TransformDecl(E->getLocStart(),
6850 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006851 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006852 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006853 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006854
Douglas Gregora16548e2009-08-11 05:31:07 +00006855 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006856 Operand.get() == E->getArgument() &&
6857 OperatorDelete == E->getOperatorDelete()) {
6858 // Mark any declarations we need as referenced.
6859 // FIXME: instantiation-specific.
6860 if (OperatorDelete)
6861 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006862
6863 if (!E->getArgument()->isTypeDependent()) {
6864 QualType Destroyed = SemaRef.Context.getBaseElementType(
6865 E->getDestroyedType());
6866 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6867 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6868 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6869 SemaRef.LookupDestructor(Record));
6870 }
6871 }
6872
John McCallc3007a22010-10-26 07:05:15 +00006873 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006874 }
Mike Stump11289f42009-09-09 15:08:12 +00006875
Douglas Gregora16548e2009-08-11 05:31:07 +00006876 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6877 E->isGlobalDelete(),
6878 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006879 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006880}
Mike Stump11289f42009-09-09 15:08:12 +00006881
Douglas Gregora16548e2009-08-11 05:31:07 +00006882template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006883ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006884TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006885 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006886 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006887 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006889
John McCallba7bf592010-08-24 05:47:05 +00006890 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006891 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006892 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006893 E->getOperatorLoc(),
6894 E->isArrow()? tok::arrow : tok::period,
6895 ObjectTypePtr,
6896 MayBePseudoDestructor);
6897 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006898 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006899
John McCallba7bf592010-08-24 05:47:05 +00006900 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006901 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6902 if (QualifierLoc) {
6903 QualifierLoc
6904 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6905 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006906 return ExprError();
6907 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006908 CXXScopeSpec SS;
6909 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006910
Douglas Gregor678f90d2010-02-25 01:56:36 +00006911 PseudoDestructorTypeStorage Destroyed;
6912 if (E->getDestroyedTypeInfo()) {
6913 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006914 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006915 ObjectType, 0,
6916 QualifierLoc.getNestedNameSpecifier());
Douglas Gregor678f90d2010-02-25 01:56:36 +00006917 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006918 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006919 Destroyed = DestroyedTypeInfo;
6920 } else if (ObjectType->isDependentType()) {
6921 // We aren't likely to be able to resolve the identifier down to a type
6922 // now anyway, so just retain the identifier.
6923 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6924 E->getDestroyedTypeLoc());
6925 } else {
6926 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006927 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006928 *E->getDestroyedTypeIdentifier(),
6929 E->getDestroyedTypeLoc(),
6930 /*Scope=*/0,
6931 SS, ObjectTypePtr,
6932 false);
6933 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006934 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006935
Douglas Gregor678f90d2010-02-25 01:56:36 +00006936 Destroyed
6937 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6938 E->getDestroyedTypeLoc());
6939 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006940
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006941 TypeSourceInfo *ScopeTypeInfo = 0;
6942 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006943 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006944 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006945 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006946 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006947
John McCallb268a282010-08-23 23:25:46 +00006948 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006949 E->getOperatorLoc(),
6950 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006951 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006952 ScopeTypeInfo,
6953 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006954 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006955 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006956}
Mike Stump11289f42009-09-09 15:08:12 +00006957
Douglas Gregorad8a3362009-09-04 17:36:40 +00006958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006959ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006960TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006961 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006962 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6963
6964 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6965 Sema::LookupOrdinaryName);
6966
6967 // Transform all the decls.
6968 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6969 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006970 NamedDecl *InstD = static_cast<NamedDecl*>(
6971 getDerived().TransformDecl(Old->getNameLoc(),
6972 *I));
John McCall84d87672009-12-10 09:41:52 +00006973 if (!InstD) {
6974 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6975 // This can happen because of dependent hiding.
6976 if (isa<UsingShadowDecl>(*I))
6977 continue;
6978 else
John McCallfaf5fb42010-08-26 23:41:50 +00006979 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006980 }
John McCalle66edc12009-11-24 19:00:30 +00006981
6982 // Expand using declarations.
6983 if (isa<UsingDecl>(InstD)) {
6984 UsingDecl *UD = cast<UsingDecl>(InstD);
6985 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6986 E = UD->shadow_end(); I != E; ++I)
6987 R.addDecl(*I);
6988 continue;
6989 }
6990
6991 R.addDecl(InstD);
6992 }
6993
6994 // Resolve a kind, but don't do any further analysis. If it's
6995 // ambiguous, the callee needs to deal with it.
6996 R.resolveKind();
6997
6998 // Rebuild the nested-name qualifier, if present.
6999 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007000 if (Old->getQualifierLoc()) {
7001 NestedNameSpecifierLoc QualifierLoc
7002 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7003 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007004 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007005
Douglas Gregor0da1d432011-02-28 20:01:57 +00007006 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007007 }
7008
Douglas Gregor9262f472010-04-27 18:19:34 +00007009 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007010 CXXRecordDecl *NamingClass
7011 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7012 Old->getNameLoc(),
7013 Old->getNamingClass()));
7014 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007015 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007016
Douglas Gregorda7be082010-04-27 16:10:10 +00007017 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007018 }
7019
7020 // If we have no template arguments, it's a normal declaration name.
7021 if (!Old->hasExplicitTemplateArgs())
7022 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7023
7024 // If we have template arguments, rebuild them, then rebuild the
7025 // templateid expression.
7026 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007027 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7028 Old->getNumTemplateArgs(),
7029 TransArgs))
7030 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007031
7032 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7033 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007034}
Mike Stump11289f42009-09-09 15:08:12 +00007035
Douglas Gregora16548e2009-08-11 05:31:07 +00007036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007037ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007038TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007039 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7040 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007041 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007042
Douglas Gregora16548e2009-08-11 05:31:07 +00007043 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007044 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007045 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007046
Mike Stump11289f42009-09-09 15:08:12 +00007047 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007048 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007049 T,
7050 E->getLocEnd());
7051}
Mike Stump11289f42009-09-09 15:08:12 +00007052
Douglas Gregora16548e2009-08-11 05:31:07 +00007053template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007054ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007055TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7056 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7057 if (!LhsT)
7058 return ExprError();
7059
7060 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7061 if (!RhsT)
7062 return ExprError();
7063
7064 if (!getDerived().AlwaysRebuild() &&
7065 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7066 return SemaRef.Owned(E);
7067
7068 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7069 E->getLocStart(),
7070 LhsT, RhsT,
7071 E->getLocEnd());
7072}
7073
7074template<typename Derived>
7075ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007076TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007077 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007078 NestedNameSpecifierLoc QualifierLoc
7079 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7080 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007081 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007082
John McCall31f82722010-11-12 08:19:04 +00007083 // TODO: If this is a conversion-function-id, verify that the
7084 // destination type name (if present) resolves the same way after
7085 // instantiation as it did in the local scope.
7086
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007087 DeclarationNameInfo NameInfo
7088 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7089 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007090 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007091
John McCalle66edc12009-11-24 19:00:30 +00007092 if (!E->hasExplicitTemplateArgs()) {
7093 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007094 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007095 // Note: it is sufficient to compare the Name component of NameInfo:
7096 // if name has not changed, DNLoc has not changed either.
7097 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007098 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007099
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007100 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007101 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007102 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007103 }
John McCall6b51f282009-11-23 01:53:49 +00007104
7105 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007106 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7107 E->getNumTemplateArgs(),
7108 TransArgs))
7109 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007110
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007111 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007112 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007113 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007114}
7115
7116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007117ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007118TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007119 // CXXConstructExprs are always implicit, so when we have a
7120 // 1-argument construction we just transform that argument.
7121 if (E->getNumArgs() == 1 ||
7122 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7123 return getDerived().TransformExpr(E->getArg(0));
7124
Douglas Gregora16548e2009-08-11 05:31:07 +00007125 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7126
7127 QualType T = getDerived().TransformType(E->getType());
7128 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007129 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007130
7131 CXXConstructorDecl *Constructor
7132 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007133 getDerived().TransformDecl(E->getLocStart(),
7134 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007135 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007136 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007137
Douglas Gregora16548e2009-08-11 05:31:07 +00007138 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007139 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007140 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7141 &ArgumentChanged))
7142 return ExprError();
7143
Douglas Gregora16548e2009-08-11 05:31:07 +00007144 if (!getDerived().AlwaysRebuild() &&
7145 T == E->getType() &&
7146 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007147 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007148 // Mark the constructor as referenced.
7149 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007150 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007151 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007152 }
Mike Stump11289f42009-09-09 15:08:12 +00007153
Douglas Gregordb121ba2009-12-14 16:27:04 +00007154 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7155 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007156 move_arg(Args),
7157 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007158 E->getConstructionKind(),
7159 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007160}
Mike Stump11289f42009-09-09 15:08:12 +00007161
Douglas Gregora16548e2009-08-11 05:31:07 +00007162/// \brief Transform a C++ temporary-binding expression.
7163///
Douglas Gregor363b1512009-12-24 18:51:59 +00007164/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7165/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007168TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007169 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007170}
Mike Stump11289f42009-09-09 15:08:12 +00007171
John McCall5d413782010-12-06 08:20:24 +00007172/// \brief Transform a C++ expression that contains cleanups that should
7173/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007174///
John McCall5d413782010-12-06 08:20:24 +00007175/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007176/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007178ExprResult
John McCall5d413782010-12-06 08:20:24 +00007179TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007180 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007181}
Mike Stump11289f42009-09-09 15:08:12 +00007182
Douglas Gregora16548e2009-08-11 05:31:07 +00007183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007184ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007185TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007186 CXXTemporaryObjectExpr *E) {
7187 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7188 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007189 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007190
Douglas Gregora16548e2009-08-11 05:31:07 +00007191 CXXConstructorDecl *Constructor
7192 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007193 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007194 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007195 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007197
Douglas Gregora16548e2009-08-11 05:31:07 +00007198 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007199 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007200 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007201 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7202 &ArgumentChanged))
7203 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007204
Douglas Gregora16548e2009-08-11 05:31:07 +00007205 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007206 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007207 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007208 !ArgumentChanged) {
7209 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007210 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007211 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007212 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007213
7214 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7215 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007216 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007217 E->getLocEnd());
7218}
Mike Stump11289f42009-09-09 15:08:12 +00007219
Douglas Gregora16548e2009-08-11 05:31:07 +00007220template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007221ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007222TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007223 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007224 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7225 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007227
Douglas Gregora16548e2009-08-11 05:31:07 +00007228 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007229 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007230 Args.reserve(E->arg_size());
7231 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7232 &ArgumentChanged))
7233 return ExprError();
7234
Douglas Gregora16548e2009-08-11 05:31:07 +00007235 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007236 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007237 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007238 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007239
Douglas Gregora16548e2009-08-11 05:31:07 +00007240 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007241 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007242 E->getLParenLoc(),
7243 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007244 E->getRParenLoc());
7245}
Mike Stump11289f42009-09-09 15:08:12 +00007246
Douglas Gregora16548e2009-08-11 05:31:07 +00007247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007248ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007249TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007250 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007251 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007252 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007253 Expr *OldBase;
7254 QualType BaseType;
7255 QualType ObjectType;
7256 if (!E->isImplicitAccess()) {
7257 OldBase = E->getBase();
7258 Base = getDerived().TransformExpr(OldBase);
7259 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007260 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007261
John McCall2d74de92009-12-01 22:10:20 +00007262 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007263 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007264 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007265 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007266 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007267 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007268 ObjectTy,
7269 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007270 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007271 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007272
John McCallba7bf592010-08-24 05:47:05 +00007273 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007274 BaseType = ((Expr*) Base.get())->getType();
7275 } else {
7276 OldBase = 0;
7277 BaseType = getDerived().TransformType(E->getBaseType());
7278 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7279 }
Mike Stump11289f42009-09-09 15:08:12 +00007280
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007281 // Transform the first part of the nested-name-specifier that qualifies
7282 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007283 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007284 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007285 E->getFirstQualifierFoundInScope(),
7286 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007287
Douglas Gregore16af532011-02-28 18:50:33 +00007288 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007289 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007290 QualifierLoc
7291 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7292 ObjectType,
7293 FirstQualifierInScope);
7294 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007295 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007296 }
Mike Stump11289f42009-09-09 15:08:12 +00007297
John McCall31f82722010-11-12 08:19:04 +00007298 // TODO: If this is a conversion-function-id, verify that the
7299 // destination type name (if present) resolves the same way after
7300 // instantiation as it did in the local scope.
7301
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007302 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007303 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007304 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007305 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007306
John McCall2d74de92009-12-01 22:10:20 +00007307 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007308 // This is a reference to a member without an explicitly-specified
7309 // template argument list. Optimize for this common case.
7310 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007311 Base.get() == OldBase &&
7312 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007313 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007314 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007315 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007316 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007317
John McCallb268a282010-08-23 23:25:46 +00007318 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007319 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007320 E->isArrow(),
7321 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007322 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007323 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007324 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007325 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007326 }
7327
John McCall6b51f282009-11-23 01:53:49 +00007328 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007329 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7330 E->getNumTemplateArgs(),
7331 TransArgs))
7332 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007333
John McCallb268a282010-08-23 23:25:46 +00007334 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007335 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007336 E->isArrow(),
7337 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007338 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007339 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007340 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007341 &TransArgs);
7342}
7343
7344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007345ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007346TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007347 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007348 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007349 QualType BaseType;
7350 if (!Old->isImplicitAccess()) {
7351 Base = getDerived().TransformExpr(Old->getBase());
7352 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007353 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007354 BaseType = ((Expr*) Base.get())->getType();
7355 } else {
7356 BaseType = getDerived().TransformType(Old->getBaseType());
7357 }
John McCall10eae182009-11-30 22:42:35 +00007358
Douglas Gregor0da1d432011-02-28 20:01:57 +00007359 NestedNameSpecifierLoc QualifierLoc;
7360 if (Old->getQualifierLoc()) {
7361 QualifierLoc
7362 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7363 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007364 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007365 }
7366
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007367 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007368 Sema::LookupOrdinaryName);
7369
7370 // Transform all the decls.
7371 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7372 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007373 NamedDecl *InstD = static_cast<NamedDecl*>(
7374 getDerived().TransformDecl(Old->getMemberLoc(),
7375 *I));
John McCall84d87672009-12-10 09:41:52 +00007376 if (!InstD) {
7377 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7378 // This can happen because of dependent hiding.
7379 if (isa<UsingShadowDecl>(*I))
7380 continue;
7381 else
John McCallfaf5fb42010-08-26 23:41:50 +00007382 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007383 }
John McCall10eae182009-11-30 22:42:35 +00007384
7385 // Expand using declarations.
7386 if (isa<UsingDecl>(InstD)) {
7387 UsingDecl *UD = cast<UsingDecl>(InstD);
7388 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7389 E = UD->shadow_end(); I != E; ++I)
7390 R.addDecl(*I);
7391 continue;
7392 }
7393
7394 R.addDecl(InstD);
7395 }
7396
7397 R.resolveKind();
7398
Douglas Gregor9262f472010-04-27 18:19:34 +00007399 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007400 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007401 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007402 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007403 Old->getMemberLoc(),
7404 Old->getNamingClass()));
7405 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007406 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007407
Douglas Gregorda7be082010-04-27 16:10:10 +00007408 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007409 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007410
John McCall10eae182009-11-30 22:42:35 +00007411 TemplateArgumentListInfo TransArgs;
7412 if (Old->hasExplicitTemplateArgs()) {
7413 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7414 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007415 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7416 Old->getNumTemplateArgs(),
7417 TransArgs))
7418 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007419 }
John McCall38836f02010-01-15 08:34:02 +00007420
7421 // FIXME: to do this check properly, we will need to preserve the
7422 // first-qualifier-in-scope here, just in case we had a dependent
7423 // base (and therefore couldn't do the check) and a
7424 // nested-name-qualifier (and therefore could do the lookup).
7425 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007426
John McCallb268a282010-08-23 23:25:46 +00007427 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007428 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007429 Old->getOperatorLoc(),
7430 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007431 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007432 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007433 R,
7434 (Old->hasExplicitTemplateArgs()
7435 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007436}
7437
7438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007439ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007440TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7441 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7442 if (SubExpr.isInvalid())
7443 return ExprError();
7444
7445 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007446 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007447
7448 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7449}
7450
7451template<typename Derived>
7452ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007453TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007454 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7455 if (Pattern.isInvalid())
7456 return ExprError();
7457
7458 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7459 return SemaRef.Owned(E);
7460
Douglas Gregorb8840002011-01-14 21:20:45 +00007461 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7462 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007463}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007464
7465template<typename Derived>
7466ExprResult
7467TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7468 // If E is not value-dependent, then nothing will change when we transform it.
7469 // Note: This is an instantiation-centric view.
7470 if (!E->isValueDependent())
7471 return SemaRef.Owned(E);
7472
7473 // Note: None of the implementations of TryExpandParameterPacks can ever
7474 // produce a diagnostic when given only a single unexpanded parameter pack,
7475 // so
7476 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7477 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007478 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007479 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007480 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7481 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007482 ShouldExpand, RetainExpansion,
7483 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007484 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007485
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007486 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007487 return SemaRef.Owned(E);
7488
7489 // We now know the length of the parameter pack, so build a new expression
7490 // that stores that length.
7491 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7492 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007493 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007494}
7495
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007496template<typename Derived>
7497ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007498TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7499 SubstNonTypeTemplateParmPackExpr *E) {
7500 // Default behavior is to do nothing with this transformation.
7501 return SemaRef.Owned(E);
7502}
7503
7504template<typename Derived>
7505ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007506TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007507 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007508}
7509
Mike Stump11289f42009-09-09 15:08:12 +00007510template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007511ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007512TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007513 TypeSourceInfo *EncodedTypeInfo
7514 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7515 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007516 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007517
Douglas Gregora16548e2009-08-11 05:31:07 +00007518 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007519 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007520 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007521
7522 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007523 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007524 E->getRParenLoc());
7525}
Mike Stump11289f42009-09-09 15:08:12 +00007526
Douglas Gregora16548e2009-08-11 05:31:07 +00007527template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007528ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007529TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007530 // Transform arguments.
7531 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007532 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007533 Args.reserve(E->getNumArgs());
7534 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7535 &ArgChanged))
7536 return ExprError();
7537
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007538 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7539 // Class message: transform the receiver type.
7540 TypeSourceInfo *ReceiverTypeInfo
7541 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7542 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007543 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007544
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007545 // If nothing changed, just retain the existing message send.
7546 if (!getDerived().AlwaysRebuild() &&
7547 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007548 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007549
7550 // Build a new class message send.
7551 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7552 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007553 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007554 E->getMethodDecl(),
7555 E->getLeftLoc(),
7556 move_arg(Args),
7557 E->getRightLoc());
7558 }
7559
7560 // Instance message: transform the receiver
7561 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7562 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007563 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007564 = getDerived().TransformExpr(E->getInstanceReceiver());
7565 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007566 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007567
7568 // If nothing changed, just retain the existing message send.
7569 if (!getDerived().AlwaysRebuild() &&
7570 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007571 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007572
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007573 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007574 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007575 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007576 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007577 E->getMethodDecl(),
7578 E->getLeftLoc(),
7579 move_arg(Args),
7580 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007581}
7582
Mike Stump11289f42009-09-09 15:08:12 +00007583template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007584ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007585TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007586 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007587}
7588
Mike Stump11289f42009-09-09 15:08:12 +00007589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007591TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007592 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007593}
7594
Mike Stump11289f42009-09-09 15:08:12 +00007595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007596ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007597TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007598 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007599 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007600 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007601 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007602
7603 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007604
Douglas Gregord51d90d2010-04-26 20:11:03 +00007605 // If nothing changed, just retain the existing expression.
7606 if (!getDerived().AlwaysRebuild() &&
7607 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007608 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007609
John McCallb268a282010-08-23 23:25:46 +00007610 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007611 E->getLocation(),
7612 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007613}
7614
Mike Stump11289f42009-09-09 15:08:12 +00007615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007616ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007617TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007618 // 'super' and types never change. Property never changes. Just
7619 // retain the existing expression.
7620 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007621 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007622
Douglas Gregor9faee212010-04-26 20:47:02 +00007623 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007624 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007625 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007626 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007627
Douglas Gregor9faee212010-04-26 20:47:02 +00007628 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007629
Douglas Gregor9faee212010-04-26 20:47:02 +00007630 // If nothing changed, just retain the existing expression.
7631 if (!getDerived().AlwaysRebuild() &&
7632 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007633 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007634
John McCallb7bd14f2010-12-02 01:19:52 +00007635 if (E->isExplicitProperty())
7636 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7637 E->getExplicitProperty(),
7638 E->getLocation());
7639
7640 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7641 E->getType(),
7642 E->getImplicitPropertyGetter(),
7643 E->getImplicitPropertySetter(),
7644 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007645}
7646
Mike Stump11289f42009-09-09 15:08:12 +00007647template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007648ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007649TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007650 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007651 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007652 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007653 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007654
Douglas Gregord51d90d2010-04-26 20:11:03 +00007655 // If nothing changed, just retain the existing expression.
7656 if (!getDerived().AlwaysRebuild() &&
7657 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007658 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007659
John McCallb268a282010-08-23 23:25:46 +00007660 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007661 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007662}
7663
Mike Stump11289f42009-09-09 15:08:12 +00007664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007665ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007666TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007667 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007668 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007669 SubExprs.reserve(E->getNumSubExprs());
7670 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7671 SubExprs, &ArgumentChanged))
7672 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007673
Douglas Gregora16548e2009-08-11 05:31:07 +00007674 if (!getDerived().AlwaysRebuild() &&
7675 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007676 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007677
Douglas Gregora16548e2009-08-11 05:31:07 +00007678 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7679 move_arg(SubExprs),
7680 E->getRParenLoc());
7681}
7682
Mike Stump11289f42009-09-09 15:08:12 +00007683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007684ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007685TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007686 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007687
John McCall490112f2011-02-04 18:33:18 +00007688 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7689 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7690
7691 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7692 llvm::SmallVector<ParmVarDecl*, 4> params;
7693 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007694
7695 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007696 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7697 oldBlock->param_begin(),
7698 oldBlock->param_size(),
7699 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007700 return true;
John McCall490112f2011-02-04 18:33:18 +00007701
7702 const FunctionType *exprFunctionType = E->getFunctionType();
7703 QualType exprResultType = exprFunctionType->getResultType();
7704 if (!exprResultType.isNull()) {
7705 if (!exprResultType->isDependentType())
7706 blockScope->ReturnType = exprResultType;
7707 else if (exprResultType != getSema().Context.DependentTy)
7708 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007709 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007710
7711 // If the return type has not been determined yet, leave it as a dependent
7712 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007713 if (blockScope->ReturnType.isNull())
7714 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007715
7716 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007717 if (blockScope->ReturnType->isObjCObjectType()) {
7718 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007719 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007720 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007721 return ExprError();
7722 }
John McCall3882ace2011-01-05 12:14:39 +00007723
John McCall490112f2011-02-04 18:33:18 +00007724 QualType functionType = getDerived().RebuildFunctionProtoType(
7725 blockScope->ReturnType,
7726 paramTypes.data(),
7727 paramTypes.size(),
7728 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007729 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007730 exprFunctionType->getExtInfo());
7731 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007732
7733 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007734 if (!params.empty())
7735 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007736
7737 // If the return type wasn't explicitly set, it will have been marked as a
7738 // dependent type (DependentTy); clear out the return type setting so
7739 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007740 if (blockScope->ReturnType == getSema().Context.DependentTy)
7741 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007742
John McCall3882ace2011-01-05 12:14:39 +00007743 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007744 StmtResult body = getDerived().TransformStmt(E->getBody());
7745 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007746 return ExprError();
7747
John McCall490112f2011-02-04 18:33:18 +00007748#ifndef NDEBUG
7749 // In builds with assertions, make sure that we captured everything we
7750 // captured before.
7751
7752 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7753
7754 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7755 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007756 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007757
7758 // Ignore parameter packs.
7759 if (isa<ParmVarDecl>(oldCapture) &&
7760 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7761 continue;
7762
7763 VarDecl *newCapture =
7764 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7765 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007766 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007767 }
7768#endif
7769
7770 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7771 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007772}
7773
Mike Stump11289f42009-09-09 15:08:12 +00007774template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007775ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007776TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007777 ValueDecl *ND
7778 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7779 E->getDecl()));
7780 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007781 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007782
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007783 if (!getDerived().AlwaysRebuild() &&
7784 ND == E->getDecl()) {
7785 // Mark it referenced in the new context regardless.
7786 // FIXME: this is a bit instantiation-specific.
7787 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7788
John McCallc3007a22010-10-26 07:05:15 +00007789 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007790 }
7791
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007792 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007793 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007794 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007795}
Mike Stump11289f42009-09-09 15:08:12 +00007796
Douglas Gregora16548e2009-08-11 05:31:07 +00007797//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007798// Type reconstruction
7799//===----------------------------------------------------------------------===//
7800
Mike Stump11289f42009-09-09 15:08:12 +00007801template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007802QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7803 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007804 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007805 getDerived().getBaseEntity());
7806}
7807
Mike Stump11289f42009-09-09 15:08:12 +00007808template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007809QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7810 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007811 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007812 getDerived().getBaseEntity());
7813}
7814
Mike Stump11289f42009-09-09 15:08:12 +00007815template<typename Derived>
7816QualType
John McCall70dd5f62009-10-30 00:06:24 +00007817TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7818 bool WrittenAsLValue,
7819 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007820 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007821 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007822}
7823
7824template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007825QualType
John McCall70dd5f62009-10-30 00:06:24 +00007826TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7827 QualType ClassType,
7828 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007829 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007830 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007831}
7832
7833template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007834QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007835TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7836 ArrayType::ArraySizeModifier SizeMod,
7837 const llvm::APInt *Size,
7838 Expr *SizeExpr,
7839 unsigned IndexTypeQuals,
7840 SourceRange BracketsRange) {
7841 if (SizeExpr || !Size)
7842 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7843 IndexTypeQuals, BracketsRange,
7844 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007845
7846 QualType Types[] = {
7847 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7848 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7849 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007850 };
7851 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7852 QualType SizeType;
7853 for (unsigned I = 0; I != NumTypes; ++I)
7854 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7855 SizeType = Types[I];
7856 break;
7857 }
Mike Stump11289f42009-09-09 15:08:12 +00007858
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007859 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7860 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007861 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007862 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007863 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007864}
Mike Stump11289f42009-09-09 15:08:12 +00007865
Douglas Gregord6ff3322009-08-04 16:50:30 +00007866template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007867QualType
7868TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007869 ArrayType::ArraySizeModifier SizeMod,
7870 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007871 unsigned IndexTypeQuals,
7872 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007873 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007874 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007875}
7876
7877template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007878QualType
Mike Stump11289f42009-09-09 15:08:12 +00007879TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007880 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007881 unsigned IndexTypeQuals,
7882 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007883 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007884 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007885}
Mike Stump11289f42009-09-09 15:08:12 +00007886
Douglas Gregord6ff3322009-08-04 16:50:30 +00007887template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007888QualType
7889TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007890 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007891 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007892 unsigned IndexTypeQuals,
7893 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007894 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007895 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007896 IndexTypeQuals, BracketsRange);
7897}
7898
7899template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007900QualType
7901TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007902 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007903 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007904 unsigned IndexTypeQuals,
7905 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007906 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007907 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007908 IndexTypeQuals, BracketsRange);
7909}
7910
7911template<typename Derived>
7912QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007913 unsigned NumElements,
7914 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007915 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007916 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007917}
Mike Stump11289f42009-09-09 15:08:12 +00007918
Douglas Gregord6ff3322009-08-04 16:50:30 +00007919template<typename Derived>
7920QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7921 unsigned NumElements,
7922 SourceLocation AttributeLoc) {
7923 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7924 NumElements, true);
7925 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007926 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7927 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007928 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007929}
Mike Stump11289f42009-09-09 15:08:12 +00007930
Douglas Gregord6ff3322009-08-04 16:50:30 +00007931template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007932QualType
7933TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007934 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007935 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007936 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007937}
Mike Stump11289f42009-09-09 15:08:12 +00007938
Douglas Gregord6ff3322009-08-04 16:50:30 +00007939template<typename Derived>
7940QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007941 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007942 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007943 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007944 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007945 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007946 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007947 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007948 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007949 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007950 getDerived().getBaseEntity(),
7951 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007952}
Mike Stump11289f42009-09-09 15:08:12 +00007953
Douglas Gregord6ff3322009-08-04 16:50:30 +00007954template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007955QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7956 return SemaRef.Context.getFunctionNoProtoType(T);
7957}
7958
7959template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007960QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7961 assert(D && "no decl found");
7962 if (D->isInvalidDecl()) return QualType();
7963
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007964 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007965 TypeDecl *Ty;
7966 if (isa<UsingDecl>(D)) {
7967 UsingDecl *Using = cast<UsingDecl>(D);
7968 assert(Using->isTypeName() &&
7969 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7970
7971 // A valid resolved using typename decl points to exactly one type decl.
7972 assert(++Using->shadow_begin() == Using->shadow_end());
7973 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007974
John McCallb96ec562009-12-04 22:46:56 +00007975 } else {
7976 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7977 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7978 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7979 }
7980
7981 return SemaRef.Context.getTypeDeclType(Ty);
7982}
7983
7984template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007985QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7986 SourceLocation Loc) {
7987 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007988}
7989
7990template<typename Derived>
7991QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7992 return SemaRef.Context.getTypeOfType(Underlying);
7993}
7994
7995template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007996QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7997 SourceLocation Loc) {
7998 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007999}
8000
8001template<typename Derived>
8002QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008003 TemplateName Template,
8004 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00008005 const TemplateArgumentListInfo &TemplateArgs) {
8006 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008007}
Mike Stump11289f42009-09-09 15:08:12 +00008008
Douglas Gregor1135c352009-08-06 05:28:30 +00008009template<typename Derived>
8010NestedNameSpecifier *
8011TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
8012 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008013 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008014 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00008015 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00008016 CXXScopeSpec SS;
8017 // FIXME: The source location information is all wrong.
Douglas Gregor869ad452011-02-24 17:54:50 +00008018 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
Douglas Gregor90c99722011-02-24 00:17:56 +00008019 if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(),
8020 /*FIXME:*/Range.getEnd(),
8021 ObjectType, false,
8022 SS, FirstQualifierInScope,
8023 false))
8024 return 0;
8025
8026 return SS.getScopeRep();
Douglas Gregor1135c352009-08-06 05:28:30 +00008027}
8028
8029template<typename Derived>
8030NestedNameSpecifier *
8031TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
8032 SourceRange Range,
8033 NamespaceDecl *NS) {
8034 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
8035}
8036
8037template<typename Derived>
8038NestedNameSpecifier *
8039TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
8040 SourceRange Range,
Douglas Gregor7b26ff92011-02-24 02:36:08 +00008041 NamespaceAliasDecl *Alias) {
8042 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias);
8043}
8044
8045template<typename Derived>
8046NestedNameSpecifier *
8047TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
8048 SourceRange Range,
Douglas Gregor1135c352009-08-06 05:28:30 +00008049 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00008050 QualType T) {
8051 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00008052 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00008053 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00008054 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
8055 T.getTypePtr());
8056 }
Mike Stump11289f42009-09-09 15:08:12 +00008057
Douglas Gregor1135c352009-08-06 05:28:30 +00008058 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
8059 return 0;
8060}
Mike Stump11289f42009-09-09 15:08:12 +00008061
Douglas Gregor71dc5092009-08-06 06:41:21 +00008062template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008063TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008064TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008065 bool TemplateKW,
8066 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008067 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008068 Template);
8069}
8070
8071template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008072TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008073TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8074 const IdentifierInfo &Name,
8075 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008076 QualType ObjectType,
8077 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008078 UnqualifiedId TemplateName;
8079 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008080 Sema::TemplateTy Template;
8081 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008082 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008083 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008084 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008085 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008086 /*EnteringContext=*/false,
8087 Template);
John McCall31f82722010-11-12 08:19:04 +00008088 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008089}
Mike Stump11289f42009-09-09 15:08:12 +00008090
Douglas Gregora16548e2009-08-11 05:31:07 +00008091template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008092TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008093TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008094 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008095 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008096 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008097 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008098 // FIXME: Bogus location information.
8099 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8100 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008101 Sema::TemplateTy Template;
8102 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008103 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008104 SS,
8105 Name,
John McCallba7bf592010-08-24 05:47:05 +00008106 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008107 /*EnteringContext=*/false,
8108 Template);
8109 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008110}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008111
Douglas Gregor71395fa2009-11-04 00:56:37 +00008112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008113ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008114TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8115 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008116 Expr *OrigCallee,
8117 Expr *First,
8118 Expr *Second) {
8119 Expr *Callee = OrigCallee->IgnoreParenCasts();
8120 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008121
Douglas Gregora16548e2009-08-11 05:31:07 +00008122 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008123 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008124 if (!First->getType()->isOverloadableType() &&
8125 !Second->getType()->isOverloadableType())
8126 return getSema().CreateBuiltinArraySubscriptExpr(First,
8127 Callee->getLocStart(),
8128 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008129 } else if (Op == OO_Arrow) {
8130 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008131 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8132 } else if (Second == 0 || isPostIncDec) {
8133 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008134 // The argument is not of overloadable type, so try to create a
8135 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008136 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008137 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008138
John McCallb268a282010-08-23 23:25:46 +00008139 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008140 }
8141 } else {
John McCallb268a282010-08-23 23:25:46 +00008142 if (!First->getType()->isOverloadableType() &&
8143 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008144 // Neither of the arguments is an overloadable type, so try to
8145 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008146 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008147 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008148 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008149 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008150 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008151
Douglas Gregora16548e2009-08-11 05:31:07 +00008152 return move(Result);
8153 }
8154 }
Mike Stump11289f42009-09-09 15:08:12 +00008155
8156 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008157 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008158 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008159
John McCallb268a282010-08-23 23:25:46 +00008160 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008161 assert(ULE->requiresADL());
8162
8163 // FIXME: Do we have to check
8164 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008165 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008166 } else {
John McCallb268a282010-08-23 23:25:46 +00008167 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008168 }
Mike Stump11289f42009-09-09 15:08:12 +00008169
Douglas Gregora16548e2009-08-11 05:31:07 +00008170 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008171 Expr *Args[2] = { First, Second };
8172 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008173
Douglas Gregora16548e2009-08-11 05:31:07 +00008174 // Create the overloaded operator invocation for unary operators.
8175 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008176 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008178 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008179 }
Mike Stump11289f42009-09-09 15:08:12 +00008180
Sebastian Redladba46e2009-10-29 20:17:01 +00008181 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00008182 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00008183 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008184 First,
8185 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00008186
Douglas Gregora16548e2009-08-11 05:31:07 +00008187 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008188 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008189 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008190 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8191 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008192 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008193
Mike Stump11289f42009-09-09 15:08:12 +00008194 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008195}
Mike Stump11289f42009-09-09 15:08:12 +00008196
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008198ExprResult
John McCallb268a282010-08-23 23:25:46 +00008199TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008200 SourceLocation OperatorLoc,
8201 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008202 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008203 TypeSourceInfo *ScopeType,
8204 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008205 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008206 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008207 QualType BaseType = Base->getType();
8208 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008209 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008210 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008211 !BaseType->getAs<PointerType>()->getPointeeType()
8212 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008213 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008214 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008215 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008216 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008217 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008218 /*FIXME?*/true);
8219 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008220
Douglas Gregor678f90d2010-02-25 01:56:36 +00008221 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008222 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8223 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8224 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8225 NameInfo.setNamedTypeInfo(DestroyedType);
8226
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008227 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008228
John McCallb268a282010-08-23 23:25:46 +00008229 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008230 OperatorLoc, isArrow,
8231 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008232 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008233 /*TemplateArgs*/ 0);
8234}
8235
Douglas Gregord6ff3322009-08-04 16:50:30 +00008236} // end namespace clang
8237
8238#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H