blob: b36fd76677023c7be334e752bffddac7944abfdc [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000024#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000025#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000027#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000030#include "clang/Sema/Ownership.h"
31#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000032#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000033#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000034#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000035#include <algorithm>
36
37namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000038using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000039
Douglas Gregord6ff3322009-08-04 16:50:30 +000040/// \brief A semantic tree transformation that allows one to transform one
41/// abstract syntax tree into another.
42///
Mike Stump11289f42009-09-09 15:08:12 +000043/// A new tree transformation is defined by creating a new subclass \c X of
44/// \c TreeTransform<X> and then overriding certain operations to provide
45/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000046/// instantiation is implemented as a tree transformation where the
47/// transformation of TemplateTypeParmType nodes involves substituting the
48/// template arguments for their corresponding template parameters; a similar
49/// transformation is performed for non-type template parameters and
50/// template template parameters.
51///
52/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000053/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000054/// override any of the transformation or rebuild operators by providing an
55/// operation with the same signature as the default implementation. The
56/// overridding function should not be virtual.
57///
58/// Semantic tree transformations are split into two stages, either of which
59/// can be replaced by a subclass. The "transform" step transforms an AST node
60/// or the parts of an AST node using the various transformation functions,
61/// then passes the pieces on to the "rebuild" step, which constructs a new AST
62/// node of the appropriate kind from the pieces. The default transformation
63/// routines recursively transform the operands to composite AST nodes (e.g.,
64/// the pointee type of a PointerType node) and, if any of those operand nodes
65/// were changed by the transformation, invokes the rebuild operation to create
66/// a new AST node.
67///
Mike Stump11289f42009-09-09 15:08:12 +000068/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000069/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
71/// TransformTemplateName(), or TransformTemplateArgument() with entirely
72/// new implementations.
73///
74/// For more fine-grained transformations, subclasses can replace any of the
75/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000076/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000078/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// parameters. Additionally, subclasses can override the \c RebuildXXX
80/// functions to control how AST nodes are rebuilt when their operands change.
81/// By default, \c TreeTransform will invoke semantic analysis to rebuild
82/// AST nodes. However, certain other tree transformations (e.g, cloning) may
83/// be able to use more efficient rebuild steps.
84///
85/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000086/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000087/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
88/// operands have not changed (\c AlwaysRebuild()), and customize the
89/// default locations and entity names used for type-checking
90/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000091template<typename Derived>
92class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000093 /// \brief Private RAII object that helps us forget and then re-remember
94 /// the template argument corresponding to a partially-substituted parameter
95 /// pack.
96 class ForgetPartiallySubstitutedPackRAII {
97 Derived &Self;
98 TemplateArgument Old;
99
100 public:
101 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
102 Old = Self.ForgetPartiallySubstitutedPack();
103 }
104
105 ~ForgetPartiallySubstitutedPackRAII() {
106 Self.RememberPartiallySubstitutedPack(Old);
107 }
108 };
109
Douglas Gregord6ff3322009-08-04 16:50:30 +0000110protected:
111 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000112
Mike Stump11289f42009-09-09 15:08:12 +0000113public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000115 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000116
Douglas Gregord6ff3322009-08-04 16:50:30 +0000117 /// \brief Retrieves a reference to the derived class.
118 Derived &getDerived() { return static_cast<Derived&>(*this); }
119
120 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000121 const Derived &getDerived() const {
122 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000123 }
124
John McCalldadc5752010-08-24 06:29:42 +0000125 static inline ExprResult Owned(Expr *E) { return E; }
126 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Retrieves a reference to the semantic analysis object used for
129 /// this tree transform.
130 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000131
Douglas Gregord6ff3322009-08-04 16:50:30 +0000132 /// \brief Whether the transformation should always rebuild AST nodes, even
133 /// if none of the children have changed.
134 ///
135 /// Subclasses may override this function to specify when the transformation
136 /// should rebuild all AST nodes.
137 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Returns the location of the entity being transformed, if that
140 /// information was not available elsewhere in the AST.
141 ///
Mike Stump11289f42009-09-09 15:08:12 +0000142 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000143 /// provide an alternative implementation that provides better location
144 /// information.
145 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000146
Douglas Gregord6ff3322009-08-04 16:50:30 +0000147 /// \brief Returns the name of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
150 /// By default, returns an empty name. Subclasses can provide an alternative
151 /// implementation with a more precise name.
152 DeclarationName getBaseEntity() { return DeclarationName(); }
153
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 /// \brief Sets the "base" location and entity when that
155 /// information is known based on another transformation.
156 ///
157 /// By default, the source location and entity are ignored. Subclasses can
158 /// override this function to provide a customized implementation.
159 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000160
Douglas Gregora16548e2009-08-11 05:31:07 +0000161 /// \brief RAII object that temporarily sets the base location and entity
162 /// used for reporting diagnostics in types.
163 class TemporaryBase {
164 TreeTransform &Self;
165 SourceLocation OldLocation;
166 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000167
Douglas Gregora16548e2009-08-11 05:31:07 +0000168 public:
169 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000170 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000171 OldLocation = Self.getDerived().getBaseLocation();
172 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000173
174 if (Location.isValid())
175 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000176 }
Mike Stump11289f42009-09-09 15:08:12 +0000177
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 ~TemporaryBase() {
179 Self.getDerived().setBase(OldLocation, OldEntity);
180 }
181 };
Mike Stump11289f42009-09-09 15:08:12 +0000182
183 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000184 /// transformed.
185 ///
186 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000187 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000188 /// not change. For example, template instantiation need not traverse
189 /// non-dependent types.
190 bool AlreadyTransformed(QualType T) {
191 return T.isNull();
192 }
193
Douglas Gregord196a582009-12-14 19:27:10 +0000194 /// \brief Determine whether the given call argument should be dropped, e.g.,
195 /// because it is a default argument.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine to
198 /// determine which kinds of call arguments get dropped. By default,
199 /// CXXDefaultArgument nodes are dropped (prior to transformation).
200 bool DropCallArgument(Expr *E) {
201 return E->isDefaultArgument();
202 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000203
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000204 /// \brief Determine whether we should expand a pack expansion with the
205 /// given set of parameter packs into separate arguments by repeatedly
206 /// transforming the pattern.
207 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000208 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000209 /// Subclasses can override this routine to provide different behavior.
210 ///
211 /// \param EllipsisLoc The location of the ellipsis that identifies the
212 /// pack expansion.
213 ///
214 /// \param PatternRange The source range that covers the entire pattern of
215 /// the pack expansion.
216 ///
217 /// \param Unexpanded The set of unexpanded parameter packs within the
218 /// pattern.
219 ///
220 /// \param NumUnexpanded The number of unexpanded parameter packs in
221 /// \p Unexpanded.
222 ///
223 /// \param ShouldExpand Will be set to \c true if the transformer should
224 /// expand the corresponding pack expansions into separate arguments. When
225 /// set, \c NumExpansions must also be set.
226 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000227 /// \param RetainExpansion Whether the caller should add an unexpanded
228 /// pack expansion after all of the expanded arguments. This is used
229 /// when extending explicitly-specified template argument packs per
230 /// C++0x [temp.arg.explicit]p9.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000233 /// the expanded form of the corresponding pack expansion. This is both an
234 /// input and an output parameter, which can be set by the caller if the
235 /// number of expansions is known a priori (e.g., due to a prior substitution)
236 /// and will be set by the callee when the number of expansions is known.
237 /// The callee must set this value when \c ShouldExpand is \c true; it may
238 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000239 ///
240 /// \returns true if an error occurred (e.g., because the parameter packs
241 /// are to be instantiated with arguments of different lengths), false
242 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
243 /// must be set.
244 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
245 SourceRange PatternRange,
246 const UnexpandedParameterPack *Unexpanded,
247 unsigned NumUnexpanded,
248 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000249 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000250 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 ShouldExpand = false;
252 return false;
253 }
254
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000255 /// \brief "Forget" about the partially-substituted pack template argument,
256 /// when performing an instantiation that must preserve the parameter pack
257 /// use.
258 ///
259 /// This routine is meant to be overridden by the template instantiator.
260 TemplateArgument ForgetPartiallySubstitutedPack() {
261 return TemplateArgument();
262 }
263
264 /// \brief "Remember" the partially-substituted pack template argument
265 /// after performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
270
Douglas Gregorf3010112011-01-07 16:43:16 +0000271 /// \brief Note to the derived class when a function parameter pack is
272 /// being expanded.
273 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
274
Douglas Gregord6ff3322009-08-04 16:50:30 +0000275 /// \brief Transforms the given type into another type.
276 ///
John McCall550e0c22009-10-21 00:40:46 +0000277 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000278 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000279 /// function. This is expensive, but we don't mind, because
280 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000281 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 ///
283 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000284 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000285
John McCall550e0c22009-10-21 00:40:46 +0000286 /// \brief Transforms the given type-with-location into a new
287 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000288 ///
John McCall550e0c22009-10-21 00:40:46 +0000289 /// By default, this routine transforms a type by delegating to the
290 /// appropriate TransformXXXType to build a new type. Subclasses
291 /// may override this function (to take over all type
292 /// transformations) or some set of the TransformXXXType functions
293 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000294 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000295
296 /// \brief Transform the given type-with-location into a new
297 /// type, collecting location information in the given builder
298 /// as necessary.
299 ///
John McCall31f82722010-11-12 08:19:04 +0000300 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000301
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000302 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000303 ///
Mike Stump11289f42009-09-09 15:08:12 +0000304 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000305 /// appropriate TransformXXXStmt function to transform a specific kind of
306 /// statement or the TransformExpr() function to transform an expression.
307 /// Subclasses may override this function to transform statements using some
308 /// other mechanism.
309 ///
310 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000311 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000312
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000313 /// \brief Transform the given expression.
314 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000315 /// By default, this routine transforms an expression by delegating to the
316 /// appropriate TransformXXXExpr function to build a new expression.
317 /// Subclasses may override this function to transform expressions using some
318 /// other mechanism.
319 ///
320 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000321 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000322
Douglas Gregora3efea12011-01-03 19:04:46 +0000323 /// \brief Transform the given list of expressions.
324 ///
325 /// This routine transforms a list of expressions by invoking
326 /// \c TransformExpr() for each subexpression. However, it also provides
327 /// support for variadic templates by expanding any pack expansions (if the
328 /// derived class permits such expansion) along the way. When pack expansions
329 /// are present, the number of outputs may not equal the number of inputs.
330 ///
331 /// \param Inputs The set of expressions to be transformed.
332 ///
333 /// \param NumInputs The number of expressions in \c Inputs.
334 ///
335 /// \param IsCall If \c true, then this transform is being performed on
336 /// function-call arguments, and any arguments that should be dropped, will
337 /// be.
338 ///
339 /// \param Outputs The transformed input expressions will be added to this
340 /// vector.
341 ///
342 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
343 /// due to transformation.
344 ///
345 /// \returns true if an error occurred, false otherwise.
346 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
347 llvm::SmallVectorImpl<Expr *> &Outputs,
348 bool *ArgChanged = 0);
349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Transform the given declaration, which is referenced from a type
351 /// or expression.
352 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000353 /// By default, acts as the identity function on declarations. Subclasses
354 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000355 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000356
357 /// \brief Transform the definition of the given declaration.
358 ///
Mike Stump11289f42009-09-09 15:08:12 +0000359 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000360 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000361 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
362 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000363 }
Mike Stump11289f42009-09-09 15:08:12 +0000364
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000365 /// \brief Transform the given declaration, which was the first part of a
366 /// nested-name-specifier in a member access expression.
367 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000368 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000369 /// identifier in a nested-name-specifier of a member access expression, e.g.,
370 /// the \c T in \c x->T::member
371 ///
372 /// By default, invokes TransformDecl() to transform the declaration.
373 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000374 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
375 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000376 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000377
Douglas Gregord6ff3322009-08-04 16:50:30 +0000378 /// \brief Transform the given nested-name-specifier.
379 ///
Mike Stump11289f42009-09-09 15:08:12 +0000380 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// nested-name-specifier. Subclasses may override this function to provide
382 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000384 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000385 QualType ObjectType = QualType(),
386 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000387
Douglas Gregor14454802011-02-25 02:25:35 +0000388 /// \brief Transform the given nested-name-specifier with source-location
389 /// information.
390 ///
391 /// By default, transforms all of the types and declarations within the
392 /// nested-name-specifier. Subclasses may override this function to provide
393 /// alternate behavior.
394 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
395 NestedNameSpecifierLoc NNS,
396 QualType ObjectType = QualType(),
397 NamedDecl *FirstQualifierInScope = 0);
398
Douglas Gregorf816bd72009-09-03 22:13:48 +0000399 /// \brief Transform the given declaration name.
400 ///
401 /// By default, transforms the types of conversion function, constructor,
402 /// and destructor names and then (if needed) rebuilds the declaration name.
403 /// Identifiers and selectors are returned unmodified. Sublcasses may
404 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000405 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000406 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000407
Douglas Gregord6ff3322009-08-04 16:50:30 +0000408 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000409 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000410 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000412 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000413 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000414 QualType ObjectType = QualType(),
415 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregord6ff3322009-08-04 16:50:30 +0000417 /// \brief Transform the given template argument.
418 ///
Mike Stump11289f42009-09-09 15:08:12 +0000419 /// By default, this operation transforms the type, expression, or
420 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000421 /// new template argument from the transformed result. Subclasses may
422 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000423 ///
424 /// Returns true if there was an error.
425 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
426 TemplateArgumentLoc &Output);
427
Douglas Gregor62e06f22010-12-20 17:31:10 +0000428 /// \brief Transform the given set of template arguments.
429 ///
430 /// By default, this operation transforms all of the template arguments
431 /// in the input set using \c TransformTemplateArgument(), and appends
432 /// the transformed arguments to the output list.
433 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000434 /// Note that this overload of \c TransformTemplateArguments() is merely
435 /// a convenience function. Subclasses that wish to override this behavior
436 /// should override the iterator-based member template version.
437 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000438 /// \param Inputs The set of template arguments to be transformed.
439 ///
440 /// \param NumInputs The number of template arguments in \p Inputs.
441 ///
442 /// \param Outputs The set of transformed template arguments output by this
443 /// routine.
444 ///
445 /// Returns true if an error occurred.
446 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
447 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000448 TemplateArgumentListInfo &Outputs) {
449 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
450 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000451
452 /// \brief Transform the given set of template arguments.
453 ///
454 /// By default, this operation transforms all of the template arguments
455 /// in the input set using \c TransformTemplateArgument(), and appends
456 /// the transformed arguments to the output list.
457 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000458 /// \param First An iterator to the first template argument.
459 ///
460 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000461 ///
462 /// \param Outputs The set of transformed template arguments output by this
463 /// routine.
464 ///
465 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000466 template<typename InputIterator>
467 bool TransformTemplateArguments(InputIterator First,
468 InputIterator Last,
469 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000470
John McCall0ad16662009-10-29 08:12:44 +0000471 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
472 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
473 TemplateArgumentLoc &ArgLoc);
474
John McCallbcd03502009-12-07 02:54:59 +0000475 /// \brief Fakes up a TypeSourceInfo for a type.
476 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
477 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000478 getDerived().getBaseLocation());
479 }
Mike Stump11289f42009-09-09 15:08:12 +0000480
John McCall550e0c22009-10-21 00:40:46 +0000481#define ABSTRACT_TYPELOC(CLASS, PARENT)
482#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000483 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000484#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000485
John McCall31f82722010-11-12 08:19:04 +0000486 QualType
487 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
488 TemplateSpecializationTypeLoc TL,
489 TemplateName Template);
490
491 QualType
492 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
493 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor5a064722011-02-28 17:23:35 +0000494 TemplateName Template);
495
496 QualType
497 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
498 DependentTemplateSpecializationTypeLoc TL,
John McCall31f82722010-11-12 08:19:04 +0000499 NestedNameSpecifier *Prefix);
500
John McCall58f10c32010-03-11 09:03:00 +0000501 /// \brief Transforms the parameters of a function type into the
502 /// given vectors.
503 ///
504 /// The result vectors should be kept in sync; null entries in the
505 /// variables vector are acceptable.
506 ///
507 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000508 bool TransformFunctionTypeParams(SourceLocation Loc,
509 ParmVarDecl **Params, unsigned NumParams,
510 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000511 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000512 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000513
514 /// \brief Transforms a single function-type parameter. Return null
515 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000516 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
517 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000518
John McCall31f82722010-11-12 08:19:04 +0000519 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000520
John McCalldadc5752010-08-24 06:29:42 +0000521 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
522 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000523
Douglas Gregorebe10102009-08-20 07:17:43 +0000524#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000525 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000526#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000527 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000528#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000529#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000530
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531 /// \brief Build a new pointer type given its pointee type.
532 ///
533 /// By default, performs semantic analysis when building the pointer type.
534 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000535 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000536
537 /// \brief Build a new block pointer type given its pointee type.
538 ///
Mike Stump11289f42009-09-09 15:08:12 +0000539 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000540 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000541 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000542
John McCall70dd5f62009-10-30 00:06:24 +0000543 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544 ///
John McCall70dd5f62009-10-30 00:06:24 +0000545 /// By default, performs semantic analysis when building the
546 /// reference type. Subclasses may override this routine to provide
547 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000548 ///
John McCall70dd5f62009-10-30 00:06:24 +0000549 /// \param LValue whether the type was written with an lvalue sigil
550 /// or an rvalue sigil.
551 QualType RebuildReferenceType(QualType ReferentType,
552 bool LValue,
553 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000554
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555 /// \brief Build a new member pointer type given the pointee type and the
556 /// class type it refers into.
557 ///
558 /// By default, performs semantic analysis when building the member pointer
559 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000560 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
561 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000562
Douglas Gregord6ff3322009-08-04 16:50:30 +0000563 /// \brief Build a new array type given the element type, size
564 /// modifier, size of the array (if known), size expression, and index type
565 /// qualifiers.
566 ///
567 /// By default, performs semantic analysis when building the array type.
568 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000569 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570 QualType RebuildArrayType(QualType ElementType,
571 ArrayType::ArraySizeModifier SizeMod,
572 const llvm::APInt *Size,
573 Expr *SizeExpr,
574 unsigned IndexTypeQuals,
575 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000576
Douglas Gregord6ff3322009-08-04 16:50:30 +0000577 /// \brief Build a new constant array type given the element type, size
578 /// modifier, (known) size of the array, and index type qualifiers.
579 ///
580 /// By default, performs semantic analysis when building the array type.
581 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000582 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000583 ArrayType::ArraySizeModifier SizeMod,
584 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000585 unsigned IndexTypeQuals,
586 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000587
Douglas Gregord6ff3322009-08-04 16:50:30 +0000588 /// \brief Build a new incomplete array type given the element type, size
589 /// modifier, and index type qualifiers.
590 ///
591 /// By default, performs semantic analysis when building the array type.
592 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000593 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000594 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000595 unsigned IndexTypeQuals,
596 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000597
Mike Stump11289f42009-09-09 15:08:12 +0000598 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 /// size modifier, size expression, and index type qualifiers.
600 ///
601 /// By default, performs semantic analysis when building the array type.
602 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000603 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000604 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000605 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000606 unsigned IndexTypeQuals,
607 SourceRange BracketsRange);
608
Mike Stump11289f42009-09-09 15:08:12 +0000609 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000610 /// size modifier, size expression, and index type qualifiers.
611 ///
612 /// By default, performs semantic analysis when building the array type.
613 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000614 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000615 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000616 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000617 unsigned IndexTypeQuals,
618 SourceRange BracketsRange);
619
620 /// \brief Build a new vector type given the element type and
621 /// number of elements.
622 ///
623 /// By default, performs semantic analysis when building the vector type.
624 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000625 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000626 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000627
Douglas Gregord6ff3322009-08-04 16:50:30 +0000628 /// \brief Build a new extended vector type given the element type and
629 /// number of elements.
630 ///
631 /// By default, performs semantic analysis when building the vector type.
632 /// Subclasses may override this routine to provide different behavior.
633 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
634 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000635
636 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000637 /// given the element type and number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000641 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000642 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000643 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000644
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645 /// \brief Build a new function type.
646 ///
647 /// By default, performs semantic analysis when building the function type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000650 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000652 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000653 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000654 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000655
John McCall550e0c22009-10-21 00:40:46 +0000656 /// \brief Build a new unprototyped function type.
657 QualType RebuildFunctionNoProtoType(QualType ResultType);
658
John McCallb96ec562009-12-04 22:46:56 +0000659 /// \brief Rebuild an unresolved typename type, given the decl that
660 /// the UnresolvedUsingTypenameDecl was transformed to.
661 QualType RebuildUnresolvedUsingType(Decl *D);
662
Douglas Gregord6ff3322009-08-04 16:50:30 +0000663 /// \brief Build a new typedef type.
664 QualType RebuildTypedefType(TypedefDecl *Typedef) {
665 return SemaRef.Context.getTypeDeclType(Typedef);
666 }
667
668 /// \brief Build a new class/struct/union type.
669 QualType RebuildRecordType(RecordDecl *Record) {
670 return SemaRef.Context.getTypeDeclType(Record);
671 }
672
673 /// \brief Build a new Enum type.
674 QualType RebuildEnumType(EnumDecl *Enum) {
675 return SemaRef.Context.getTypeDeclType(Enum);
676 }
John McCallfcc33b02009-09-05 00:15:47 +0000677
Mike Stump11289f42009-09-09 15:08:12 +0000678 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 ///
680 /// By default, performs semantic analysis when building the typeof type.
681 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000682 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683
Mike Stump11289f42009-09-09 15:08:12 +0000684 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 ///
686 /// By default, builds a new TypeOfType with the given underlying type.
687 QualType RebuildTypeOfType(QualType Underlying);
688
Mike Stump11289f42009-09-09 15:08:12 +0000689 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 ///
691 /// By default, performs semantic analysis when building the decltype type.
692 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000693 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000694
Richard Smith30482bc2011-02-20 03:19:35 +0000695 /// \brief Build a new C++0x auto type.
696 ///
697 /// By default, builds a new AutoType with the given deduced type.
698 QualType RebuildAutoType(QualType Deduced) {
699 return SemaRef.Context.getAutoType(Deduced);
700 }
701
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 /// \brief Build a new template specialization type.
703 ///
704 /// By default, performs semantic analysis when building the template
705 /// specialization type. Subclasses may override this routine to provide
706 /// different behavior.
707 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000708 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000709 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000710
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000711 /// \brief Build a new parenthesized type.
712 ///
713 /// By default, builds a new ParenType type from the inner type.
714 /// Subclasses may override this routine to provide different behavior.
715 QualType RebuildParenType(QualType InnerType) {
716 return SemaRef.Context.getParenType(InnerType);
717 }
718
Douglas Gregord6ff3322009-08-04 16:50:30 +0000719 /// \brief Build a new qualified name type.
720 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000721 /// By default, builds a new ElaboratedType type from the keyword,
722 /// the nested-name-specifier and the named type.
723 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000724 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
725 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000726 NestedNameSpecifier *NNS, QualType Named) {
727 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000728 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729
730 /// \brief Build a new typename type that refers to a template-id.
731 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000732 /// By default, builds a new DependentNameType type from the
733 /// nested-name-specifier and the given type. Subclasses may override
734 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000735 QualType RebuildDependentTemplateSpecializationType(
736 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000737 NestedNameSpecifier *Qualifier,
738 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000739 const IdentifierInfo *Name,
740 SourceLocation NameLoc,
741 const TemplateArgumentListInfo &Args) {
742 // Rebuild the template name.
743 // TODO: avoid TemplateName abstraction
744 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000745 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000746 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000747
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000748 if (InstName.isNull())
749 return QualType();
750
John McCallc392f372010-06-11 00:33:02 +0000751 // If it's still dependent, make a dependent specialization.
752 if (InstName.getAsDependentTemplateName())
753 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000754 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000755
756 // Otherwise, make an elaborated type wrapping a non-dependent
757 // specialization.
758 QualType T =
759 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
760 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000761
Douglas Gregor5a064722011-02-28 17:23:35 +0000762 if (Keyword == ETK_None && Qualifier == 0)
Douglas Gregor6e068012011-02-28 00:04:36 +0000763 return T;
764
Douglas Gregor5a064722011-02-28 17:23:35 +0000765 return SemaRef.Context.getElaboratedType(Keyword, Qualifier, T);
Mike Stump11289f42009-09-09 15:08:12 +0000766 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000767
768 /// \brief Build a new typename type that refers to an identifier.
769 ///
770 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000771 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000772 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000773 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000774 NestedNameSpecifier *NNS,
775 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000776 SourceLocation KeywordLoc,
777 SourceRange NNSRange,
778 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000779 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +0000780 SS.MakeTrivial(SemaRef.Context, NNS, NNSRange);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000781
Douglas Gregore677daf2010-03-31 22:19:08 +0000782 if (NNS->isDependent()) {
783 // If the name is still dependent, just build a new dependent name type.
784 if (!SemaRef.computeDeclContext(SS))
785 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
786 }
787
Abramo Bagnara6150c882010-05-11 21:36:43 +0000788 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000789 return SemaRef.CheckTypenameType(Keyword, KeywordLoc,
790 SS.getWithLocInContext(SemaRef.Context),
791 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000792
793 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
794
Abramo Bagnarad7548482010-05-19 21:37:53 +0000795 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000796 // into a non-dependent elaborated-type-specifier. Find the tag we're
797 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000798 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000799 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
800 if (!DC)
801 return QualType();
802
John McCallbf8c5192010-05-27 06:40:31 +0000803 if (SemaRef.RequireCompleteDeclContext(SS, DC))
804 return QualType();
805
Douglas Gregore677daf2010-03-31 22:19:08 +0000806 TagDecl *Tag = 0;
807 SemaRef.LookupQualifiedName(Result, DC);
808 switch (Result.getResultKind()) {
809 case LookupResult::NotFound:
810 case LookupResult::NotFoundInCurrentInstantiation:
811 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000812
Douglas Gregore677daf2010-03-31 22:19:08 +0000813 case LookupResult::Found:
814 Tag = Result.getAsSingle<TagDecl>();
815 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000816
Douglas Gregore677daf2010-03-31 22:19:08 +0000817 case LookupResult::FoundOverloaded:
818 case LookupResult::FoundUnresolvedValue:
819 llvm_unreachable("Tag lookup cannot find non-tags");
820 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000821
Douglas Gregore677daf2010-03-31 22:19:08 +0000822 case LookupResult::Ambiguous:
823 // Let the LookupResult structure handle ambiguities.
824 return QualType();
825 }
826
827 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000828 // Check where the name exists but isn't a tag type and use that to emit
829 // better diagnostics.
830 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
831 SemaRef.LookupQualifiedName(Result, DC);
832 switch (Result.getResultKind()) {
833 case LookupResult::Found:
834 case LookupResult::FoundOverloaded:
835 case LookupResult::FoundUnresolvedValue: {
836 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
837 unsigned Kind = 0;
838 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
839 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
840 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
841 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
842 break;
843 }
844 default:
845 // FIXME: Would be nice to highlight just the source range.
846 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
847 << Kind << Id << DC;
848 break;
849 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000850 return QualType();
851 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000852
Abramo Bagnarad7548482010-05-19 21:37:53 +0000853 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
854 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000855 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
856 return QualType();
857 }
858
859 // Build the elaborated-type-specifier type.
860 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000861 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000862 }
Mike Stump11289f42009-09-09 15:08:12 +0000863
Douglas Gregor822d0302011-01-12 17:07:58 +0000864 /// \brief Build a new pack expansion type.
865 ///
866 /// By default, builds a new PackExpansionType type from the given pattern.
867 /// Subclasses may override this routine to provide different behavior.
868 QualType RebuildPackExpansionType(QualType Pattern,
869 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000870 SourceLocation EllipsisLoc,
871 llvm::Optional<unsigned> NumExpansions) {
872 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
873 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000874 }
875
Douglas Gregor1135c352009-08-06 05:28:30 +0000876 /// \brief Build a new nested-name-specifier given the prefix and an
877 /// identifier that names the next step in the nested-name-specifier.
878 ///
879 /// By default, performs semantic analysis when building the new
880 /// nested-name-specifier. Subclasses may override this routine to provide
881 /// different behavior.
882 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
883 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000884 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000885 QualType ObjectType,
886 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000887
888 /// \brief Build a new nested-name-specifier given the prefix and the
889 /// namespace named in the next step in the nested-name-specifier.
890 ///
891 /// By default, performs semantic analysis when building the new
892 /// nested-name-specifier. Subclasses may override this routine to provide
893 /// different behavior.
894 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
895 SourceRange Range,
896 NamespaceDecl *NS);
897
898 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor7b26ff92011-02-24 02:36:08 +0000899 /// namespace alias named in the next step in the nested-name-specifier.
900 ///
901 /// By default, performs semantic analysis when building the new
902 /// nested-name-specifier. Subclasses may override this routine to provide
903 /// different behavior.
904 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
905 SourceRange Range,
906 NamespaceAliasDecl *Alias);
907
908 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor1135c352009-08-06 05:28:30 +0000909 /// type named in the next step in the nested-name-specifier.
910 ///
911 /// By default, performs semantic analysis when building the new
912 /// nested-name-specifier. Subclasses may override this routine to provide
913 /// different behavior.
914 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
915 SourceRange Range,
916 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000917 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000918
919 /// \brief Build a new template name given a nested name specifier, a flag
920 /// indicating whether the "template" keyword was provided, and the template
921 /// that the template name refers to.
922 ///
923 /// By default, builds the new template name directly. Subclasses may override
924 /// this routine to provide different behavior.
925 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
926 bool TemplateKW,
927 TemplateDecl *Template);
928
Douglas Gregor71dc5092009-08-06 06:41:21 +0000929 /// \brief Build a new template name given a nested name specifier and the
930 /// name that is referred to as a template.
931 ///
932 /// By default, performs semantic analysis to determine whether the name can
933 /// be resolved to a specific template, then builds the appropriate kind of
934 /// template name. Subclasses may override this routine to provide different
935 /// behavior.
936 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000937 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000938 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000939 QualType ObjectType,
940 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000941
Douglas Gregor71395fa2009-11-04 00:56:37 +0000942 /// \brief Build a new template name given a nested name specifier and the
943 /// overloaded operator name that is referred to as a template.
944 ///
945 /// By default, performs semantic analysis to determine whether the name can
946 /// be resolved to a specific template, then builds the appropriate kind of
947 /// template name. Subclasses may override this routine to provide different
948 /// behavior.
949 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
950 OverloadedOperatorKind Operator,
951 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000952
953 /// \brief Build a new template name given a template template parameter pack
954 /// and the
955 ///
956 /// By default, performs semantic analysis to determine whether the name can
957 /// be resolved to a specific template, then builds the appropriate kind of
958 /// template name. Subclasses may override this routine to provide different
959 /// behavior.
960 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
961 const TemplateArgument &ArgPack) {
962 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
963 }
964
Douglas Gregorebe10102009-08-20 07:17:43 +0000965 /// \brief Build a new compound statement.
966 ///
967 /// By default, performs semantic analysis to build the new statement.
968 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000969 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000970 MultiStmtArg Statements,
971 SourceLocation RBraceLoc,
972 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000973 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000974 IsStmtExpr);
975 }
976
977 /// \brief Build a new case statement.
978 ///
979 /// By default, performs semantic analysis to build the new statement.
980 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000981 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000982 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000984 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000985 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000986 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 ColonLoc);
988 }
Mike Stump11289f42009-09-09 15:08:12 +0000989
Douglas Gregorebe10102009-08-20 07:17:43 +0000990 /// \brief Attach the body to a new case statement.
991 ///
992 /// By default, performs semantic analysis to build the new statement.
993 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000994 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000995 getSema().ActOnCaseStmtBody(S, Body);
996 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000997 }
Mike Stump11289f42009-09-09 15:08:12 +0000998
Douglas Gregorebe10102009-08-20 07:17:43 +0000999 /// \brief Build a new default statement.
1000 ///
1001 /// By default, performs semantic analysis to build the new statement.
1002 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001003 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001004 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001005 Stmt *SubStmt) {
1006 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001007 /*CurScope=*/0);
1008 }
Mike Stump11289f42009-09-09 15:08:12 +00001009
Douglas Gregorebe10102009-08-20 07:17:43 +00001010 /// \brief Build a new label statement.
1011 ///
1012 /// By default, performs semantic analysis to build the new statement.
1013 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001014 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1015 SourceLocation ColonLoc, Stmt *SubStmt) {
1016 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001017 }
Mike Stump11289f42009-09-09 15:08:12 +00001018
Douglas Gregorebe10102009-08-20 07:17:43 +00001019 /// \brief Build a new "if" statement.
1020 ///
1021 /// By default, performs semantic analysis to build the new statement.
1022 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001023 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001024 VarDecl *CondVar, Stmt *Then,
1025 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001026 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001027 }
Mike Stump11289f42009-09-09 15:08:12 +00001028
Douglas Gregorebe10102009-08-20 07:17:43 +00001029 /// \brief Start building a new switch statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001033 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001034 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001035 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001036 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001037 }
Mike Stump11289f42009-09-09 15:08:12 +00001038
Douglas Gregorebe10102009-08-20 07:17:43 +00001039 /// \brief Attach the body to the switch statement.
1040 ///
1041 /// By default, performs semantic analysis to build the new statement.
1042 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001043 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001044 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001045 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001046 }
1047
1048 /// \brief Build a new while statement.
1049 ///
1050 /// By default, performs semantic analysis to build the new statement.
1051 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001052 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1053 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001054 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001055 }
Mike Stump11289f42009-09-09 15:08:12 +00001056
Douglas Gregorebe10102009-08-20 07:17:43 +00001057 /// \brief Build a new do-while statement.
1058 ///
1059 /// By default, performs semantic analysis to build the new statement.
1060 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001061 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001062 SourceLocation WhileLoc, SourceLocation LParenLoc,
1063 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001064 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1065 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001066 }
1067
1068 /// \brief Build a new for statement.
1069 ///
1070 /// By default, performs semantic analysis to build the new statement.
1071 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001072 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1073 Stmt *Init, Sema::FullExprArg Cond,
1074 VarDecl *CondVar, Sema::FullExprArg Inc,
1075 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001076 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001077 CondVar, Inc, RParenLoc, Body);
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 Build a new goto statement.
1081 ///
1082 /// By default, performs semantic analysis to build the new statement.
1083 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001084 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1085 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001086 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 }
1088
1089 /// \brief Build a new indirect goto statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001093 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001094 SourceLocation StarLoc,
1095 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001096 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001097 }
Mike Stump11289f42009-09-09 15:08:12 +00001098
Douglas Gregorebe10102009-08-20 07:17:43 +00001099 /// \brief Build a new return statement.
1100 ///
1101 /// By default, performs semantic analysis to build the new statement.
1102 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001103 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001104 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 }
Mike Stump11289f42009-09-09 15:08:12 +00001106
Douglas Gregorebe10102009-08-20 07:17:43 +00001107 /// \brief Build a new declaration statement.
1108 ///
1109 /// By default, performs semantic analysis to build the new statement.
1110 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001111 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001112 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001114 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1115 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 }
Mike Stump11289f42009-09-09 15:08:12 +00001117
Anders Carlssonaaeef072010-01-24 05:50:09 +00001118 /// \brief Build a new inline asm statement.
1119 ///
1120 /// By default, performs semantic analysis to build the new statement.
1121 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001122 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001123 bool IsSimple,
1124 bool IsVolatile,
1125 unsigned NumOutputs,
1126 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001127 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001128 MultiExprArg Constraints,
1129 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001130 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001131 MultiExprArg Clobbers,
1132 SourceLocation RParenLoc,
1133 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001134 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001135 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001136 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001137 RParenLoc, MSAsm);
1138 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001139
1140 /// \brief Build a new Objective-C @try statement.
1141 ///
1142 /// By default, performs semantic analysis to build the new statement.
1143 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001144 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001145 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001146 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001147 Stmt *Finally) {
1148 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1149 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001150 }
1151
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001152 /// \brief Rebuild an Objective-C exception declaration.
1153 ///
1154 /// By default, performs semantic analysis to build the new declaration.
1155 /// Subclasses may override this routine to provide different behavior.
1156 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1157 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001158 return getSema().BuildObjCExceptionDecl(TInfo, T,
1159 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001160 ExceptionDecl->getLocation());
1161 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001162
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001163 /// \brief Build a new Objective-C @catch statement.
1164 ///
1165 /// By default, performs semantic analysis to build the new statement.
1166 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001167 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001168 SourceLocation RParenLoc,
1169 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001170 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001171 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001172 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001173 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001174
Douglas Gregor306de2f2010-04-22 23:59:56 +00001175 /// \brief Build a new Objective-C @finally statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001180 Stmt *Body) {
1181 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001182 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001183
Douglas Gregor6148de72010-04-22 22:01:21 +00001184 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001185 ///
1186 /// By default, performs semantic analysis to build the new statement.
1187 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001188 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001189 Expr *Operand) {
1190 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001191 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001192
Douglas Gregor6148de72010-04-22 22:01:21 +00001193 /// \brief Build a new Objective-C @synchronized statement.
1194 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001197 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001198 Expr *Object,
1199 Stmt *Body) {
1200 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1201 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001202 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001203
1204 /// \brief Build a new Objective-C fast enumeration 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 RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001209 SourceLocation LParenLoc,
1210 Stmt *Element,
1211 Expr *Collection,
1212 SourceLocation RParenLoc,
1213 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001214 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001215 Element,
1216 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001217 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001218 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001219 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001220
Douglas Gregorebe10102009-08-20 07:17:43 +00001221 /// \brief Build a new C++ exception declaration.
1222 ///
1223 /// By default, performs semantic analysis to build the new decaration.
1224 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001225 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001226 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001227 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001228 SourceLocation Loc) {
1229 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001230 }
1231
1232 /// \brief Build a new C++ catch statement.
1233 ///
1234 /// By default, performs semantic analysis to build the new statement.
1235 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001236 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001237 VarDecl *ExceptionDecl,
1238 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001239 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1240 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001241 }
Mike Stump11289f42009-09-09 15:08:12 +00001242
Douglas Gregorebe10102009-08-20 07:17:43 +00001243 /// \brief Build a new C++ try statement.
1244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001247 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001248 Stmt *TryBlock,
1249 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001250 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001251 }
Mike Stump11289f42009-09-09 15:08:12 +00001252
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 /// \brief Build a new expression that references a declaration.
1254 ///
1255 /// By default, performs semantic analysis to build the new expression.
1256 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001257 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001258 LookupResult &R,
1259 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001260 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1261 }
1262
1263
1264 /// \brief Build a new expression that references a declaration.
1265 ///
1266 /// By default, performs semantic analysis to build the new expression.
1267 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001268 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001269 ValueDecl *VD,
1270 const DeclarationNameInfo &NameInfo,
1271 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001272 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001273 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001274
1275 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001276
1277 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 }
Mike Stump11289f42009-09-09 15:08:12 +00001279
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001281 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 /// By default, performs semantic analysis to build the new expression.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001286 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 }
1288
Douglas Gregorad8a3362009-09-04 17:36:40 +00001289 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001290 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001291 /// By default, performs semantic analysis to build the new expression.
1292 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001293 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001294 SourceLocation OperatorLoc,
1295 bool isArrow,
1296 CXXScopeSpec &SS,
1297 TypeSourceInfo *ScopeType,
1298 SourceLocation CCLoc,
1299 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001300 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001301
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001303 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 /// By default, performs semantic analysis to build the new expression.
1305 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001306 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001307 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001308 Expr *SubExpr) {
1309 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 }
Mike Stump11289f42009-09-09 15:08:12 +00001311
Douglas Gregor882211c2010-04-28 22:16:22 +00001312 /// \brief Build a new builtin offsetof expression.
1313 ///
1314 /// By default, performs semantic analysis to build the new expression.
1315 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001316 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001317 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001318 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001319 unsigned NumComponents,
1320 SourceLocation RParenLoc) {
1321 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1322 NumComponents, RParenLoc);
1323 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001324
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001326 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001327 /// By default, performs semantic analysis to build the new expression.
1328 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001329 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001330 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001332 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 }
1334
Mike Stump11289f42009-09-09 15:08:12 +00001335 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001337 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 /// By default, performs semantic analysis to build the new expression.
1339 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001340 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001342 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001343 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001345 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001346
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 return move(Result);
1348 }
Mike Stump11289f42009-09-09 15:08:12 +00001349
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001351 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001352 /// By default, performs semantic analysis to build the new expression.
1353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001354 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001356 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001358 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1359 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 RBracketLoc);
1361 }
1362
1363 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001364 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 /// By default, performs semantic analysis to build the new expression.
1366 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001367 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001369 SourceLocation RParenLoc,
1370 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001371 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001372 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 }
1374
1375 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001376 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 /// By default, performs semantic analysis to build the new expression.
1378 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001379 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001380 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001381 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001382 const DeclarationNameInfo &MemberNameInfo,
1383 ValueDecl *Member,
1384 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001385 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001386 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001387 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001388 // We have a reference to an unnamed field. This is always the
1389 // base of an anonymous struct/union member access, i.e. the
1390 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001391 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001392 assert(Member->getType()->isRecordType() &&
1393 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001394
Douglas Gregorea972d32011-02-28 21:54:11 +00001395 if (getSema().PerformObjectMemberConversion(Base,
1396 QualifierLoc.getNestedNameSpecifier(),
John McCall16df1e52010-03-30 21:47:33 +00001397 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001398 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001399
John McCall7decc9e2010-11-18 06:31:45 +00001400 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001401 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001402 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001403 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001404 cast<FieldDecl>(Member)->getType(),
1405 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001406 return getSema().Owned(ME);
1407 }
Mike Stump11289f42009-09-09 15:08:12 +00001408
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001409 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001410 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001411
John McCallb268a282010-08-23 23:25:46 +00001412 getSema().DefaultFunctionArrayConversion(Base);
1413 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001414
John McCall16df1e52010-03-30 21:47:33 +00001415 // FIXME: this involves duplicating earlier analysis in a lot of
1416 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001417 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001418 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001419 R.resolveKind();
1420
John McCallb268a282010-08-23 23:25:46 +00001421 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001422 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001423 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 }
Mike Stump11289f42009-09-09 15:08:12 +00001425
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001427 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 /// By default, performs semantic analysis to build the new expression.
1429 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001430 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001431 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001432 Expr *LHS, Expr *RHS) {
1433 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 }
1435
1436 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001437 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 /// By default, performs semantic analysis to build the new expression.
1439 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001440 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001441 SourceLocation QuestionLoc,
1442 Expr *LHS,
1443 SourceLocation ColonLoc,
1444 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001445 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1446 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 }
1448
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001450 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 /// By default, performs semantic analysis to build the new expression.
1452 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001453 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001454 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001455 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001456 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001457 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001458 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001459 }
Mike Stump11289f42009-09-09 15:08:12 +00001460
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001462 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001465 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001466 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001468 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001469 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001470 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 }
Mike Stump11289f42009-09-09 15:08:12 +00001472
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001474 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 /// By default, performs semantic analysis to build the new expression.
1476 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001477 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 SourceLocation OpLoc,
1479 SourceLocation AccessorLoc,
1480 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001481
John McCall10eae182009-11-30 22:42:35 +00001482 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001483 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001484 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001485 OpLoc, /*IsArrow*/ false,
1486 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001487 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001488 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 }
Mike Stump11289f42009-09-09 15:08:12 +00001490
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001492 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001495 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001497 SourceLocation RBraceLoc,
1498 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001499 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001500 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1501 if (Result.isInvalid() || ResultTy->isDependentType())
1502 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001503
Douglas Gregord3d93062009-11-09 17:16:50 +00001504 // Patch in the result type we were given, which may have been computed
1505 // when the initial InitListExpr was built.
1506 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1507 ILE->setType(ResultTy);
1508 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 }
Mike Stump11289f42009-09-09 15:08:12 +00001510
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001512 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001515 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 MultiExprArg ArrayExprs,
1517 SourceLocation EqualOrColonLoc,
1518 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001519 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001520 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001522 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001525
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 ArrayExprs.release();
1527 return move(Result);
1528 }
Mike Stump11289f42009-09-09 15:08:12 +00001529
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001531 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 /// By default, builds the implicit value initialization without performing
1533 /// any semantic analysis. Subclasses may override this routine to provide
1534 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001535 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1537 }
Mike Stump11289f42009-09-09 15:08:12 +00001538
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001540 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 /// By default, performs semantic analysis to build the new expression.
1542 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001543 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001544 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001545 SourceLocation RParenLoc) {
1546 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001547 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001548 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 }
1550
1551 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001552 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 /// By default, performs semantic analysis to build the new expression.
1554 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001555 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 MultiExprArg SubExprs,
1557 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001558 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001559 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 }
Mike Stump11289f42009-09-09 15:08:12 +00001561
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001563 ///
1564 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 /// rather than attempting to map the label statement itself.
1566 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001567 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001568 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001569 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 }
Mike Stump11289f42009-09-09 15:08:12 +00001571
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001573 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 /// By default, performs semantic analysis to build the new expression.
1575 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001576 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001577 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001579 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 }
Mike Stump11289f42009-09-09 15:08:12 +00001581
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 /// \brief Build a new __builtin_choose_expr expression.
1583 ///
1584 /// By default, performs semantic analysis to build the new expression.
1585 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001586 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001587 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 SourceLocation RParenLoc) {
1589 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001590 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 RParenLoc);
1592 }
Mike Stump11289f42009-09-09 15:08:12 +00001593
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 /// \brief Build a new overloaded operator call expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// The semantic analysis provides the behavior of template instantiation,
1598 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001599 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 /// argument-dependent lookup, etc. Subclasses may override this routine to
1601 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001602 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001604 Expr *Callee,
1605 Expr *First,
1606 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001607
1608 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 /// reinterpret_cast.
1610 ///
1611 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001612 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001613 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001614 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 Stmt::StmtClass Class,
1616 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001617 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 SourceLocation RAngleLoc,
1619 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001620 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 SourceLocation RParenLoc) {
1622 switch (Class) {
1623 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001624 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001625 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001626 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001627
1628 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001629 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001630 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001631 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001632
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001634 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001635 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001636 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001638
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001640 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001641 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001642 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001643
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 default:
1645 assert(false && "Invalid C++ named cast");
1646 break;
1647 }
Mike Stump11289f42009-09-09 15:08:12 +00001648
John McCallfaf5fb42010-08-26 23:41:50 +00001649 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 }
Mike Stump11289f42009-09-09 15:08:12 +00001651
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 /// \brief Build a new C++ static_cast expression.
1653 ///
1654 /// By default, performs semantic analysis to build the new expression.
1655 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001656 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 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) {
John McCalld377e042010-01-15 19:13:16 +00001663 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001664 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001665 SourceRange(LAngleLoc, RAngleLoc),
1666 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 }
1668
1669 /// \brief Build a new C++ dynamic_cast expression.
1670 ///
1671 /// By default, performs semantic analysis to build the new expression.
1672 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001673 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001675 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 SourceLocation RAngleLoc,
1677 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001678 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001680 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001681 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001682 SourceRange(LAngleLoc, RAngleLoc),
1683 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001684 }
1685
1686 /// \brief Build a new C++ reinterpret_cast expression.
1687 ///
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001690 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001692 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 SourceLocation RAngleLoc,
1694 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001695 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001697 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001698 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001699 SourceRange(LAngleLoc, RAngleLoc),
1700 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 }
1702
1703 /// \brief Build a new C++ const_cast expression.
1704 ///
1705 /// By default, performs semantic analysis to build the new expression.
1706 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001707 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001709 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 SourceLocation RAngleLoc,
1711 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001712 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001714 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001715 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001716 SourceRange(LAngleLoc, RAngleLoc),
1717 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 }
Mike Stump11289f42009-09-09 15:08:12 +00001719
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 /// \brief Build a new C++ functional-style cast expression.
1721 ///
1722 /// By default, performs semantic analysis to build the new expression.
1723 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001724 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1725 SourceLocation LParenLoc,
1726 Expr *Sub,
1727 SourceLocation RParenLoc) {
1728 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001729 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 RParenLoc);
1731 }
Mike Stump11289f42009-09-09 15:08:12 +00001732
Douglas Gregora16548e2009-08-11 05:31:07 +00001733 /// \brief Build a new C++ typeid(type) expression.
1734 ///
1735 /// By default, performs semantic analysis to build the new expression.
1736 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001737 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001738 SourceLocation TypeidLoc,
1739 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001741 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001742 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 }
Mike Stump11289f42009-09-09 15:08:12 +00001744
Francois Pichet9f4f2072010-09-08 12:20:18 +00001745
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 /// \brief Build a new C++ typeid(expr) expression.
1747 ///
1748 /// By default, performs semantic analysis to build the new expression.
1749 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001750 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001751 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001752 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001754 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001755 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001756 }
1757
Francois Pichet9f4f2072010-09-08 12:20:18 +00001758 /// \brief Build a new C++ __uuidof(type) expression.
1759 ///
1760 /// By default, performs semantic analysis to build the new expression.
1761 /// Subclasses may override this routine to provide different behavior.
1762 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1763 SourceLocation TypeidLoc,
1764 TypeSourceInfo *Operand,
1765 SourceLocation RParenLoc) {
1766 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1767 RParenLoc);
1768 }
1769
1770 /// \brief Build a new C++ __uuidof(expr) expression.
1771 ///
1772 /// By default, performs semantic analysis to build the new expression.
1773 /// Subclasses may override this routine to provide different behavior.
1774 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1775 SourceLocation TypeidLoc,
1776 Expr *Operand,
1777 SourceLocation RParenLoc) {
1778 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1779 RParenLoc);
1780 }
1781
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 /// \brief Build a new C++ "this" expression.
1783 ///
1784 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001785 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001787 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001788 QualType ThisType,
1789 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001791 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1792 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 }
1794
1795 /// \brief Build a new C++ throw expression.
1796 ///
1797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001799 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001800 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001801 }
1802
1803 /// \brief Build a new C++ default-argument expression.
1804 ///
1805 /// By default, builds a new default-argument expression, which does not
1806 /// require any semantic analysis. Subclasses may override this routine to
1807 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001808 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001809 ParmVarDecl *Param) {
1810 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1811 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 }
1813
1814 /// \brief Build a new C++ zero-initialization expression.
1815 ///
1816 /// By default, performs semantic analysis to build the new expression.
1817 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001818 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1819 SourceLocation LParenLoc,
1820 SourceLocation RParenLoc) {
1821 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001822 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001823 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 }
Mike Stump11289f42009-09-09 15:08:12 +00001825
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 /// \brief Build a new C++ "new" expression.
1827 ///
1828 /// By default, performs semantic analysis to build the new expression.
1829 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001830 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001831 bool UseGlobal,
1832 SourceLocation PlacementLParen,
1833 MultiExprArg PlacementArgs,
1834 SourceLocation PlacementRParen,
1835 SourceRange TypeIdParens,
1836 QualType AllocatedType,
1837 TypeSourceInfo *AllocatedTypeInfo,
1838 Expr *ArraySize,
1839 SourceLocation ConstructorLParen,
1840 MultiExprArg ConstructorArgs,
1841 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001842 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001843 PlacementLParen,
1844 move(PlacementArgs),
1845 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001846 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001847 AllocatedType,
1848 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001849 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 ConstructorLParen,
1851 move(ConstructorArgs),
1852 ConstructorRParen);
1853 }
Mike Stump11289f42009-09-09 15:08:12 +00001854
Douglas Gregora16548e2009-08-11 05:31:07 +00001855 /// \brief Build a new C++ "delete" expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001859 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001860 bool IsGlobalDelete,
1861 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001862 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001864 Operand);
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 unary type trait 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 RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001872 SourceLocation StartLoc,
1873 TypeSourceInfo *T,
1874 SourceLocation RParenLoc) {
1875 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 }
1877
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001878 /// \brief Build a new binary type trait expression.
1879 ///
1880 /// By default, performs semantic analysis to build the new expression.
1881 /// Subclasses may override this routine to provide different behavior.
1882 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1883 SourceLocation StartLoc,
1884 TypeSourceInfo *LhsT,
1885 TypeSourceInfo *RhsT,
1886 SourceLocation RParenLoc) {
1887 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1888 }
1889
Mike Stump11289f42009-09-09 15:08:12 +00001890 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 /// expression.
1892 ///
1893 /// By default, performs semantic analysis to build the new expression.
1894 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001895 ExprResult RebuildDependentScopeDeclRefExpr(
1896 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001897 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001898 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001900 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001901
1902 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001903 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001904 *TemplateArgs);
1905
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001906 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001907 }
1908
1909 /// \brief Build a new template-id expression.
1910 ///
1911 /// By default, performs semantic analysis to build the new expression.
1912 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001913 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001914 LookupResult &R,
1915 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001916 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001917 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 }
1919
1920 /// \brief Build a new object-construction expression.
1921 ///
1922 /// By default, performs semantic analysis to build the new expression.
1923 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001924 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001925 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 CXXConstructorDecl *Constructor,
1927 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001928 MultiExprArg Args,
1929 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001930 CXXConstructExpr::ConstructionKind ConstructKind,
1931 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001932 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001933 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001934 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001935 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001936
Douglas Gregordb121ba2009-12-14 16:27:04 +00001937 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001938 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001939 RequiresZeroInit, ConstructKind,
1940 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 }
1942
1943 /// \brief Build a new object-construction expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001947 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1948 SourceLocation LParenLoc,
1949 MultiExprArg Args,
1950 SourceLocation RParenLoc) {
1951 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 LParenLoc,
1953 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 RParenLoc);
1955 }
1956
1957 /// \brief Build a new object-construction expression.
1958 ///
1959 /// By default, performs semantic analysis to build the new expression.
1960 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001961 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1962 SourceLocation LParenLoc,
1963 MultiExprArg Args,
1964 SourceLocation RParenLoc) {
1965 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 LParenLoc,
1967 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 RParenLoc);
1969 }
Mike Stump11289f42009-09-09 15:08:12 +00001970
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 /// \brief Build a new member reference expression.
1972 ///
1973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001975 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00001976 QualType BaseType,
1977 bool IsArrow,
1978 SourceLocation OperatorLoc,
1979 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00001980 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001981 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001982 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00001984 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001985
John McCallb268a282010-08-23 23:25:46 +00001986 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001987 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001988 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001989 MemberNameInfo,
1990 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 }
1992
John McCall10eae182009-11-30 22:42:35 +00001993 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001994 ///
1995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001997 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001998 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001999 SourceLocation OperatorLoc,
2000 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002001 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002002 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002003 LookupResult &R,
2004 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002005 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002006 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002007
John McCallb268a282010-08-23 23:25:46 +00002008 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002009 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002010 SS, FirstQualifierInScope,
2011 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002012 }
Mike Stump11289f42009-09-09 15:08:12 +00002013
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002014 /// \brief Build a new noexcept expression.
2015 ///
2016 /// By default, performs semantic analysis to build the new expression.
2017 /// Subclasses may override this routine to provide different behavior.
2018 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2019 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2020 }
2021
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002022 /// \brief Build a new expression to compute the length of a parameter pack.
2023 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2024 SourceLocation PackLoc,
2025 SourceLocation RParenLoc,
2026 unsigned Length) {
2027 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2028 OperatorLoc, Pack, PackLoc,
2029 RParenLoc, Length);
2030 }
2031
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 /// \brief Build a new Objective-C @encode expression.
2033 ///
2034 /// By default, performs semantic analysis to build the new expression.
2035 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002036 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002037 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002039 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002041 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002042
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002043 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002044 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002045 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002046 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002047 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002048 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002049 MultiExprArg Args,
2050 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002051 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2052 ReceiverTypeInfo->getType(),
2053 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002054 Sel, Method, LBracLoc, SelectorLoc,
2055 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002056 }
2057
2058 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002059 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002060 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002061 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002062 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002063 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002064 MultiExprArg Args,
2065 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002066 return SemaRef.BuildInstanceMessage(Receiver,
2067 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002068 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002069 Sel, Method, LBracLoc, SelectorLoc,
2070 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002071 }
2072
Douglas Gregord51d90d2010-04-26 20:11:03 +00002073 /// \brief Build a new Objective-C ivar reference 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 RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002078 SourceLocation IvarLoc,
2079 bool IsArrow, bool IsFreeIvar) {
2080 // FIXME: We lose track of the IsFreeIvar bit.
2081 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002082 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002083 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2084 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002085 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002086 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002087 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002088 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002089 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002090 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002091
Douglas Gregord51d90d2010-04-26 20:11:03 +00002092 if (Result.get())
2093 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002094
John McCallb268a282010-08-23 23:25:46 +00002095 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002096 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002097 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002098 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002099 /*TemplateArgs=*/0);
2100 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002101
2102 /// \brief Build a new Objective-C property reference expression.
2103 ///
2104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002106 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002107 ObjCPropertyDecl *Property,
2108 SourceLocation PropertyLoc) {
2109 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002110 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002111 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2112 Sema::LookupMemberName);
2113 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002114 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002115 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002116 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002117 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002118 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002119
Douglas Gregor9faee212010-04-26 20:47:02 +00002120 if (Result.get())
2121 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002122
John McCallb268a282010-08-23 23:25:46 +00002123 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002124 /*FIXME:*/PropertyLoc, IsArrow,
2125 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002126 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002127 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002128 /*TemplateArgs=*/0);
2129 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002130
John McCallb7bd14f2010-12-02 01:19:52 +00002131 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002132 ///
2133 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002134 /// Subclasses may override this routine to provide different behavior.
2135 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2136 ObjCMethodDecl *Getter,
2137 ObjCMethodDecl *Setter,
2138 SourceLocation PropertyLoc) {
2139 // Since these expressions can only be value-dependent, we do not
2140 // need to perform semantic analysis again.
2141 return Owned(
2142 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2143 VK_LValue, OK_ObjCProperty,
2144 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002145 }
2146
Douglas Gregord51d90d2010-04-26 20:11:03 +00002147 /// \brief Build a new Objective-C "isa" expression.
2148 ///
2149 /// By default, performs semantic analysis to build the new expression.
2150 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002151 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002152 bool IsArrow) {
2153 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002154 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002155 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2156 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002157 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002158 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002159 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002160 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002161 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002162
Douglas Gregord51d90d2010-04-26 20:11:03 +00002163 if (Result.get())
2164 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002165
John McCallb268a282010-08-23 23:25:46 +00002166 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002167 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002168 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002169 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002170 /*TemplateArgs=*/0);
2171 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002172
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 /// \brief Build a new shuffle vector expression.
2174 ///
2175 /// By default, performs semantic analysis to build the new expression.
2176 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002177 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002178 MultiExprArg SubExprs,
2179 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002181 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2183 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2184 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2185 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002186
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 // Build a reference to the __builtin_shufflevector builtin
2188 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002189 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002191 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002193
2194 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 unsigned NumSubExprs = SubExprs.size();
2196 Expr **Subs = (Expr **)SubExprs.release();
2197 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2198 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002199 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002200 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002202 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002203
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002205 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002207 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002208
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002210 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 }
John McCall31f82722010-11-12 08:19:04 +00002212
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002213 /// \brief Build a new template argument pack expansion.
2214 ///
2215 /// By default, performs semantic analysis to build a new pack expansion
2216 /// for a template argument. Subclasses may override this routine to provide
2217 /// different behavior.
2218 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002219 SourceLocation EllipsisLoc,
2220 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002221 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002222 case TemplateArgument::Expression: {
2223 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002224 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2225 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002226 if (Result.isInvalid())
2227 return TemplateArgumentLoc();
2228
2229 return TemplateArgumentLoc(Result.get(), Result.get());
2230 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002231
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002232 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002233 return TemplateArgumentLoc(TemplateArgument(
2234 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002235 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002236 Pattern.getTemplateQualifierRange(),
2237 Pattern.getTemplateNameLoc(),
2238 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002239
2240 case TemplateArgument::Null:
2241 case TemplateArgument::Integral:
2242 case TemplateArgument::Declaration:
2243 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002244 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002245 llvm_unreachable("Pack expansion pattern has no parameter packs");
2246
2247 case TemplateArgument::Type:
2248 if (TypeSourceInfo *Expansion
2249 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002250 EllipsisLoc,
2251 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002252 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2253 Expansion);
2254 break;
2255 }
2256
2257 return TemplateArgumentLoc();
2258 }
2259
Douglas Gregor968f23a2011-01-03 19:31:53 +00002260 /// \brief Build a new expression pack expansion.
2261 ///
2262 /// By default, performs semantic analysis to build a new pack expansion
2263 /// for an expression. Subclasses may override this routine to provide
2264 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002265 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2266 llvm::Optional<unsigned> NumExpansions) {
2267 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002268 }
2269
John McCall31f82722010-11-12 08:19:04 +00002270private:
2271 QualType TransformTypeInObjectScope(QualType T,
2272 QualType ObjectType,
2273 NamedDecl *FirstQualifierInScope,
2274 NestedNameSpecifier *Prefix);
2275
2276 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2277 QualType ObjectType,
2278 NamedDecl *FirstQualifierInScope,
2279 NestedNameSpecifier *Prefix);
Douglas Gregor14454802011-02-25 02:25:35 +00002280
2281 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2282 QualType ObjectType,
2283 NamedDecl *FirstQualifierInScope,
2284 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002285};
Douglas Gregora16548e2009-08-11 05:31:07 +00002286
Douglas Gregorebe10102009-08-20 07:17:43 +00002287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002288StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002289 if (!S)
2290 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002291
Douglas Gregorebe10102009-08-20 07:17:43 +00002292 switch (S->getStmtClass()) {
2293 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002294
Douglas Gregorebe10102009-08-20 07:17:43 +00002295 // Transform individual statement nodes
2296#define STMT(Node, Parent) \
2297 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002298#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002299#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002300#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002301
Douglas Gregorebe10102009-08-20 07:17:43 +00002302 // Transform expressions by calling TransformExpr.
2303#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002304#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002305#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002306#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002307 {
John McCalldadc5752010-08-24 06:29:42 +00002308 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002309 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002310 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002311
John McCallb268a282010-08-23 23:25:46 +00002312 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002313 }
Mike Stump11289f42009-09-09 15:08:12 +00002314 }
2315
John McCallc3007a22010-10-26 07:05:15 +00002316 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002317}
Mike Stump11289f42009-09-09 15:08:12 +00002318
2319
Douglas Gregore922c772009-08-04 22:27:00 +00002320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002321ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 if (!E)
2323 return SemaRef.Owned(E);
2324
2325 switch (E->getStmtClass()) {
2326 case Stmt::NoStmtClass: break;
2327#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002328#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002329#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002330 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002331#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002332 }
2333
John McCallc3007a22010-10-26 07:05:15 +00002334 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002335}
2336
2337template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002338bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2339 unsigned NumInputs,
2340 bool IsCall,
2341 llvm::SmallVectorImpl<Expr *> &Outputs,
2342 bool *ArgChanged) {
2343 for (unsigned I = 0; I != NumInputs; ++I) {
2344 // If requested, drop call arguments that need to be dropped.
2345 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2346 if (ArgChanged)
2347 *ArgChanged = true;
2348
2349 break;
2350 }
2351
Douglas Gregor968f23a2011-01-03 19:31:53 +00002352 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2353 Expr *Pattern = Expansion->getPattern();
2354
2355 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2356 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2357 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2358
2359 // Determine whether the set of unexpanded parameter packs can and should
2360 // be expanded.
2361 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002362 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002363 llvm::Optional<unsigned> OrigNumExpansions
2364 = Expansion->getNumExpansions();
2365 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002366 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2367 Pattern->getSourceRange(),
2368 Unexpanded.data(),
2369 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002370 Expand, RetainExpansion,
2371 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002372 return true;
2373
2374 if (!Expand) {
2375 // The transform has determined that we should perform a simple
2376 // transformation on the pack expansion, producing another pack
2377 // expansion.
2378 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2379 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2380 if (OutPattern.isInvalid())
2381 return true;
2382
2383 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002384 Expansion->getEllipsisLoc(),
2385 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002386 if (Out.isInvalid())
2387 return true;
2388
2389 if (ArgChanged)
2390 *ArgChanged = true;
2391 Outputs.push_back(Out.get());
2392 continue;
2393 }
2394
2395 // The transform has determined that we should perform an elementwise
2396 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002397 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002398 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2399 ExprResult Out = getDerived().TransformExpr(Pattern);
2400 if (Out.isInvalid())
2401 return true;
2402
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002403 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002404 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2405 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002406 if (Out.isInvalid())
2407 return true;
2408 }
2409
Douglas Gregor968f23a2011-01-03 19:31:53 +00002410 if (ArgChanged)
2411 *ArgChanged = true;
2412 Outputs.push_back(Out.get());
2413 }
2414
2415 continue;
2416 }
2417
Douglas Gregora3efea12011-01-03 19:04:46 +00002418 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2419 if (Result.isInvalid())
2420 return true;
2421
2422 if (Result.get() != Inputs[I] && ArgChanged)
2423 *ArgChanged = true;
2424
2425 Outputs.push_back(Result.get());
2426 }
2427
2428 return false;
2429}
2430
2431template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002432NestedNameSpecifier *
2433TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002434 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002435 QualType ObjectType,
2436 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002437 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002438
Douglas Gregorebe10102009-08-20 07:17:43 +00002439 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002440 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002441 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002442 ObjectType,
2443 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002444 if (!Prefix)
2445 return 0;
2446 }
Mike Stump11289f42009-09-09 15:08:12 +00002447
Douglas Gregor1135c352009-08-06 05:28:30 +00002448 switch (NNS->getKind()) {
2449 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002450 if (Prefix) {
2451 // The object type and qualifier-in-scope really apply to the
2452 // leftmost entity.
2453 ObjectType = QualType();
2454 FirstQualifierInScope = 0;
2455 }
2456
Mike Stump11289f42009-09-09 15:08:12 +00002457 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002458 "Identifier nested-name-specifier with no prefix or object type");
2459 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2460 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002461 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002462
2463 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002464 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002465 ObjectType,
2466 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002467
Douglas Gregor1135c352009-08-06 05:28:30 +00002468 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002469 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002470 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002471 getDerived().TransformDecl(Range.getBegin(),
2472 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002473 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002474 Prefix == NNS->getPrefix() &&
2475 NS == NNS->getAsNamespace())
2476 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002477
Douglas Gregor1135c352009-08-06 05:28:30 +00002478 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2479 }
Mike Stump11289f42009-09-09 15:08:12 +00002480
Douglas Gregor7b26ff92011-02-24 02:36:08 +00002481 case NestedNameSpecifier::NamespaceAlias: {
2482 NamespaceAliasDecl *Alias
2483 = cast_or_null<NamespaceAliasDecl>(
2484 getDerived().TransformDecl(Range.getBegin(),
2485 NNS->getAsNamespaceAlias()));
2486 if (!getDerived().AlwaysRebuild() &&
2487 Prefix == NNS->getPrefix() &&
2488 Alias == NNS->getAsNamespaceAlias())
2489 return NNS;
2490
2491 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias);
2492 }
2493
Douglas Gregor1135c352009-08-06 05:28:30 +00002494 case NestedNameSpecifier::Global:
2495 // There is no meaningful transformation that one could perform on the
2496 // global scope.
2497 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002498
Douglas Gregor1135c352009-08-06 05:28:30 +00002499 case NestedNameSpecifier::TypeSpecWithTemplate:
2500 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002501 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002502 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2503 ObjectType,
2504 FirstQualifierInScope,
2505 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002506 if (T.isNull())
2507 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002508
Douglas Gregor1135c352009-08-06 05:28:30 +00002509 if (!getDerived().AlwaysRebuild() &&
2510 Prefix == NNS->getPrefix() &&
2511 T == QualType(NNS->getAsType(), 0))
2512 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002513
2514 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2515 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002516 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002517 }
2518 }
Mike Stump11289f42009-09-09 15:08:12 +00002519
Douglas Gregor1135c352009-08-06 05:28:30 +00002520 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002521 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002522}
2523
2524template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002525NestedNameSpecifierLoc
2526TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2527 NestedNameSpecifierLoc NNS,
2528 QualType ObjectType,
2529 NamedDecl *FirstQualifierInScope) {
2530 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2531 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2532 Qualifier = Qualifier.getPrefix())
2533 Qualifiers.push_back(Qualifier);
2534
2535 CXXScopeSpec SS;
2536 while (!Qualifiers.empty()) {
2537 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2538 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2539
2540 switch (QNNS->getKind()) {
2541 case NestedNameSpecifier::Identifier:
2542 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2543 *QNNS->getAsIdentifier(),
2544 Q.getLocalBeginLoc(),
2545 Q.getLocalEndLoc(),
2546 ObjectType, false, SS,
2547 FirstQualifierInScope, false))
2548 return NestedNameSpecifierLoc();
2549
2550 break;
2551
2552 case NestedNameSpecifier::Namespace: {
2553 NamespaceDecl *NS
2554 = cast_or_null<NamespaceDecl>(
2555 getDerived().TransformDecl(
2556 Q.getLocalBeginLoc(),
2557 QNNS->getAsNamespace()));
2558 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2559 break;
2560 }
2561
2562 case NestedNameSpecifier::NamespaceAlias: {
2563 NamespaceAliasDecl *Alias
2564 = cast_or_null<NamespaceAliasDecl>(
2565 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2566 QNNS->getAsNamespaceAlias()));
2567 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2568 Q.getLocalEndLoc());
2569 break;
2570 }
2571
2572 case NestedNameSpecifier::Global:
2573 // There is no meaningful transformation that one could perform on the
2574 // global scope.
2575 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2576 break;
2577
2578 case NestedNameSpecifier::TypeSpecWithTemplate:
2579 case NestedNameSpecifier::TypeSpec: {
2580 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2581 FirstQualifierInScope, SS);
2582
2583 if (!TL)
2584 return NestedNameSpecifierLoc();
2585
2586 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2587 (SemaRef.getLangOptions().CPlusPlus0x &&
2588 TL.getType()->isEnumeralType())) {
2589 assert(!TL.getType().hasLocalQualifiers() &&
2590 "Can't get cv-qualifiers here");
2591 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2592 Q.getLocalEndLoc());
2593 break;
2594 }
2595
2596 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2597 << TL.getType() << SS.getRange();
2598 return NestedNameSpecifierLoc();
2599 }
Douglas Gregore16af532011-02-28 18:50:33 +00002600 }
Douglas Gregor14454802011-02-25 02:25:35 +00002601
Douglas Gregore16af532011-02-28 18:50:33 +00002602 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002603 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002604 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002605 }
2606
2607 // Don't rebuild the nested-name-specifier if we don't have to.
2608 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2609 !getDerived().AlwaysRebuild())
2610 return NNS;
2611
2612 // If we can re-use the source-location data from the original
2613 // nested-name-specifier, do so.
2614 if (SS.location_size() == NNS.getDataLength() &&
2615 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2616 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2617
2618 // Allocate new nested-name-specifier location information.
2619 return SS.getWithLocInContext(SemaRef.Context);
2620}
2621
2622template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002623DeclarationNameInfo
2624TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002625::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002626 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002627 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002628 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002629
2630 switch (Name.getNameKind()) {
2631 case DeclarationName::Identifier:
2632 case DeclarationName::ObjCZeroArgSelector:
2633 case DeclarationName::ObjCOneArgSelector:
2634 case DeclarationName::ObjCMultiArgSelector:
2635 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002636 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002637 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002638 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002639
Douglas Gregorf816bd72009-09-03 22:13:48 +00002640 case DeclarationName::CXXConstructorName:
2641 case DeclarationName::CXXDestructorName:
2642 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002643 TypeSourceInfo *NewTInfo;
2644 CanQualType NewCanTy;
2645 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002646 NewTInfo = getDerived().TransformType(OldTInfo);
2647 if (!NewTInfo)
2648 return DeclarationNameInfo();
2649 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002650 }
2651 else {
2652 NewTInfo = 0;
2653 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002654 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002655 if (NewT.isNull())
2656 return DeclarationNameInfo();
2657 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2658 }
Mike Stump11289f42009-09-09 15:08:12 +00002659
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002660 DeclarationName NewName
2661 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2662 NewCanTy);
2663 DeclarationNameInfo NewNameInfo(NameInfo);
2664 NewNameInfo.setName(NewName);
2665 NewNameInfo.setNamedTypeInfo(NewTInfo);
2666 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002667 }
Mike Stump11289f42009-09-09 15:08:12 +00002668 }
2669
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002670 assert(0 && "Unknown name kind.");
2671 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002672}
2673
2674template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002675TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002676TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002677 QualType ObjectType,
2678 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002679 SourceLocation Loc = getDerived().getBaseLocation();
2680
Douglas Gregor71dc5092009-08-06 06:41:21 +00002681 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002682 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002683 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002684 /*FIXME*/ SourceRange(Loc),
2685 ObjectType,
2686 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002687 if (!NNS)
2688 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002689
Douglas Gregor71dc5092009-08-06 06:41:21 +00002690 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002691 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002692 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002693 if (!TransTemplate)
2694 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002695
Douglas Gregor71dc5092009-08-06 06:41:21 +00002696 if (!getDerived().AlwaysRebuild() &&
2697 NNS == QTN->getQualifier() &&
2698 TransTemplate == Template)
2699 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002700
Douglas Gregor71dc5092009-08-06 06:41:21 +00002701 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2702 TransTemplate);
2703 }
Mike Stump11289f42009-09-09 15:08:12 +00002704
John McCalle66edc12009-11-24 19:00:30 +00002705 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002706 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002707 }
Mike Stump11289f42009-09-09 15:08:12 +00002708
Douglas Gregor71dc5092009-08-06 06:41:21 +00002709 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002710 NestedNameSpecifier *NNS = DTN->getQualifier();
2711 if (NNS) {
2712 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2713 /*FIXME:*/SourceRange(Loc),
2714 ObjectType,
2715 FirstQualifierInScope);
2716 if (!NNS) return TemplateName();
2717
2718 // These apply to the scope specifier, not the template.
2719 ObjectType = QualType();
2720 FirstQualifierInScope = 0;
2721 }
Mike Stump11289f42009-09-09 15:08:12 +00002722
Douglas Gregor71dc5092009-08-06 06:41:21 +00002723 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002724 NNS == DTN->getQualifier() &&
2725 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002726 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002727
Douglas Gregora5614c52010-09-08 23:56:00 +00002728 if (DTN->isIdentifier()) {
2729 // FIXME: Bad range
2730 SourceRange QualifierRange(getDerived().getBaseLocation());
2731 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2732 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002733 ObjectType,
2734 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002735 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002736
2737 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002738 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002739 }
Mike Stump11289f42009-09-09 15:08:12 +00002740
Douglas Gregor71dc5092009-08-06 06:41:21 +00002741 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002742 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002743 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002744 if (!TransTemplate)
2745 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002746
Douglas Gregor71dc5092009-08-06 06:41:21 +00002747 if (!getDerived().AlwaysRebuild() &&
2748 TransTemplate == Template)
2749 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002750
Douglas Gregor71dc5092009-08-06 06:41:21 +00002751 return TemplateName(TransTemplate);
2752 }
Mike Stump11289f42009-09-09 15:08:12 +00002753
Douglas Gregor5590be02011-01-15 06:45:20 +00002754 if (SubstTemplateTemplateParmPackStorage *SubstPack
2755 = Name.getAsSubstTemplateTemplateParmPack()) {
2756 TemplateTemplateParmDecl *TransParam
2757 = cast_or_null<TemplateTemplateParmDecl>(
2758 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2759 if (!TransParam)
2760 return TemplateName();
2761
2762 if (!getDerived().AlwaysRebuild() &&
2763 TransParam == SubstPack->getParameterPack())
2764 return Name;
2765
2766 return getDerived().RebuildTemplateName(TransParam,
2767 SubstPack->getArgumentPack());
2768 }
2769
John McCalle66edc12009-11-24 19:00:30 +00002770 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002771 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002772 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002773}
2774
2775template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002776void TreeTransform<Derived>::InventTemplateArgumentLoc(
2777 const TemplateArgument &Arg,
2778 TemplateArgumentLoc &Output) {
2779 SourceLocation Loc = getDerived().getBaseLocation();
2780 switch (Arg.getKind()) {
2781 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002782 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002783 break;
2784
2785 case TemplateArgument::Type:
2786 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002787 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002788
John McCall0ad16662009-10-29 08:12:44 +00002789 break;
2790
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002791 case TemplateArgument::Template:
2792 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2793 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002794
2795 case TemplateArgument::TemplateExpansion:
2796 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2797 break;
2798
John McCall0ad16662009-10-29 08:12:44 +00002799 case TemplateArgument::Expression:
2800 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2801 break;
2802
2803 case TemplateArgument::Declaration:
2804 case TemplateArgument::Integral:
2805 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002806 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002807 break;
2808 }
2809}
2810
2811template<typename Derived>
2812bool TreeTransform<Derived>::TransformTemplateArgument(
2813 const TemplateArgumentLoc &Input,
2814 TemplateArgumentLoc &Output) {
2815 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002816 switch (Arg.getKind()) {
2817 case TemplateArgument::Null:
2818 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002819 Output = Input;
2820 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002821
Douglas Gregore922c772009-08-04 22:27:00 +00002822 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002823 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002824 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002825 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002826
2827 DI = getDerived().TransformType(DI);
2828 if (!DI) return true;
2829
2830 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2831 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002832 }
Mike Stump11289f42009-09-09 15:08:12 +00002833
Douglas Gregore922c772009-08-04 22:27:00 +00002834 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002835 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002836 DeclarationName Name;
2837 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2838 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002839 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002840 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002841 if (!D) return true;
2842
John McCall0d07eb32009-10-29 18:45:58 +00002843 Expr *SourceExpr = Input.getSourceDeclExpression();
2844 if (SourceExpr) {
2845 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002846 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002847 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002848 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002849 }
2850
2851 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002852 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002853 }
Mike Stump11289f42009-09-09 15:08:12 +00002854
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002855 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002856 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002857 TemplateName Template
2858 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2859 if (Template.isNull())
2860 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002861
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002862 Output = TemplateArgumentLoc(TemplateArgument(Template),
2863 Input.getTemplateQualifierRange(),
2864 Input.getTemplateNameLoc());
2865 return false;
2866 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002867
2868 case TemplateArgument::TemplateExpansion:
2869 llvm_unreachable("Caller should expand pack expansions");
2870
Douglas Gregore922c772009-08-04 22:27:00 +00002871 case TemplateArgument::Expression: {
2872 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002873 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002874 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002875
John McCall0ad16662009-10-29 08:12:44 +00002876 Expr *InputExpr = Input.getSourceExpression();
2877 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2878
John McCalldadc5752010-08-24 06:29:42 +00002879 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002880 = getDerived().TransformExpr(InputExpr);
2881 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002882 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002883 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002884 }
Mike Stump11289f42009-09-09 15:08:12 +00002885
Douglas Gregore922c772009-08-04 22:27:00 +00002886 case TemplateArgument::Pack: {
2887 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2888 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002889 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002890 AEnd = Arg.pack_end();
2891 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002892
John McCall0ad16662009-10-29 08:12:44 +00002893 // FIXME: preserve source information here when we start
2894 // caring about parameter packs.
2895
John McCall0d07eb32009-10-29 18:45:58 +00002896 TemplateArgumentLoc InputArg;
2897 TemplateArgumentLoc OutputArg;
2898 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2899 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002900 return true;
2901
John McCall0d07eb32009-10-29 18:45:58 +00002902 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002903 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002904
2905 TemplateArgument *TransformedArgsPtr
2906 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2907 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2908 TransformedArgsPtr);
2909 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2910 TransformedArgs.size()),
2911 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002912 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002913 }
2914 }
Mike Stump11289f42009-09-09 15:08:12 +00002915
Douglas Gregore922c772009-08-04 22:27:00 +00002916 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002917 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002918}
2919
Douglas Gregorfe921a72010-12-20 23:36:19 +00002920/// \brief Iterator adaptor that invents template argument location information
2921/// for each of the template arguments in its underlying iterator.
2922template<typename Derived, typename InputIterator>
2923class TemplateArgumentLocInventIterator {
2924 TreeTransform<Derived> &Self;
2925 InputIterator Iter;
2926
2927public:
2928 typedef TemplateArgumentLoc value_type;
2929 typedef TemplateArgumentLoc reference;
2930 typedef typename std::iterator_traits<InputIterator>::difference_type
2931 difference_type;
2932 typedef std::input_iterator_tag iterator_category;
2933
2934 class pointer {
2935 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002936
Douglas Gregorfe921a72010-12-20 23:36:19 +00002937 public:
2938 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2939
2940 const TemplateArgumentLoc *operator->() const { return &Arg; }
2941 };
2942
2943 TemplateArgumentLocInventIterator() { }
2944
2945 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2946 InputIterator Iter)
2947 : Self(Self), Iter(Iter) { }
2948
2949 TemplateArgumentLocInventIterator &operator++() {
2950 ++Iter;
2951 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002952 }
2953
Douglas Gregorfe921a72010-12-20 23:36:19 +00002954 TemplateArgumentLocInventIterator operator++(int) {
2955 TemplateArgumentLocInventIterator Old(*this);
2956 ++(*this);
2957 return Old;
2958 }
2959
2960 reference operator*() const {
2961 TemplateArgumentLoc Result;
2962 Self.InventTemplateArgumentLoc(*Iter, Result);
2963 return Result;
2964 }
2965
2966 pointer operator->() const { return pointer(**this); }
2967
2968 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2969 const TemplateArgumentLocInventIterator &Y) {
2970 return X.Iter == Y.Iter;
2971 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002972
Douglas Gregorfe921a72010-12-20 23:36:19 +00002973 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2974 const TemplateArgumentLocInventIterator &Y) {
2975 return X.Iter != Y.Iter;
2976 }
2977};
2978
Douglas Gregor42cafa82010-12-20 17:42:22 +00002979template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002980template<typename InputIterator>
2981bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2982 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002983 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002984 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002985 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002986 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002987
2988 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2989 // Unpack argument packs, which we translate them into separate
2990 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002991 // FIXME: We could do much better if we could guarantee that the
2992 // TemplateArgumentLocInfo for the pack expansion would be usable for
2993 // all of the template arguments in the argument pack.
2994 typedef TemplateArgumentLocInventIterator<Derived,
2995 TemplateArgument::pack_iterator>
2996 PackLocIterator;
2997 if (TransformTemplateArguments(PackLocIterator(*this,
2998 In.getArgument().pack_begin()),
2999 PackLocIterator(*this,
3000 In.getArgument().pack_end()),
3001 Outputs))
3002 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003003
3004 continue;
3005 }
3006
3007 if (In.getArgument().isPackExpansion()) {
3008 // We have a pack expansion, for which we will be substituting into
3009 // the pattern.
3010 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003011 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003012 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003013 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3014 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003015
3016 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3017 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3018 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3019
3020 // Determine whether the set of unexpanded parameter packs can and should
3021 // be expanded.
3022 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003023 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003024 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003025 if (getDerived().TryExpandParameterPacks(Ellipsis,
3026 Pattern.getSourceRange(),
3027 Unexpanded.data(),
3028 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003029 Expand,
3030 RetainExpansion,
3031 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003032 return true;
3033
3034 if (!Expand) {
3035 // The transform has determined that we should perform a simple
3036 // transformation on the pack expansion, producing another pack
3037 // expansion.
3038 TemplateArgumentLoc OutPattern;
3039 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3040 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3041 return true;
3042
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003043 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3044 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003045 if (Out.getArgument().isNull())
3046 return true;
3047
3048 Outputs.addArgument(Out);
3049 continue;
3050 }
3051
3052 // The transform has determined that we should perform an elementwise
3053 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003054 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003055 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3056
3057 if (getDerived().TransformTemplateArgument(Pattern, Out))
3058 return true;
3059
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003060 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003061 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3062 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003063 if (Out.getArgument().isNull())
3064 return true;
3065 }
3066
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003067 Outputs.addArgument(Out);
3068 }
3069
Douglas Gregor48d24112011-01-10 20:53:55 +00003070 // If we're supposed to retain a pack expansion, do so by temporarily
3071 // forgetting the partially-substituted parameter pack.
3072 if (RetainExpansion) {
3073 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3074
3075 if (getDerived().TransformTemplateArgument(Pattern, Out))
3076 return true;
3077
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003078 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3079 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003080 if (Out.getArgument().isNull())
3081 return true;
3082
3083 Outputs.addArgument(Out);
3084 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003085
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003086 continue;
3087 }
3088
3089 // The simple case:
3090 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003091 return true;
3092
3093 Outputs.addArgument(Out);
3094 }
3095
3096 return false;
3097
3098}
3099
Douglas Gregord6ff3322009-08-04 16:50:30 +00003100//===----------------------------------------------------------------------===//
3101// Type transformation
3102//===----------------------------------------------------------------------===//
3103
3104template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003105QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003106 if (getDerived().AlreadyTransformed(T))
3107 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003108
John McCall550e0c22009-10-21 00:40:46 +00003109 // Temporary workaround. All of these transformations should
3110 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003111 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3112 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003113
John McCall31f82722010-11-12 08:19:04 +00003114 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003115
John McCall550e0c22009-10-21 00:40:46 +00003116 if (!NewDI)
3117 return QualType();
3118
3119 return NewDI->getType();
3120}
3121
3122template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003123TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003124 if (getDerived().AlreadyTransformed(DI->getType()))
3125 return DI;
3126
3127 TypeLocBuilder TLB;
3128
3129 TypeLoc TL = DI->getTypeLoc();
3130 TLB.reserve(TL.getFullDataSize());
3131
John McCall31f82722010-11-12 08:19:04 +00003132 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003133 if (Result.isNull())
3134 return 0;
3135
John McCallbcd03502009-12-07 02:54:59 +00003136 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003137}
3138
3139template<typename Derived>
3140QualType
John McCall31f82722010-11-12 08:19:04 +00003141TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003142 switch (T.getTypeLocClass()) {
3143#define ABSTRACT_TYPELOC(CLASS, PARENT)
3144#define TYPELOC(CLASS, PARENT) \
3145 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003146 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003147#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003148 }
Mike Stump11289f42009-09-09 15:08:12 +00003149
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003150 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003151 return QualType();
3152}
3153
3154/// FIXME: By default, this routine adds type qualifiers only to types
3155/// that can have qualifiers, and silently suppresses those qualifiers
3156/// that are not permitted (e.g., qualifiers on reference or function
3157/// types). This is the right thing for template instantiation, but
3158/// probably not for other clients.
3159template<typename Derived>
3160QualType
3161TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003162 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003163 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003164
John McCall31f82722010-11-12 08:19:04 +00003165 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003166 if (Result.isNull())
3167 return QualType();
3168
3169 // Silently suppress qualifiers if the result type can't be qualified.
3170 // FIXME: this is the right thing for template instantiation, but
3171 // probably not for other clients.
3172 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003173 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003174
John McCallcb0f89a2010-06-05 06:41:15 +00003175 if (!Quals.empty()) {
3176 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3177 TLB.push<QualifiedTypeLoc>(Result);
3178 // No location information to preserve.
3179 }
John McCall550e0c22009-10-21 00:40:46 +00003180
3181 return Result;
3182}
3183
John McCall31f82722010-11-12 08:19:04 +00003184/// \brief Transforms a type that was written in a scope specifier,
3185/// given an object type, the results of unqualified lookup, and
3186/// an already-instantiated prefix.
3187///
3188/// The object type is provided iff the scope specifier qualifies the
3189/// member of a dependent member-access expression. The prefix is
3190/// provided iff the the scope specifier in which this appears has a
3191/// prefix.
3192///
3193/// This is private to TreeTransform.
3194template<typename Derived>
3195QualType
3196TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3197 QualType ObjectType,
3198 NamedDecl *UnqualLookup,
3199 NestedNameSpecifier *Prefix) {
3200 if (getDerived().AlreadyTransformed(T))
3201 return T;
3202
3203 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003204 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003205
3206 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3207 UnqualLookup, Prefix);
3208 if (!TSI) return QualType();
3209 return TSI->getType();
3210}
3211
3212template<typename Derived>
3213TypeSourceInfo *
3214TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3215 QualType ObjectType,
3216 NamedDecl *UnqualLookup,
3217 NestedNameSpecifier *Prefix) {
Douglas Gregor14454802011-02-25 02:25:35 +00003218 // TODO: in some cases, we might have some verification to do here.
John McCall31f82722010-11-12 08:19:04 +00003219 if (ObjectType.isNull())
3220 return getDerived().TransformType(TSI);
3221
3222 QualType T = TSI->getType();
3223 if (getDerived().AlreadyTransformed(T))
3224 return TSI;
3225
3226 TypeLocBuilder TLB;
3227 QualType Result;
3228
3229 if (isa<TemplateSpecializationType>(T)) {
3230 TemplateSpecializationTypeLoc TL
3231 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3232
3233 TemplateName Template =
3234 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3235 ObjectType, UnqualLookup);
3236 if (Template.isNull()) return 0;
3237
3238 Result = getDerived()
3239 .TransformTemplateSpecializationType(TLB, TL, Template);
3240 } else if (isa<DependentTemplateSpecializationType>(T)) {
3241 DependentTemplateSpecializationTypeLoc TL
3242 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3243
Douglas Gregor5a064722011-02-28 17:23:35 +00003244 TemplateName Template
3245 = SemaRef.Context.getDependentTemplateName(
3246 TL.getTypePtr()->getQualifier(),
3247 TL.getTypePtr()->getIdentifier());
3248
3249 Template = getDerived().TransformTemplateName(Template, ObjectType,
3250 UnqualLookup);
3251 if (Template.isNull())
3252 return 0;
3253
3254 Result = getDerived().TransformDependentTemplateSpecializationType(TLB, TL,
3255 Template);
John McCall31f82722010-11-12 08:19:04 +00003256 } else {
3257 // Nothing special needs to be done for these.
3258 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3259 }
3260
3261 if (Result.isNull()) return 0;
3262 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3263}
3264
Douglas Gregor14454802011-02-25 02:25:35 +00003265template<typename Derived>
3266TypeLoc
3267TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3268 QualType ObjectType,
3269 NamedDecl *UnqualLookup,
3270 CXXScopeSpec &SS) {
3271 // FIXME: Painfully copy-paste from the above!
3272
Douglas Gregor14454802011-02-25 02:25:35 +00003273 QualType T = TL.getType();
3274 if (getDerived().AlreadyTransformed(T))
3275 return TL;
3276
3277 TypeLocBuilder TLB;
3278 QualType Result;
3279
3280 if (isa<TemplateSpecializationType>(T)) {
3281 TemplateSpecializationTypeLoc SpecTL
3282 = cast<TemplateSpecializationTypeLoc>(TL);
3283
3284 TemplateName Template =
3285 getDerived().TransformTemplateName(SpecTL.getTypePtr()->getTemplateName(),
3286 ObjectType, UnqualLookup);
3287 if (Template.isNull())
3288 return TypeLoc();
3289
3290 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3291 Template);
3292 } else if (isa<DependentTemplateSpecializationType>(T)) {
3293 DependentTemplateSpecializationTypeLoc SpecTL
3294 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3295
Douglas Gregor5a064722011-02-28 17:23:35 +00003296 TemplateName Template
Douglas Gregore16af532011-02-28 18:50:33 +00003297 = getDerived().RebuildTemplateName(SS.getScopeRep(), SS.getRange(),
3298 *SpecTL.getTypePtr()->getIdentifier(),
3299 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003300 if (Template.isNull())
3301 return TypeLoc();
3302
Douglas Gregor14454802011-02-25 02:25:35 +00003303 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003304 SpecTL,
3305 Template);
Douglas Gregor14454802011-02-25 02:25:35 +00003306 } else {
3307 // Nothing special needs to be done for these.
3308 Result = getDerived().TransformType(TLB, TL);
3309 }
3310
3311 if (Result.isNull())
3312 return TypeLoc();
3313
3314 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3315}
3316
John McCall550e0c22009-10-21 00:40:46 +00003317template <class TyLoc> static inline
3318QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3319 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3320 NewT.setNameLoc(T.getNameLoc());
3321 return T.getType();
3322}
3323
John McCall550e0c22009-10-21 00:40:46 +00003324template<typename Derived>
3325QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003326 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003327 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3328 NewT.setBuiltinLoc(T.getBuiltinLoc());
3329 if (T.needsExtraLocalData())
3330 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3331 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003332}
Mike Stump11289f42009-09-09 15:08:12 +00003333
Douglas Gregord6ff3322009-08-04 16:50:30 +00003334template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003335QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003336 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003337 // FIXME: recurse?
3338 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003339}
Mike Stump11289f42009-09-09 15:08:12 +00003340
Douglas Gregord6ff3322009-08-04 16:50:30 +00003341template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003342QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003343 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003344 QualType PointeeType
3345 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003346 if (PointeeType.isNull())
3347 return QualType();
3348
3349 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003350 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003351 // A dependent pointer type 'T *' has is being transformed such
3352 // that an Objective-C class type is being replaced for 'T'. The
3353 // resulting pointer type is an ObjCObjectPointerType, not a
3354 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003355 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003356
John McCall8b07ec22010-05-15 11:32:37 +00003357 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3358 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003359 return Result;
3360 }
John McCall31f82722010-11-12 08:19:04 +00003361
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003362 if (getDerived().AlwaysRebuild() ||
3363 PointeeType != TL.getPointeeLoc().getType()) {
3364 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3365 if (Result.isNull())
3366 return QualType();
3367 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003368
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003369 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3370 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003371 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003372}
Mike Stump11289f42009-09-09 15:08:12 +00003373
3374template<typename Derived>
3375QualType
John McCall550e0c22009-10-21 00:40:46 +00003376TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003377 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003378 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003379 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3380 if (PointeeType.isNull())
3381 return QualType();
3382
3383 QualType Result = TL.getType();
3384 if (getDerived().AlwaysRebuild() ||
3385 PointeeType != TL.getPointeeLoc().getType()) {
3386 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003387 TL.getSigilLoc());
3388 if (Result.isNull())
3389 return QualType();
3390 }
3391
Douglas Gregor049211a2010-04-22 16:50:51 +00003392 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003393 NewT.setSigilLoc(TL.getSigilLoc());
3394 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003395}
3396
John McCall70dd5f62009-10-30 00:06:24 +00003397/// Transforms a reference type. Note that somewhat paradoxically we
3398/// don't care whether the type itself is an l-value type or an r-value
3399/// type; we only care if the type was *written* as an l-value type
3400/// or an r-value type.
3401template<typename Derived>
3402QualType
3403TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003404 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003405 const ReferenceType *T = TL.getTypePtr();
3406
3407 // Note that this works with the pointee-as-written.
3408 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3409 if (PointeeType.isNull())
3410 return QualType();
3411
3412 QualType Result = TL.getType();
3413 if (getDerived().AlwaysRebuild() ||
3414 PointeeType != T->getPointeeTypeAsWritten()) {
3415 Result = getDerived().RebuildReferenceType(PointeeType,
3416 T->isSpelledAsLValue(),
3417 TL.getSigilLoc());
3418 if (Result.isNull())
3419 return QualType();
3420 }
3421
3422 // r-value references can be rebuilt as l-value references.
3423 ReferenceTypeLoc NewTL;
3424 if (isa<LValueReferenceType>(Result))
3425 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3426 else
3427 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3428 NewTL.setSigilLoc(TL.getSigilLoc());
3429
3430 return Result;
3431}
3432
Mike Stump11289f42009-09-09 15:08:12 +00003433template<typename Derived>
3434QualType
John McCall550e0c22009-10-21 00:40:46 +00003435TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003436 LValueReferenceTypeLoc TL) {
3437 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003438}
3439
Mike Stump11289f42009-09-09 15:08:12 +00003440template<typename Derived>
3441QualType
John McCall550e0c22009-10-21 00:40:46 +00003442TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003443 RValueReferenceTypeLoc TL) {
3444 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003445}
Mike Stump11289f42009-09-09 15:08:12 +00003446
Douglas Gregord6ff3322009-08-04 16:50:30 +00003447template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003448QualType
John McCall550e0c22009-10-21 00:40:46 +00003449TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003450 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003451 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003452
3453 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003454 if (PointeeType.isNull())
3455 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003456
John McCall550e0c22009-10-21 00:40:46 +00003457 // TODO: preserve source information for this.
3458 QualType ClassType
3459 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003460 if (ClassType.isNull())
3461 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003462
John McCall550e0c22009-10-21 00:40:46 +00003463 QualType Result = TL.getType();
3464 if (getDerived().AlwaysRebuild() ||
3465 PointeeType != T->getPointeeType() ||
3466 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003467 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3468 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003469 if (Result.isNull())
3470 return QualType();
3471 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003472
John McCall550e0c22009-10-21 00:40:46 +00003473 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3474 NewTL.setSigilLoc(TL.getSigilLoc());
3475
3476 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003477}
3478
Mike Stump11289f42009-09-09 15:08:12 +00003479template<typename Derived>
3480QualType
John McCall550e0c22009-10-21 00:40:46 +00003481TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003482 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003483 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003484 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003485 if (ElementType.isNull())
3486 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003487
John McCall550e0c22009-10-21 00:40:46 +00003488 QualType Result = TL.getType();
3489 if (getDerived().AlwaysRebuild() ||
3490 ElementType != T->getElementType()) {
3491 Result = getDerived().RebuildConstantArrayType(ElementType,
3492 T->getSizeModifier(),
3493 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003494 T->getIndexTypeCVRQualifiers(),
3495 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003496 if (Result.isNull())
3497 return QualType();
3498 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003499
John McCall550e0c22009-10-21 00:40:46 +00003500 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3501 NewTL.setLBracketLoc(TL.getLBracketLoc());
3502 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003503
John McCall550e0c22009-10-21 00:40:46 +00003504 Expr *Size = TL.getSizeExpr();
3505 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003506 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003507 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3508 }
3509 NewTL.setSizeExpr(Size);
3510
3511 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003512}
Mike Stump11289f42009-09-09 15:08:12 +00003513
Douglas Gregord6ff3322009-08-04 16:50:30 +00003514template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003515QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003516 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003517 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003518 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003519 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003520 if (ElementType.isNull())
3521 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003522
John McCall550e0c22009-10-21 00:40:46 +00003523 QualType Result = TL.getType();
3524 if (getDerived().AlwaysRebuild() ||
3525 ElementType != T->getElementType()) {
3526 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003527 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003528 T->getIndexTypeCVRQualifiers(),
3529 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003530 if (Result.isNull())
3531 return QualType();
3532 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003533
John McCall550e0c22009-10-21 00:40:46 +00003534 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3535 NewTL.setLBracketLoc(TL.getLBracketLoc());
3536 NewTL.setRBracketLoc(TL.getRBracketLoc());
3537 NewTL.setSizeExpr(0);
3538
3539 return Result;
3540}
3541
3542template<typename Derived>
3543QualType
3544TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003545 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003546 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003547 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3548 if (ElementType.isNull())
3549 return QualType();
3550
3551 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003552 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003553
John McCalldadc5752010-08-24 06:29:42 +00003554 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003555 = getDerived().TransformExpr(T->getSizeExpr());
3556 if (SizeResult.isInvalid())
3557 return QualType();
3558
John McCallb268a282010-08-23 23:25:46 +00003559 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003560
3561 QualType Result = TL.getType();
3562 if (getDerived().AlwaysRebuild() ||
3563 ElementType != T->getElementType() ||
3564 Size != T->getSizeExpr()) {
3565 Result = getDerived().RebuildVariableArrayType(ElementType,
3566 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003567 Size,
John McCall550e0c22009-10-21 00:40:46 +00003568 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003569 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003570 if (Result.isNull())
3571 return QualType();
3572 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003573
John McCall550e0c22009-10-21 00:40:46 +00003574 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3575 NewTL.setLBracketLoc(TL.getLBracketLoc());
3576 NewTL.setRBracketLoc(TL.getRBracketLoc());
3577 NewTL.setSizeExpr(Size);
3578
3579 return Result;
3580}
3581
3582template<typename Derived>
3583QualType
3584TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003585 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003586 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003587 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3588 if (ElementType.isNull())
3589 return QualType();
3590
3591 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003592 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003593
John McCall33ddac02011-01-19 10:06:00 +00003594 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3595 Expr *origSize = TL.getSizeExpr();
3596 if (!origSize) origSize = T->getSizeExpr();
3597
3598 ExprResult sizeResult
3599 = getDerived().TransformExpr(origSize);
3600 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003601 return QualType();
3602
John McCall33ddac02011-01-19 10:06:00 +00003603 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003604
3605 QualType Result = TL.getType();
3606 if (getDerived().AlwaysRebuild() ||
3607 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003608 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003609 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3610 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003611 size,
John McCall550e0c22009-10-21 00:40:46 +00003612 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003613 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003614 if (Result.isNull())
3615 return QualType();
3616 }
John McCall550e0c22009-10-21 00:40:46 +00003617
3618 // We might have any sort of array type now, but fortunately they
3619 // all have the same location layout.
3620 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3621 NewTL.setLBracketLoc(TL.getLBracketLoc());
3622 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003623 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003624
3625 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003626}
Mike Stump11289f42009-09-09 15:08:12 +00003627
3628template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003629QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003630 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003631 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003632 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003633
3634 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003635 QualType ElementType = getDerived().TransformType(T->getElementType());
3636 if (ElementType.isNull())
3637 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003638
Douglas Gregore922c772009-08-04 22:27:00 +00003639 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003640 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003641
John McCalldadc5752010-08-24 06:29:42 +00003642 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003643 if (Size.isInvalid())
3644 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003645
John McCall550e0c22009-10-21 00:40:46 +00003646 QualType Result = TL.getType();
3647 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003648 ElementType != T->getElementType() ||
3649 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003650 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003651 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003652 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003653 if (Result.isNull())
3654 return QualType();
3655 }
John McCall550e0c22009-10-21 00:40:46 +00003656
3657 // Result might be dependent or not.
3658 if (isa<DependentSizedExtVectorType>(Result)) {
3659 DependentSizedExtVectorTypeLoc NewTL
3660 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3661 NewTL.setNameLoc(TL.getNameLoc());
3662 } else {
3663 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3664 NewTL.setNameLoc(TL.getNameLoc());
3665 }
3666
3667 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003668}
Mike Stump11289f42009-09-09 15:08:12 +00003669
3670template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003671QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003672 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003673 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003674 QualType ElementType = getDerived().TransformType(T->getElementType());
3675 if (ElementType.isNull())
3676 return QualType();
3677
John McCall550e0c22009-10-21 00:40:46 +00003678 QualType Result = TL.getType();
3679 if (getDerived().AlwaysRebuild() ||
3680 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003681 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003682 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003683 if (Result.isNull())
3684 return QualType();
3685 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003686
John McCall550e0c22009-10-21 00:40:46 +00003687 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3688 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003689
John McCall550e0c22009-10-21 00:40:46 +00003690 return Result;
3691}
3692
3693template<typename Derived>
3694QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003695 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003696 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003697 QualType ElementType = getDerived().TransformType(T->getElementType());
3698 if (ElementType.isNull())
3699 return QualType();
3700
3701 QualType Result = TL.getType();
3702 if (getDerived().AlwaysRebuild() ||
3703 ElementType != T->getElementType()) {
3704 Result = getDerived().RebuildExtVectorType(ElementType,
3705 T->getNumElements(),
3706 /*FIXME*/ SourceLocation());
3707 if (Result.isNull())
3708 return QualType();
3709 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003710
John McCall550e0c22009-10-21 00:40:46 +00003711 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3712 NewTL.setNameLoc(TL.getNameLoc());
3713
3714 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003715}
Mike Stump11289f42009-09-09 15:08:12 +00003716
3717template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003718ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003719TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3720 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003721 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003722 TypeSourceInfo *NewDI = 0;
3723
3724 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3725 // If we're substituting into a pack expansion type and we know the
3726 TypeLoc OldTL = OldDI->getTypeLoc();
3727 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3728
3729 TypeLocBuilder TLB;
3730 TypeLoc NewTL = OldDI->getTypeLoc();
3731 TLB.reserve(NewTL.getFullDataSize());
3732
3733 QualType Result = getDerived().TransformType(TLB,
3734 OldExpansionTL.getPatternLoc());
3735 if (Result.isNull())
3736 return 0;
3737
3738 Result = RebuildPackExpansionType(Result,
3739 OldExpansionTL.getPatternLoc().getSourceRange(),
3740 OldExpansionTL.getEllipsisLoc(),
3741 NumExpansions);
3742 if (Result.isNull())
3743 return 0;
3744
3745 PackExpansionTypeLoc NewExpansionTL
3746 = TLB.push<PackExpansionTypeLoc>(Result);
3747 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3748 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3749 } else
3750 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003751 if (!NewDI)
3752 return 0;
3753
3754 if (NewDI == OldDI)
3755 return OldParm;
3756 else
3757 return ParmVarDecl::Create(SemaRef.Context,
3758 OldParm->getDeclContext(),
3759 OldParm->getLocation(),
3760 OldParm->getIdentifier(),
3761 NewDI->getType(),
3762 NewDI,
3763 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003764 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003765 /* DefArg */ NULL);
3766}
3767
3768template<typename Derived>
3769bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003770 TransformFunctionTypeParams(SourceLocation Loc,
3771 ParmVarDecl **Params, unsigned NumParams,
3772 const QualType *ParamTypes,
3773 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3774 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3775 for (unsigned i = 0; i != NumParams; ++i) {
3776 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003777 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003778 if (OldParm->isParameterPack()) {
3779 // We have a function parameter pack that may need to be expanded.
3780 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003781
Douglas Gregor5499af42011-01-05 23:12:31 +00003782 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003783 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3784 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3785 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3786 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003787
3788 // Determine whether we should expand the parameter packs.
3789 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003790 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003791 llvm::Optional<unsigned> OrigNumExpansions
3792 = ExpansionTL.getTypePtr()->getNumExpansions();
3793 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003794 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3795 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003796 Unexpanded.data(),
3797 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003798 ShouldExpand,
3799 RetainExpansion,
3800 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003801 return true;
3802 }
3803
3804 if (ShouldExpand) {
3805 // Expand the function parameter pack into multiple, separate
3806 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003807 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003808 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003809 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3810 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003811 = getDerived().TransformFunctionTypeParam(OldParm,
3812 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003813 if (!NewParm)
3814 return true;
3815
Douglas Gregordd472162011-01-07 00:20:55 +00003816 OutParamTypes.push_back(NewParm->getType());
3817 if (PVars)
3818 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003819 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003820
3821 // If we're supposed to retain a pack expansion, do so by temporarily
3822 // forgetting the partially-substituted parameter pack.
3823 if (RetainExpansion) {
3824 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3825 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003826 = getDerived().TransformFunctionTypeParam(OldParm,
3827 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003828 if (!NewParm)
3829 return true;
3830
3831 OutParamTypes.push_back(NewParm->getType());
3832 if (PVars)
3833 PVars->push_back(NewParm);
3834 }
3835
Douglas Gregor5499af42011-01-05 23:12:31 +00003836 // We're done with the pack expansion.
3837 continue;
3838 }
3839
3840 // We'll substitute the parameter now without expanding the pack
3841 // expansion.
3842 }
3843
3844 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003845 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3846 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003847 if (!NewParm)
3848 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003849
Douglas Gregordd472162011-01-07 00:20:55 +00003850 OutParamTypes.push_back(NewParm->getType());
3851 if (PVars)
3852 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003853 continue;
3854 }
John McCall58f10c32010-03-11 09:03:00 +00003855
3856 // Deal with the possibility that we don't have a parameter
3857 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003858 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003859 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003860 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003861 if (const PackExpansionType *Expansion
3862 = dyn_cast<PackExpansionType>(OldType)) {
3863 // We have a function parameter pack that may need to be expanded.
3864 QualType Pattern = Expansion->getPattern();
3865 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3866 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3867
3868 // Determine whether we should expand the parameter packs.
3869 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003870 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003871 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003872 Unexpanded.data(),
3873 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003874 ShouldExpand,
3875 RetainExpansion,
3876 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003877 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003878 }
3879
3880 if (ShouldExpand) {
3881 // Expand the function parameter pack into multiple, separate
3882 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003883 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003884 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3885 QualType NewType = getDerived().TransformType(Pattern);
3886 if (NewType.isNull())
3887 return true;
John McCall58f10c32010-03-11 09:03:00 +00003888
Douglas Gregordd472162011-01-07 00:20:55 +00003889 OutParamTypes.push_back(NewType);
3890 if (PVars)
3891 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003892 }
3893
3894 // We're done with the pack expansion.
3895 continue;
3896 }
3897
Douglas Gregor48d24112011-01-10 20:53:55 +00003898 // If we're supposed to retain a pack expansion, do so by temporarily
3899 // forgetting the partially-substituted parameter pack.
3900 if (RetainExpansion) {
3901 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3902 QualType NewType = getDerived().TransformType(Pattern);
3903 if (NewType.isNull())
3904 return true;
3905
3906 OutParamTypes.push_back(NewType);
3907 if (PVars)
3908 PVars->push_back(0);
3909 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003910
Douglas Gregor5499af42011-01-05 23:12:31 +00003911 // We'll substitute the parameter now without expanding the pack
3912 // expansion.
3913 OldType = Expansion->getPattern();
3914 IsPackExpansion = true;
3915 }
3916
3917 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3918 QualType NewType = getDerived().TransformType(OldType);
3919 if (NewType.isNull())
3920 return true;
3921
3922 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003923 NewType = getSema().Context.getPackExpansionType(NewType,
3924 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003925
Douglas Gregordd472162011-01-07 00:20:55 +00003926 OutParamTypes.push_back(NewType);
3927 if (PVars)
3928 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003929 }
3930
3931 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003932 }
John McCall58f10c32010-03-11 09:03:00 +00003933
3934template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003935QualType
John McCall550e0c22009-10-21 00:40:46 +00003936TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003937 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003938 // Transform the parameters and return type.
3939 //
3940 // We instantiate in source order, with the return type first followed by
3941 // the parameters, because users tend to expect this (even if they shouldn't
3942 // rely on it!).
3943 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003944 // When the function has a trailing return type, we instantiate the
3945 // parameters before the return type, since the return type can then refer
3946 // to the parameters themselves (via decltype, sizeof, etc.).
3947 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003948 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003949 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003950 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003951
Douglas Gregor7fb25412010-10-01 18:44:50 +00003952 QualType ResultType;
3953
3954 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003955 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3956 TL.getParmArray(),
3957 TL.getNumArgs(),
3958 TL.getTypePtr()->arg_type_begin(),
3959 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003960 return QualType();
3961
3962 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3963 if (ResultType.isNull())
3964 return QualType();
3965 }
3966 else {
3967 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3968 if (ResultType.isNull())
3969 return QualType();
3970
Douglas Gregordd472162011-01-07 00:20:55 +00003971 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3972 TL.getParmArray(),
3973 TL.getNumArgs(),
3974 TL.getTypePtr()->arg_type_begin(),
3975 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003976 return QualType();
3977 }
3978
John McCall550e0c22009-10-21 00:40:46 +00003979 QualType Result = TL.getType();
3980 if (getDerived().AlwaysRebuild() ||
3981 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003982 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003983 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3984 Result = getDerived().RebuildFunctionProtoType(ResultType,
3985 ParamTypes.data(),
3986 ParamTypes.size(),
3987 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003988 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003989 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003990 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003991 if (Result.isNull())
3992 return QualType();
3993 }
Mike Stump11289f42009-09-09 15:08:12 +00003994
John McCall550e0c22009-10-21 00:40:46 +00003995 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3996 NewTL.setLParenLoc(TL.getLParenLoc());
3997 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003998 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003999 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4000 NewTL.setArg(i, ParamDecls[i]);
4001
4002 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004003}
Mike Stump11289f42009-09-09 15:08:12 +00004004
Douglas Gregord6ff3322009-08-04 16:50:30 +00004005template<typename Derived>
4006QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004007 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004008 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004009 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004010 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4011 if (ResultType.isNull())
4012 return QualType();
4013
4014 QualType Result = TL.getType();
4015 if (getDerived().AlwaysRebuild() ||
4016 ResultType != T->getResultType())
4017 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4018
4019 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4020 NewTL.setLParenLoc(TL.getLParenLoc());
4021 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004022 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004023
4024 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004025}
Mike Stump11289f42009-09-09 15:08:12 +00004026
John McCallb96ec562009-12-04 22:46:56 +00004027template<typename Derived> QualType
4028TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004029 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004030 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004031 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004032 if (!D)
4033 return QualType();
4034
4035 QualType Result = TL.getType();
4036 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4037 Result = getDerived().RebuildUnresolvedUsingType(D);
4038 if (Result.isNull())
4039 return QualType();
4040 }
4041
4042 // We might get an arbitrary type spec type back. We should at
4043 // least always get a type spec type, though.
4044 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4045 NewTL.setNameLoc(TL.getNameLoc());
4046
4047 return Result;
4048}
4049
Douglas Gregord6ff3322009-08-04 16:50:30 +00004050template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004051QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004052 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004053 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004054 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004055 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4056 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004057 if (!Typedef)
4058 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004059
John McCall550e0c22009-10-21 00:40:46 +00004060 QualType Result = TL.getType();
4061 if (getDerived().AlwaysRebuild() ||
4062 Typedef != T->getDecl()) {
4063 Result = getDerived().RebuildTypedefType(Typedef);
4064 if (Result.isNull())
4065 return QualType();
4066 }
Mike Stump11289f42009-09-09 15:08:12 +00004067
John McCall550e0c22009-10-21 00:40:46 +00004068 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4069 NewTL.setNameLoc(TL.getNameLoc());
4070
4071 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004072}
Mike Stump11289f42009-09-09 15:08:12 +00004073
Douglas Gregord6ff3322009-08-04 16:50:30 +00004074template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004075QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004076 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004077 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004078 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004079
John McCalldadc5752010-08-24 06:29:42 +00004080 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004081 if (E.isInvalid())
4082 return QualType();
4083
John McCall550e0c22009-10-21 00:40:46 +00004084 QualType Result = TL.getType();
4085 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004086 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004087 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004088 if (Result.isNull())
4089 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004090 }
John McCall550e0c22009-10-21 00:40:46 +00004091 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004092
John McCall550e0c22009-10-21 00:40:46 +00004093 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004094 NewTL.setTypeofLoc(TL.getTypeofLoc());
4095 NewTL.setLParenLoc(TL.getLParenLoc());
4096 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004097
4098 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004099}
Mike Stump11289f42009-09-09 15:08:12 +00004100
4101template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004102QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004103 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004104 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4105 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4106 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004107 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004108
John McCall550e0c22009-10-21 00:40:46 +00004109 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004110 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4111 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004112 if (Result.isNull())
4113 return QualType();
4114 }
Mike Stump11289f42009-09-09 15:08:12 +00004115
John McCall550e0c22009-10-21 00:40:46 +00004116 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004117 NewTL.setTypeofLoc(TL.getTypeofLoc());
4118 NewTL.setLParenLoc(TL.getLParenLoc());
4119 NewTL.setRParenLoc(TL.getRParenLoc());
4120 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004121
4122 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004123}
Mike Stump11289f42009-09-09 15:08:12 +00004124
4125template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004126QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004127 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004128 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004129
Douglas Gregore922c772009-08-04 22:27:00 +00004130 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004131 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004132
John McCalldadc5752010-08-24 06:29:42 +00004133 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004134 if (E.isInvalid())
4135 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004136
John McCall550e0c22009-10-21 00:40:46 +00004137 QualType Result = TL.getType();
4138 if (getDerived().AlwaysRebuild() ||
4139 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004140 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004141 if (Result.isNull())
4142 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004143 }
John McCall550e0c22009-10-21 00:40:46 +00004144 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004145
John McCall550e0c22009-10-21 00:40:46 +00004146 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4147 NewTL.setNameLoc(TL.getNameLoc());
4148
4149 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004150}
4151
4152template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004153QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4154 AutoTypeLoc TL) {
4155 const AutoType *T = TL.getTypePtr();
4156 QualType OldDeduced = T->getDeducedType();
4157 QualType NewDeduced;
4158 if (!OldDeduced.isNull()) {
4159 NewDeduced = getDerived().TransformType(OldDeduced);
4160 if (NewDeduced.isNull())
4161 return QualType();
4162 }
4163
4164 QualType Result = TL.getType();
4165 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4166 Result = getDerived().RebuildAutoType(NewDeduced);
4167 if (Result.isNull())
4168 return QualType();
4169 }
4170
4171 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4172 NewTL.setNameLoc(TL.getNameLoc());
4173
4174 return Result;
4175}
4176
4177template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004178QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004179 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004180 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004181 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004182 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4183 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004184 if (!Record)
4185 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004186
John McCall550e0c22009-10-21 00:40:46 +00004187 QualType Result = TL.getType();
4188 if (getDerived().AlwaysRebuild() ||
4189 Record != T->getDecl()) {
4190 Result = getDerived().RebuildRecordType(Record);
4191 if (Result.isNull())
4192 return QualType();
4193 }
Mike Stump11289f42009-09-09 15:08:12 +00004194
John McCall550e0c22009-10-21 00:40:46 +00004195 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4196 NewTL.setNameLoc(TL.getNameLoc());
4197
4198 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004199}
Mike Stump11289f42009-09-09 15:08:12 +00004200
4201template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004202QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004203 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004204 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004205 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004206 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4207 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004208 if (!Enum)
4209 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004210
John McCall550e0c22009-10-21 00:40:46 +00004211 QualType Result = TL.getType();
4212 if (getDerived().AlwaysRebuild() ||
4213 Enum != T->getDecl()) {
4214 Result = getDerived().RebuildEnumType(Enum);
4215 if (Result.isNull())
4216 return QualType();
4217 }
Mike Stump11289f42009-09-09 15:08:12 +00004218
John McCall550e0c22009-10-21 00:40:46 +00004219 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4220 NewTL.setNameLoc(TL.getNameLoc());
4221
4222 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004223}
John McCallfcc33b02009-09-05 00:15:47 +00004224
John McCalle78aac42010-03-10 03:28:59 +00004225template<typename Derived>
4226QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4227 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004228 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004229 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4230 TL.getTypePtr()->getDecl());
4231 if (!D) return QualType();
4232
4233 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4234 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4235 return T;
4236}
4237
Douglas Gregord6ff3322009-08-04 16:50:30 +00004238template<typename Derived>
4239QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004240 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004241 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004242 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004243}
4244
Mike Stump11289f42009-09-09 15:08:12 +00004245template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004246QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004247 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004248 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004249 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004250}
4251
4252template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004253QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4254 TypeLocBuilder &TLB,
4255 SubstTemplateTypeParmPackTypeLoc TL) {
4256 return TransformTypeSpecType(TLB, TL);
4257}
4258
4259template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004260QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004261 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004262 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004263 const TemplateSpecializationType *T = TL.getTypePtr();
4264
Mike Stump11289f42009-09-09 15:08:12 +00004265 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004266 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004267 if (Template.isNull())
4268 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004269
John McCall31f82722010-11-12 08:19:04 +00004270 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4271}
4272
Douglas Gregorfe921a72010-12-20 23:36:19 +00004273namespace {
4274 /// \brief Simple iterator that traverses the template arguments in a
4275 /// container that provides a \c getArgLoc() member function.
4276 ///
4277 /// This iterator is intended to be used with the iterator form of
4278 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4279 template<typename ArgLocContainer>
4280 class TemplateArgumentLocContainerIterator {
4281 ArgLocContainer *Container;
4282 unsigned Index;
4283
4284 public:
4285 typedef TemplateArgumentLoc value_type;
4286 typedef TemplateArgumentLoc reference;
4287 typedef int difference_type;
4288 typedef std::input_iterator_tag iterator_category;
4289
4290 class pointer {
4291 TemplateArgumentLoc Arg;
4292
4293 public:
4294 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4295
4296 const TemplateArgumentLoc *operator->() const {
4297 return &Arg;
4298 }
4299 };
4300
4301
4302 TemplateArgumentLocContainerIterator() {}
4303
4304 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4305 unsigned Index)
4306 : Container(&Container), Index(Index) { }
4307
4308 TemplateArgumentLocContainerIterator &operator++() {
4309 ++Index;
4310 return *this;
4311 }
4312
4313 TemplateArgumentLocContainerIterator operator++(int) {
4314 TemplateArgumentLocContainerIterator Old(*this);
4315 ++(*this);
4316 return Old;
4317 }
4318
4319 TemplateArgumentLoc operator*() const {
4320 return Container->getArgLoc(Index);
4321 }
4322
4323 pointer operator->() const {
4324 return pointer(Container->getArgLoc(Index));
4325 }
4326
4327 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004328 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004329 return X.Container == Y.Container && X.Index == Y.Index;
4330 }
4331
4332 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004333 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004334 return !(X == Y);
4335 }
4336 };
4337}
4338
4339
John McCall31f82722010-11-12 08:19:04 +00004340template <typename Derived>
4341QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4342 TypeLocBuilder &TLB,
4343 TemplateSpecializationTypeLoc TL,
4344 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004345 TemplateArgumentListInfo NewTemplateArgs;
4346 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4347 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004348 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4349 ArgIterator;
4350 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4351 ArgIterator(TL, TL.getNumArgs()),
4352 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004353 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004354
John McCall0ad16662009-10-29 08:12:44 +00004355 // FIXME: maybe don't rebuild if all the template arguments are the same.
4356
4357 QualType Result =
4358 getDerived().RebuildTemplateSpecializationType(Template,
4359 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004360 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004361
4362 if (!Result.isNull()) {
4363 TemplateSpecializationTypeLoc NewTL
4364 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4365 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4366 NewTL.setLAngleLoc(TL.getLAngleLoc());
4367 NewTL.setRAngleLoc(TL.getRAngleLoc());
4368 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4369 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004370 }
Mike Stump11289f42009-09-09 15:08:12 +00004371
John McCall0ad16662009-10-29 08:12:44 +00004372 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004373}
Mike Stump11289f42009-09-09 15:08:12 +00004374
Douglas Gregor5a064722011-02-28 17:23:35 +00004375template <typename Derived>
4376QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4377 TypeLocBuilder &TLB,
4378 DependentTemplateSpecializationTypeLoc TL,
4379 TemplateName Template) {
4380 TemplateArgumentListInfo NewTemplateArgs;
4381 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4382 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4383 typedef TemplateArgumentLocContainerIterator<
4384 DependentTemplateSpecializationTypeLoc> ArgIterator;
4385 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4386 ArgIterator(TL, TL.getNumArgs()),
4387 NewTemplateArgs))
4388 return QualType();
4389
4390 // FIXME: maybe don't rebuild if all the template arguments are the same.
4391
4392 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4393 QualType Result
4394 = getSema().Context.getDependentTemplateSpecializationType(
4395 TL.getTypePtr()->getKeyword(),
4396 DTN->getQualifier(),
4397 DTN->getIdentifier(),
4398 NewTemplateArgs);
4399
4400 DependentTemplateSpecializationTypeLoc NewTL
4401 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4402 NewTL.setKeywordLoc(TL.getKeywordLoc());
4403 NewTL.setQualifierRange(TL.getQualifierRange());
4404 NewTL.setNameLoc(TL.getNameLoc());
4405 NewTL.setLAngleLoc(TL.getLAngleLoc());
4406 NewTL.setRAngleLoc(TL.getRAngleLoc());
4407 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4408 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4409 return Result;
4410 }
4411
4412 QualType Result
4413 = getDerived().RebuildTemplateSpecializationType(Template,
4414 TL.getNameLoc(),
4415 NewTemplateArgs);
4416
4417 if (!Result.isNull()) {
4418 /// FIXME: Wrap this in an elaborated-type-specifier?
4419 TemplateSpecializationTypeLoc NewTL
4420 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4421 NewTL.setTemplateNameLoc(TL.getNameLoc());
4422 NewTL.setLAngleLoc(TL.getLAngleLoc());
4423 NewTL.setRAngleLoc(TL.getRAngleLoc());
4424 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4425 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4426 }
4427
4428 return Result;
4429}
4430
Mike Stump11289f42009-09-09 15:08:12 +00004431template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004432QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004433TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004434 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004435 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004436
4437 NestedNameSpecifier *NNS = 0;
4438 // NOTE: the qualifier in an ElaboratedType is optional.
4439 if (T->getQualifier() != 0) {
4440 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004441 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004442 if (!NNS)
4443 return QualType();
4444 }
Mike Stump11289f42009-09-09 15:08:12 +00004445
John McCall31f82722010-11-12 08:19:04 +00004446 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4447 if (NamedT.isNull())
4448 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004449
John McCall550e0c22009-10-21 00:40:46 +00004450 QualType Result = TL.getType();
4451 if (getDerived().AlwaysRebuild() ||
4452 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004453 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004454 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4455 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004456 if (Result.isNull())
4457 return QualType();
4458 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004459
Abramo Bagnara6150c882010-05-11 21:36:43 +00004460 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004461 NewTL.setKeywordLoc(TL.getKeywordLoc());
4462 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004463
4464 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004465}
Mike Stump11289f42009-09-09 15:08:12 +00004466
4467template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004468QualType TreeTransform<Derived>::TransformAttributedType(
4469 TypeLocBuilder &TLB,
4470 AttributedTypeLoc TL) {
4471 const AttributedType *oldType = TL.getTypePtr();
4472 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4473 if (modifiedType.isNull())
4474 return QualType();
4475
4476 QualType result = TL.getType();
4477
4478 // FIXME: dependent operand expressions?
4479 if (getDerived().AlwaysRebuild() ||
4480 modifiedType != oldType->getModifiedType()) {
4481 // TODO: this is really lame; we should really be rebuilding the
4482 // equivalent type from first principles.
4483 QualType equivalentType
4484 = getDerived().TransformType(oldType->getEquivalentType());
4485 if (equivalentType.isNull())
4486 return QualType();
4487 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4488 modifiedType,
4489 equivalentType);
4490 }
4491
4492 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4493 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4494 if (TL.hasAttrOperand())
4495 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4496 if (TL.hasAttrExprOperand())
4497 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4498 else if (TL.hasAttrEnumOperand())
4499 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4500
4501 return result;
4502}
4503
4504template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004505QualType
4506TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4507 ParenTypeLoc TL) {
4508 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4509 if (Inner.isNull())
4510 return QualType();
4511
4512 QualType Result = TL.getType();
4513 if (getDerived().AlwaysRebuild() ||
4514 Inner != TL.getInnerLoc().getType()) {
4515 Result = getDerived().RebuildParenType(Inner);
4516 if (Result.isNull())
4517 return QualType();
4518 }
4519
4520 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4521 NewTL.setLParenLoc(TL.getLParenLoc());
4522 NewTL.setRParenLoc(TL.getRParenLoc());
4523 return Result;
4524}
4525
4526template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004527QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004528 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004529 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004530
Douglas Gregord6ff3322009-08-04 16:50:30 +00004531 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004532 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004533 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004534 if (!NNS)
4535 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004536
John McCallc392f372010-06-11 00:33:02 +00004537 QualType Result
4538 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4539 T->getIdentifier(),
4540 TL.getKeywordLoc(),
4541 TL.getQualifierRange(),
4542 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004543 if (Result.isNull())
4544 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004545
Abramo Bagnarad7548482010-05-19 21:37:53 +00004546 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4547 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004548 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4549
Abramo Bagnarad7548482010-05-19 21:37:53 +00004550 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4551 NewTL.setKeywordLoc(TL.getKeywordLoc());
4552 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004553 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004554 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4555 NewTL.setKeywordLoc(TL.getKeywordLoc());
4556 NewTL.setQualifierRange(TL.getQualifierRange());
4557 NewTL.setNameLoc(TL.getNameLoc());
4558 }
John McCall550e0c22009-10-21 00:40:46 +00004559 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004560}
Mike Stump11289f42009-09-09 15:08:12 +00004561
Douglas Gregord6ff3322009-08-04 16:50:30 +00004562template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004563QualType TreeTransform<Derived>::
4564 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004565 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004566 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004567
Douglas Gregor5a064722011-02-28 17:23:35 +00004568 NestedNameSpecifier *NNS = 0;
4569 if (T->getQualifier()) {
4570 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
4571 TL.getQualifierRange());
4572 if (!NNS)
4573 return QualType();
4574 }
4575
John McCall31f82722010-11-12 08:19:04 +00004576 return getDerived()
4577 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4578}
4579
4580template<typename Derived>
4581QualType TreeTransform<Derived>::
4582 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4583 DependentTemplateSpecializationTypeLoc TL,
4584 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004585 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004586
John McCallc392f372010-06-11 00:33:02 +00004587 TemplateArgumentListInfo NewTemplateArgs;
4588 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4589 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor14454802011-02-25 02:25:35 +00004590
4591 // FIXME: Nested-name-specifier source location info!
Douglas Gregorfe921a72010-12-20 23:36:19 +00004592 typedef TemplateArgumentLocContainerIterator<
4593 DependentTemplateSpecializationTypeLoc> ArgIterator;
4594 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4595 ArgIterator(TL, TL.getNumArgs()),
4596 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004597 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004598
Douglas Gregora5614c52010-09-08 23:56:00 +00004599 QualType Result
4600 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4601 NNS,
4602 TL.getQualifierRange(),
4603 T->getIdentifier(),
4604 TL.getNameLoc(),
4605 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004606 if (Result.isNull())
4607 return QualType();
4608
4609 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4610 QualType NamedT = ElabT->getNamedType();
4611
4612 // Copy information relevant to the template specialization.
4613 TemplateSpecializationTypeLoc NamedTL
4614 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4615 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4616 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4617 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4618 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4619
4620 // Copy information relevant to the elaborated type.
4621 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4622 NewTL.setKeywordLoc(TL.getKeywordLoc());
4623 NewTL.setQualifierRange(TL.getQualifierRange());
4624 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004625 TypeLoc NewTL(Result, TL.getOpaqueData());
4626 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004627 }
4628 return Result;
4629}
4630
4631template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004632QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4633 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004634 QualType Pattern
4635 = getDerived().TransformType(TLB, TL.getPatternLoc());
4636 if (Pattern.isNull())
4637 return QualType();
4638
4639 QualType Result = TL.getType();
4640 if (getDerived().AlwaysRebuild() ||
4641 Pattern != TL.getPatternLoc().getType()) {
4642 Result = getDerived().RebuildPackExpansionType(Pattern,
4643 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004644 TL.getEllipsisLoc(),
4645 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004646 if (Result.isNull())
4647 return QualType();
4648 }
4649
4650 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4651 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4652 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004653}
4654
4655template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004656QualType
4657TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004658 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004659 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004660 TLB.pushFullCopy(TL);
4661 return TL.getType();
4662}
4663
4664template<typename Derived>
4665QualType
4666TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004667 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004668 // ObjCObjectType is never dependent.
4669 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004670 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004671}
Mike Stump11289f42009-09-09 15:08:12 +00004672
4673template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004674QualType
4675TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004676 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004677 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004678 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004679 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004680}
4681
Douglas Gregord6ff3322009-08-04 16:50:30 +00004682//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004683// Statement transformation
4684//===----------------------------------------------------------------------===//
4685template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004686StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004687TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004688 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004689}
4690
4691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004692StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004693TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4694 return getDerived().TransformCompoundStmt(S, false);
4695}
4696
4697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004698StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004699TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004700 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004701 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004702 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004703 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004704 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4705 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004706 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004707 if (Result.isInvalid()) {
4708 // Immediately fail if this was a DeclStmt, since it's very
4709 // likely that this will cause problems for future statements.
4710 if (isa<DeclStmt>(*B))
4711 return StmtError();
4712
4713 // Otherwise, just keep processing substatements and fail later.
4714 SubStmtInvalid = true;
4715 continue;
4716 }
Mike Stump11289f42009-09-09 15:08:12 +00004717
Douglas Gregorebe10102009-08-20 07:17:43 +00004718 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4719 Statements.push_back(Result.takeAs<Stmt>());
4720 }
Mike Stump11289f42009-09-09 15:08:12 +00004721
John McCall1ababa62010-08-27 19:56:05 +00004722 if (SubStmtInvalid)
4723 return StmtError();
4724
Douglas Gregorebe10102009-08-20 07:17:43 +00004725 if (!getDerived().AlwaysRebuild() &&
4726 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004727 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004728
4729 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4730 move_arg(Statements),
4731 S->getRBracLoc(),
4732 IsStmtExpr);
4733}
Mike Stump11289f42009-09-09 15:08:12 +00004734
Douglas Gregorebe10102009-08-20 07:17:43 +00004735template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004736StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004737TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004738 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004739 {
4740 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004741 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004742
Eli Friedman06577382009-11-19 03:14:00 +00004743 // Transform the left-hand case value.
4744 LHS = getDerived().TransformExpr(S->getLHS());
4745 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004746 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004747
Eli Friedman06577382009-11-19 03:14:00 +00004748 // Transform the right-hand case value (for the GNU case-range extension).
4749 RHS = getDerived().TransformExpr(S->getRHS());
4750 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004751 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004752 }
Mike Stump11289f42009-09-09 15:08:12 +00004753
Douglas Gregorebe10102009-08-20 07:17:43 +00004754 // Build the case statement.
4755 // Case statements are always rebuilt so that they will attached to their
4756 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004757 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004758 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004759 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004760 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004761 S->getColonLoc());
4762 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004763 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004764
Douglas Gregorebe10102009-08-20 07:17:43 +00004765 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004766 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004767 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004768 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004769
Douglas Gregorebe10102009-08-20 07:17:43 +00004770 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004771 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004772}
4773
4774template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004775StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004776TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004777 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004778 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004779 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004780 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004781
Douglas Gregorebe10102009-08-20 07:17:43 +00004782 // Default statements are always rebuilt
4783 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004784 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004785}
Mike Stump11289f42009-09-09 15:08:12 +00004786
Douglas Gregorebe10102009-08-20 07:17:43 +00004787template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004788StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004789TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004790 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004791 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004792 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004793
Chris Lattnercab02a62011-02-17 20:34:02 +00004794 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4795 S->getDecl());
4796 if (!LD)
4797 return StmtError();
4798
4799
Douglas Gregorebe10102009-08-20 07:17:43 +00004800 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004801 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004802 cast<LabelDecl>(LD), SourceLocation(),
4803 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004804}
Mike Stump11289f42009-09-09 15:08:12 +00004805
Douglas Gregorebe10102009-08-20 07:17:43 +00004806template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004807StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004808TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004809 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004810 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004811 VarDecl *ConditionVar = 0;
4812 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004813 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004814 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004815 getDerived().TransformDefinition(
4816 S->getConditionVariable()->getLocation(),
4817 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004818 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004819 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004820 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004821 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004822
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004823 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004824 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004825
4826 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004827 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004828 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4829 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004830 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004831 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004832
John McCallb268a282010-08-23 23:25:46 +00004833 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004834 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004835 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004836
John McCallb268a282010-08-23 23:25:46 +00004837 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4838 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004839 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004840
Douglas Gregorebe10102009-08-20 07:17:43 +00004841 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004842 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004843 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004844 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004845
Douglas Gregorebe10102009-08-20 07:17:43 +00004846 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004847 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004848 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004849 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004850
Douglas Gregorebe10102009-08-20 07:17:43 +00004851 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004852 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004853 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004854 Then.get() == S->getThen() &&
4855 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004856 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004857
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004858 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004859 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004860 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004861}
4862
4863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004864StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004865TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004866 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004867 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004868 VarDecl *ConditionVar = 0;
4869 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004870 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004871 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004872 getDerived().TransformDefinition(
4873 S->getConditionVariable()->getLocation(),
4874 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004875 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004876 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004877 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004878 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004879
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004880 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004881 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004882 }
Mike Stump11289f42009-09-09 15:08:12 +00004883
Douglas Gregorebe10102009-08-20 07:17:43 +00004884 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004885 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004886 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004887 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004888 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004889 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004890
Douglas Gregorebe10102009-08-20 07:17:43 +00004891 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004892 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004893 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004894 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004895
Douglas Gregorebe10102009-08-20 07:17:43 +00004896 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004897 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4898 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004899}
Mike Stump11289f42009-09-09 15:08:12 +00004900
Douglas Gregorebe10102009-08-20 07:17:43 +00004901template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004902StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004903TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004904 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004905 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004906 VarDecl *ConditionVar = 0;
4907 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004908 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004909 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004910 getDerived().TransformDefinition(
4911 S->getConditionVariable()->getLocation(),
4912 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004913 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004914 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004915 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004916 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004917
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004918 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004919 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004920
4921 if (S->getCond()) {
4922 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004923 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4924 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004925 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004926 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004927 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004928 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004929 }
Mike Stump11289f42009-09-09 15:08:12 +00004930
John McCallb268a282010-08-23 23:25:46 +00004931 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4932 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004933 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004934
Douglas Gregorebe10102009-08-20 07:17:43 +00004935 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004936 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004937 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004938 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004939
Douglas Gregorebe10102009-08-20 07:17:43 +00004940 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004941 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004942 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004943 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004944 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004945
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004946 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004947 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004948}
Mike Stump11289f42009-09-09 15:08:12 +00004949
Douglas Gregorebe10102009-08-20 07:17:43 +00004950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004951StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004952TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004953 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004954 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004955 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004956 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004957
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004958 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004959 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004960 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004961 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004962
Douglas Gregorebe10102009-08-20 07:17:43 +00004963 if (!getDerived().AlwaysRebuild() &&
4964 Cond.get() == S->getCond() &&
4965 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004966 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004967
John McCallb268a282010-08-23 23:25:46 +00004968 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4969 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004970 S->getRParenLoc());
4971}
Mike Stump11289f42009-09-09 15:08:12 +00004972
Douglas Gregorebe10102009-08-20 07:17:43 +00004973template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004974StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004975TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004976 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004977 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004978 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004979 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004980
Douglas Gregorebe10102009-08-20 07:17:43 +00004981 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004982 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004983 VarDecl *ConditionVar = 0;
4984 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004985 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004986 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004987 getDerived().TransformDefinition(
4988 S->getConditionVariable()->getLocation(),
4989 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004990 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004991 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004992 } else {
4993 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004994
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004995 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004996 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004997
4998 if (S->getCond()) {
4999 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005000 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5001 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005002 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005003 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005004
John McCallb268a282010-08-23 23:25:46 +00005005 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005006 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005007 }
Mike Stump11289f42009-09-09 15:08:12 +00005008
John McCallb268a282010-08-23 23:25:46 +00005009 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5010 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005011 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005012
Douglas Gregorebe10102009-08-20 07:17:43 +00005013 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005014 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005015 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005016 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005017
John McCallb268a282010-08-23 23:25:46 +00005018 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5019 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005020 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005021
Douglas Gregorebe10102009-08-20 07:17:43 +00005022 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005023 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005024 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005025 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005026
Douglas Gregorebe10102009-08-20 07:17:43 +00005027 if (!getDerived().AlwaysRebuild() &&
5028 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005029 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005030 Inc.get() == S->getInc() &&
5031 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005032 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005033
Douglas Gregorebe10102009-08-20 07:17:43 +00005034 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005035 Init.get(), FullCond, ConditionVar,
5036 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005037}
5038
5039template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005040StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005041TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005042 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5043 S->getLabel());
5044 if (!LD)
5045 return StmtError();
5046
Douglas Gregorebe10102009-08-20 07:17:43 +00005047 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005048 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005049 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005050}
5051
5052template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005053StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005054TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005055 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005056 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005057 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005058
Douglas Gregorebe10102009-08-20 07:17:43 +00005059 if (!getDerived().AlwaysRebuild() &&
5060 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005061 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005062
5063 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005064 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005065}
5066
5067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005068StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005069TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005070 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005071}
Mike Stump11289f42009-09-09 15:08:12 +00005072
Douglas Gregorebe10102009-08-20 07:17:43 +00005073template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005074StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005075TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005076 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005077}
Mike Stump11289f42009-09-09 15:08:12 +00005078
Douglas Gregorebe10102009-08-20 07:17:43 +00005079template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005080StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005081TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005082 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005083 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005084 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005085
Mike Stump11289f42009-09-09 15:08:12 +00005086 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005087 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005088 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005089}
Mike Stump11289f42009-09-09 15:08:12 +00005090
Douglas Gregorebe10102009-08-20 07:17:43 +00005091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005092StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005093TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005094 bool DeclChanged = false;
5095 llvm::SmallVector<Decl *, 4> Decls;
5096 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5097 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005098 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5099 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005100 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005101 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005102
Douglas Gregorebe10102009-08-20 07:17:43 +00005103 if (Transformed != *D)
5104 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005105
Douglas Gregorebe10102009-08-20 07:17:43 +00005106 Decls.push_back(Transformed);
5107 }
Mike Stump11289f42009-09-09 15:08:12 +00005108
Douglas Gregorebe10102009-08-20 07:17:43 +00005109 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005110 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005111
5112 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005113 S->getStartLoc(), S->getEndLoc());
5114}
Mike Stump11289f42009-09-09 15:08:12 +00005115
Douglas Gregorebe10102009-08-20 07:17:43 +00005116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005117StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005118TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005119
John McCall37ad5512010-08-23 06:44:23 +00005120 ASTOwningVector<Expr*> Constraints(getSema());
5121 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005122 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005123
John McCalldadc5752010-08-24 06:29:42 +00005124 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005125 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005126
5127 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005128
Anders Carlssonaaeef072010-01-24 05:50:09 +00005129 // Go through the outputs.
5130 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005131 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005132
Anders Carlssonaaeef072010-01-24 05:50:09 +00005133 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005134 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005135
Anders Carlssonaaeef072010-01-24 05:50:09 +00005136 // Transform the output expr.
5137 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005138 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005139 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005140 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005141
Anders Carlssonaaeef072010-01-24 05:50:09 +00005142 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005143
John McCallb268a282010-08-23 23:25:46 +00005144 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005145 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005146
Anders Carlssonaaeef072010-01-24 05:50:09 +00005147 // Go through the inputs.
5148 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005149 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005150
Anders Carlssonaaeef072010-01-24 05:50:09 +00005151 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005152 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005153
Anders Carlssonaaeef072010-01-24 05:50:09 +00005154 // Transform the input expr.
5155 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005156 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005157 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005158 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005159
Anders Carlssonaaeef072010-01-24 05:50:09 +00005160 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005161
John McCallb268a282010-08-23 23:25:46 +00005162 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005163 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005164
Anders Carlssonaaeef072010-01-24 05:50:09 +00005165 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005166 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005167
5168 // Go through the clobbers.
5169 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005170 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005171
5172 // No need to transform the asm string literal.
5173 AsmString = SemaRef.Owned(S->getAsmString());
5174
5175 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5176 S->isSimple(),
5177 S->isVolatile(),
5178 S->getNumOutputs(),
5179 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005180 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005181 move_arg(Constraints),
5182 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005183 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005184 move_arg(Clobbers),
5185 S->getRParenLoc(),
5186 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005187}
5188
5189
5190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005191StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005192TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005193 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005194 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005195 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005196 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005197
Douglas Gregor96c79492010-04-23 22:50:49 +00005198 // Transform the @catch statements (if present).
5199 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005200 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005201 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005202 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005203 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005204 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005205 if (Catch.get() != S->getCatchStmt(I))
5206 AnyCatchChanged = true;
5207 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005208 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005209
Douglas Gregor306de2f2010-04-22 23:59:56 +00005210 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005211 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005212 if (S->getFinallyStmt()) {
5213 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5214 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005215 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005216 }
5217
5218 // If nothing changed, just retain this statement.
5219 if (!getDerived().AlwaysRebuild() &&
5220 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005221 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005222 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005223 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005224
Douglas Gregor306de2f2010-04-22 23:59:56 +00005225 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005226 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5227 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005228}
Mike Stump11289f42009-09-09 15:08:12 +00005229
Douglas Gregorebe10102009-08-20 07:17:43 +00005230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005231StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005232TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005233 // Transform the @catch parameter, if there is one.
5234 VarDecl *Var = 0;
5235 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5236 TypeSourceInfo *TSInfo = 0;
5237 if (FromVar->getTypeSourceInfo()) {
5238 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5239 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005240 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005241 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005242
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005243 QualType T;
5244 if (TSInfo)
5245 T = TSInfo->getType();
5246 else {
5247 T = getDerived().TransformType(FromVar->getType());
5248 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005249 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005250 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005251
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005252 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5253 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005254 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005255 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005256
John McCalldadc5752010-08-24 06:29:42 +00005257 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005258 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005259 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005260
5261 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005262 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005263 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005264}
Mike Stump11289f42009-09-09 15:08:12 +00005265
Douglas Gregorebe10102009-08-20 07:17:43 +00005266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005267StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005268TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005269 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005270 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005271 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005272 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005273
Douglas Gregor306de2f2010-04-22 23:59:56 +00005274 // If nothing changed, just retain this statement.
5275 if (!getDerived().AlwaysRebuild() &&
5276 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005277 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005278
5279 // Build a new statement.
5280 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005281 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005282}
Mike Stump11289f42009-09-09 15:08:12 +00005283
Douglas Gregorebe10102009-08-20 07:17:43 +00005284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005285StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005286TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005287 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005288 if (S->getThrowExpr()) {
5289 Operand = getDerived().TransformExpr(S->getThrowExpr());
5290 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005291 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005292 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005293
Douglas Gregor2900c162010-04-22 21:44:01 +00005294 if (!getDerived().AlwaysRebuild() &&
5295 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005296 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005297
John McCallb268a282010-08-23 23:25:46 +00005298 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
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
Douglas Gregorebe10102009-08-20 07:17:43 +00005303TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005304 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005305 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005306 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005307 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005308 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005309
Douglas Gregor6148de72010-04-22 22:01:21 +00005310 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005311 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005312 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005313 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005314
Douglas Gregor6148de72010-04-22 22:01:21 +00005315 // If nothing change, just retain the current statement.
5316 if (!getDerived().AlwaysRebuild() &&
5317 Object.get() == S->getSynchExpr() &&
5318 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005319 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005320
5321 // Build a new statement.
5322 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005323 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005324}
5325
5326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005327StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005328TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005329 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005330 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005331 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005332 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005333 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005334
Douglas Gregorf68a5082010-04-22 23:10:45 +00005335 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005336 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005337 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005338 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005339
Douglas Gregorf68a5082010-04-22 23:10:45 +00005340 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005341 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005342 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005343 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005344
Douglas Gregorf68a5082010-04-22 23:10:45 +00005345 // If nothing changed, just retain this statement.
5346 if (!getDerived().AlwaysRebuild() &&
5347 Element.get() == S->getElement() &&
5348 Collection.get() == S->getCollection() &&
5349 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005350 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005351
Douglas Gregorf68a5082010-04-22 23:10:45 +00005352 // Build a new statement.
5353 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5354 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005355 Element.get(),
5356 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005357 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005358 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005359}
5360
5361
5362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005363StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005364TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5365 // Transform the exception declaration, if any.
5366 VarDecl *Var = 0;
5367 if (S->getExceptionDecl()) {
5368 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005369 TypeSourceInfo *T = getDerived().TransformType(
5370 ExceptionDecl->getTypeSourceInfo());
5371 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005372 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005373
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005374 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005375 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005376 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005377 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005378 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005379 }
Mike Stump11289f42009-09-09 15:08:12 +00005380
Douglas Gregorebe10102009-08-20 07:17:43 +00005381 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005382 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005383 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005384 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005385
Douglas Gregorebe10102009-08-20 07:17:43 +00005386 if (!getDerived().AlwaysRebuild() &&
5387 !Var &&
5388 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005389 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005390
5391 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5392 Var,
John McCallb268a282010-08-23 23:25:46 +00005393 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005394}
Mike Stump11289f42009-09-09 15:08:12 +00005395
Douglas Gregorebe10102009-08-20 07:17:43 +00005396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005397StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005398TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5399 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005400 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005401 = getDerived().TransformCompoundStmt(S->getTryBlock());
5402 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005403 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005404
Douglas Gregorebe10102009-08-20 07:17:43 +00005405 // Transform the handlers.
5406 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005407 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005408 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005409 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005410 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5411 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005412 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005413
Douglas Gregorebe10102009-08-20 07:17:43 +00005414 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5415 Handlers.push_back(Handler.takeAs<Stmt>());
5416 }
Mike Stump11289f42009-09-09 15:08:12 +00005417
Douglas Gregorebe10102009-08-20 07:17:43 +00005418 if (!getDerived().AlwaysRebuild() &&
5419 TryBlock.get() == S->getTryBlock() &&
5420 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005421 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005422
John McCallb268a282010-08-23 23:25:46 +00005423 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005424 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005425}
Mike Stump11289f42009-09-09 15:08:12 +00005426
Douglas Gregorebe10102009-08-20 07:17:43 +00005427//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005428// Expression transformation
5429//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005431ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005432TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005433 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005434}
Mike Stump11289f42009-09-09 15:08:12 +00005435
5436template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005437ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005438TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005439 NestedNameSpecifierLoc QualifierLoc;
5440 if (E->getQualifierLoc()) {
5441 QualifierLoc
5442 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5443 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005444 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005445 }
John McCallce546572009-12-08 09:08:17 +00005446
5447 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005448 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5449 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005450 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005452
John McCall815039a2010-08-17 21:27:17 +00005453 DeclarationNameInfo NameInfo = E->getNameInfo();
5454 if (NameInfo.getName()) {
5455 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5456 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005457 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005458 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005459
5460 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005461 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005462 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005463 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005464 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005465
5466 // Mark it referenced in the new context regardless.
5467 // FIXME: this is a bit instantiation-specific.
5468 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5469
John McCallc3007a22010-10-26 07:05:15 +00005470 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005471 }
John McCallce546572009-12-08 09:08:17 +00005472
5473 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005474 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005475 TemplateArgs = &TransArgs;
5476 TransArgs.setLAngleLoc(E->getLAngleLoc());
5477 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005478 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5479 E->getNumTemplateArgs(),
5480 TransArgs))
5481 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005482 }
5483
Douglas Gregorea972d32011-02-28 21:54:11 +00005484 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5485 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005486}
Mike Stump11289f42009-09-09 15:08:12 +00005487
Douglas Gregora16548e2009-08-11 05:31:07 +00005488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005489ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005490TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005491 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005492}
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregora16548e2009-08-11 05:31:07 +00005494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005496TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005497 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005498}
Mike Stump11289f42009-09-09 15:08:12 +00005499
Douglas Gregora16548e2009-08-11 05:31:07 +00005500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005501ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005502TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005503 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005504}
Mike Stump11289f42009-09-09 15:08:12 +00005505
Douglas Gregora16548e2009-08-11 05:31:07 +00005506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005507ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005508TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005509 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005510}
Mike Stump11289f42009-09-09 15:08:12 +00005511
Douglas Gregora16548e2009-08-11 05:31:07 +00005512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005513ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005514TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005515 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005516}
5517
5518template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005519ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005520TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005521 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005523 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005524
Douglas Gregora16548e2009-08-11 05:31:07 +00005525 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005526 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005527
John McCallb268a282010-08-23 23:25:46 +00005528 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005529 E->getRParen());
5530}
5531
Mike Stump11289f42009-09-09 15:08:12 +00005532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005533ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005534TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005535 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005536 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005537 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005538
Douglas Gregora16548e2009-08-11 05:31:07 +00005539 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005540 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005541
Douglas Gregora16548e2009-08-11 05:31:07 +00005542 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5543 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005544 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005545}
Mike Stump11289f42009-09-09 15:08:12 +00005546
Douglas Gregora16548e2009-08-11 05:31:07 +00005547template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005548ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005549TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5550 // Transform the type.
5551 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5552 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005553 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005554
Douglas Gregor882211c2010-04-28 22:16:22 +00005555 // Transform all of the components into components similar to what the
5556 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005557 // FIXME: It would be slightly more efficient in the non-dependent case to
5558 // just map FieldDecls, rather than requiring the rebuilder to look for
5559 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005560 // template code that we don't care.
5561 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005562 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005563 typedef OffsetOfExpr::OffsetOfNode Node;
5564 llvm::SmallVector<Component, 4> Components;
5565 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5566 const Node &ON = E->getComponent(I);
5567 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005568 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005569 Comp.LocStart = ON.getRange().getBegin();
5570 Comp.LocEnd = ON.getRange().getEnd();
5571 switch (ON.getKind()) {
5572 case Node::Array: {
5573 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005574 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005575 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005576 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005577
Douglas Gregor882211c2010-04-28 22:16:22 +00005578 ExprChanged = ExprChanged || Index.get() != FromIndex;
5579 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005580 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005581 break;
5582 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005583
Douglas Gregor882211c2010-04-28 22:16:22 +00005584 case Node::Field:
5585 case Node::Identifier:
5586 Comp.isBrackets = false;
5587 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005588 if (!Comp.U.IdentInfo)
5589 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005590
Douglas Gregor882211c2010-04-28 22:16:22 +00005591 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005592
Douglas Gregord1702062010-04-29 00:18:15 +00005593 case Node::Base:
5594 // Will be recomputed during the rebuild.
5595 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005596 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005597
Douglas Gregor882211c2010-04-28 22:16:22 +00005598 Components.push_back(Comp);
5599 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005600
Douglas Gregor882211c2010-04-28 22:16:22 +00005601 // If nothing changed, retain the existing expression.
5602 if (!getDerived().AlwaysRebuild() &&
5603 Type == E->getTypeSourceInfo() &&
5604 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005605 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005606
Douglas Gregor882211c2010-04-28 22:16:22 +00005607 // Build a new offsetof expression.
5608 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5609 Components.data(), Components.size(),
5610 E->getRParenLoc());
5611}
5612
5613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005614ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005615TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5616 assert(getDerived().AlreadyTransformed(E->getType()) &&
5617 "opaque value expression requires transformation");
5618 return SemaRef.Owned(E);
5619}
5620
5621template<typename Derived>
5622ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005623TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005624 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005625 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005626
John McCallbcd03502009-12-07 02:54:59 +00005627 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005628 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005629 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005630
John McCall4c98fd82009-11-04 07:28:41 +00005631 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005632 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005633
John McCall4c98fd82009-11-04 07:28:41 +00005634 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005635 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005636 E->getSourceRange());
5637 }
Mike Stump11289f42009-09-09 15:08:12 +00005638
John McCalldadc5752010-08-24 06:29:42 +00005639 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005640 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005641 // C++0x [expr.sizeof]p1:
5642 // The operand is either an expression, which is an unevaluated operand
5643 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005644 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005645
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5647 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005651 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005652 }
Mike Stump11289f42009-09-09 15:08:12 +00005653
John McCallb268a282010-08-23 23:25:46 +00005654 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005655 E->isSizeOf(),
5656 E->getSourceRange());
5657}
Mike Stump11289f42009-09-09 15:08:12 +00005658
Douglas Gregora16548e2009-08-11 05:31:07 +00005659template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005660ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005661TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005662 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005663 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005664 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005665
John McCalldadc5752010-08-24 06:29:42 +00005666 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005667 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005669
5670
Douglas Gregora16548e2009-08-11 05:31:07 +00005671 if (!getDerived().AlwaysRebuild() &&
5672 LHS.get() == E->getLHS() &&
5673 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005674 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005675
John McCallb268a282010-08-23 23:25:46 +00005676 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005677 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005678 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005679 E->getRBracketLoc());
5680}
Mike Stump11289f42009-09-09 15:08:12 +00005681
5682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005683ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005684TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005685 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005686 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005687 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005688 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005689
5690 // Transform arguments.
5691 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005692 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005693 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5694 &ArgChanged))
5695 return ExprError();
5696
Douglas Gregora16548e2009-08-11 05:31:07 +00005697 if (!getDerived().AlwaysRebuild() &&
5698 Callee.get() == E->getCallee() &&
5699 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005700 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005701
Douglas Gregora16548e2009-08-11 05:31:07 +00005702 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005703 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005704 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005705 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005707 E->getRParenLoc());
5708}
Mike Stump11289f42009-09-09 15:08:12 +00005709
5710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005711ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005712TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005713 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005715 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005716
Douglas Gregorea972d32011-02-28 21:54:11 +00005717 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005718 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005719 QualifierLoc
5720 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5721
5722 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005723 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005724 }
Mike Stump11289f42009-09-09 15:08:12 +00005725
Eli Friedman2cfcef62009-12-04 06:40:45 +00005726 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005727 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5728 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005729 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005730 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005731
John McCall16df1e52010-03-30 21:47:33 +00005732 NamedDecl *FoundDecl = E->getFoundDecl();
5733 if (FoundDecl == E->getMemberDecl()) {
5734 FoundDecl = Member;
5735 } else {
5736 FoundDecl = cast_or_null<NamedDecl>(
5737 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5738 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005739 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005740 }
5741
Douglas Gregora16548e2009-08-11 05:31:07 +00005742 if (!getDerived().AlwaysRebuild() &&
5743 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005744 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005745 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005746 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005747 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005748
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005749 // Mark it referenced in the new context regardless.
5750 // FIXME: this is a bit instantiation-specific.
5751 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005752 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005753 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005754
John McCall6b51f282009-11-23 01:53:49 +00005755 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005756 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005757 TransArgs.setLAngleLoc(E->getLAngleLoc());
5758 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005759 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5760 E->getNumTemplateArgs(),
5761 TransArgs))
5762 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005763 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005764
Douglas Gregora16548e2009-08-11 05:31:07 +00005765 // FIXME: Bogus source location for the operator
5766 SourceLocation FakeOperatorLoc
5767 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5768
John McCall38836f02010-01-15 08:34:02 +00005769 // FIXME: to do this check properly, we will need to preserve the
5770 // first-qualifier-in-scope here, just in case we had a dependent
5771 // base (and therefore couldn't do the check) and a
5772 // nested-name-qualifier (and therefore could do the lookup).
5773 NamedDecl *FirstQualifierInScope = 0;
5774
John McCallb268a282010-08-23 23:25:46 +00005775 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005776 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005777 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005778 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005779 Member,
John McCall16df1e52010-03-30 21:47:33 +00005780 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005781 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005782 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005783 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005784}
Mike Stump11289f42009-09-09 15:08:12 +00005785
Douglas Gregora16548e2009-08-11 05:31:07 +00005786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005787ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005788TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005789 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005790 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005791 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005792
John McCalldadc5752010-08-24 06:29:42 +00005793 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005794 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005795 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005796
Douglas Gregora16548e2009-08-11 05:31:07 +00005797 if (!getDerived().AlwaysRebuild() &&
5798 LHS.get() == E->getLHS() &&
5799 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005800 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005801
Douglas Gregora16548e2009-08-11 05:31:07 +00005802 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005803 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005804}
5805
Mike Stump11289f42009-09-09 15:08:12 +00005806template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005807ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005808TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005809 CompoundAssignOperator *E) {
5810 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005811}
Mike Stump11289f42009-09-09 15:08:12 +00005812
Douglas Gregora16548e2009-08-11 05:31:07 +00005813template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005814ExprResult TreeTransform<Derived>::
5815TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5816 // Just rebuild the common and RHS expressions and see whether we
5817 // get any changes.
5818
5819 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5820 if (commonExpr.isInvalid())
5821 return ExprError();
5822
5823 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5824 if (rhs.isInvalid())
5825 return ExprError();
5826
5827 if (!getDerived().AlwaysRebuild() &&
5828 commonExpr.get() == e->getCommon() &&
5829 rhs.get() == e->getFalseExpr())
5830 return SemaRef.Owned(e);
5831
5832 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5833 e->getQuestionLoc(),
5834 0,
5835 e->getColonLoc(),
5836 rhs.get());
5837}
5838
5839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005840ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005841TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005842 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005843 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005844 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005845
John McCalldadc5752010-08-24 06:29:42 +00005846 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005847 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005849
John McCalldadc5752010-08-24 06:29:42 +00005850 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005851 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005852 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005853
Douglas Gregora16548e2009-08-11 05:31:07 +00005854 if (!getDerived().AlwaysRebuild() &&
5855 Cond.get() == E->getCond() &&
5856 LHS.get() == E->getLHS() &&
5857 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005858 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005859
John McCallb268a282010-08-23 23:25:46 +00005860 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005861 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005862 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005863 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005864 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005865}
Mike Stump11289f42009-09-09 15:08:12 +00005866
5867template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005868ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005869TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005870 // Implicit casts are eliminated during transformation, since they
5871 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005872 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005873}
Mike Stump11289f42009-09-09 15:08:12 +00005874
Douglas Gregora16548e2009-08-11 05:31:07 +00005875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005876ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005877TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005878 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5879 if (!Type)
5880 return ExprError();
5881
John McCalldadc5752010-08-24 06:29:42 +00005882 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005883 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005886
Douglas Gregora16548e2009-08-11 05:31:07 +00005887 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005888 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005890 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005891
John McCall97513962010-01-15 18:39:57 +00005892 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005893 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005894 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005895 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005896}
Mike Stump11289f42009-09-09 15:08:12 +00005897
Douglas Gregora16548e2009-08-11 05:31:07 +00005898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005899ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005900TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005901 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5902 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5903 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005905
John McCalldadc5752010-08-24 06:29:42 +00005906 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005907 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005908 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005909
Douglas Gregora16548e2009-08-11 05:31:07 +00005910 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005911 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005912 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005913 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005914
John McCall5d7aa7f2010-01-19 22:33:45 +00005915 // Note: the expression type doesn't necessarily match the
5916 // type-as-written, but that's okay, because it should always be
5917 // derivable from the initializer.
5918
John McCalle15bbff2010-01-18 19:35:47 +00005919 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005920 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005921 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005922}
Mike Stump11289f42009-09-09 15:08:12 +00005923
Douglas Gregora16548e2009-08-11 05:31:07 +00005924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005925ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005926TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005927 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005928 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005930
Douglas Gregora16548e2009-08-11 05:31:07 +00005931 if (!getDerived().AlwaysRebuild() &&
5932 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005933 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005934
Douglas Gregora16548e2009-08-11 05:31:07 +00005935 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005936 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005937 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005938 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005939 E->getAccessorLoc(),
5940 E->getAccessor());
5941}
Mike Stump11289f42009-09-09 15:08:12 +00005942
Douglas Gregora16548e2009-08-11 05:31:07 +00005943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005944ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005945TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005946 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005947
John McCall37ad5512010-08-23 06:44:23 +00005948 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005949 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5950 Inits, &InitChanged))
5951 return ExprError();
5952
Douglas Gregora16548e2009-08-11 05:31:07 +00005953 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005954 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005955
Douglas Gregora16548e2009-08-11 05:31:07 +00005956 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005957 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005958}
Mike Stump11289f42009-09-09 15:08:12 +00005959
Douglas Gregora16548e2009-08-11 05:31:07 +00005960template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005961ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005962TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005963 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005964
Douglas Gregorebe10102009-08-20 07:17:43 +00005965 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005966 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005967 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005968 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005969
Douglas Gregorebe10102009-08-20 07:17:43 +00005970 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005971 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005972 bool ExprChanged = false;
5973 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5974 DEnd = E->designators_end();
5975 D != DEnd; ++D) {
5976 if (D->isFieldDesignator()) {
5977 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5978 D->getDotLoc(),
5979 D->getFieldLoc()));
5980 continue;
5981 }
Mike Stump11289f42009-09-09 15:08:12 +00005982
Douglas Gregora16548e2009-08-11 05:31:07 +00005983 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005984 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005985 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005986 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005987
5988 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005989 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005990
Douglas Gregora16548e2009-08-11 05:31:07 +00005991 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5992 ArrayExprs.push_back(Index.release());
5993 continue;
5994 }
Mike Stump11289f42009-09-09 15:08:12 +00005995
Douglas Gregora16548e2009-08-11 05:31:07 +00005996 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005997 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005998 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5999 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006000 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006001
John McCalldadc5752010-08-24 06:29:42 +00006002 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006003 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006004 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006005
6006 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006007 End.get(),
6008 D->getLBracketLoc(),
6009 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006010
Douglas Gregora16548e2009-08-11 05:31:07 +00006011 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6012 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006013
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 ArrayExprs.push_back(Start.release());
6015 ArrayExprs.push_back(End.release());
6016 }
Mike Stump11289f42009-09-09 15:08:12 +00006017
Douglas Gregora16548e2009-08-11 05:31:07 +00006018 if (!getDerived().AlwaysRebuild() &&
6019 Init.get() == E->getInit() &&
6020 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006021 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006022
Douglas Gregora16548e2009-08-11 05:31:07 +00006023 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6024 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006025 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006026}
Mike Stump11289f42009-09-09 15:08:12 +00006027
Douglas Gregora16548e2009-08-11 05:31:07 +00006028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006029ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006030TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006031 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006032 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006033
Douglas Gregor3da3c062009-10-28 00:29:27 +00006034 // FIXME: Will we ever have proper type location here? Will we actually
6035 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006036 QualType T = getDerived().TransformType(E->getType());
6037 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006038 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006039
Douglas Gregora16548e2009-08-11 05:31:07 +00006040 if (!getDerived().AlwaysRebuild() &&
6041 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006042 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006043
Douglas Gregora16548e2009-08-11 05:31:07 +00006044 return getDerived().RebuildImplicitValueInitExpr(T);
6045}
Mike Stump11289f42009-09-09 15:08:12 +00006046
Douglas Gregora16548e2009-08-11 05:31:07 +00006047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006048ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006049TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006050 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6051 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006052 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006053
John McCalldadc5752010-08-24 06:29:42 +00006054 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006055 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006057
Douglas Gregora16548e2009-08-11 05:31:07 +00006058 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006059 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006060 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006061 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006062
John McCallb268a282010-08-23 23:25:46 +00006063 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006064 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006065}
6066
6067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006068ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006069TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006070 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006071 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006072 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6073 &ArgumentChanged))
6074 return ExprError();
6075
Douglas Gregora16548e2009-08-11 05:31:07 +00006076 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6077 move_arg(Inits),
6078 E->getRParenLoc());
6079}
Mike Stump11289f42009-09-09 15:08:12 +00006080
Douglas Gregora16548e2009-08-11 05:31:07 +00006081/// \brief Transform an address-of-label expression.
6082///
6083/// By default, the transformation of an address-of-label expression always
6084/// rebuilds the expression, so that the label identifier can be resolved to
6085/// the corresponding label statement by semantic analysis.
6086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006087ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006088TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006089 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6090 E->getLabel());
6091 if (!LD)
6092 return ExprError();
6093
Douglas Gregora16548e2009-08-11 05:31:07 +00006094 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006095 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006096}
Mike Stump11289f42009-09-09 15:08:12 +00006097
6098template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006099ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006100TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006101 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006102 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6103 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006105
Douglas Gregora16548e2009-08-11 05:31:07 +00006106 if (!getDerived().AlwaysRebuild() &&
6107 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006108 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006109
6110 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006111 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006112 E->getRParenLoc());
6113}
Mike Stump11289f42009-09-09 15:08:12 +00006114
Douglas Gregora16548e2009-08-11 05:31:07 +00006115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006116ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006117TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006118 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006119 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006120 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006121
John McCalldadc5752010-08-24 06:29:42 +00006122 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006123 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006125
John McCalldadc5752010-08-24 06:29:42 +00006126 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006127 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006128 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006129
Douglas Gregora16548e2009-08-11 05:31:07 +00006130 if (!getDerived().AlwaysRebuild() &&
6131 Cond.get() == E->getCond() &&
6132 LHS.get() == E->getLHS() &&
6133 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006134 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006135
Douglas Gregora16548e2009-08-11 05:31:07 +00006136 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006137 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006138 E->getRParenLoc());
6139}
Mike Stump11289f42009-09-09 15:08:12 +00006140
Douglas Gregora16548e2009-08-11 05:31:07 +00006141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006142ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006143TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006144 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006145}
6146
6147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006149TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006150 switch (E->getOperator()) {
6151 case OO_New:
6152 case OO_Delete:
6153 case OO_Array_New:
6154 case OO_Array_Delete:
6155 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006156 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006157
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006158 case OO_Call: {
6159 // This is a call to an object's operator().
6160 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6161
6162 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006163 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006164 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006165 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006166
6167 // FIXME: Poor location information
6168 SourceLocation FakeLParenLoc
6169 = SemaRef.PP.getLocForEndOfToken(
6170 static_cast<Expr *>(Object.get())->getLocEnd());
6171
6172 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006173 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006174 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6175 Args))
6176 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006177
John McCallb268a282010-08-23 23:25:46 +00006178 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006179 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006180 E->getLocEnd());
6181 }
6182
6183#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6184 case OO_##Name:
6185#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6186#include "clang/Basic/OperatorKinds.def"
6187 case OO_Subscript:
6188 // Handled below.
6189 break;
6190
6191 case OO_Conditional:
6192 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006193 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006194
6195 case OO_None:
6196 case NUM_OVERLOADED_OPERATORS:
6197 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006198 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006199 }
6200
John McCalldadc5752010-08-24 06:29:42 +00006201 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006202 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006203 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006204
John McCalldadc5752010-08-24 06:29:42 +00006205 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006206 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006207 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006208
John McCalldadc5752010-08-24 06:29:42 +00006209 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006210 if (E->getNumArgs() == 2) {
6211 Second = getDerived().TransformExpr(E->getArg(1));
6212 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006213 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006214 }
Mike Stump11289f42009-09-09 15:08:12 +00006215
Douglas Gregora16548e2009-08-11 05:31:07 +00006216 if (!getDerived().AlwaysRebuild() &&
6217 Callee.get() == E->getCallee() &&
6218 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006219 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006220 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006221
Douglas Gregora16548e2009-08-11 05:31:07 +00006222 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6223 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006224 Callee.get(),
6225 First.get(),
6226 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006227}
Mike Stump11289f42009-09-09 15:08:12 +00006228
Douglas Gregora16548e2009-08-11 05:31:07 +00006229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006230ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006231TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6232 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006233}
Mike Stump11289f42009-09-09 15:08:12 +00006234
Douglas Gregora16548e2009-08-11 05:31:07 +00006235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006236ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006237TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6238 // Transform the callee.
6239 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6240 if (Callee.isInvalid())
6241 return ExprError();
6242
6243 // Transform exec config.
6244 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6245 if (EC.isInvalid())
6246 return ExprError();
6247
6248 // Transform arguments.
6249 bool ArgChanged = false;
6250 ASTOwningVector<Expr*> Args(SemaRef);
6251 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6252 &ArgChanged))
6253 return ExprError();
6254
6255 if (!getDerived().AlwaysRebuild() &&
6256 Callee.get() == E->getCallee() &&
6257 !ArgChanged)
6258 return SemaRef.Owned(E);
6259
6260 // FIXME: Wrong source location information for the '('.
6261 SourceLocation FakeLParenLoc
6262 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6263 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6264 move_arg(Args),
6265 E->getRParenLoc(), EC.get());
6266}
6267
6268template<typename Derived>
6269ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006270TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006271 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6272 if (!Type)
6273 return ExprError();
6274
John McCalldadc5752010-08-24 06:29:42 +00006275 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006276 = getDerived().TransformExpr(E->getSubExprAsWritten());
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() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006281 Type == E->getTypeInfoAsWritten() &&
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
Douglas Gregora16548e2009-08-11 05:31:07 +00006285 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006286 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006287 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6288 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6289 SourceLocation FakeRParenLoc
6290 = SemaRef.PP.getLocForEndOfToken(
6291 E->getSubExpr()->getSourceRange().getEnd());
6292 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006293 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006294 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006295 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006296 FakeRAngleLoc,
6297 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006298 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006299 FakeRParenLoc);
6300}
Mike Stump11289f42009-09-09 15:08:12 +00006301
Douglas Gregora16548e2009-08-11 05:31:07 +00006302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006303ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006304TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6305 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006306}
Mike Stump11289f42009-09-09 15:08:12 +00006307
6308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006309ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006310TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6311 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006312}
6313
Douglas Gregora16548e2009-08-11 05:31:07 +00006314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006315ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006316TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006317 CXXReinterpretCastExpr *E) {
6318 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006319}
Mike Stump11289f42009-09-09 15:08:12 +00006320
Douglas Gregora16548e2009-08-11 05:31:07 +00006321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006322ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006323TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6324 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006325}
Mike Stump11289f42009-09-09 15:08:12 +00006326
Douglas Gregora16548e2009-08-11 05:31:07 +00006327template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006328ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006329TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006330 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006331 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6332 if (!Type)
6333 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006334
John McCalldadc5752010-08-24 06:29:42 +00006335 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006336 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006337 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006338 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006339
Douglas Gregora16548e2009-08-11 05:31:07 +00006340 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006341 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006342 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006343 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006344
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006345 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006346 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006347 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006348 E->getRParenLoc());
6349}
Mike Stump11289f42009-09-09 15:08:12 +00006350
Douglas Gregora16548e2009-08-11 05:31:07 +00006351template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006352ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006353TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006354 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006355 TypeSourceInfo *TInfo
6356 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6357 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006358 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006359
Douglas Gregora16548e2009-08-11 05:31:07 +00006360 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006361 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006362 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006363
Douglas Gregor9da64192010-04-26 22:37:10 +00006364 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6365 E->getLocStart(),
6366 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006367 E->getLocEnd());
6368 }
Mike Stump11289f42009-09-09 15:08:12 +00006369
Douglas Gregora16548e2009-08-11 05:31:07 +00006370 // We don't know whether the expression is potentially evaluated until
6371 // after we perform semantic analysis, so the expression is potentially
6372 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006373 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006374 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006375
John McCalldadc5752010-08-24 06:29:42 +00006376 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006377 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006378 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006379
Douglas Gregora16548e2009-08-11 05:31:07 +00006380 if (!getDerived().AlwaysRebuild() &&
6381 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006382 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregor9da64192010-04-26 22:37:10 +00006384 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6385 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006386 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006387 E->getLocEnd());
6388}
6389
6390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006391ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006392TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6393 if (E->isTypeOperand()) {
6394 TypeSourceInfo *TInfo
6395 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6396 if (!TInfo)
6397 return ExprError();
6398
6399 if (!getDerived().AlwaysRebuild() &&
6400 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006401 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006402
6403 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6404 E->getLocStart(),
6405 TInfo,
6406 E->getLocEnd());
6407 }
6408
6409 // We don't know whether the expression is potentially evaluated until
6410 // after we perform semantic analysis, so the expression is potentially
6411 // potentially evaluated.
6412 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6413
6414 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6415 if (SubExpr.isInvalid())
6416 return ExprError();
6417
6418 if (!getDerived().AlwaysRebuild() &&
6419 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006420 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006421
6422 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6423 E->getLocStart(),
6424 SubExpr.get(),
6425 E->getLocEnd());
6426}
6427
6428template<typename Derived>
6429ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006430TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006431 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006432}
Mike Stump11289f42009-09-09 15:08:12 +00006433
Douglas Gregora16548e2009-08-11 05:31:07 +00006434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006435ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006436TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006437 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006438 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006439}
Mike Stump11289f42009-09-09 15:08:12 +00006440
Douglas Gregora16548e2009-08-11 05:31:07 +00006441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006442ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006443TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006444 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6445 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6446 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006447
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006448 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006449 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006450
Douglas Gregorb15af892010-01-07 23:12:05 +00006451 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006452}
Mike Stump11289f42009-09-09 15:08:12 +00006453
Douglas Gregora16548e2009-08-11 05:31:07 +00006454template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006455ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006456TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006457 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006458 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006459 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006460
Douglas Gregora16548e2009-08-11 05:31:07 +00006461 if (!getDerived().AlwaysRebuild() &&
6462 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006463 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006464
John McCallb268a282010-08-23 23:25:46 +00006465 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006466}
Mike Stump11289f42009-09-09 15:08:12 +00006467
Douglas Gregora16548e2009-08-11 05:31:07 +00006468template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006469ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006470TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006471 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006472 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6473 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006474 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006475 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006476
Chandler Carruth794da4c2010-02-08 06:42:49 +00006477 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006478 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006479 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006480
Douglas Gregor033f6752009-12-23 23:03:06 +00006481 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006482}
Mike Stump11289f42009-09-09 15:08:12 +00006483
Douglas Gregora16548e2009-08-11 05:31:07 +00006484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006485ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006486TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6487 CXXScalarValueInitExpr *E) {
6488 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6489 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006490 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006491
Douglas Gregora16548e2009-08-11 05:31:07 +00006492 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006493 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006494 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006495
Douglas Gregor2b88c112010-09-08 00:15:04 +00006496 return getDerived().RebuildCXXScalarValueInitExpr(T,
6497 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006498 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006499}
Mike Stump11289f42009-09-09 15:08:12 +00006500
Douglas Gregora16548e2009-08-11 05:31:07 +00006501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006502ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006503TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006504 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006505 TypeSourceInfo *AllocTypeInfo
6506 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6507 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006508 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006509
Douglas Gregora16548e2009-08-11 05:31:07 +00006510 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006511 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006512 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006513 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006514
Douglas Gregora16548e2009-08-11 05:31:07 +00006515 // Transform the placement arguments (if any).
6516 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006517 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006518 if (getDerived().TransformExprs(E->getPlacementArgs(),
6519 E->getNumPlacementArgs(), true,
6520 PlacementArgs, &ArgumentChanged))
6521 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006522
Douglas Gregorebe10102009-08-20 07:17:43 +00006523 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006524 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006525 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6526 ConstructorArgs, &ArgumentChanged))
6527 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006528
Douglas Gregord2d9da02010-02-26 00:38:10 +00006529 // Transform constructor, new operator, and delete operator.
6530 CXXConstructorDecl *Constructor = 0;
6531 if (E->getConstructor()) {
6532 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006533 getDerived().TransformDecl(E->getLocStart(),
6534 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006535 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006536 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006537 }
6538
6539 FunctionDecl *OperatorNew = 0;
6540 if (E->getOperatorNew()) {
6541 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006542 getDerived().TransformDecl(E->getLocStart(),
6543 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006544 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006545 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006546 }
6547
6548 FunctionDecl *OperatorDelete = 0;
6549 if (E->getOperatorDelete()) {
6550 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006551 getDerived().TransformDecl(E->getLocStart(),
6552 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006553 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006554 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006555 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006556
Douglas Gregora16548e2009-08-11 05:31:07 +00006557 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006558 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006559 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006560 Constructor == E->getConstructor() &&
6561 OperatorNew == E->getOperatorNew() &&
6562 OperatorDelete == E->getOperatorDelete() &&
6563 !ArgumentChanged) {
6564 // Mark any declarations we need as referenced.
6565 // FIXME: instantiation-specific.
6566 if (Constructor)
6567 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6568 if (OperatorNew)
6569 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6570 if (OperatorDelete)
6571 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006572 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006573 }
Mike Stump11289f42009-09-09 15:08:12 +00006574
Douglas Gregor0744ef62010-09-07 21:49:58 +00006575 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006576 if (!ArraySize.get()) {
6577 // If no array size was specified, but the new expression was
6578 // instantiated with an array type (e.g., "new T" where T is
6579 // instantiated with "int[4]"), extract the outer bound from the
6580 // array type as our array size. We do this with constant and
6581 // dependently-sized array types.
6582 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6583 if (!ArrayT) {
6584 // Do nothing
6585 } else if (const ConstantArrayType *ConsArrayT
6586 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006587 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006588 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6589 ConsArrayT->getSize(),
6590 SemaRef.Context.getSizeType(),
6591 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006592 AllocType = ConsArrayT->getElementType();
6593 } else if (const DependentSizedArrayType *DepArrayT
6594 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6595 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006596 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006597 AllocType = DepArrayT->getElementType();
6598 }
6599 }
6600 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006601
Douglas Gregora16548e2009-08-11 05:31:07 +00006602 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6603 E->isGlobalNew(),
6604 /*FIXME:*/E->getLocStart(),
6605 move_arg(PlacementArgs),
6606 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006607 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006608 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006609 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006610 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006611 /*FIXME:*/E->getLocStart(),
6612 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006613 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006614}
Mike Stump11289f42009-09-09 15:08:12 +00006615
Douglas Gregora16548e2009-08-11 05:31:07 +00006616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006617ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006618TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006619 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006620 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006621 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006622
Douglas Gregord2d9da02010-02-26 00:38:10 +00006623 // Transform the delete operator, if known.
6624 FunctionDecl *OperatorDelete = 0;
6625 if (E->getOperatorDelete()) {
6626 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006627 getDerived().TransformDecl(E->getLocStart(),
6628 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006629 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006630 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006631 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006632
Douglas Gregora16548e2009-08-11 05:31:07 +00006633 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006634 Operand.get() == E->getArgument() &&
6635 OperatorDelete == E->getOperatorDelete()) {
6636 // Mark any declarations we need as referenced.
6637 // FIXME: instantiation-specific.
6638 if (OperatorDelete)
6639 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006640
6641 if (!E->getArgument()->isTypeDependent()) {
6642 QualType Destroyed = SemaRef.Context.getBaseElementType(
6643 E->getDestroyedType());
6644 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6645 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6646 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6647 SemaRef.LookupDestructor(Record));
6648 }
6649 }
6650
John McCallc3007a22010-10-26 07:05:15 +00006651 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006652 }
Mike Stump11289f42009-09-09 15:08:12 +00006653
Douglas Gregora16548e2009-08-11 05:31:07 +00006654 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6655 E->isGlobalDelete(),
6656 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006657 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006658}
Mike Stump11289f42009-09-09 15:08:12 +00006659
Douglas Gregora16548e2009-08-11 05:31:07 +00006660template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006661ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006662TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006663 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006664 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006665 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006666 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006667
John McCallba7bf592010-08-24 05:47:05 +00006668 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006669 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006670 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006671 E->getOperatorLoc(),
6672 E->isArrow()? tok::arrow : tok::period,
6673 ObjectTypePtr,
6674 MayBePseudoDestructor);
6675 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006676 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006677
John McCallba7bf592010-08-24 05:47:05 +00006678 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006679 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6680 if (QualifierLoc) {
6681 QualifierLoc
6682 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6683 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006684 return ExprError();
6685 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006686 CXXScopeSpec SS;
6687 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006688
Douglas Gregor678f90d2010-02-25 01:56:36 +00006689 PseudoDestructorTypeStorage Destroyed;
6690 if (E->getDestroyedTypeInfo()) {
6691 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006692 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006693 ObjectType, 0,
6694 QualifierLoc.getNestedNameSpecifier());
Douglas Gregor678f90d2010-02-25 01:56:36 +00006695 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006696 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006697 Destroyed = DestroyedTypeInfo;
6698 } else if (ObjectType->isDependentType()) {
6699 // We aren't likely to be able to resolve the identifier down to a type
6700 // now anyway, so just retain the identifier.
6701 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6702 E->getDestroyedTypeLoc());
6703 } else {
6704 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006705 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006706 *E->getDestroyedTypeIdentifier(),
6707 E->getDestroyedTypeLoc(),
6708 /*Scope=*/0,
6709 SS, ObjectTypePtr,
6710 false);
6711 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006712 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006713
Douglas Gregor678f90d2010-02-25 01:56:36 +00006714 Destroyed
6715 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6716 E->getDestroyedTypeLoc());
6717 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006718
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006719 TypeSourceInfo *ScopeTypeInfo = 0;
6720 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006721 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006722 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006723 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006724 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006725
John McCallb268a282010-08-23 23:25:46 +00006726 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006727 E->getOperatorLoc(),
6728 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006729 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006730 ScopeTypeInfo,
6731 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006732 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006733 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006734}
Mike Stump11289f42009-09-09 15:08:12 +00006735
Douglas Gregorad8a3362009-09-04 17:36:40 +00006736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006737ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006738TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006739 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006740 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6741
6742 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6743 Sema::LookupOrdinaryName);
6744
6745 // Transform all the decls.
6746 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6747 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006748 NamedDecl *InstD = static_cast<NamedDecl*>(
6749 getDerived().TransformDecl(Old->getNameLoc(),
6750 *I));
John McCall84d87672009-12-10 09:41:52 +00006751 if (!InstD) {
6752 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6753 // This can happen because of dependent hiding.
6754 if (isa<UsingShadowDecl>(*I))
6755 continue;
6756 else
John McCallfaf5fb42010-08-26 23:41:50 +00006757 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006758 }
John McCalle66edc12009-11-24 19:00:30 +00006759
6760 // Expand using declarations.
6761 if (isa<UsingDecl>(InstD)) {
6762 UsingDecl *UD = cast<UsingDecl>(InstD);
6763 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6764 E = UD->shadow_end(); I != E; ++I)
6765 R.addDecl(*I);
6766 continue;
6767 }
6768
6769 R.addDecl(InstD);
6770 }
6771
6772 // Resolve a kind, but don't do any further analysis. If it's
6773 // ambiguous, the callee needs to deal with it.
6774 R.resolveKind();
6775
6776 // Rebuild the nested-name qualifier, if present.
6777 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006778 if (Old->getQualifierLoc()) {
6779 NestedNameSpecifierLoc QualifierLoc
6780 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6781 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006782 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006783
Douglas Gregor0da1d432011-02-28 20:01:57 +00006784 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006785 }
6786
Douglas Gregor9262f472010-04-27 18:19:34 +00006787 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006788 CXXRecordDecl *NamingClass
6789 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6790 Old->getNameLoc(),
6791 Old->getNamingClass()));
6792 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006793 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006794
Douglas Gregorda7be082010-04-27 16:10:10 +00006795 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006796 }
6797
6798 // If we have no template arguments, it's a normal declaration name.
6799 if (!Old->hasExplicitTemplateArgs())
6800 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6801
6802 // If we have template arguments, rebuild them, then rebuild the
6803 // templateid expression.
6804 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006805 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6806 Old->getNumTemplateArgs(),
6807 TransArgs))
6808 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006809
6810 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6811 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006812}
Mike Stump11289f42009-09-09 15:08:12 +00006813
Douglas Gregora16548e2009-08-11 05:31:07 +00006814template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006815ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006816TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006817 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6818 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006819 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006820
Douglas Gregora16548e2009-08-11 05:31:07 +00006821 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006822 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006823 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006824
Mike Stump11289f42009-09-09 15:08:12 +00006825 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006826 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006827 T,
6828 E->getLocEnd());
6829}
Mike Stump11289f42009-09-09 15:08:12 +00006830
Douglas Gregora16548e2009-08-11 05:31:07 +00006831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006832ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006833TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6834 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6835 if (!LhsT)
6836 return ExprError();
6837
6838 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6839 if (!RhsT)
6840 return ExprError();
6841
6842 if (!getDerived().AlwaysRebuild() &&
6843 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6844 return SemaRef.Owned(E);
6845
6846 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6847 E->getLocStart(),
6848 LhsT, RhsT,
6849 E->getLocEnd());
6850}
6851
6852template<typename Derived>
6853ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006854TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006855 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006856 NestedNameSpecifierLoc QualifierLoc
6857 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6858 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006859 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006860
John McCall31f82722010-11-12 08:19:04 +00006861 // TODO: If this is a conversion-function-id, verify that the
6862 // destination type name (if present) resolves the same way after
6863 // instantiation as it did in the local scope.
6864
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006865 DeclarationNameInfo NameInfo
6866 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6867 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006868 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006869
John McCalle66edc12009-11-24 19:00:30 +00006870 if (!E->hasExplicitTemplateArgs()) {
6871 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006872 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006873 // Note: it is sufficient to compare the Name component of NameInfo:
6874 // if name has not changed, DNLoc has not changed either.
6875 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006876 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006877
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006878 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006879 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006880 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006881 }
John McCall6b51f282009-11-23 01:53:49 +00006882
6883 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006884 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6885 E->getNumTemplateArgs(),
6886 TransArgs))
6887 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006888
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006889 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006890 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006891 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006892}
6893
6894template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006895ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006896TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006897 // CXXConstructExprs are always implicit, so when we have a
6898 // 1-argument construction we just transform that argument.
6899 if (E->getNumArgs() == 1 ||
6900 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6901 return getDerived().TransformExpr(E->getArg(0));
6902
Douglas Gregora16548e2009-08-11 05:31:07 +00006903 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6904
6905 QualType T = getDerived().TransformType(E->getType());
6906 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006907 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006908
6909 CXXConstructorDecl *Constructor
6910 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006911 getDerived().TransformDecl(E->getLocStart(),
6912 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006913 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006914 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006915
Douglas Gregora16548e2009-08-11 05:31:07 +00006916 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006917 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006918 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6919 &ArgumentChanged))
6920 return ExprError();
6921
Douglas Gregora16548e2009-08-11 05:31:07 +00006922 if (!getDerived().AlwaysRebuild() &&
6923 T == E->getType() &&
6924 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006925 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006926 // Mark the constructor as referenced.
6927 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006928 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006929 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006930 }
Mike Stump11289f42009-09-09 15:08:12 +00006931
Douglas Gregordb121ba2009-12-14 16:27:04 +00006932 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6933 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006934 move_arg(Args),
6935 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006936 E->getConstructionKind(),
6937 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006938}
Mike Stump11289f42009-09-09 15:08:12 +00006939
Douglas Gregora16548e2009-08-11 05:31:07 +00006940/// \brief Transform a C++ temporary-binding expression.
6941///
Douglas Gregor363b1512009-12-24 18:51:59 +00006942/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6943/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006945ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006946TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006947 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006948}
Mike Stump11289f42009-09-09 15:08:12 +00006949
John McCall5d413782010-12-06 08:20:24 +00006950/// \brief Transform a C++ expression that contains cleanups that should
6951/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006952///
John McCall5d413782010-12-06 08:20:24 +00006953/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006954/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006955template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006956ExprResult
John McCall5d413782010-12-06 08:20:24 +00006957TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006958 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006959}
Mike Stump11289f42009-09-09 15:08:12 +00006960
Douglas Gregora16548e2009-08-11 05:31:07 +00006961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006962ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006963TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006964 CXXTemporaryObjectExpr *E) {
6965 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6966 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006967 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006968
Douglas Gregora16548e2009-08-11 05:31:07 +00006969 CXXConstructorDecl *Constructor
6970 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006971 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006972 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006973 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006974 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006975
Douglas Gregora16548e2009-08-11 05:31:07 +00006976 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006977 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006978 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006979 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6980 &ArgumentChanged))
6981 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006982
Douglas Gregora16548e2009-08-11 05:31:07 +00006983 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006984 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006985 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006986 !ArgumentChanged) {
6987 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006988 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006989 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006990 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006991
6992 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6993 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006994 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006995 E->getLocEnd());
6996}
Mike Stump11289f42009-09-09 15:08:12 +00006997
Douglas Gregora16548e2009-08-11 05:31:07 +00006998template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006999ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007000TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007001 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007002 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7003 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007004 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007005
Douglas Gregora16548e2009-08-11 05:31:07 +00007006 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007007 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007008 Args.reserve(E->arg_size());
7009 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7010 &ArgumentChanged))
7011 return ExprError();
7012
Douglas Gregora16548e2009-08-11 05:31:07 +00007013 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007014 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007015 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007016 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007017
Douglas Gregora16548e2009-08-11 05:31:07 +00007018 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007019 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007020 E->getLParenLoc(),
7021 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007022 E->getRParenLoc());
7023}
Mike Stump11289f42009-09-09 15:08:12 +00007024
Douglas Gregora16548e2009-08-11 05:31:07 +00007025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007026ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007027TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007028 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007029 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007030 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007031 Expr *OldBase;
7032 QualType BaseType;
7033 QualType ObjectType;
7034 if (!E->isImplicitAccess()) {
7035 OldBase = E->getBase();
7036 Base = getDerived().TransformExpr(OldBase);
7037 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007038 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007039
John McCall2d74de92009-12-01 22:10:20 +00007040 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007041 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007042 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007043 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007044 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007045 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007046 ObjectTy,
7047 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007048 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007049 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007050
John McCallba7bf592010-08-24 05:47:05 +00007051 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007052 BaseType = ((Expr*) Base.get())->getType();
7053 } else {
7054 OldBase = 0;
7055 BaseType = getDerived().TransformType(E->getBaseType());
7056 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7057 }
Mike Stump11289f42009-09-09 15:08:12 +00007058
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007059 // Transform the first part of the nested-name-specifier that qualifies
7060 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007061 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007062 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007063 E->getFirstQualifierFoundInScope(),
7064 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007065
Douglas Gregore16af532011-02-28 18:50:33 +00007066 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007067 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007068 QualifierLoc
7069 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7070 ObjectType,
7071 FirstQualifierInScope);
7072 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007073 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007074 }
Mike Stump11289f42009-09-09 15:08:12 +00007075
John McCall31f82722010-11-12 08:19:04 +00007076 // TODO: If this is a conversion-function-id, verify that the
7077 // destination type name (if present) resolves the same way after
7078 // instantiation as it did in the local scope.
7079
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007080 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007081 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007082 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007083 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007084
John McCall2d74de92009-12-01 22:10:20 +00007085 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007086 // This is a reference to a member without an explicitly-specified
7087 // template argument list. Optimize for this common case.
7088 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007089 Base.get() == OldBase &&
7090 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007091 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007092 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007093 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007094 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007095
John McCallb268a282010-08-23 23:25:46 +00007096 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007097 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007098 E->isArrow(),
7099 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007100 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007101 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007102 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007103 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007104 }
7105
John McCall6b51f282009-11-23 01:53:49 +00007106 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007107 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7108 E->getNumTemplateArgs(),
7109 TransArgs))
7110 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007111
John McCallb268a282010-08-23 23:25:46 +00007112 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007113 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007114 E->isArrow(),
7115 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007116 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007117 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007118 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007119 &TransArgs);
7120}
7121
7122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007123ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007124TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007125 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007126 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007127 QualType BaseType;
7128 if (!Old->isImplicitAccess()) {
7129 Base = getDerived().TransformExpr(Old->getBase());
7130 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007131 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007132 BaseType = ((Expr*) Base.get())->getType();
7133 } else {
7134 BaseType = getDerived().TransformType(Old->getBaseType());
7135 }
John McCall10eae182009-11-30 22:42:35 +00007136
Douglas Gregor0da1d432011-02-28 20:01:57 +00007137 NestedNameSpecifierLoc QualifierLoc;
7138 if (Old->getQualifierLoc()) {
7139 QualifierLoc
7140 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7141 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007142 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007143 }
7144
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007145 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007146 Sema::LookupOrdinaryName);
7147
7148 // Transform all the decls.
7149 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7150 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007151 NamedDecl *InstD = static_cast<NamedDecl*>(
7152 getDerived().TransformDecl(Old->getMemberLoc(),
7153 *I));
John McCall84d87672009-12-10 09:41:52 +00007154 if (!InstD) {
7155 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7156 // This can happen because of dependent hiding.
7157 if (isa<UsingShadowDecl>(*I))
7158 continue;
7159 else
John McCallfaf5fb42010-08-26 23:41:50 +00007160 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007161 }
John McCall10eae182009-11-30 22:42:35 +00007162
7163 // Expand using declarations.
7164 if (isa<UsingDecl>(InstD)) {
7165 UsingDecl *UD = cast<UsingDecl>(InstD);
7166 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7167 E = UD->shadow_end(); I != E; ++I)
7168 R.addDecl(*I);
7169 continue;
7170 }
7171
7172 R.addDecl(InstD);
7173 }
7174
7175 R.resolveKind();
7176
Douglas Gregor9262f472010-04-27 18:19:34 +00007177 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007178 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007179 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007180 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007181 Old->getMemberLoc(),
7182 Old->getNamingClass()));
7183 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007184 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007185
Douglas Gregorda7be082010-04-27 16:10:10 +00007186 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007187 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007188
John McCall10eae182009-11-30 22:42:35 +00007189 TemplateArgumentListInfo TransArgs;
7190 if (Old->hasExplicitTemplateArgs()) {
7191 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7192 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007193 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7194 Old->getNumTemplateArgs(),
7195 TransArgs))
7196 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007197 }
John McCall38836f02010-01-15 08:34:02 +00007198
7199 // FIXME: to do this check properly, we will need to preserve the
7200 // first-qualifier-in-scope here, just in case we had a dependent
7201 // base (and therefore couldn't do the check) and a
7202 // nested-name-qualifier (and therefore could do the lookup).
7203 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007204
John McCallb268a282010-08-23 23:25:46 +00007205 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007206 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007207 Old->getOperatorLoc(),
7208 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007209 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007210 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007211 R,
7212 (Old->hasExplicitTemplateArgs()
7213 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007214}
7215
7216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007217ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007218TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7219 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7220 if (SubExpr.isInvalid())
7221 return ExprError();
7222
7223 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007224 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007225
7226 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7227}
7228
7229template<typename Derived>
7230ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007231TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007232 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7233 if (Pattern.isInvalid())
7234 return ExprError();
7235
7236 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7237 return SemaRef.Owned(E);
7238
Douglas Gregorb8840002011-01-14 21:20:45 +00007239 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7240 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007241}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007242
7243template<typename Derived>
7244ExprResult
7245TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7246 // If E is not value-dependent, then nothing will change when we transform it.
7247 // Note: This is an instantiation-centric view.
7248 if (!E->isValueDependent())
7249 return SemaRef.Owned(E);
7250
7251 // Note: None of the implementations of TryExpandParameterPacks can ever
7252 // produce a diagnostic when given only a single unexpanded parameter pack,
7253 // so
7254 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7255 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007256 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007257 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007258 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7259 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007260 ShouldExpand, RetainExpansion,
7261 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007262 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007263
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007264 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007265 return SemaRef.Owned(E);
7266
7267 // We now know the length of the parameter pack, so build a new expression
7268 // that stores that length.
7269 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7270 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007271 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007272}
7273
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007274template<typename Derived>
7275ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007276TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7277 SubstNonTypeTemplateParmPackExpr *E) {
7278 // Default behavior is to do nothing with this transformation.
7279 return SemaRef.Owned(E);
7280}
7281
7282template<typename Derived>
7283ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007284TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007285 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007286}
7287
Mike Stump11289f42009-09-09 15:08:12 +00007288template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007289ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007290TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007291 TypeSourceInfo *EncodedTypeInfo
7292 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7293 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007294 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007295
Douglas Gregora16548e2009-08-11 05:31:07 +00007296 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007297 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007298 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007299
7300 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007301 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007302 E->getRParenLoc());
7303}
Mike Stump11289f42009-09-09 15:08:12 +00007304
Douglas Gregora16548e2009-08-11 05:31:07 +00007305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007306ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007307TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007308 // Transform arguments.
7309 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007310 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007311 Args.reserve(E->getNumArgs());
7312 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7313 &ArgChanged))
7314 return ExprError();
7315
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007316 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7317 // Class message: transform the receiver type.
7318 TypeSourceInfo *ReceiverTypeInfo
7319 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7320 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007321 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007322
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007323 // If nothing changed, just retain the existing message send.
7324 if (!getDerived().AlwaysRebuild() &&
7325 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007326 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007327
7328 // Build a new class message send.
7329 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7330 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007331 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007332 E->getMethodDecl(),
7333 E->getLeftLoc(),
7334 move_arg(Args),
7335 E->getRightLoc());
7336 }
7337
7338 // Instance message: transform the receiver
7339 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7340 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007341 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007342 = getDerived().TransformExpr(E->getInstanceReceiver());
7343 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007344 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007345
7346 // If nothing changed, just retain the existing message send.
7347 if (!getDerived().AlwaysRebuild() &&
7348 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007349 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007350
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007351 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007352 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007353 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007354 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007355 E->getMethodDecl(),
7356 E->getLeftLoc(),
7357 move_arg(Args),
7358 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007359}
7360
Mike Stump11289f42009-09-09 15:08:12 +00007361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007362ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007363TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007364 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007365}
7366
Mike Stump11289f42009-09-09 15:08:12 +00007367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007369TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007370 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007371}
7372
Mike Stump11289f42009-09-09 15:08:12 +00007373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007374ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007375TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007376 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007377 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007378 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007379 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007380
7381 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007382
Douglas Gregord51d90d2010-04-26 20:11:03 +00007383 // If nothing changed, just retain the existing expression.
7384 if (!getDerived().AlwaysRebuild() &&
7385 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007386 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007387
John McCallb268a282010-08-23 23:25:46 +00007388 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007389 E->getLocation(),
7390 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007391}
7392
Mike Stump11289f42009-09-09 15:08:12 +00007393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007394ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007395TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007396 // 'super' and types never change. Property never changes. Just
7397 // retain the existing expression.
7398 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007399 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007400
Douglas Gregor9faee212010-04-26 20:47:02 +00007401 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007402 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007403 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007404 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007405
Douglas Gregor9faee212010-04-26 20:47:02 +00007406 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007407
Douglas Gregor9faee212010-04-26 20:47:02 +00007408 // If nothing changed, just retain the existing expression.
7409 if (!getDerived().AlwaysRebuild() &&
7410 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007411 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007412
John McCallb7bd14f2010-12-02 01:19:52 +00007413 if (E->isExplicitProperty())
7414 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7415 E->getExplicitProperty(),
7416 E->getLocation());
7417
7418 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7419 E->getType(),
7420 E->getImplicitPropertyGetter(),
7421 E->getImplicitPropertySetter(),
7422 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007423}
7424
Mike Stump11289f42009-09-09 15:08:12 +00007425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007426ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007427TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007428 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007429 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007430 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007431 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007432
Douglas Gregord51d90d2010-04-26 20:11:03 +00007433 // If nothing changed, just retain the existing expression.
7434 if (!getDerived().AlwaysRebuild() &&
7435 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007436 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007437
John McCallb268a282010-08-23 23:25:46 +00007438 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007439 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007440}
7441
Mike Stump11289f42009-09-09 15:08:12 +00007442template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007443ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007444TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007445 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007446 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007447 SubExprs.reserve(E->getNumSubExprs());
7448 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7449 SubExprs, &ArgumentChanged))
7450 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007451
Douglas Gregora16548e2009-08-11 05:31:07 +00007452 if (!getDerived().AlwaysRebuild() &&
7453 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007454 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007455
Douglas Gregora16548e2009-08-11 05:31:07 +00007456 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7457 move_arg(SubExprs),
7458 E->getRParenLoc());
7459}
7460
Mike Stump11289f42009-09-09 15:08:12 +00007461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007462ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007463TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007464 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007465
John McCall490112f2011-02-04 18:33:18 +00007466 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7467 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7468
7469 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7470 llvm::SmallVector<ParmVarDecl*, 4> params;
7471 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007472
7473 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007474 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7475 oldBlock->param_begin(),
7476 oldBlock->param_size(),
7477 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007478 return true;
John McCall490112f2011-02-04 18:33:18 +00007479
7480 const FunctionType *exprFunctionType = E->getFunctionType();
7481 QualType exprResultType = exprFunctionType->getResultType();
7482 if (!exprResultType.isNull()) {
7483 if (!exprResultType->isDependentType())
7484 blockScope->ReturnType = exprResultType;
7485 else if (exprResultType != getSema().Context.DependentTy)
7486 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007487 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007488
7489 // If the return type has not been determined yet, leave it as a dependent
7490 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007491 if (blockScope->ReturnType.isNull())
7492 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007493
7494 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007495 if (blockScope->ReturnType->isObjCObjectType()) {
7496 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007497 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007498 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007499 return ExprError();
7500 }
John McCall3882ace2011-01-05 12:14:39 +00007501
John McCall490112f2011-02-04 18:33:18 +00007502 QualType functionType = getDerived().RebuildFunctionProtoType(
7503 blockScope->ReturnType,
7504 paramTypes.data(),
7505 paramTypes.size(),
7506 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007507 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007508 exprFunctionType->getExtInfo());
7509 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007510
7511 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007512 if (!params.empty())
7513 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007514
7515 // If the return type wasn't explicitly set, it will have been marked as a
7516 // dependent type (DependentTy); clear out the return type setting so
7517 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007518 if (blockScope->ReturnType == getSema().Context.DependentTy)
7519 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007520
John McCall3882ace2011-01-05 12:14:39 +00007521 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007522 StmtResult body = getDerived().TransformStmt(E->getBody());
7523 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007524 return ExprError();
7525
John McCall490112f2011-02-04 18:33:18 +00007526#ifndef NDEBUG
7527 // In builds with assertions, make sure that we captured everything we
7528 // captured before.
7529
7530 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7531
7532 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7533 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007534 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007535
7536 // Ignore parameter packs.
7537 if (isa<ParmVarDecl>(oldCapture) &&
7538 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7539 continue;
7540
7541 VarDecl *newCapture =
7542 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7543 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007544 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007545 }
7546#endif
7547
7548 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7549 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007550}
7551
Mike Stump11289f42009-09-09 15:08:12 +00007552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007553ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007554TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007555 ValueDecl *ND
7556 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7557 E->getDecl()));
7558 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007559 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007560
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007561 if (!getDerived().AlwaysRebuild() &&
7562 ND == E->getDecl()) {
7563 // Mark it referenced in the new context regardless.
7564 // FIXME: this is a bit instantiation-specific.
7565 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7566
John McCallc3007a22010-10-26 07:05:15 +00007567 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007568 }
7569
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007570 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007571 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007572 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007573}
Mike Stump11289f42009-09-09 15:08:12 +00007574
Douglas Gregora16548e2009-08-11 05:31:07 +00007575//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007576// Type reconstruction
7577//===----------------------------------------------------------------------===//
7578
Mike Stump11289f42009-09-09 15:08:12 +00007579template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007580QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7581 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007582 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007583 getDerived().getBaseEntity());
7584}
7585
Mike Stump11289f42009-09-09 15:08:12 +00007586template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007587QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7588 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007589 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007590 getDerived().getBaseEntity());
7591}
7592
Mike Stump11289f42009-09-09 15:08:12 +00007593template<typename Derived>
7594QualType
John McCall70dd5f62009-10-30 00:06:24 +00007595TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7596 bool WrittenAsLValue,
7597 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007598 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007599 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007600}
7601
7602template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007603QualType
John McCall70dd5f62009-10-30 00:06:24 +00007604TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7605 QualType ClassType,
7606 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007607 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007608 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007609}
7610
7611template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007612QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007613TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7614 ArrayType::ArraySizeModifier SizeMod,
7615 const llvm::APInt *Size,
7616 Expr *SizeExpr,
7617 unsigned IndexTypeQuals,
7618 SourceRange BracketsRange) {
7619 if (SizeExpr || !Size)
7620 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7621 IndexTypeQuals, BracketsRange,
7622 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007623
7624 QualType Types[] = {
7625 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7626 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7627 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007628 };
7629 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7630 QualType SizeType;
7631 for (unsigned I = 0; I != NumTypes; ++I)
7632 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7633 SizeType = Types[I];
7634 break;
7635 }
Mike Stump11289f42009-09-09 15:08:12 +00007636
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007637 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7638 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007639 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007640 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007641 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007642}
Mike Stump11289f42009-09-09 15:08:12 +00007643
Douglas Gregord6ff3322009-08-04 16:50:30 +00007644template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007645QualType
7646TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007647 ArrayType::ArraySizeModifier SizeMod,
7648 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007649 unsigned IndexTypeQuals,
7650 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007651 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007652 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007653}
7654
7655template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007656QualType
Mike Stump11289f42009-09-09 15:08:12 +00007657TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007658 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007659 unsigned IndexTypeQuals,
7660 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007661 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007662 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007663}
Mike Stump11289f42009-09-09 15:08:12 +00007664
Douglas Gregord6ff3322009-08-04 16:50:30 +00007665template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007666QualType
7667TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007668 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007669 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007670 unsigned IndexTypeQuals,
7671 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007672 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007673 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007674 IndexTypeQuals, BracketsRange);
7675}
7676
7677template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007678QualType
7679TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007680 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007681 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007682 unsigned IndexTypeQuals,
7683 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007684 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007685 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007686 IndexTypeQuals, BracketsRange);
7687}
7688
7689template<typename Derived>
7690QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007691 unsigned NumElements,
7692 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007693 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007694 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007695}
Mike Stump11289f42009-09-09 15:08:12 +00007696
Douglas Gregord6ff3322009-08-04 16:50:30 +00007697template<typename Derived>
7698QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7699 unsigned NumElements,
7700 SourceLocation AttributeLoc) {
7701 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7702 NumElements, true);
7703 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007704 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7705 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007706 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007707}
Mike Stump11289f42009-09-09 15:08:12 +00007708
Douglas Gregord6ff3322009-08-04 16:50:30 +00007709template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007710QualType
7711TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007712 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007713 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007714 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007715}
Mike Stump11289f42009-09-09 15:08:12 +00007716
Douglas Gregord6ff3322009-08-04 16:50:30 +00007717template<typename Derived>
7718QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007719 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007720 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007721 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007722 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007723 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007724 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007725 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007726 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007727 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007728 getDerived().getBaseEntity(),
7729 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007730}
Mike Stump11289f42009-09-09 15:08:12 +00007731
Douglas Gregord6ff3322009-08-04 16:50:30 +00007732template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007733QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7734 return SemaRef.Context.getFunctionNoProtoType(T);
7735}
7736
7737template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007738QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7739 assert(D && "no decl found");
7740 if (D->isInvalidDecl()) return QualType();
7741
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007742 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007743 TypeDecl *Ty;
7744 if (isa<UsingDecl>(D)) {
7745 UsingDecl *Using = cast<UsingDecl>(D);
7746 assert(Using->isTypeName() &&
7747 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7748
7749 // A valid resolved using typename decl points to exactly one type decl.
7750 assert(++Using->shadow_begin() == Using->shadow_end());
7751 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007752
John McCallb96ec562009-12-04 22:46:56 +00007753 } else {
7754 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7755 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7756 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7757 }
7758
7759 return SemaRef.Context.getTypeDeclType(Ty);
7760}
7761
7762template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007763QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7764 SourceLocation Loc) {
7765 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007766}
7767
7768template<typename Derived>
7769QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7770 return SemaRef.Context.getTypeOfType(Underlying);
7771}
7772
7773template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007774QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7775 SourceLocation Loc) {
7776 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007777}
7778
7779template<typename Derived>
7780QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007781 TemplateName Template,
7782 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007783 const TemplateArgumentListInfo &TemplateArgs) {
7784 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007785}
Mike Stump11289f42009-09-09 15:08:12 +00007786
Douglas Gregor1135c352009-08-06 05:28:30 +00007787template<typename Derived>
7788NestedNameSpecifier *
7789TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7790 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007791 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007792 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007793 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007794 CXXScopeSpec SS;
7795 // FIXME: The source location information is all wrong.
Douglas Gregor869ad452011-02-24 17:54:50 +00007796 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
Douglas Gregor90c99722011-02-24 00:17:56 +00007797 if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(),
7798 /*FIXME:*/Range.getEnd(),
7799 ObjectType, false,
7800 SS, FirstQualifierInScope,
7801 false))
7802 return 0;
7803
7804 return SS.getScopeRep();
Douglas Gregor1135c352009-08-06 05:28:30 +00007805}
7806
7807template<typename Derived>
7808NestedNameSpecifier *
7809TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7810 SourceRange Range,
7811 NamespaceDecl *NS) {
7812 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7813}
7814
7815template<typename Derived>
7816NestedNameSpecifier *
7817TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7818 SourceRange Range,
Douglas Gregor7b26ff92011-02-24 02:36:08 +00007819 NamespaceAliasDecl *Alias) {
7820 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias);
7821}
7822
7823template<typename Derived>
7824NestedNameSpecifier *
7825TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7826 SourceRange Range,
Douglas Gregor1135c352009-08-06 05:28:30 +00007827 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007828 QualType T) {
7829 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007830 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007831 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007832 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7833 T.getTypePtr());
7834 }
Mike Stump11289f42009-09-09 15:08:12 +00007835
Douglas Gregor1135c352009-08-06 05:28:30 +00007836 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7837 return 0;
7838}
Mike Stump11289f42009-09-09 15:08:12 +00007839
Douglas Gregor71dc5092009-08-06 06:41:21 +00007840template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007841TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007842TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7843 bool TemplateKW,
7844 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007845 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007846 Template);
7847}
7848
7849template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007850TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007851TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007852 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007853 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007854 QualType ObjectType,
7855 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007856 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007857 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007858 UnqualifiedId Name;
7859 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007860 Sema::TemplateTy Template;
7861 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7862 /*FIXME:*/getDerived().getBaseLocation(),
7863 SS,
7864 Name,
John McCallba7bf592010-08-24 05:47:05 +00007865 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007866 /*EnteringContext=*/false,
7867 Template);
John McCall31f82722010-11-12 08:19:04 +00007868 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007869}
Mike Stump11289f42009-09-09 15:08:12 +00007870
Douglas Gregora16548e2009-08-11 05:31:07 +00007871template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007872TemplateName
7873TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7874 OverloadedOperatorKind Operator,
7875 QualType ObjectType) {
7876 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007877 SS.MakeTrivial(SemaRef.Context, Qualifier, SourceRange(getDerived().getBaseLocation()));
Douglas Gregor71395fa2009-11-04 00:56:37 +00007878 UnqualifiedId Name;
7879 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7880 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7881 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007882 Sema::TemplateTy Template;
7883 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007884 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007885 SS,
7886 Name,
John McCallba7bf592010-08-24 05:47:05 +00007887 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007888 /*EnteringContext=*/false,
7889 Template);
7890 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007891}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007892
Douglas Gregor71395fa2009-11-04 00:56:37 +00007893template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007894ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007895TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7896 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007897 Expr *OrigCallee,
7898 Expr *First,
7899 Expr *Second) {
7900 Expr *Callee = OrigCallee->IgnoreParenCasts();
7901 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007902
Douglas Gregora16548e2009-08-11 05:31:07 +00007903 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007904 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007905 if (!First->getType()->isOverloadableType() &&
7906 !Second->getType()->isOverloadableType())
7907 return getSema().CreateBuiltinArraySubscriptExpr(First,
7908 Callee->getLocStart(),
7909 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007910 } else if (Op == OO_Arrow) {
7911 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007912 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7913 } else if (Second == 0 || isPostIncDec) {
7914 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007915 // The argument is not of overloadable type, so try to create a
7916 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007917 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007918 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007919
John McCallb268a282010-08-23 23:25:46 +00007920 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007921 }
7922 } else {
John McCallb268a282010-08-23 23:25:46 +00007923 if (!First->getType()->isOverloadableType() &&
7924 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007925 // Neither of the arguments is an overloadable type, so try to
7926 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007927 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007928 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007929 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007930 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007931 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007932
Douglas Gregora16548e2009-08-11 05:31:07 +00007933 return move(Result);
7934 }
7935 }
Mike Stump11289f42009-09-09 15:08:12 +00007936
7937 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007938 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007939 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007940
John McCallb268a282010-08-23 23:25:46 +00007941 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007942 assert(ULE->requiresADL());
7943
7944 // FIXME: Do we have to check
7945 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007946 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007947 } else {
John McCallb268a282010-08-23 23:25:46 +00007948 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007949 }
Mike Stump11289f42009-09-09 15:08:12 +00007950
Douglas Gregora16548e2009-08-11 05:31:07 +00007951 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007952 Expr *Args[2] = { First, Second };
7953 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007954
Douglas Gregora16548e2009-08-11 05:31:07 +00007955 // Create the overloaded operator invocation for unary operators.
7956 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007957 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007958 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007959 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007960 }
Mike Stump11289f42009-09-09 15:08:12 +00007961
Sebastian Redladba46e2009-10-29 20:17:01 +00007962 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007963 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007964 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007965 First,
7966 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007967
Douglas Gregora16548e2009-08-11 05:31:07 +00007968 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007969 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007970 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007971 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7972 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007973 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007974
Mike Stump11289f42009-09-09 15:08:12 +00007975 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007976}
Mike Stump11289f42009-09-09 15:08:12 +00007977
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007979ExprResult
John McCallb268a282010-08-23 23:25:46 +00007980TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007981 SourceLocation OperatorLoc,
7982 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00007983 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007984 TypeSourceInfo *ScopeType,
7985 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007986 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007987 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00007988 QualType BaseType = Base->getType();
7989 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007990 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007991 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007992 !BaseType->getAs<PointerType>()->getPointeeType()
7993 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007994 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007995 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007996 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007997 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007998 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007999 /*FIXME?*/true);
8000 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008001
Douglas Gregor678f90d2010-02-25 01:56:36 +00008002 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008003 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8004 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8005 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8006 NameInfo.setNamedTypeInfo(DestroyedType);
8007
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008008 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008009
John McCallb268a282010-08-23 23:25:46 +00008010 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008011 OperatorLoc, isArrow,
8012 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008013 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008014 /*TemplateArgs*/ 0);
8015}
8016
Douglas Gregord6ff3322009-08-04 16:50:30 +00008017} // end namespace clang
8018
8019#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H