blob: bd1e67629acfe170241e44b806b7f520999f8e01 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000024#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000025#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000027#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000030#include "clang/Sema/Ownership.h"
31#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000032#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000033#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000034#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000035#include <algorithm>
36
37namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000038using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000039
Douglas Gregord6ff3322009-08-04 16:50:30 +000040/// \brief A semantic tree transformation that allows one to transform one
41/// abstract syntax tree into another.
42///
Mike Stump11289f42009-09-09 15:08:12 +000043/// A new tree transformation is defined by creating a new subclass \c X of
44/// \c TreeTransform<X> and then overriding certain operations to provide
45/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000046/// instantiation is implemented as a tree transformation where the
47/// transformation of TemplateTypeParmType nodes involves substituting the
48/// template arguments for their corresponding template parameters; a similar
49/// transformation is performed for non-type template parameters and
50/// template template parameters.
51///
52/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000053/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000054/// override any of the transformation or rebuild operators by providing an
55/// operation with the same signature as the default implementation. The
56/// overridding function should not be virtual.
57///
58/// Semantic tree transformations are split into two stages, either of which
59/// can be replaced by a subclass. The "transform" step transforms an AST node
60/// or the parts of an AST node using the various transformation functions,
61/// then passes the pieces on to the "rebuild" step, which constructs a new AST
62/// node of the appropriate kind from the pieces. The default transformation
63/// routines recursively transform the operands to composite AST nodes (e.g.,
64/// the pointee type of a PointerType node) and, if any of those operand nodes
65/// were changed by the transformation, invokes the rebuild operation to create
66/// a new AST node.
67///
Mike Stump11289f42009-09-09 15:08:12 +000068/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000069/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
71/// TransformTemplateName(), or TransformTemplateArgument() with entirely
72/// new implementations.
73///
74/// For more fine-grained transformations, subclasses can replace any of the
75/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000076/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000078/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// parameters. Additionally, subclasses can override the \c RebuildXXX
80/// functions to control how AST nodes are rebuilt when their operands change.
81/// By default, \c TreeTransform will invoke semantic analysis to rebuild
82/// AST nodes. However, certain other tree transformations (e.g, cloning) may
83/// be able to use more efficient rebuild steps.
84///
85/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000086/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000087/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
88/// operands have not changed (\c AlwaysRebuild()), and customize the
89/// default locations and entity names used for type-checking
90/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000091template<typename Derived>
92class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000093 /// \brief Private RAII object that helps us forget and then re-remember
94 /// the template argument corresponding to a partially-substituted parameter
95 /// pack.
96 class ForgetPartiallySubstitutedPackRAII {
97 Derived &Self;
98 TemplateArgument Old;
99
100 public:
101 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
102 Old = Self.ForgetPartiallySubstitutedPack();
103 }
104
105 ~ForgetPartiallySubstitutedPackRAII() {
106 Self.RememberPartiallySubstitutedPack(Old);
107 }
108 };
109
Douglas Gregord6ff3322009-08-04 16:50:30 +0000110protected:
111 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000112
Mike Stump11289f42009-09-09 15:08:12 +0000113public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000115 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000116
Douglas Gregord6ff3322009-08-04 16:50:30 +0000117 /// \brief Retrieves a reference to the derived class.
118 Derived &getDerived() { return static_cast<Derived&>(*this); }
119
120 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000121 const Derived &getDerived() const {
122 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000123 }
124
John McCalldadc5752010-08-24 06:29:42 +0000125 static inline ExprResult Owned(Expr *E) { return E; }
126 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Retrieves a reference to the semantic analysis object used for
129 /// this tree transform.
130 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000131
Douglas Gregord6ff3322009-08-04 16:50:30 +0000132 /// \brief Whether the transformation should always rebuild AST nodes, even
133 /// if none of the children have changed.
134 ///
135 /// Subclasses may override this function to specify when the transformation
136 /// should rebuild all AST nodes.
137 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Returns the location of the entity being transformed, if that
140 /// information was not available elsewhere in the AST.
141 ///
Mike Stump11289f42009-09-09 15:08:12 +0000142 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000143 /// provide an alternative implementation that provides better location
144 /// information.
145 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000146
Douglas Gregord6ff3322009-08-04 16:50:30 +0000147 /// \brief Returns the name of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
150 /// By default, returns an empty name. Subclasses can provide an alternative
151 /// implementation with a more precise name.
152 DeclarationName getBaseEntity() { return DeclarationName(); }
153
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 /// \brief Sets the "base" location and entity when that
155 /// information is known based on another transformation.
156 ///
157 /// By default, the source location and entity are ignored. Subclasses can
158 /// override this function to provide a customized implementation.
159 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000160
Douglas Gregora16548e2009-08-11 05:31:07 +0000161 /// \brief RAII object that temporarily sets the base location and entity
162 /// used for reporting diagnostics in types.
163 class TemporaryBase {
164 TreeTransform &Self;
165 SourceLocation OldLocation;
166 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000167
Douglas Gregora16548e2009-08-11 05:31:07 +0000168 public:
169 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000170 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000171 OldLocation = Self.getDerived().getBaseLocation();
172 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000173
174 if (Location.isValid())
175 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000176 }
Mike Stump11289f42009-09-09 15:08:12 +0000177
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 ~TemporaryBase() {
179 Self.getDerived().setBase(OldLocation, OldEntity);
180 }
181 };
Mike Stump11289f42009-09-09 15:08:12 +0000182
183 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000184 /// transformed.
185 ///
186 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000187 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000188 /// not change. For example, template instantiation need not traverse
189 /// non-dependent types.
190 bool AlreadyTransformed(QualType T) {
191 return T.isNull();
192 }
193
Douglas Gregord196a582009-12-14 19:27:10 +0000194 /// \brief Determine whether the given call argument should be dropped, e.g.,
195 /// because it is a default argument.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine to
198 /// determine which kinds of call arguments get dropped. By default,
199 /// CXXDefaultArgument nodes are dropped (prior to transformation).
200 bool DropCallArgument(Expr *E) {
201 return E->isDefaultArgument();
202 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000203
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000204 /// \brief Determine whether we should expand a pack expansion with the
205 /// given set of parameter packs into separate arguments by repeatedly
206 /// transforming the pattern.
207 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000208 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000209 /// Subclasses can override this routine to provide different behavior.
210 ///
211 /// \param EllipsisLoc The location of the ellipsis that identifies the
212 /// pack expansion.
213 ///
214 /// \param PatternRange The source range that covers the entire pattern of
215 /// the pack expansion.
216 ///
217 /// \param Unexpanded The set of unexpanded parameter packs within the
218 /// pattern.
219 ///
220 /// \param NumUnexpanded The number of unexpanded parameter packs in
221 /// \p Unexpanded.
222 ///
223 /// \param ShouldExpand Will be set to \c true if the transformer should
224 /// expand the corresponding pack expansions into separate arguments. When
225 /// set, \c NumExpansions must also be set.
226 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000227 /// \param RetainExpansion Whether the caller should add an unexpanded
228 /// pack expansion after all of the expanded arguments. This is used
229 /// when extending explicitly-specified template argument packs per
230 /// C++0x [temp.arg.explicit]p9.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000233 /// the expanded form of the corresponding pack expansion. This is both an
234 /// input and an output parameter, which can be set by the caller if the
235 /// number of expansions is known a priori (e.g., due to a prior substitution)
236 /// and will be set by the callee when the number of expansions is known.
237 /// The callee must set this value when \c ShouldExpand is \c true; it may
238 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000239 ///
240 /// \returns true if an error occurred (e.g., because the parameter packs
241 /// are to be instantiated with arguments of different lengths), false
242 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
243 /// must be set.
244 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
245 SourceRange PatternRange,
246 const UnexpandedParameterPack *Unexpanded,
247 unsigned NumUnexpanded,
248 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000249 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000250 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 ShouldExpand = false;
252 return false;
253 }
254
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000255 /// \brief "Forget" about the partially-substituted pack template argument,
256 /// when performing an instantiation that must preserve the parameter pack
257 /// use.
258 ///
259 /// This routine is meant to be overridden by the template instantiator.
260 TemplateArgument ForgetPartiallySubstitutedPack() {
261 return TemplateArgument();
262 }
263
264 /// \brief "Remember" the partially-substituted pack template argument
265 /// after performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
270
Douglas Gregorf3010112011-01-07 16:43:16 +0000271 /// \brief Note to the derived class when a function parameter pack is
272 /// being expanded.
273 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
274
Douglas Gregord6ff3322009-08-04 16:50:30 +0000275 /// \brief Transforms the given type into another type.
276 ///
John McCall550e0c22009-10-21 00:40:46 +0000277 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000278 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000279 /// function. This is expensive, but we don't mind, because
280 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000281 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 ///
283 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000284 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000285
John McCall550e0c22009-10-21 00:40:46 +0000286 /// \brief Transforms the given type-with-location into a new
287 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000288 ///
John McCall550e0c22009-10-21 00:40:46 +0000289 /// By default, this routine transforms a type by delegating to the
290 /// appropriate TransformXXXType to build a new type. Subclasses
291 /// may override this function (to take over all type
292 /// transformations) or some set of the TransformXXXType functions
293 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000294 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000295
296 /// \brief Transform the given type-with-location into a new
297 /// type, collecting location information in the given builder
298 /// as necessary.
299 ///
John McCall31f82722010-11-12 08:19:04 +0000300 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000301
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000302 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000303 ///
Mike Stump11289f42009-09-09 15:08:12 +0000304 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000305 /// appropriate TransformXXXStmt function to transform a specific kind of
306 /// statement or the TransformExpr() function to transform an expression.
307 /// Subclasses may override this function to transform statements using some
308 /// other mechanism.
309 ///
310 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000311 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000312
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000313 /// \brief Transform the given expression.
314 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000315 /// By default, this routine transforms an expression by delegating to the
316 /// appropriate TransformXXXExpr function to build a new expression.
317 /// Subclasses may override this function to transform expressions using some
318 /// other mechanism.
319 ///
320 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000321 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000322
Douglas Gregora3efea12011-01-03 19:04:46 +0000323 /// \brief Transform the given list of expressions.
324 ///
325 /// This routine transforms a list of expressions by invoking
326 /// \c TransformExpr() for each subexpression. However, it also provides
327 /// support for variadic templates by expanding any pack expansions (if the
328 /// derived class permits such expansion) along the way. When pack expansions
329 /// are present, the number of outputs may not equal the number of inputs.
330 ///
331 /// \param Inputs The set of expressions to be transformed.
332 ///
333 /// \param NumInputs The number of expressions in \c Inputs.
334 ///
335 /// \param IsCall If \c true, then this transform is being performed on
336 /// function-call arguments, and any arguments that should be dropped, will
337 /// be.
338 ///
339 /// \param Outputs The transformed input expressions will be added to this
340 /// vector.
341 ///
342 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
343 /// due to transformation.
344 ///
345 /// \returns true if an error occurred, false otherwise.
346 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
347 llvm::SmallVectorImpl<Expr *> &Outputs,
348 bool *ArgChanged = 0);
349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Transform the given declaration, which is referenced from a type
351 /// or expression.
352 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000353 /// By default, acts as the identity function on declarations. Subclasses
354 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000355 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000356
357 /// \brief Transform the definition of the given declaration.
358 ///
Mike Stump11289f42009-09-09 15:08:12 +0000359 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000360 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000361 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
362 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000363 }
Mike Stump11289f42009-09-09 15:08:12 +0000364
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000365 /// \brief Transform the given declaration, which was the first part of a
366 /// nested-name-specifier in a member access expression.
367 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000368 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000369 /// identifier in a nested-name-specifier of a member access expression, e.g.,
370 /// the \c T in \c x->T::member
371 ///
372 /// By default, invokes TransformDecl() to transform the declaration.
373 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000374 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
375 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000376 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000377
Douglas Gregord6ff3322009-08-04 16:50:30 +0000378 /// \brief Transform the given nested-name-specifier.
379 ///
Mike Stump11289f42009-09-09 15:08:12 +0000380 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// nested-name-specifier. Subclasses may override this function to provide
382 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000384 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000385 QualType ObjectType = QualType(),
386 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000387
Douglas Gregor14454802011-02-25 02:25:35 +0000388 /// \brief Transform the given nested-name-specifier with source-location
389 /// information.
390 ///
391 /// By default, transforms all of the types and declarations within the
392 /// nested-name-specifier. Subclasses may override this function to provide
393 /// alternate behavior.
394 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
395 NestedNameSpecifierLoc NNS,
396 QualType ObjectType = QualType(),
397 NamedDecl *FirstQualifierInScope = 0);
398
Douglas Gregorf816bd72009-09-03 22:13:48 +0000399 /// \brief Transform the given declaration name.
400 ///
401 /// By default, transforms the types of conversion function, constructor,
402 /// and destructor names and then (if needed) rebuilds the declaration name.
403 /// Identifiers and selectors are returned unmodified. Sublcasses may
404 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000405 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000406 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000407
Douglas Gregord6ff3322009-08-04 16:50:30 +0000408 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000409 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000410 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000412 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000413 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000414 QualType ObjectType = QualType(),
415 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregord6ff3322009-08-04 16:50:30 +0000417 /// \brief Transform the given template argument.
418 ///
Mike Stump11289f42009-09-09 15:08:12 +0000419 /// By default, this operation transforms the type, expression, or
420 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000421 /// new template argument from the transformed result. Subclasses may
422 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000423 ///
424 /// Returns true if there was an error.
425 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
426 TemplateArgumentLoc &Output);
427
Douglas Gregor62e06f22010-12-20 17:31:10 +0000428 /// \brief Transform the given set of template arguments.
429 ///
430 /// By default, this operation transforms all of the template arguments
431 /// in the input set using \c TransformTemplateArgument(), and appends
432 /// the transformed arguments to the output list.
433 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000434 /// Note that this overload of \c TransformTemplateArguments() is merely
435 /// a convenience function. Subclasses that wish to override this behavior
436 /// should override the iterator-based member template version.
437 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000438 /// \param Inputs The set of template arguments to be transformed.
439 ///
440 /// \param NumInputs The number of template arguments in \p Inputs.
441 ///
442 /// \param Outputs The set of transformed template arguments output by this
443 /// routine.
444 ///
445 /// Returns true if an error occurred.
446 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
447 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000448 TemplateArgumentListInfo &Outputs) {
449 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
450 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000451
452 /// \brief Transform the given set of template arguments.
453 ///
454 /// By default, this operation transforms all of the template arguments
455 /// in the input set using \c TransformTemplateArgument(), and appends
456 /// the transformed arguments to the output list.
457 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000458 /// \param First An iterator to the first template argument.
459 ///
460 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000461 ///
462 /// \param Outputs The set of transformed template arguments output by this
463 /// routine.
464 ///
465 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000466 template<typename InputIterator>
467 bool TransformTemplateArguments(InputIterator First,
468 InputIterator Last,
469 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000470
John McCall0ad16662009-10-29 08:12:44 +0000471 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
472 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
473 TemplateArgumentLoc &ArgLoc);
474
John McCallbcd03502009-12-07 02:54:59 +0000475 /// \brief Fakes up a TypeSourceInfo for a type.
476 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
477 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000478 getDerived().getBaseLocation());
479 }
Mike Stump11289f42009-09-09 15:08:12 +0000480
John McCall550e0c22009-10-21 00:40:46 +0000481#define ABSTRACT_TYPELOC(CLASS, PARENT)
482#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000483 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000484#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000485
John McCall31f82722010-11-12 08:19:04 +0000486 QualType
487 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
488 TemplateSpecializationTypeLoc TL,
489 TemplateName Template);
490
491 QualType
492 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
493 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor5a064722011-02-28 17:23:35 +0000494 TemplateName Template);
495
496 QualType
497 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
498 DependentTemplateSpecializationTypeLoc TL,
John McCall31f82722010-11-12 08:19:04 +0000499 NestedNameSpecifier *Prefix);
500
Douglas Gregora7a795b2011-03-01 20:11:18 +0000501 QualType
502 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
503 DependentTemplateSpecializationTypeLoc TL,
504 NestedNameSpecifierLoc QualifierLoc);
505
John McCall58f10c32010-03-11 09:03:00 +0000506 /// \brief Transforms the parameters of a function type into the
507 /// given vectors.
508 ///
509 /// The result vectors should be kept in sync; null entries in the
510 /// variables vector are acceptable.
511 ///
512 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000513 bool TransformFunctionTypeParams(SourceLocation Loc,
514 ParmVarDecl **Params, unsigned NumParams,
515 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000516 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000517 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000518
519 /// \brief Transforms a single function-type parameter. Return null
520 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000521 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
522 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000523
John McCall31f82722010-11-12 08:19:04 +0000524 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000525
John McCalldadc5752010-08-24 06:29:42 +0000526 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
527 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000528
Douglas Gregorebe10102009-08-20 07:17:43 +0000529#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000530 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000531#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000532 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000533#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000534#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000535
Douglas Gregord6ff3322009-08-04 16:50:30 +0000536 /// \brief Build a new pointer type given its pointee type.
537 ///
538 /// By default, performs semantic analysis when building the pointer type.
539 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000540 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000541
542 /// \brief Build a new block pointer type given its pointee type.
543 ///
Mike Stump11289f42009-09-09 15:08:12 +0000544 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000545 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000546 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000547
John McCall70dd5f62009-10-30 00:06:24 +0000548 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549 ///
John McCall70dd5f62009-10-30 00:06:24 +0000550 /// By default, performs semantic analysis when building the
551 /// reference type. Subclasses may override this routine to provide
552 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000553 ///
John McCall70dd5f62009-10-30 00:06:24 +0000554 /// \param LValue whether the type was written with an lvalue sigil
555 /// or an rvalue sigil.
556 QualType RebuildReferenceType(QualType ReferentType,
557 bool LValue,
558 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000559
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 /// \brief Build a new member pointer type given the pointee type and the
561 /// class type it refers into.
562 ///
563 /// By default, performs semantic analysis when building the member pointer
564 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000565 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
566 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000567
Douglas Gregord6ff3322009-08-04 16:50:30 +0000568 /// \brief Build a new array type given the element type, size
569 /// modifier, size of the array (if known), size expression, and index type
570 /// qualifiers.
571 ///
572 /// By default, performs semantic analysis when building the array type.
573 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000574 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000575 QualType RebuildArrayType(QualType ElementType,
576 ArrayType::ArraySizeModifier SizeMod,
577 const llvm::APInt *Size,
578 Expr *SizeExpr,
579 unsigned IndexTypeQuals,
580 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000581
Douglas Gregord6ff3322009-08-04 16:50:30 +0000582 /// \brief Build a new constant array type given the element type, size
583 /// modifier, (known) size of the array, and index type qualifiers.
584 ///
585 /// By default, performs semantic analysis when building the array type.
586 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000587 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000588 ArrayType::ArraySizeModifier SizeMod,
589 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000592
Douglas Gregord6ff3322009-08-04 16:50:30 +0000593 /// \brief Build a new incomplete array type given the element type, size
594 /// modifier, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000598 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000600 unsigned IndexTypeQuals,
601 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000602
Mike Stump11289f42009-09-09 15:08:12 +0000603 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000604 /// size modifier, size expression, and index type qualifiers.
605 ///
606 /// By default, performs semantic analysis when building the array type.
607 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000608 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000609 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000610 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
613
Mike Stump11289f42009-09-09 15:08:12 +0000614 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000619 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
625 /// \brief Build a new vector type given the element type and
626 /// number of elements.
627 ///
628 /// By default, performs semantic analysis when building the vector type.
629 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000630 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000631 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000632
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633 /// \brief Build a new extended vector type given the element type and
634 /// number of elements.
635 ///
636 /// By default, performs semantic analysis when building the vector type.
637 /// Subclasses may override this routine to provide different behavior.
638 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
639 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000640
641 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000642 /// given the element type and number of elements.
643 ///
644 /// By default, performs semantic analysis when building the vector type.
645 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000646 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000647 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000648 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000649
Douglas Gregord6ff3322009-08-04 16:50:30 +0000650 /// \brief Build a new function type.
651 ///
652 /// By default, performs semantic analysis when building the function type.
653 /// Subclasses may override this routine to provide different behavior.
654 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000655 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000656 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000657 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000658 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000659 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000660
John McCall550e0c22009-10-21 00:40:46 +0000661 /// \brief Build a new unprototyped function type.
662 QualType RebuildFunctionNoProtoType(QualType ResultType);
663
John McCallb96ec562009-12-04 22:46:56 +0000664 /// \brief Rebuild an unresolved typename type, given the decl that
665 /// the UnresolvedUsingTypenameDecl was transformed to.
666 QualType RebuildUnresolvedUsingType(Decl *D);
667
Douglas Gregord6ff3322009-08-04 16:50:30 +0000668 /// \brief Build a new typedef type.
669 QualType RebuildTypedefType(TypedefDecl *Typedef) {
670 return SemaRef.Context.getTypeDeclType(Typedef);
671 }
672
673 /// \brief Build a new class/struct/union type.
674 QualType RebuildRecordType(RecordDecl *Record) {
675 return SemaRef.Context.getTypeDeclType(Record);
676 }
677
678 /// \brief Build a new Enum type.
679 QualType RebuildEnumType(EnumDecl *Enum) {
680 return SemaRef.Context.getTypeDeclType(Enum);
681 }
John McCallfcc33b02009-09-05 00:15:47 +0000682
Mike Stump11289f42009-09-09 15:08:12 +0000683 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684 ///
685 /// By default, performs semantic analysis when building the typeof type.
686 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000687 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000688
Mike Stump11289f42009-09-09 15:08:12 +0000689 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 ///
691 /// By default, builds a new TypeOfType with the given underlying type.
692 QualType RebuildTypeOfType(QualType Underlying);
693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the decltype type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000698 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000699
Richard Smith30482bc2011-02-20 03:19:35 +0000700 /// \brief Build a new C++0x auto type.
701 ///
702 /// By default, builds a new AutoType with the given deduced type.
703 QualType RebuildAutoType(QualType Deduced) {
704 return SemaRef.Context.getAutoType(Deduced);
705 }
706
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 /// \brief Build a new template specialization type.
708 ///
709 /// By default, performs semantic analysis when building the template
710 /// specialization type. Subclasses may override this routine to provide
711 /// different behavior.
712 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000713 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000714 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000715
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000716 /// \brief Build a new parenthesized type.
717 ///
718 /// By default, builds a new ParenType type from the inner type.
719 /// Subclasses may override this routine to provide different behavior.
720 QualType RebuildParenType(QualType InnerType) {
721 return SemaRef.Context.getParenType(InnerType);
722 }
723
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// \brief Build a new qualified name type.
725 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000726 /// By default, builds a new ElaboratedType type from the keyword,
727 /// the nested-name-specifier and the named type.
728 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000729 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
730 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000731 NestedNameSpecifierLoc QualifierLoc,
732 QualType Named) {
733 return SemaRef.Context.getElaboratedType(Keyword,
734 QualifierLoc.getNestedNameSpecifier(),
735 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000736 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000737
738 /// \brief Build a new typename type that refers to a template-id.
739 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000740 /// By default, builds a new DependentNameType type from the
741 /// nested-name-specifier and the given type. Subclasses may override
742 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000743 QualType RebuildDependentTemplateSpecializationType(
744 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000745 NestedNameSpecifier *Qualifier,
746 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000747 const IdentifierInfo *Name,
748 SourceLocation NameLoc,
749 const TemplateArgumentListInfo &Args) {
750 // Rebuild the template name.
751 // TODO: avoid TemplateName abstraction
752 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000753 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000754 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000755
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000756 if (InstName.isNull())
757 return QualType();
758
John McCallc392f372010-06-11 00:33:02 +0000759 // If it's still dependent, make a dependent specialization.
760 if (InstName.getAsDependentTemplateName())
761 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000762 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000763
764 // Otherwise, make an elaborated type wrapping a non-dependent
765 // specialization.
766 QualType T =
767 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
768 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000769
Douglas Gregor5a064722011-02-28 17:23:35 +0000770 if (Keyword == ETK_None && Qualifier == 0)
Douglas Gregor6e068012011-02-28 00:04:36 +0000771 return T;
772
Douglas Gregor5a064722011-02-28 17:23:35 +0000773 return SemaRef.Context.getElaboratedType(Keyword, Qualifier, T);
Mike Stump11289f42009-09-09 15:08:12 +0000774 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000775
Douglas Gregora7a795b2011-03-01 20:11:18 +0000776 /// \brief Build a new typename type that refers to a template-id.
777 ///
778 /// By default, builds a new DependentNameType type from the
779 /// nested-name-specifier and the given type. Subclasses may override
780 /// this routine to provide different behavior.
781 QualType RebuildDependentTemplateSpecializationType(
782 ElaboratedTypeKeyword Keyword,
783 NestedNameSpecifierLoc QualifierLoc,
784 const IdentifierInfo *Name,
785 SourceLocation NameLoc,
786 const TemplateArgumentListInfo &Args) {
787 // Rebuild the template name.
788 // TODO: avoid TemplateName abstraction
789 TemplateName InstName
790 = getDerived().RebuildTemplateName(QualifierLoc.getNestedNameSpecifier(),
791 QualifierLoc.getSourceRange(), *Name,
792 QualType(), 0);
793
794 if (InstName.isNull())
795 return QualType();
796
797 // If it's still dependent, make a dependent specialization.
798 if (InstName.getAsDependentTemplateName())
799 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
800 QualifierLoc.getNestedNameSpecifier(),
801 Name,
802 Args);
803
804 // Otherwise, make an elaborated type wrapping a non-dependent
805 // specialization.
806 QualType T =
807 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
808 if (T.isNull()) return QualType();
809
810 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
811 return T;
812
813 return SemaRef.Context.getElaboratedType(Keyword,
814 QualifierLoc.getNestedNameSpecifier(),
815 T);
816 }
817
Douglas Gregord6ff3322009-08-04 16:50:30 +0000818 /// \brief Build a new typename type that refers to an identifier.
819 ///
820 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000821 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000823 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000824 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000825 NestedNameSpecifierLoc QualifierLoc,
826 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000827 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000828 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000829 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000830
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000831 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000832 // If the name is still dependent, just build a new dependent name type.
833 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000834 return SemaRef.Context.getDependentNameType(Keyword,
835 QualifierLoc.getNestedNameSpecifier(),
836 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000837 }
838
Abramo Bagnara6150c882010-05-11 21:36:43 +0000839 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000840 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000841 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000842
843 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
844
Abramo Bagnarad7548482010-05-19 21:37:53 +0000845 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000846 // into a non-dependent elaborated-type-specifier. Find the tag we're
847 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000848 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000849 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
850 if (!DC)
851 return QualType();
852
John McCallbf8c5192010-05-27 06:40:31 +0000853 if (SemaRef.RequireCompleteDeclContext(SS, DC))
854 return QualType();
855
Douglas Gregore677daf2010-03-31 22:19:08 +0000856 TagDecl *Tag = 0;
857 SemaRef.LookupQualifiedName(Result, DC);
858 switch (Result.getResultKind()) {
859 case LookupResult::NotFound:
860 case LookupResult::NotFoundInCurrentInstantiation:
861 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000862
Douglas Gregore677daf2010-03-31 22:19:08 +0000863 case LookupResult::Found:
864 Tag = Result.getAsSingle<TagDecl>();
865 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000866
Douglas Gregore677daf2010-03-31 22:19:08 +0000867 case LookupResult::FoundOverloaded:
868 case LookupResult::FoundUnresolvedValue:
869 llvm_unreachable("Tag lookup cannot find non-tags");
870 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000871
Douglas Gregore677daf2010-03-31 22:19:08 +0000872 case LookupResult::Ambiguous:
873 // Let the LookupResult structure handle ambiguities.
874 return QualType();
875 }
876
877 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000878 // Check where the name exists but isn't a tag type and use that to emit
879 // better diagnostics.
880 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
881 SemaRef.LookupQualifiedName(Result, DC);
882 switch (Result.getResultKind()) {
883 case LookupResult::Found:
884 case LookupResult::FoundOverloaded:
885 case LookupResult::FoundUnresolvedValue: {
886 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
887 unsigned Kind = 0;
888 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
889 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
890 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
891 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
892 break;
893 }
894 default:
895 // FIXME: Would be nice to highlight just the source range.
896 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
897 << Kind << Id << DC;
898 break;
899 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000900 return QualType();
901 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000902
Abramo Bagnarad7548482010-05-19 21:37:53 +0000903 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
904 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000905 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
906 return QualType();
907 }
908
909 // Build the elaborated-type-specifier type.
910 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000911 return SemaRef.Context.getElaboratedType(Keyword,
912 QualifierLoc.getNestedNameSpecifier(),
913 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000914 }
Mike Stump11289f42009-09-09 15:08:12 +0000915
Douglas Gregor822d0302011-01-12 17:07:58 +0000916 /// \brief Build a new pack expansion type.
917 ///
918 /// By default, builds a new PackExpansionType type from the given pattern.
919 /// Subclasses may override this routine to provide different behavior.
920 QualType RebuildPackExpansionType(QualType Pattern,
921 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000922 SourceLocation EllipsisLoc,
923 llvm::Optional<unsigned> NumExpansions) {
924 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
925 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000926 }
927
Douglas Gregor1135c352009-08-06 05:28:30 +0000928 /// \brief Build a new nested-name-specifier given the prefix and an
929 /// identifier that names the next step in the nested-name-specifier.
930 ///
931 /// By default, performs semantic analysis when building the new
932 /// nested-name-specifier. Subclasses may override this routine to provide
933 /// different behavior.
934 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
935 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000936 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000937 QualType ObjectType,
938 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000939
940 /// \brief Build a new nested-name-specifier given the prefix and the
941 /// namespace named in the next step in the nested-name-specifier.
942 ///
943 /// By default, performs semantic analysis when building the new
944 /// nested-name-specifier. Subclasses may override this routine to provide
945 /// different behavior.
946 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
947 SourceRange Range,
948 NamespaceDecl *NS);
949
950 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor7b26ff92011-02-24 02:36:08 +0000951 /// namespace alias named in the next step in the nested-name-specifier.
952 ///
953 /// By default, performs semantic analysis when building the new
954 /// nested-name-specifier. Subclasses may override this routine to provide
955 /// different behavior.
956 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
957 SourceRange Range,
958 NamespaceAliasDecl *Alias);
959
960 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor1135c352009-08-06 05:28:30 +0000961 /// type named in the next step in the nested-name-specifier.
962 ///
963 /// By default, performs semantic analysis when building the new
964 /// nested-name-specifier. Subclasses may override this routine to provide
965 /// different behavior.
966 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
967 SourceRange Range,
968 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000969 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000970
971 /// \brief Build a new template name given a nested name specifier, a flag
972 /// indicating whether the "template" keyword was provided, and the template
973 /// that the template name refers to.
974 ///
975 /// By default, builds the new template name directly. Subclasses may override
976 /// this routine to provide different behavior.
977 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
978 bool TemplateKW,
979 TemplateDecl *Template);
980
Douglas Gregor71dc5092009-08-06 06:41:21 +0000981 /// \brief Build a new template name given a nested name specifier and the
982 /// name that is referred to as a template.
983 ///
984 /// By default, performs semantic analysis to determine whether the name can
985 /// be resolved to a specific template, then builds the appropriate kind of
986 /// template name. Subclasses may override this routine to provide different
987 /// behavior.
988 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000989 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000990 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000991 QualType ObjectType,
992 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000993
Douglas Gregor71395fa2009-11-04 00:56:37 +0000994 /// \brief Build a new template name given a nested name specifier and the
995 /// overloaded operator name that is referred to as a template.
996 ///
997 /// By default, performs semantic analysis to determine whether the name can
998 /// be resolved to a specific template, then builds the appropriate kind of
999 /// template name. Subclasses may override this routine to provide different
1000 /// behavior.
1001 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
1002 OverloadedOperatorKind Operator,
1003 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001004
1005 /// \brief Build a new template name given a template template parameter pack
1006 /// and the
1007 ///
1008 /// By default, performs semantic analysis to determine whether the name can
1009 /// be resolved to a specific template, then builds the appropriate kind of
1010 /// template name. Subclasses may override this routine to provide different
1011 /// behavior.
1012 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1013 const TemplateArgument &ArgPack) {
1014 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1015 }
1016
Douglas Gregorebe10102009-08-20 07:17:43 +00001017 /// \brief Build a new compound statement.
1018 ///
1019 /// By default, performs semantic analysis to build the new statement.
1020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001021 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001022 MultiStmtArg Statements,
1023 SourceLocation RBraceLoc,
1024 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001025 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001026 IsStmtExpr);
1027 }
1028
1029 /// \brief Build a new case statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001033 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001034 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001035 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001036 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001037 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001038 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001039 ColonLoc);
1040 }
Mike Stump11289f42009-09-09 15:08:12 +00001041
Douglas Gregorebe10102009-08-20 07:17:43 +00001042 /// \brief Attach the body to a new case statement.
1043 ///
1044 /// By default, performs semantic analysis to build the new statement.
1045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001046 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001047 getSema().ActOnCaseStmtBody(S, Body);
1048 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001049 }
Mike Stump11289f42009-09-09 15:08:12 +00001050
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 /// \brief Build a new default statement.
1052 ///
1053 /// By default, performs semantic analysis to build the new statement.
1054 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001055 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001056 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001057 Stmt *SubStmt) {
1058 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 /*CurScope=*/0);
1060 }
Mike Stump11289f42009-09-09 15:08:12 +00001061
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 /// \brief Build a new label statement.
1063 ///
1064 /// By default, performs semantic analysis to build the new statement.
1065 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001066 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1067 SourceLocation ColonLoc, Stmt *SubStmt) {
1068 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001069 }
Mike Stump11289f42009-09-09 15:08:12 +00001070
Douglas Gregorebe10102009-08-20 07:17:43 +00001071 /// \brief Build a new "if" statement.
1072 ///
1073 /// By default, performs semantic analysis to build the new statement.
1074 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001075 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001076 VarDecl *CondVar, Stmt *Then,
1077 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001078 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 }
Mike Stump11289f42009-09-09 15:08:12 +00001080
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 /// \brief Start building a new switch statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001085 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001086 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001087 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001088 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001089 }
Mike Stump11289f42009-09-09 15:08:12 +00001090
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 /// \brief Attach the body to the switch statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001095 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001096 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001097 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001098 }
1099
1100 /// \brief Build a new while statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001104 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1105 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001106 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001107 }
Mike Stump11289f42009-09-09 15:08:12 +00001108
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 /// \brief Build a new do-while statement.
1110 ///
1111 /// By default, performs semantic analysis to build the new statement.
1112 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001113 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001114 SourceLocation WhileLoc, SourceLocation LParenLoc,
1115 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001116 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1117 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001118 }
1119
1120 /// \brief Build a new for statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001124 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1125 Stmt *Init, Sema::FullExprArg Cond,
1126 VarDecl *CondVar, Sema::FullExprArg Inc,
1127 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001128 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001129 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 }
Mike Stump11289f42009-09-09 15:08:12 +00001131
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 /// \brief Build a new goto statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001136 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1137 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001138 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 }
1140
1141 /// \brief Build a new indirect goto statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001145 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001146 SourceLocation StarLoc,
1147 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001148 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001149 }
Mike Stump11289f42009-09-09 15:08:12 +00001150
Douglas Gregorebe10102009-08-20 07:17:43 +00001151 /// \brief Build a new return statement.
1152 ///
1153 /// By default, performs semantic analysis to build the new statement.
1154 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001155 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001156 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001157 }
Mike Stump11289f42009-09-09 15:08:12 +00001158
Douglas Gregorebe10102009-08-20 07:17:43 +00001159 /// \brief Build a new declaration statement.
1160 ///
1161 /// By default, performs semantic analysis to build the new statement.
1162 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001163 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001164 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001165 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001166 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1167 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Anders Carlssonaaeef072010-01-24 05:50:09 +00001170 /// \brief Build a new inline asm statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001174 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001175 bool IsSimple,
1176 bool IsVolatile,
1177 unsigned NumOutputs,
1178 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001179 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001180 MultiExprArg Constraints,
1181 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001182 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001183 MultiExprArg Clobbers,
1184 SourceLocation RParenLoc,
1185 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001186 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001187 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001188 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001189 RParenLoc, MSAsm);
1190 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001191
1192 /// \brief Build a new Objective-C @try statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001196 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001197 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001198 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001199 Stmt *Finally) {
1200 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1201 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001202 }
1203
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001204 /// \brief Rebuild an Objective-C exception declaration.
1205 ///
1206 /// By default, performs semantic analysis to build the new declaration.
1207 /// Subclasses may override this routine to provide different behavior.
1208 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1209 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001210 return getSema().BuildObjCExceptionDecl(TInfo, T,
1211 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001212 ExceptionDecl->getLocation());
1213 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001214
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001215 /// \brief Build a new Objective-C @catch statement.
1216 ///
1217 /// By default, performs semantic analysis to build the new statement.
1218 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001219 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001220 SourceLocation RParenLoc,
1221 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001222 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001223 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001224 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001225 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001226
Douglas Gregor306de2f2010-04-22 23:59:56 +00001227 /// \brief Build a new Objective-C @finally statement.
1228 ///
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001231 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001232 Stmt *Body) {
1233 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001234 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001235
Douglas Gregor6148de72010-04-22 22:01:21 +00001236 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001237 ///
1238 /// By default, performs semantic analysis to build the new statement.
1239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001240 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001241 Expr *Operand) {
1242 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001243 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001244
Douglas Gregor6148de72010-04-22 22:01:21 +00001245 /// \brief Build a new Objective-C @synchronized statement.
1246 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001247 /// By default, performs semantic analysis to build the new statement.
1248 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001249 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001250 Expr *Object,
1251 Stmt *Body) {
1252 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1253 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001254 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001255
1256 /// \brief Build a new Objective-C fast enumeration statement.
1257 ///
1258 /// By default, performs semantic analysis to build the new statement.
1259 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001260 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001261 SourceLocation LParenLoc,
1262 Stmt *Element,
1263 Expr *Collection,
1264 SourceLocation RParenLoc,
1265 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001266 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001267 Element,
1268 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001269 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001270 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001271 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001272
Douglas Gregorebe10102009-08-20 07:17:43 +00001273 /// \brief Build a new C++ exception declaration.
1274 ///
1275 /// By default, performs semantic analysis to build the new decaration.
1276 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001277 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001278 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001279 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001280 SourceLocation Loc) {
1281 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001282 }
1283
1284 /// \brief Build a new C++ catch statement.
1285 ///
1286 /// By default, performs semantic analysis to build the new statement.
1287 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001288 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001289 VarDecl *ExceptionDecl,
1290 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001291 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1292 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001293 }
Mike Stump11289f42009-09-09 15:08:12 +00001294
Douglas Gregorebe10102009-08-20 07:17:43 +00001295 /// \brief Build a new C++ try statement.
1296 ///
1297 /// By default, performs semantic analysis to build the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001299 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001300 Stmt *TryBlock,
1301 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001302 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001303 }
Mike Stump11289f42009-09-09 15:08:12 +00001304
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 /// \brief Build a new expression that references a declaration.
1306 ///
1307 /// By default, performs semantic analysis to build the new expression.
1308 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001309 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001310 LookupResult &R,
1311 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001312 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1313 }
1314
1315
1316 /// \brief Build a new expression that references a declaration.
1317 ///
1318 /// By default, performs semantic analysis to build the new expression.
1319 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001320 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001321 ValueDecl *VD,
1322 const DeclarationNameInfo &NameInfo,
1323 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001324 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001325 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001326
1327 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001328
1329 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001333 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001336 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001338 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 }
1340
Douglas Gregorad8a3362009-09-04 17:36:40 +00001341 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001342 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001345 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001346 SourceLocation OperatorLoc,
1347 bool isArrow,
1348 CXXScopeSpec &SS,
1349 TypeSourceInfo *ScopeType,
1350 SourceLocation CCLoc,
1351 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001352 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001353
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001355 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001356 /// By default, performs semantic analysis to build the new expression.
1357 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001358 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001359 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001360 Expr *SubExpr) {
1361 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 }
Mike Stump11289f42009-09-09 15:08:12 +00001363
Douglas Gregor882211c2010-04-28 22:16:22 +00001364 /// \brief Build a new builtin offsetof expression.
1365 ///
1366 /// By default, performs semantic analysis to build the new expression.
1367 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001368 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001369 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001370 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001371 unsigned NumComponents,
1372 SourceLocation RParenLoc) {
1373 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1374 NumComponents, RParenLoc);
1375 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001376
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001378 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001379 /// By default, performs semantic analysis to build the new expression.
1380 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001381 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001382 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001384 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 }
1386
Mike Stump11289f42009-09-09 15:08:12 +00001387 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001388 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001389 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 /// By default, performs semantic analysis to build the new expression.
1391 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001392 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001394 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001395 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001396 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001397 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001398
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 return move(Result);
1400 }
Mike Stump11289f42009-09-09 15:08:12 +00001401
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001403 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001406 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001407 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001408 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001410 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1411 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 RBracketLoc);
1413 }
1414
1415 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001416 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001419 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001421 SourceLocation RParenLoc,
1422 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001423 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001424 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 }
1426
1427 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001428 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 /// By default, performs semantic analysis to build the new expression.
1430 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001431 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001432 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001433 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001434 const DeclarationNameInfo &MemberNameInfo,
1435 ValueDecl *Member,
1436 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001437 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001438 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001439 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001440 // We have a reference to an unnamed field. This is always the
1441 // base of an anonymous struct/union member access, i.e. the
1442 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001443 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001444 assert(Member->getType()->isRecordType() &&
1445 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001446
Douglas Gregorea972d32011-02-28 21:54:11 +00001447 if (getSema().PerformObjectMemberConversion(Base,
1448 QualifierLoc.getNestedNameSpecifier(),
John McCall16df1e52010-03-30 21:47:33 +00001449 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001450 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001451
John McCall7decc9e2010-11-18 06:31:45 +00001452 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001453 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001454 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001455 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001456 cast<FieldDecl>(Member)->getType(),
1457 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001458 return getSema().Owned(ME);
1459 }
Mike Stump11289f42009-09-09 15:08:12 +00001460
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001461 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001462 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001463
John McCallb268a282010-08-23 23:25:46 +00001464 getSema().DefaultFunctionArrayConversion(Base);
1465 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001466
John McCall16df1e52010-03-30 21:47:33 +00001467 // FIXME: this involves duplicating earlier analysis in a lot of
1468 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001469 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001470 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001471 R.resolveKind();
1472
John McCallb268a282010-08-23 23:25:46 +00001473 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001474 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001475 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001476 }
Mike Stump11289f42009-09-09 15:08:12 +00001477
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001479 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 /// By default, performs semantic analysis to build the new expression.
1481 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001482 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001483 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001484 Expr *LHS, Expr *RHS) {
1485 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 }
1487
1488 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001489 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 /// By default, performs semantic analysis to build the new expression.
1491 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001492 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001493 SourceLocation QuestionLoc,
1494 Expr *LHS,
1495 SourceLocation ColonLoc,
1496 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001497 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1498 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 }
1500
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001502 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 /// By default, performs semantic analysis to build the new expression.
1504 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001505 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001506 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001508 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001509 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001510 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 }
Mike Stump11289f42009-09-09 15:08:12 +00001512
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001514 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001517 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001518 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001520 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001521 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001522 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 }
Mike Stump11289f42009-09-09 15:08:12 +00001524
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001526 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001529 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 SourceLocation OpLoc,
1531 SourceLocation AccessorLoc,
1532 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001533
John McCall10eae182009-11-30 22:42:35 +00001534 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001535 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001536 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001537 OpLoc, /*IsArrow*/ false,
1538 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001539 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001540 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 }
Mike Stump11289f42009-09-09 15:08:12 +00001542
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001544 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001547 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001549 SourceLocation RBraceLoc,
1550 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001551 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001552 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1553 if (Result.isInvalid() || ResultTy->isDependentType())
1554 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001555
Douglas Gregord3d93062009-11-09 17:16:50 +00001556 // Patch in the result type we were given, which may have been computed
1557 // when the initial InitListExpr was built.
1558 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1559 ILE->setType(ResultTy);
1560 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 }
Mike Stump11289f42009-09-09 15:08:12 +00001562
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001564 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 /// By default, performs semantic analysis to build the new expression.
1566 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001567 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 MultiExprArg ArrayExprs,
1569 SourceLocation EqualOrColonLoc,
1570 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001571 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001572 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001574 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001576 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001577
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 ArrayExprs.release();
1579 return move(Result);
1580 }
Mike Stump11289f42009-09-09 15:08:12 +00001581
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001583 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 /// By default, builds the implicit value initialization without performing
1585 /// any semantic analysis. Subclasses may override this routine to provide
1586 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001587 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1589 }
Mike Stump11289f42009-09-09 15:08:12 +00001590
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001592 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 /// By default, performs semantic analysis to build the new expression.
1594 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001595 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001596 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001597 SourceLocation RParenLoc) {
1598 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001599 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001600 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 }
1602
1603 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001604 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 /// By default, performs semantic analysis to build the new expression.
1606 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001607 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 MultiExprArg SubExprs,
1609 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001610 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001611 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 }
Mike Stump11289f42009-09-09 15:08:12 +00001613
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001615 ///
1616 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 /// rather than attempting to map the label statement itself.
1618 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001619 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001620 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001621 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 }
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001625 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// By default, performs semantic analysis to build the new expression.
1627 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001628 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001629 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001631 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 }
Mike Stump11289f42009-09-09 15:08:12 +00001633
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 /// \brief Build a new __builtin_choose_expr expression.
1635 ///
1636 /// By default, performs semantic analysis to build the new expression.
1637 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001638 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001639 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SourceLocation RParenLoc) {
1641 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001642 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 RParenLoc);
1644 }
Mike Stump11289f42009-09-09 15:08:12 +00001645
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 /// \brief Build a new overloaded operator call expression.
1647 ///
1648 /// By default, performs semantic analysis to build the new expression.
1649 /// The semantic analysis provides the behavior of template instantiation,
1650 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001651 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 /// argument-dependent lookup, etc. Subclasses may override this routine to
1653 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001654 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001656 Expr *Callee,
1657 Expr *First,
1658 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001659
1660 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 /// reinterpret_cast.
1662 ///
1663 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001664 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001666 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 Stmt::StmtClass Class,
1668 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001669 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 SourceLocation RAngleLoc,
1671 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001672 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 SourceLocation RParenLoc) {
1674 switch (Class) {
1675 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001676 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001677 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001678 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001679
1680 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001681 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001682 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001683 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001684
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001686 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001687 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001688 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001690
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001692 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001693 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001694 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001695
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 default:
1697 assert(false && "Invalid C++ named cast");
1698 break;
1699 }
Mike Stump11289f42009-09-09 15:08:12 +00001700
John McCallfaf5fb42010-08-26 23:41:50 +00001701 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001702 }
Mike Stump11289f42009-09-09 15:08:12 +00001703
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 /// \brief Build a new C++ static_cast expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001708 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001710 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 SourceLocation RAngleLoc,
1712 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001713 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001715 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001716 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001717 SourceRange(LAngleLoc, RAngleLoc),
1718 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 }
1720
1721 /// \brief Build a new C++ dynamic_cast expression.
1722 ///
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001725 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001727 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 SourceLocation RAngleLoc,
1729 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001730 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001732 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001733 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001734 SourceRange(LAngleLoc, RAngleLoc),
1735 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 }
1737
1738 /// \brief Build a new C++ reinterpret_cast expression.
1739 ///
1740 /// By default, performs semantic analysis to build the new expression.
1741 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001742 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001744 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 SourceLocation RAngleLoc,
1746 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001747 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001749 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001750 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001751 SourceRange(LAngleLoc, RAngleLoc),
1752 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 }
1754
1755 /// \brief Build a new C++ const_cast expression.
1756 ///
1757 /// By default, performs semantic analysis to build the new expression.
1758 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001759 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001761 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 SourceLocation RAngleLoc,
1763 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001764 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001766 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001767 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001768 SourceRange(LAngleLoc, RAngleLoc),
1769 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 }
Mike Stump11289f42009-09-09 15:08:12 +00001771
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 /// \brief Build a new C++ functional-style cast expression.
1773 ///
1774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001776 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1777 SourceLocation LParenLoc,
1778 Expr *Sub,
1779 SourceLocation RParenLoc) {
1780 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001781 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 RParenLoc);
1783 }
Mike Stump11289f42009-09-09 15:08:12 +00001784
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 /// \brief Build a new C++ typeid(type) expression.
1786 ///
1787 /// By default, performs semantic analysis to build the new expression.
1788 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001789 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001790 SourceLocation TypeidLoc,
1791 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001793 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001794 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 }
Mike Stump11289f42009-09-09 15:08:12 +00001796
Francois Pichet9f4f2072010-09-08 12:20:18 +00001797
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 /// \brief Build a new C++ typeid(expr) expression.
1799 ///
1800 /// By default, performs semantic analysis to build the new expression.
1801 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001802 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001803 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001804 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001806 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001807 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001808 }
1809
Francois Pichet9f4f2072010-09-08 12:20:18 +00001810 /// \brief Build a new C++ __uuidof(type) expression.
1811 ///
1812 /// By default, performs semantic analysis to build the new expression.
1813 /// Subclasses may override this routine to provide different behavior.
1814 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1815 SourceLocation TypeidLoc,
1816 TypeSourceInfo *Operand,
1817 SourceLocation RParenLoc) {
1818 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1819 RParenLoc);
1820 }
1821
1822 /// \brief Build a new C++ __uuidof(expr) expression.
1823 ///
1824 /// By default, performs semantic analysis to build the new expression.
1825 /// Subclasses may override this routine to provide different behavior.
1826 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1827 SourceLocation TypeidLoc,
1828 Expr *Operand,
1829 SourceLocation RParenLoc) {
1830 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1831 RParenLoc);
1832 }
1833
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 /// \brief Build a new C++ "this" expression.
1835 ///
1836 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001837 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001839 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001840 QualType ThisType,
1841 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001843 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1844 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001845 }
1846
1847 /// \brief Build a new C++ throw expression.
1848 ///
1849 /// By default, performs semantic analysis to build the new expression.
1850 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001851 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001852 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 }
1854
1855 /// \brief Build a new C++ default-argument expression.
1856 ///
1857 /// By default, builds a new default-argument expression, which does not
1858 /// require any semantic analysis. Subclasses may override this routine to
1859 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001860 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001861 ParmVarDecl *Param) {
1862 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1863 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 }
1865
1866 /// \brief Build a new C++ zero-initialization expression.
1867 ///
1868 /// By default, performs semantic analysis to build the new expression.
1869 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001870 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1871 SourceLocation LParenLoc,
1872 SourceLocation RParenLoc) {
1873 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001874 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001875 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 }
Mike Stump11289f42009-09-09 15:08:12 +00001877
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 /// \brief Build a new C++ "new" expression.
1879 ///
1880 /// By default, performs semantic analysis to build the new expression.
1881 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001882 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001883 bool UseGlobal,
1884 SourceLocation PlacementLParen,
1885 MultiExprArg PlacementArgs,
1886 SourceLocation PlacementRParen,
1887 SourceRange TypeIdParens,
1888 QualType AllocatedType,
1889 TypeSourceInfo *AllocatedTypeInfo,
1890 Expr *ArraySize,
1891 SourceLocation ConstructorLParen,
1892 MultiExprArg ConstructorArgs,
1893 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001894 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 PlacementLParen,
1896 move(PlacementArgs),
1897 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001898 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001899 AllocatedType,
1900 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001901 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001902 ConstructorLParen,
1903 move(ConstructorArgs),
1904 ConstructorRParen);
1905 }
Mike Stump11289f42009-09-09 15:08:12 +00001906
Douglas Gregora16548e2009-08-11 05:31:07 +00001907 /// \brief Build a new C++ "delete" expression.
1908 ///
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001911 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 bool IsGlobalDelete,
1913 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001914 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001916 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 }
Mike Stump11289f42009-09-09 15:08:12 +00001918
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 /// \brief Build a new unary type trait expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001923 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001924 SourceLocation StartLoc,
1925 TypeSourceInfo *T,
1926 SourceLocation RParenLoc) {
1927 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 }
1929
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001930 /// \brief Build a new binary type trait expression.
1931 ///
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
1934 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1935 SourceLocation StartLoc,
1936 TypeSourceInfo *LhsT,
1937 TypeSourceInfo *RhsT,
1938 SourceLocation RParenLoc) {
1939 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1940 }
1941
Mike Stump11289f42009-09-09 15:08:12 +00001942 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001947 ExprResult RebuildDependentScopeDeclRefExpr(
1948 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001949 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001950 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001952 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001953
1954 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001955 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001956 *TemplateArgs);
1957
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001958 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 }
1960
1961 /// \brief Build a new template-id expression.
1962 ///
1963 /// By default, performs semantic analysis to build the new expression.
1964 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001965 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001966 LookupResult &R,
1967 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001968 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001969 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 }
1971
1972 /// \brief Build a new object-construction expression.
1973 ///
1974 /// By default, performs semantic analysis to build the new expression.
1975 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001976 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001977 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 CXXConstructorDecl *Constructor,
1979 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001980 MultiExprArg Args,
1981 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001982 CXXConstructExpr::ConstructionKind ConstructKind,
1983 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001984 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001985 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001986 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001987 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001988
Douglas Gregordb121ba2009-12-14 16:27:04 +00001989 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001990 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001991 RequiresZeroInit, ConstructKind,
1992 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 }
1994
1995 /// \brief Build a new object-construction expression.
1996 ///
1997 /// By default, performs semantic analysis to build the new expression.
1998 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001999 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2000 SourceLocation LParenLoc,
2001 MultiExprArg Args,
2002 SourceLocation RParenLoc) {
2003 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 LParenLoc,
2005 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 RParenLoc);
2007 }
2008
2009 /// \brief Build a new object-construction expression.
2010 ///
2011 /// By default, performs semantic analysis to build the new expression.
2012 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002013 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2014 SourceLocation LParenLoc,
2015 MultiExprArg Args,
2016 SourceLocation RParenLoc) {
2017 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 LParenLoc,
2019 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 RParenLoc);
2021 }
Mike Stump11289f42009-09-09 15:08:12 +00002022
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 /// \brief Build a new member reference expression.
2024 ///
2025 /// By default, performs semantic analysis to build the new expression.
2026 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002027 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002028 QualType BaseType,
2029 bool IsArrow,
2030 SourceLocation OperatorLoc,
2031 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002032 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002033 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002034 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002036 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002037
John McCallb268a282010-08-23 23:25:46 +00002038 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002039 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002040 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002041 MemberNameInfo,
2042 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 }
2044
John McCall10eae182009-11-30 22:42:35 +00002045 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002046 ///
2047 /// By default, performs semantic analysis to build the new expression.
2048 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002049 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002050 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002051 SourceLocation OperatorLoc,
2052 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002053 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002054 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002055 LookupResult &R,
2056 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002057 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002058 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002059
John McCallb268a282010-08-23 23:25:46 +00002060 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002061 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002062 SS, FirstQualifierInScope,
2063 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002064 }
Mike Stump11289f42009-09-09 15:08:12 +00002065
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002066 /// \brief Build a new noexcept expression.
2067 ///
2068 /// By default, performs semantic analysis to build the new expression.
2069 /// Subclasses may override this routine to provide different behavior.
2070 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2071 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2072 }
2073
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002074 /// \brief Build a new expression to compute the length of a parameter pack.
2075 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2076 SourceLocation PackLoc,
2077 SourceLocation RParenLoc,
2078 unsigned Length) {
2079 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2080 OperatorLoc, Pack, PackLoc,
2081 RParenLoc, Length);
2082 }
2083
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 /// \brief Build a new Objective-C @encode expression.
2085 ///
2086 /// By default, performs semantic analysis to build the new expression.
2087 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002088 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002089 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002090 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002091 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002093 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002094
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002095 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002096 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002097 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002098 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002099 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002100 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002101 MultiExprArg Args,
2102 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002103 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2104 ReceiverTypeInfo->getType(),
2105 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002106 Sel, Method, LBracLoc, SelectorLoc,
2107 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002108 }
2109
2110 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002111 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002112 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002113 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002114 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002115 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002116 MultiExprArg Args,
2117 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002118 return SemaRef.BuildInstanceMessage(Receiver,
2119 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002120 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002121 Sel, Method, LBracLoc, SelectorLoc,
2122 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002123 }
2124
Douglas Gregord51d90d2010-04-26 20:11:03 +00002125 /// \brief Build a new Objective-C ivar reference expression.
2126 ///
2127 /// By default, performs semantic analysis to build the new expression.
2128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002129 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002130 SourceLocation IvarLoc,
2131 bool IsArrow, bool IsFreeIvar) {
2132 // FIXME: We lose track of the IsFreeIvar bit.
2133 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002134 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002135 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2136 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002138 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002139 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002140 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002141 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002142 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002143
Douglas Gregord51d90d2010-04-26 20:11:03 +00002144 if (Result.get())
2145 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002146
John McCallb268a282010-08-23 23:25:46 +00002147 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002148 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002149 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002150 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002151 /*TemplateArgs=*/0);
2152 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002153
2154 /// \brief Build a new Objective-C property reference expression.
2155 ///
2156 /// By default, performs semantic analysis to build the new expression.
2157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002158 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002159 ObjCPropertyDecl *Property,
2160 SourceLocation PropertyLoc) {
2161 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002162 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002163 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2164 Sema::LookupMemberName);
2165 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002166 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002167 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002168 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002169 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002170 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002171
Douglas Gregor9faee212010-04-26 20:47:02 +00002172 if (Result.get())
2173 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002174
John McCallb268a282010-08-23 23:25:46 +00002175 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002176 /*FIXME:*/PropertyLoc, IsArrow,
2177 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002178 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002179 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002180 /*TemplateArgs=*/0);
2181 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002182
John McCallb7bd14f2010-12-02 01:19:52 +00002183 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002184 ///
2185 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002186 /// Subclasses may override this routine to provide different behavior.
2187 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2188 ObjCMethodDecl *Getter,
2189 ObjCMethodDecl *Setter,
2190 SourceLocation PropertyLoc) {
2191 // Since these expressions can only be value-dependent, we do not
2192 // need to perform semantic analysis again.
2193 return Owned(
2194 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2195 VK_LValue, OK_ObjCProperty,
2196 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002197 }
2198
Douglas Gregord51d90d2010-04-26 20:11:03 +00002199 /// \brief Build a new Objective-C "isa" expression.
2200 ///
2201 /// By default, performs semantic analysis to build the new expression.
2202 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002203 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002204 bool IsArrow) {
2205 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002206 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002207 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2208 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002209 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002210 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002211 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002212 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002213 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002214
Douglas Gregord51d90d2010-04-26 20:11:03 +00002215 if (Result.get())
2216 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002217
John McCallb268a282010-08-23 23:25:46 +00002218 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002219 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002220 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002221 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002222 /*TemplateArgs=*/0);
2223 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002224
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 /// \brief Build a new shuffle vector expression.
2226 ///
2227 /// By default, performs semantic analysis to build the new expression.
2228 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002229 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002230 MultiExprArg SubExprs,
2231 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002233 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2235 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2236 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2237 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002238
Douglas Gregora16548e2009-08-11 05:31:07 +00002239 // Build a reference to the __builtin_shufflevector builtin
2240 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002241 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002243 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002244 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002245
2246 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 unsigned NumSubExprs = SubExprs.size();
2248 Expr **Subs = (Expr **)SubExprs.release();
2249 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2250 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002251 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002252 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002253 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002254 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002255
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002257 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002259 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002260
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002262 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002263 }
John McCall31f82722010-11-12 08:19:04 +00002264
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002265 /// \brief Build a new template argument pack expansion.
2266 ///
2267 /// By default, performs semantic analysis to build a new pack expansion
2268 /// for a template argument. Subclasses may override this routine to provide
2269 /// different behavior.
2270 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002271 SourceLocation EllipsisLoc,
2272 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002273 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002274 case TemplateArgument::Expression: {
2275 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002276 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2277 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002278 if (Result.isInvalid())
2279 return TemplateArgumentLoc();
2280
2281 return TemplateArgumentLoc(Result.get(), Result.get());
2282 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002283
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002284 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002285 return TemplateArgumentLoc(TemplateArgument(
2286 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002287 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002288 Pattern.getTemplateQualifierRange(),
2289 Pattern.getTemplateNameLoc(),
2290 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002291
2292 case TemplateArgument::Null:
2293 case TemplateArgument::Integral:
2294 case TemplateArgument::Declaration:
2295 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002296 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002297 llvm_unreachable("Pack expansion pattern has no parameter packs");
2298
2299 case TemplateArgument::Type:
2300 if (TypeSourceInfo *Expansion
2301 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002302 EllipsisLoc,
2303 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002304 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2305 Expansion);
2306 break;
2307 }
2308
2309 return TemplateArgumentLoc();
2310 }
2311
Douglas Gregor968f23a2011-01-03 19:31:53 +00002312 /// \brief Build a new expression pack expansion.
2313 ///
2314 /// By default, performs semantic analysis to build a new pack expansion
2315 /// for an expression. Subclasses may override this routine to provide
2316 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002317 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2318 llvm::Optional<unsigned> NumExpansions) {
2319 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002320 }
2321
John McCall31f82722010-11-12 08:19:04 +00002322private:
2323 QualType TransformTypeInObjectScope(QualType T,
2324 QualType ObjectType,
2325 NamedDecl *FirstQualifierInScope,
2326 NestedNameSpecifier *Prefix);
2327
2328 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2329 QualType ObjectType,
2330 NamedDecl *FirstQualifierInScope,
2331 NestedNameSpecifier *Prefix);
Douglas Gregor14454802011-02-25 02:25:35 +00002332
2333 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2334 QualType ObjectType,
2335 NamedDecl *FirstQualifierInScope,
2336 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002337};
Douglas Gregora16548e2009-08-11 05:31:07 +00002338
Douglas Gregorebe10102009-08-20 07:17:43 +00002339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002340StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002341 if (!S)
2342 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002343
Douglas Gregorebe10102009-08-20 07:17:43 +00002344 switch (S->getStmtClass()) {
2345 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002346
Douglas Gregorebe10102009-08-20 07:17:43 +00002347 // Transform individual statement nodes
2348#define STMT(Node, Parent) \
2349 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002350#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002351#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002352#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002353
Douglas Gregorebe10102009-08-20 07:17:43 +00002354 // Transform expressions by calling TransformExpr.
2355#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002356#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002357#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002358#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002359 {
John McCalldadc5752010-08-24 06:29:42 +00002360 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002361 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002362 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002363
John McCallb268a282010-08-23 23:25:46 +00002364 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002365 }
Mike Stump11289f42009-09-09 15:08:12 +00002366 }
2367
John McCallc3007a22010-10-26 07:05:15 +00002368 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002369}
Mike Stump11289f42009-09-09 15:08:12 +00002370
2371
Douglas Gregore922c772009-08-04 22:27:00 +00002372template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002373ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002374 if (!E)
2375 return SemaRef.Owned(E);
2376
2377 switch (E->getStmtClass()) {
2378 case Stmt::NoStmtClass: break;
2379#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002380#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002381#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002382 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002383#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002384 }
2385
John McCallc3007a22010-10-26 07:05:15 +00002386 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002387}
2388
2389template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002390bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2391 unsigned NumInputs,
2392 bool IsCall,
2393 llvm::SmallVectorImpl<Expr *> &Outputs,
2394 bool *ArgChanged) {
2395 for (unsigned I = 0; I != NumInputs; ++I) {
2396 // If requested, drop call arguments that need to be dropped.
2397 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2398 if (ArgChanged)
2399 *ArgChanged = true;
2400
2401 break;
2402 }
2403
Douglas Gregor968f23a2011-01-03 19:31:53 +00002404 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2405 Expr *Pattern = Expansion->getPattern();
2406
2407 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2408 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2409 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2410
2411 // Determine whether the set of unexpanded parameter packs can and should
2412 // be expanded.
2413 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002414 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002415 llvm::Optional<unsigned> OrigNumExpansions
2416 = Expansion->getNumExpansions();
2417 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002418 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2419 Pattern->getSourceRange(),
2420 Unexpanded.data(),
2421 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002422 Expand, RetainExpansion,
2423 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002424 return true;
2425
2426 if (!Expand) {
2427 // The transform has determined that we should perform a simple
2428 // transformation on the pack expansion, producing another pack
2429 // expansion.
2430 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2431 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2432 if (OutPattern.isInvalid())
2433 return true;
2434
2435 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002436 Expansion->getEllipsisLoc(),
2437 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002438 if (Out.isInvalid())
2439 return true;
2440
2441 if (ArgChanged)
2442 *ArgChanged = true;
2443 Outputs.push_back(Out.get());
2444 continue;
2445 }
2446
2447 // The transform has determined that we should perform an elementwise
2448 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002449 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002450 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2451 ExprResult Out = getDerived().TransformExpr(Pattern);
2452 if (Out.isInvalid())
2453 return true;
2454
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002455 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002456 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2457 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002458 if (Out.isInvalid())
2459 return true;
2460 }
2461
Douglas Gregor968f23a2011-01-03 19:31:53 +00002462 if (ArgChanged)
2463 *ArgChanged = true;
2464 Outputs.push_back(Out.get());
2465 }
2466
2467 continue;
2468 }
2469
Douglas Gregora3efea12011-01-03 19:04:46 +00002470 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2471 if (Result.isInvalid())
2472 return true;
2473
2474 if (Result.get() != Inputs[I] && ArgChanged)
2475 *ArgChanged = true;
2476
2477 Outputs.push_back(Result.get());
2478 }
2479
2480 return false;
2481}
2482
2483template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002484NestedNameSpecifier *
2485TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002486 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002487 QualType ObjectType,
2488 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002489 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002490
Douglas Gregorebe10102009-08-20 07:17:43 +00002491 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002492 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002493 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002494 ObjectType,
2495 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002496 if (!Prefix)
2497 return 0;
2498 }
Mike Stump11289f42009-09-09 15:08:12 +00002499
Douglas Gregor1135c352009-08-06 05:28:30 +00002500 switch (NNS->getKind()) {
2501 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002502 if (Prefix) {
2503 // The object type and qualifier-in-scope really apply to the
2504 // leftmost entity.
2505 ObjectType = QualType();
2506 FirstQualifierInScope = 0;
2507 }
2508
Mike Stump11289f42009-09-09 15:08:12 +00002509 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002510 "Identifier nested-name-specifier with no prefix or object type");
2511 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2512 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002513 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002514
2515 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002516 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002517 ObjectType,
2518 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002519
Douglas Gregor1135c352009-08-06 05:28:30 +00002520 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002521 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002522 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002523 getDerived().TransformDecl(Range.getBegin(),
2524 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002525 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002526 Prefix == NNS->getPrefix() &&
2527 NS == NNS->getAsNamespace())
2528 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002529
Douglas Gregor1135c352009-08-06 05:28:30 +00002530 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2531 }
Mike Stump11289f42009-09-09 15:08:12 +00002532
Douglas Gregor7b26ff92011-02-24 02:36:08 +00002533 case NestedNameSpecifier::NamespaceAlias: {
2534 NamespaceAliasDecl *Alias
2535 = cast_or_null<NamespaceAliasDecl>(
2536 getDerived().TransformDecl(Range.getBegin(),
2537 NNS->getAsNamespaceAlias()));
2538 if (!getDerived().AlwaysRebuild() &&
2539 Prefix == NNS->getPrefix() &&
2540 Alias == NNS->getAsNamespaceAlias())
2541 return NNS;
2542
2543 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias);
2544 }
2545
Douglas Gregor1135c352009-08-06 05:28:30 +00002546 case NestedNameSpecifier::Global:
2547 // There is no meaningful transformation that one could perform on the
2548 // global scope.
2549 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002550
Douglas Gregor1135c352009-08-06 05:28:30 +00002551 case NestedNameSpecifier::TypeSpecWithTemplate:
2552 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002553 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002554 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2555 ObjectType,
2556 FirstQualifierInScope,
2557 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002558 if (T.isNull())
2559 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002560
Douglas Gregor1135c352009-08-06 05:28:30 +00002561 if (!getDerived().AlwaysRebuild() &&
2562 Prefix == NNS->getPrefix() &&
2563 T == QualType(NNS->getAsType(), 0))
2564 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002565
2566 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2567 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002568 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002569 }
2570 }
Mike Stump11289f42009-09-09 15:08:12 +00002571
Douglas Gregor1135c352009-08-06 05:28:30 +00002572 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002573 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002574}
2575
2576template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002577NestedNameSpecifierLoc
2578TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2579 NestedNameSpecifierLoc NNS,
2580 QualType ObjectType,
2581 NamedDecl *FirstQualifierInScope) {
2582 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2583 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2584 Qualifier = Qualifier.getPrefix())
2585 Qualifiers.push_back(Qualifier);
2586
2587 CXXScopeSpec SS;
2588 while (!Qualifiers.empty()) {
2589 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2590 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2591
2592 switch (QNNS->getKind()) {
2593 case NestedNameSpecifier::Identifier:
2594 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2595 *QNNS->getAsIdentifier(),
2596 Q.getLocalBeginLoc(),
2597 Q.getLocalEndLoc(),
2598 ObjectType, false, SS,
2599 FirstQualifierInScope, false))
2600 return NestedNameSpecifierLoc();
2601
2602 break;
2603
2604 case NestedNameSpecifier::Namespace: {
2605 NamespaceDecl *NS
2606 = cast_or_null<NamespaceDecl>(
2607 getDerived().TransformDecl(
2608 Q.getLocalBeginLoc(),
2609 QNNS->getAsNamespace()));
2610 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2611 break;
2612 }
2613
2614 case NestedNameSpecifier::NamespaceAlias: {
2615 NamespaceAliasDecl *Alias
2616 = cast_or_null<NamespaceAliasDecl>(
2617 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2618 QNNS->getAsNamespaceAlias()));
2619 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2620 Q.getLocalEndLoc());
2621 break;
2622 }
2623
2624 case NestedNameSpecifier::Global:
2625 // There is no meaningful transformation that one could perform on the
2626 // global scope.
2627 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2628 break;
2629
2630 case NestedNameSpecifier::TypeSpecWithTemplate:
2631 case NestedNameSpecifier::TypeSpec: {
2632 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2633 FirstQualifierInScope, SS);
2634
2635 if (!TL)
2636 return NestedNameSpecifierLoc();
2637
2638 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2639 (SemaRef.getLangOptions().CPlusPlus0x &&
2640 TL.getType()->isEnumeralType())) {
2641 assert(!TL.getType().hasLocalQualifiers() &&
2642 "Can't get cv-qualifiers here");
2643 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2644 Q.getLocalEndLoc());
2645 break;
2646 }
2647
2648 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2649 << TL.getType() << SS.getRange();
2650 return NestedNameSpecifierLoc();
2651 }
Douglas Gregore16af532011-02-28 18:50:33 +00002652 }
Douglas Gregor14454802011-02-25 02:25:35 +00002653
Douglas Gregore16af532011-02-28 18:50:33 +00002654 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002655 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002656 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002657 }
2658
2659 // Don't rebuild the nested-name-specifier if we don't have to.
2660 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2661 !getDerived().AlwaysRebuild())
2662 return NNS;
2663
2664 // If we can re-use the source-location data from the original
2665 // nested-name-specifier, do so.
2666 if (SS.location_size() == NNS.getDataLength() &&
2667 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2668 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2669
2670 // Allocate new nested-name-specifier location information.
2671 return SS.getWithLocInContext(SemaRef.Context);
2672}
2673
2674template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002675DeclarationNameInfo
2676TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002677::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002678 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002679 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002680 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002681
2682 switch (Name.getNameKind()) {
2683 case DeclarationName::Identifier:
2684 case DeclarationName::ObjCZeroArgSelector:
2685 case DeclarationName::ObjCOneArgSelector:
2686 case DeclarationName::ObjCMultiArgSelector:
2687 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002688 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002689 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002690 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002691
Douglas Gregorf816bd72009-09-03 22:13:48 +00002692 case DeclarationName::CXXConstructorName:
2693 case DeclarationName::CXXDestructorName:
2694 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002695 TypeSourceInfo *NewTInfo;
2696 CanQualType NewCanTy;
2697 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002698 NewTInfo = getDerived().TransformType(OldTInfo);
2699 if (!NewTInfo)
2700 return DeclarationNameInfo();
2701 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002702 }
2703 else {
2704 NewTInfo = 0;
2705 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002706 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002707 if (NewT.isNull())
2708 return DeclarationNameInfo();
2709 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2710 }
Mike Stump11289f42009-09-09 15:08:12 +00002711
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002712 DeclarationName NewName
2713 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2714 NewCanTy);
2715 DeclarationNameInfo NewNameInfo(NameInfo);
2716 NewNameInfo.setName(NewName);
2717 NewNameInfo.setNamedTypeInfo(NewTInfo);
2718 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002719 }
Mike Stump11289f42009-09-09 15:08:12 +00002720 }
2721
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002722 assert(0 && "Unknown name kind.");
2723 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002724}
2725
2726template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002727TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002728TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002729 QualType ObjectType,
2730 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002731 SourceLocation Loc = getDerived().getBaseLocation();
2732
Douglas Gregor71dc5092009-08-06 06:41:21 +00002733 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002734 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002735 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002736 /*FIXME*/ SourceRange(Loc),
2737 ObjectType,
2738 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002739 if (!NNS)
2740 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002741
Douglas Gregor71dc5092009-08-06 06:41:21 +00002742 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002743 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002744 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002745 if (!TransTemplate)
2746 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002747
Douglas Gregor71dc5092009-08-06 06:41:21 +00002748 if (!getDerived().AlwaysRebuild() &&
2749 NNS == QTN->getQualifier() &&
2750 TransTemplate == Template)
2751 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002752
Douglas Gregor71dc5092009-08-06 06:41:21 +00002753 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2754 TransTemplate);
2755 }
Mike Stump11289f42009-09-09 15:08:12 +00002756
John McCalle66edc12009-11-24 19:00:30 +00002757 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002758 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002759 }
Mike Stump11289f42009-09-09 15:08:12 +00002760
Douglas Gregor71dc5092009-08-06 06:41:21 +00002761 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002762 NestedNameSpecifier *NNS = DTN->getQualifier();
2763 if (NNS) {
2764 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2765 /*FIXME:*/SourceRange(Loc),
2766 ObjectType,
2767 FirstQualifierInScope);
2768 if (!NNS) return TemplateName();
2769
2770 // These apply to the scope specifier, not the template.
2771 ObjectType = QualType();
2772 FirstQualifierInScope = 0;
2773 }
Mike Stump11289f42009-09-09 15:08:12 +00002774
Douglas Gregor71dc5092009-08-06 06:41:21 +00002775 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002776 NNS == DTN->getQualifier() &&
2777 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002778 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002779
Douglas Gregora5614c52010-09-08 23:56:00 +00002780 if (DTN->isIdentifier()) {
2781 // FIXME: Bad range
2782 SourceRange QualifierRange(getDerived().getBaseLocation());
2783 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2784 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002785 ObjectType,
2786 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002787 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002788
2789 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002790 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002791 }
Mike Stump11289f42009-09-09 15:08:12 +00002792
Douglas Gregor71dc5092009-08-06 06:41:21 +00002793 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002794 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002795 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002796 if (!TransTemplate)
2797 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002798
Douglas Gregor71dc5092009-08-06 06:41:21 +00002799 if (!getDerived().AlwaysRebuild() &&
2800 TransTemplate == Template)
2801 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002802
Douglas Gregor71dc5092009-08-06 06:41:21 +00002803 return TemplateName(TransTemplate);
2804 }
Mike Stump11289f42009-09-09 15:08:12 +00002805
Douglas Gregor5590be02011-01-15 06:45:20 +00002806 if (SubstTemplateTemplateParmPackStorage *SubstPack
2807 = Name.getAsSubstTemplateTemplateParmPack()) {
2808 TemplateTemplateParmDecl *TransParam
2809 = cast_or_null<TemplateTemplateParmDecl>(
2810 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2811 if (!TransParam)
2812 return TemplateName();
2813
2814 if (!getDerived().AlwaysRebuild() &&
2815 TransParam == SubstPack->getParameterPack())
2816 return Name;
2817
2818 return getDerived().RebuildTemplateName(TransParam,
2819 SubstPack->getArgumentPack());
2820 }
2821
John McCalle66edc12009-11-24 19:00:30 +00002822 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002823 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002824 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002825}
2826
2827template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002828void TreeTransform<Derived>::InventTemplateArgumentLoc(
2829 const TemplateArgument &Arg,
2830 TemplateArgumentLoc &Output) {
2831 SourceLocation Loc = getDerived().getBaseLocation();
2832 switch (Arg.getKind()) {
2833 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002834 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002835 break;
2836
2837 case TemplateArgument::Type:
2838 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002839 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002840
John McCall0ad16662009-10-29 08:12:44 +00002841 break;
2842
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002843 case TemplateArgument::Template:
2844 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2845 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002846
2847 case TemplateArgument::TemplateExpansion:
2848 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2849 break;
2850
John McCall0ad16662009-10-29 08:12:44 +00002851 case TemplateArgument::Expression:
2852 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2853 break;
2854
2855 case TemplateArgument::Declaration:
2856 case TemplateArgument::Integral:
2857 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002858 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002859 break;
2860 }
2861}
2862
2863template<typename Derived>
2864bool TreeTransform<Derived>::TransformTemplateArgument(
2865 const TemplateArgumentLoc &Input,
2866 TemplateArgumentLoc &Output) {
2867 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002868 switch (Arg.getKind()) {
2869 case TemplateArgument::Null:
2870 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002871 Output = Input;
2872 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002873
Douglas Gregore922c772009-08-04 22:27:00 +00002874 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002875 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002876 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002877 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002878
2879 DI = getDerived().TransformType(DI);
2880 if (!DI) return true;
2881
2882 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2883 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002884 }
Mike Stump11289f42009-09-09 15:08:12 +00002885
Douglas Gregore922c772009-08-04 22:27:00 +00002886 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002887 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002888 DeclarationName Name;
2889 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2890 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002891 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002892 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002893 if (!D) return true;
2894
John McCall0d07eb32009-10-29 18:45:58 +00002895 Expr *SourceExpr = Input.getSourceDeclExpression();
2896 if (SourceExpr) {
2897 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002898 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002899 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002900 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002901 }
2902
2903 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002904 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002905 }
Mike Stump11289f42009-09-09 15:08:12 +00002906
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002907 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002908 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002909 TemplateName Template
2910 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2911 if (Template.isNull())
2912 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002913
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002914 Output = TemplateArgumentLoc(TemplateArgument(Template),
2915 Input.getTemplateQualifierRange(),
2916 Input.getTemplateNameLoc());
2917 return false;
2918 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002919
2920 case TemplateArgument::TemplateExpansion:
2921 llvm_unreachable("Caller should expand pack expansions");
2922
Douglas Gregore922c772009-08-04 22:27:00 +00002923 case TemplateArgument::Expression: {
2924 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002925 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002926 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002927
John McCall0ad16662009-10-29 08:12:44 +00002928 Expr *InputExpr = Input.getSourceExpression();
2929 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2930
John McCalldadc5752010-08-24 06:29:42 +00002931 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002932 = getDerived().TransformExpr(InputExpr);
2933 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002934 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002935 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002936 }
Mike Stump11289f42009-09-09 15:08:12 +00002937
Douglas Gregore922c772009-08-04 22:27:00 +00002938 case TemplateArgument::Pack: {
2939 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2940 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002941 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002942 AEnd = Arg.pack_end();
2943 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002944
John McCall0ad16662009-10-29 08:12:44 +00002945 // FIXME: preserve source information here when we start
2946 // caring about parameter packs.
2947
John McCall0d07eb32009-10-29 18:45:58 +00002948 TemplateArgumentLoc InputArg;
2949 TemplateArgumentLoc OutputArg;
2950 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2951 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002952 return true;
2953
John McCall0d07eb32009-10-29 18:45:58 +00002954 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002955 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002956
2957 TemplateArgument *TransformedArgsPtr
2958 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2959 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2960 TransformedArgsPtr);
2961 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2962 TransformedArgs.size()),
2963 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002964 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002965 }
2966 }
Mike Stump11289f42009-09-09 15:08:12 +00002967
Douglas Gregore922c772009-08-04 22:27:00 +00002968 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002969 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002970}
2971
Douglas Gregorfe921a72010-12-20 23:36:19 +00002972/// \brief Iterator adaptor that invents template argument location information
2973/// for each of the template arguments in its underlying iterator.
2974template<typename Derived, typename InputIterator>
2975class TemplateArgumentLocInventIterator {
2976 TreeTransform<Derived> &Self;
2977 InputIterator Iter;
2978
2979public:
2980 typedef TemplateArgumentLoc value_type;
2981 typedef TemplateArgumentLoc reference;
2982 typedef typename std::iterator_traits<InputIterator>::difference_type
2983 difference_type;
2984 typedef std::input_iterator_tag iterator_category;
2985
2986 class pointer {
2987 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002988
Douglas Gregorfe921a72010-12-20 23:36:19 +00002989 public:
2990 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2991
2992 const TemplateArgumentLoc *operator->() const { return &Arg; }
2993 };
2994
2995 TemplateArgumentLocInventIterator() { }
2996
2997 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2998 InputIterator Iter)
2999 : Self(Self), Iter(Iter) { }
3000
3001 TemplateArgumentLocInventIterator &operator++() {
3002 ++Iter;
3003 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003004 }
3005
Douglas Gregorfe921a72010-12-20 23:36:19 +00003006 TemplateArgumentLocInventIterator operator++(int) {
3007 TemplateArgumentLocInventIterator Old(*this);
3008 ++(*this);
3009 return Old;
3010 }
3011
3012 reference operator*() const {
3013 TemplateArgumentLoc Result;
3014 Self.InventTemplateArgumentLoc(*Iter, Result);
3015 return Result;
3016 }
3017
3018 pointer operator->() const { return pointer(**this); }
3019
3020 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3021 const TemplateArgumentLocInventIterator &Y) {
3022 return X.Iter == Y.Iter;
3023 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003024
Douglas Gregorfe921a72010-12-20 23:36:19 +00003025 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3026 const TemplateArgumentLocInventIterator &Y) {
3027 return X.Iter != Y.Iter;
3028 }
3029};
3030
Douglas Gregor42cafa82010-12-20 17:42:22 +00003031template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003032template<typename InputIterator>
3033bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3034 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003035 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003036 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003037 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003038 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003039
3040 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3041 // Unpack argument packs, which we translate them into separate
3042 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003043 // FIXME: We could do much better if we could guarantee that the
3044 // TemplateArgumentLocInfo for the pack expansion would be usable for
3045 // all of the template arguments in the argument pack.
3046 typedef TemplateArgumentLocInventIterator<Derived,
3047 TemplateArgument::pack_iterator>
3048 PackLocIterator;
3049 if (TransformTemplateArguments(PackLocIterator(*this,
3050 In.getArgument().pack_begin()),
3051 PackLocIterator(*this,
3052 In.getArgument().pack_end()),
3053 Outputs))
3054 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003055
3056 continue;
3057 }
3058
3059 if (In.getArgument().isPackExpansion()) {
3060 // We have a pack expansion, for which we will be substituting into
3061 // the pattern.
3062 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003063 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003064 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003065 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3066 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003067
3068 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3069 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3070 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3071
3072 // Determine whether the set of unexpanded parameter packs can and should
3073 // be expanded.
3074 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003075 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003076 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003077 if (getDerived().TryExpandParameterPacks(Ellipsis,
3078 Pattern.getSourceRange(),
3079 Unexpanded.data(),
3080 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003081 Expand,
3082 RetainExpansion,
3083 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003084 return true;
3085
3086 if (!Expand) {
3087 // The transform has determined that we should perform a simple
3088 // transformation on the pack expansion, producing another pack
3089 // expansion.
3090 TemplateArgumentLoc OutPattern;
3091 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3092 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3093 return true;
3094
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003095 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3096 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003097 if (Out.getArgument().isNull())
3098 return true;
3099
3100 Outputs.addArgument(Out);
3101 continue;
3102 }
3103
3104 // The transform has determined that we should perform an elementwise
3105 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003106 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003107 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3108
3109 if (getDerived().TransformTemplateArgument(Pattern, Out))
3110 return true;
3111
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003112 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003113 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3114 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003115 if (Out.getArgument().isNull())
3116 return true;
3117 }
3118
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003119 Outputs.addArgument(Out);
3120 }
3121
Douglas Gregor48d24112011-01-10 20:53:55 +00003122 // If we're supposed to retain a pack expansion, do so by temporarily
3123 // forgetting the partially-substituted parameter pack.
3124 if (RetainExpansion) {
3125 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3126
3127 if (getDerived().TransformTemplateArgument(Pattern, Out))
3128 return true;
3129
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003130 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3131 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003132 if (Out.getArgument().isNull())
3133 return true;
3134
3135 Outputs.addArgument(Out);
3136 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003137
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003138 continue;
3139 }
3140
3141 // The simple case:
3142 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003143 return true;
3144
3145 Outputs.addArgument(Out);
3146 }
3147
3148 return false;
3149
3150}
3151
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152//===----------------------------------------------------------------------===//
3153// Type transformation
3154//===----------------------------------------------------------------------===//
3155
3156template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003157QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003158 if (getDerived().AlreadyTransformed(T))
3159 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003160
John McCall550e0c22009-10-21 00:40:46 +00003161 // Temporary workaround. All of these transformations should
3162 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003163 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3164 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003165
John McCall31f82722010-11-12 08:19:04 +00003166 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003167
John McCall550e0c22009-10-21 00:40:46 +00003168 if (!NewDI)
3169 return QualType();
3170
3171 return NewDI->getType();
3172}
3173
3174template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003175TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003176 if (getDerived().AlreadyTransformed(DI->getType()))
3177 return DI;
3178
3179 TypeLocBuilder TLB;
3180
3181 TypeLoc TL = DI->getTypeLoc();
3182 TLB.reserve(TL.getFullDataSize());
3183
John McCall31f82722010-11-12 08:19:04 +00003184 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003185 if (Result.isNull())
3186 return 0;
3187
John McCallbcd03502009-12-07 02:54:59 +00003188 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003189}
3190
3191template<typename Derived>
3192QualType
John McCall31f82722010-11-12 08:19:04 +00003193TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003194 switch (T.getTypeLocClass()) {
3195#define ABSTRACT_TYPELOC(CLASS, PARENT)
3196#define TYPELOC(CLASS, PARENT) \
3197 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003198 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003199#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003200 }
Mike Stump11289f42009-09-09 15:08:12 +00003201
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003202 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003203 return QualType();
3204}
3205
3206/// FIXME: By default, this routine adds type qualifiers only to types
3207/// that can have qualifiers, and silently suppresses those qualifiers
3208/// that are not permitted (e.g., qualifiers on reference or function
3209/// types). This is the right thing for template instantiation, but
3210/// probably not for other clients.
3211template<typename Derived>
3212QualType
3213TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003214 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003215 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003216
John McCall31f82722010-11-12 08:19:04 +00003217 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003218 if (Result.isNull())
3219 return QualType();
3220
3221 // Silently suppress qualifiers if the result type can't be qualified.
3222 // FIXME: this is the right thing for template instantiation, but
3223 // probably not for other clients.
3224 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003225 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003226
John McCallcb0f89a2010-06-05 06:41:15 +00003227 if (!Quals.empty()) {
3228 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3229 TLB.push<QualifiedTypeLoc>(Result);
3230 // No location information to preserve.
3231 }
John McCall550e0c22009-10-21 00:40:46 +00003232
3233 return Result;
3234}
3235
John McCall31f82722010-11-12 08:19:04 +00003236/// \brief Transforms a type that was written in a scope specifier,
3237/// given an object type, the results of unqualified lookup, and
3238/// an already-instantiated prefix.
3239///
3240/// The object type is provided iff the scope specifier qualifies the
3241/// member of a dependent member-access expression. The prefix is
3242/// provided iff the the scope specifier in which this appears has a
3243/// prefix.
3244///
3245/// This is private to TreeTransform.
3246template<typename Derived>
3247QualType
3248TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3249 QualType ObjectType,
3250 NamedDecl *UnqualLookup,
3251 NestedNameSpecifier *Prefix) {
3252 if (getDerived().AlreadyTransformed(T))
3253 return T;
3254
3255 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003256 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003257
3258 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3259 UnqualLookup, Prefix);
3260 if (!TSI) return QualType();
3261 return TSI->getType();
3262}
3263
3264template<typename Derived>
3265TypeSourceInfo *
3266TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3267 QualType ObjectType,
3268 NamedDecl *UnqualLookup,
3269 NestedNameSpecifier *Prefix) {
Douglas Gregor14454802011-02-25 02:25:35 +00003270 // TODO: in some cases, we might have some verification to do here.
John McCall31f82722010-11-12 08:19:04 +00003271 if (ObjectType.isNull())
3272 return getDerived().TransformType(TSI);
3273
3274 QualType T = TSI->getType();
3275 if (getDerived().AlreadyTransformed(T))
3276 return TSI;
3277
3278 TypeLocBuilder TLB;
3279 QualType Result;
3280
3281 if (isa<TemplateSpecializationType>(T)) {
3282 TemplateSpecializationTypeLoc TL
3283 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3284
3285 TemplateName Template =
3286 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3287 ObjectType, UnqualLookup);
3288 if (Template.isNull()) return 0;
3289
3290 Result = getDerived()
3291 .TransformTemplateSpecializationType(TLB, TL, Template);
3292 } else if (isa<DependentTemplateSpecializationType>(T)) {
3293 DependentTemplateSpecializationTypeLoc TL
3294 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3295
Douglas Gregor5a064722011-02-28 17:23:35 +00003296 TemplateName Template
3297 = SemaRef.Context.getDependentTemplateName(
3298 TL.getTypePtr()->getQualifier(),
3299 TL.getTypePtr()->getIdentifier());
3300
3301 Template = getDerived().TransformTemplateName(Template, ObjectType,
3302 UnqualLookup);
3303 if (Template.isNull())
3304 return 0;
3305
3306 Result = getDerived().TransformDependentTemplateSpecializationType(TLB, TL,
3307 Template);
John McCall31f82722010-11-12 08:19:04 +00003308 } else {
3309 // Nothing special needs to be done for these.
3310 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3311 }
3312
3313 if (Result.isNull()) return 0;
3314 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3315}
3316
Douglas Gregor14454802011-02-25 02:25:35 +00003317template<typename Derived>
3318TypeLoc
3319TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3320 QualType ObjectType,
3321 NamedDecl *UnqualLookup,
3322 CXXScopeSpec &SS) {
3323 // FIXME: Painfully copy-paste from the above!
3324
Douglas Gregor14454802011-02-25 02:25:35 +00003325 QualType T = TL.getType();
3326 if (getDerived().AlreadyTransformed(T))
3327 return TL;
3328
3329 TypeLocBuilder TLB;
3330 QualType Result;
3331
3332 if (isa<TemplateSpecializationType>(T)) {
3333 TemplateSpecializationTypeLoc SpecTL
3334 = cast<TemplateSpecializationTypeLoc>(TL);
3335
3336 TemplateName Template =
3337 getDerived().TransformTemplateName(SpecTL.getTypePtr()->getTemplateName(),
3338 ObjectType, UnqualLookup);
3339 if (Template.isNull())
3340 return TypeLoc();
3341
3342 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3343 Template);
3344 } else if (isa<DependentTemplateSpecializationType>(T)) {
3345 DependentTemplateSpecializationTypeLoc SpecTL
3346 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3347
Douglas Gregor5a064722011-02-28 17:23:35 +00003348 TemplateName Template
Douglas Gregore16af532011-02-28 18:50:33 +00003349 = getDerived().RebuildTemplateName(SS.getScopeRep(), SS.getRange(),
3350 *SpecTL.getTypePtr()->getIdentifier(),
3351 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003352 if (Template.isNull())
3353 return TypeLoc();
3354
Douglas Gregor14454802011-02-25 02:25:35 +00003355 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003356 SpecTL,
3357 Template);
Douglas Gregor14454802011-02-25 02:25:35 +00003358 } else {
3359 // Nothing special needs to be done for these.
3360 Result = getDerived().TransformType(TLB, TL);
3361 }
3362
3363 if (Result.isNull())
3364 return TypeLoc();
3365
3366 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3367}
3368
John McCall550e0c22009-10-21 00:40:46 +00003369template <class TyLoc> static inline
3370QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3371 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3372 NewT.setNameLoc(T.getNameLoc());
3373 return T.getType();
3374}
3375
John McCall550e0c22009-10-21 00:40:46 +00003376template<typename Derived>
3377QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003378 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003379 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3380 NewT.setBuiltinLoc(T.getBuiltinLoc());
3381 if (T.needsExtraLocalData())
3382 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3383 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003384}
Mike Stump11289f42009-09-09 15:08:12 +00003385
Douglas Gregord6ff3322009-08-04 16:50:30 +00003386template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003387QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003388 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003389 // FIXME: recurse?
3390 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003391}
Mike Stump11289f42009-09-09 15:08:12 +00003392
Douglas Gregord6ff3322009-08-04 16:50:30 +00003393template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003394QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003395 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003396 QualType PointeeType
3397 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003398 if (PointeeType.isNull())
3399 return QualType();
3400
3401 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003402 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003403 // A dependent pointer type 'T *' has is being transformed such
3404 // that an Objective-C class type is being replaced for 'T'. The
3405 // resulting pointer type is an ObjCObjectPointerType, not a
3406 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003407 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003408
John McCall8b07ec22010-05-15 11:32:37 +00003409 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3410 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003411 return Result;
3412 }
John McCall31f82722010-11-12 08:19:04 +00003413
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003414 if (getDerived().AlwaysRebuild() ||
3415 PointeeType != TL.getPointeeLoc().getType()) {
3416 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3417 if (Result.isNull())
3418 return QualType();
3419 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003420
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003421 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3422 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003423 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003424}
Mike Stump11289f42009-09-09 15:08:12 +00003425
3426template<typename Derived>
3427QualType
John McCall550e0c22009-10-21 00:40:46 +00003428TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003429 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003430 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003431 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3432 if (PointeeType.isNull())
3433 return QualType();
3434
3435 QualType Result = TL.getType();
3436 if (getDerived().AlwaysRebuild() ||
3437 PointeeType != TL.getPointeeLoc().getType()) {
3438 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003439 TL.getSigilLoc());
3440 if (Result.isNull())
3441 return QualType();
3442 }
3443
Douglas Gregor049211a2010-04-22 16:50:51 +00003444 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003445 NewT.setSigilLoc(TL.getSigilLoc());
3446 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003447}
3448
John McCall70dd5f62009-10-30 00:06:24 +00003449/// Transforms a reference type. Note that somewhat paradoxically we
3450/// don't care whether the type itself is an l-value type or an r-value
3451/// type; we only care if the type was *written* as an l-value type
3452/// or an r-value type.
3453template<typename Derived>
3454QualType
3455TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003456 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003457 const ReferenceType *T = TL.getTypePtr();
3458
3459 // Note that this works with the pointee-as-written.
3460 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3461 if (PointeeType.isNull())
3462 return QualType();
3463
3464 QualType Result = TL.getType();
3465 if (getDerived().AlwaysRebuild() ||
3466 PointeeType != T->getPointeeTypeAsWritten()) {
3467 Result = getDerived().RebuildReferenceType(PointeeType,
3468 T->isSpelledAsLValue(),
3469 TL.getSigilLoc());
3470 if (Result.isNull())
3471 return QualType();
3472 }
3473
3474 // r-value references can be rebuilt as l-value references.
3475 ReferenceTypeLoc NewTL;
3476 if (isa<LValueReferenceType>(Result))
3477 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3478 else
3479 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3480 NewTL.setSigilLoc(TL.getSigilLoc());
3481
3482 return Result;
3483}
3484
Mike Stump11289f42009-09-09 15:08:12 +00003485template<typename Derived>
3486QualType
John McCall550e0c22009-10-21 00:40:46 +00003487TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003488 LValueReferenceTypeLoc TL) {
3489 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003490}
3491
Mike Stump11289f42009-09-09 15:08:12 +00003492template<typename Derived>
3493QualType
John McCall550e0c22009-10-21 00:40:46 +00003494TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003495 RValueReferenceTypeLoc TL) {
3496 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003497}
Mike Stump11289f42009-09-09 15:08:12 +00003498
Douglas Gregord6ff3322009-08-04 16:50:30 +00003499template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003500QualType
John McCall550e0c22009-10-21 00:40:46 +00003501TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003502 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003503 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003504
3505 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003506 if (PointeeType.isNull())
3507 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003508
John McCall550e0c22009-10-21 00:40:46 +00003509 // TODO: preserve source information for this.
3510 QualType ClassType
3511 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003512 if (ClassType.isNull())
3513 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003514
John McCall550e0c22009-10-21 00:40:46 +00003515 QualType Result = TL.getType();
3516 if (getDerived().AlwaysRebuild() ||
3517 PointeeType != T->getPointeeType() ||
3518 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003519 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3520 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003521 if (Result.isNull())
3522 return QualType();
3523 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003524
John McCall550e0c22009-10-21 00:40:46 +00003525 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3526 NewTL.setSigilLoc(TL.getSigilLoc());
3527
3528 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003529}
3530
Mike Stump11289f42009-09-09 15:08:12 +00003531template<typename Derived>
3532QualType
John McCall550e0c22009-10-21 00:40:46 +00003533TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003534 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003535 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003536 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003537 if (ElementType.isNull())
3538 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003539
John McCall550e0c22009-10-21 00:40:46 +00003540 QualType Result = TL.getType();
3541 if (getDerived().AlwaysRebuild() ||
3542 ElementType != T->getElementType()) {
3543 Result = getDerived().RebuildConstantArrayType(ElementType,
3544 T->getSizeModifier(),
3545 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003546 T->getIndexTypeCVRQualifiers(),
3547 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003548 if (Result.isNull())
3549 return QualType();
3550 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003551
John McCall550e0c22009-10-21 00:40:46 +00003552 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3553 NewTL.setLBracketLoc(TL.getLBracketLoc());
3554 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003555
John McCall550e0c22009-10-21 00:40:46 +00003556 Expr *Size = TL.getSizeExpr();
3557 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003558 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003559 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3560 }
3561 NewTL.setSizeExpr(Size);
3562
3563 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003564}
Mike Stump11289f42009-09-09 15:08:12 +00003565
Douglas Gregord6ff3322009-08-04 16:50:30 +00003566template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003567QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003568 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003569 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003570 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003571 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003572 if (ElementType.isNull())
3573 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003574
John McCall550e0c22009-10-21 00:40:46 +00003575 QualType Result = TL.getType();
3576 if (getDerived().AlwaysRebuild() ||
3577 ElementType != T->getElementType()) {
3578 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003579 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003580 T->getIndexTypeCVRQualifiers(),
3581 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003582 if (Result.isNull())
3583 return QualType();
3584 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003585
John McCall550e0c22009-10-21 00:40:46 +00003586 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3587 NewTL.setLBracketLoc(TL.getLBracketLoc());
3588 NewTL.setRBracketLoc(TL.getRBracketLoc());
3589 NewTL.setSizeExpr(0);
3590
3591 return Result;
3592}
3593
3594template<typename Derived>
3595QualType
3596TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003597 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003598 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003599 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3600 if (ElementType.isNull())
3601 return QualType();
3602
3603 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003604 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003605
John McCalldadc5752010-08-24 06:29:42 +00003606 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003607 = getDerived().TransformExpr(T->getSizeExpr());
3608 if (SizeResult.isInvalid())
3609 return QualType();
3610
John McCallb268a282010-08-23 23:25:46 +00003611 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003612
3613 QualType Result = TL.getType();
3614 if (getDerived().AlwaysRebuild() ||
3615 ElementType != T->getElementType() ||
3616 Size != T->getSizeExpr()) {
3617 Result = getDerived().RebuildVariableArrayType(ElementType,
3618 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003619 Size,
John McCall550e0c22009-10-21 00:40:46 +00003620 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003621 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003622 if (Result.isNull())
3623 return QualType();
3624 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003625
John McCall550e0c22009-10-21 00:40:46 +00003626 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3627 NewTL.setLBracketLoc(TL.getLBracketLoc());
3628 NewTL.setRBracketLoc(TL.getRBracketLoc());
3629 NewTL.setSizeExpr(Size);
3630
3631 return Result;
3632}
3633
3634template<typename Derived>
3635QualType
3636TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003637 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003638 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003639 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3640 if (ElementType.isNull())
3641 return QualType();
3642
3643 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003644 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003645
John McCall33ddac02011-01-19 10:06:00 +00003646 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3647 Expr *origSize = TL.getSizeExpr();
3648 if (!origSize) origSize = T->getSizeExpr();
3649
3650 ExprResult sizeResult
3651 = getDerived().TransformExpr(origSize);
3652 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003653 return QualType();
3654
John McCall33ddac02011-01-19 10:06:00 +00003655 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003656
3657 QualType Result = TL.getType();
3658 if (getDerived().AlwaysRebuild() ||
3659 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003660 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003661 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3662 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003663 size,
John McCall550e0c22009-10-21 00:40:46 +00003664 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003665 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003666 if (Result.isNull())
3667 return QualType();
3668 }
John McCall550e0c22009-10-21 00:40:46 +00003669
3670 // We might have any sort of array type now, but fortunately they
3671 // all have the same location layout.
3672 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3673 NewTL.setLBracketLoc(TL.getLBracketLoc());
3674 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003675 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003676
3677 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003678}
Mike Stump11289f42009-09-09 15:08:12 +00003679
3680template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003681QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003682 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003683 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003684 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003685
3686 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003687 QualType ElementType = getDerived().TransformType(T->getElementType());
3688 if (ElementType.isNull())
3689 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003690
Douglas Gregore922c772009-08-04 22:27:00 +00003691 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003692 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003693
John McCalldadc5752010-08-24 06:29:42 +00003694 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003695 if (Size.isInvalid())
3696 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003697
John McCall550e0c22009-10-21 00:40:46 +00003698 QualType Result = TL.getType();
3699 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003700 ElementType != T->getElementType() ||
3701 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003702 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003703 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003704 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003705 if (Result.isNull())
3706 return QualType();
3707 }
John McCall550e0c22009-10-21 00:40:46 +00003708
3709 // Result might be dependent or not.
3710 if (isa<DependentSizedExtVectorType>(Result)) {
3711 DependentSizedExtVectorTypeLoc NewTL
3712 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3713 NewTL.setNameLoc(TL.getNameLoc());
3714 } else {
3715 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3716 NewTL.setNameLoc(TL.getNameLoc());
3717 }
3718
3719 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003720}
Mike Stump11289f42009-09-09 15:08:12 +00003721
3722template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003723QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003724 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003725 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003726 QualType ElementType = getDerived().TransformType(T->getElementType());
3727 if (ElementType.isNull())
3728 return QualType();
3729
John McCall550e0c22009-10-21 00:40:46 +00003730 QualType Result = TL.getType();
3731 if (getDerived().AlwaysRebuild() ||
3732 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003733 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003734 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003735 if (Result.isNull())
3736 return QualType();
3737 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003738
John McCall550e0c22009-10-21 00:40:46 +00003739 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3740 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003741
John McCall550e0c22009-10-21 00:40:46 +00003742 return Result;
3743}
3744
3745template<typename Derived>
3746QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003747 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003748 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003749 QualType ElementType = getDerived().TransformType(T->getElementType());
3750 if (ElementType.isNull())
3751 return QualType();
3752
3753 QualType Result = TL.getType();
3754 if (getDerived().AlwaysRebuild() ||
3755 ElementType != T->getElementType()) {
3756 Result = getDerived().RebuildExtVectorType(ElementType,
3757 T->getNumElements(),
3758 /*FIXME*/ SourceLocation());
3759 if (Result.isNull())
3760 return QualType();
3761 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003762
John McCall550e0c22009-10-21 00:40:46 +00003763 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3764 NewTL.setNameLoc(TL.getNameLoc());
3765
3766 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003767}
Mike Stump11289f42009-09-09 15:08:12 +00003768
3769template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003770ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003771TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3772 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003773 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003774 TypeSourceInfo *NewDI = 0;
3775
3776 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3777 // If we're substituting into a pack expansion type and we know the
3778 TypeLoc OldTL = OldDI->getTypeLoc();
3779 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3780
3781 TypeLocBuilder TLB;
3782 TypeLoc NewTL = OldDI->getTypeLoc();
3783 TLB.reserve(NewTL.getFullDataSize());
3784
3785 QualType Result = getDerived().TransformType(TLB,
3786 OldExpansionTL.getPatternLoc());
3787 if (Result.isNull())
3788 return 0;
3789
3790 Result = RebuildPackExpansionType(Result,
3791 OldExpansionTL.getPatternLoc().getSourceRange(),
3792 OldExpansionTL.getEllipsisLoc(),
3793 NumExpansions);
3794 if (Result.isNull())
3795 return 0;
3796
3797 PackExpansionTypeLoc NewExpansionTL
3798 = TLB.push<PackExpansionTypeLoc>(Result);
3799 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3800 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3801 } else
3802 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003803 if (!NewDI)
3804 return 0;
3805
3806 if (NewDI == OldDI)
3807 return OldParm;
3808 else
3809 return ParmVarDecl::Create(SemaRef.Context,
3810 OldParm->getDeclContext(),
3811 OldParm->getLocation(),
3812 OldParm->getIdentifier(),
3813 NewDI->getType(),
3814 NewDI,
3815 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003816 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003817 /* DefArg */ NULL);
3818}
3819
3820template<typename Derived>
3821bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003822 TransformFunctionTypeParams(SourceLocation Loc,
3823 ParmVarDecl **Params, unsigned NumParams,
3824 const QualType *ParamTypes,
3825 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3826 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3827 for (unsigned i = 0; i != NumParams; ++i) {
3828 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003829 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003830 if (OldParm->isParameterPack()) {
3831 // We have a function parameter pack that may need to be expanded.
3832 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003833
Douglas Gregor5499af42011-01-05 23:12:31 +00003834 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003835 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3836 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3837 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3838 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003839
3840 // Determine whether we should expand the parameter packs.
3841 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003842 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003843 llvm::Optional<unsigned> OrigNumExpansions
3844 = ExpansionTL.getTypePtr()->getNumExpansions();
3845 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003846 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3847 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003848 Unexpanded.data(),
3849 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003850 ShouldExpand,
3851 RetainExpansion,
3852 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003853 return true;
3854 }
3855
3856 if (ShouldExpand) {
3857 // Expand the function parameter pack into multiple, separate
3858 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003859 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003860 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003861 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3862 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003863 = getDerived().TransformFunctionTypeParam(OldParm,
3864 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003865 if (!NewParm)
3866 return true;
3867
Douglas Gregordd472162011-01-07 00:20:55 +00003868 OutParamTypes.push_back(NewParm->getType());
3869 if (PVars)
3870 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003871 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003872
3873 // If we're supposed to retain a pack expansion, do so by temporarily
3874 // forgetting the partially-substituted parameter pack.
3875 if (RetainExpansion) {
3876 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3877 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003878 = getDerived().TransformFunctionTypeParam(OldParm,
3879 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003880 if (!NewParm)
3881 return true;
3882
3883 OutParamTypes.push_back(NewParm->getType());
3884 if (PVars)
3885 PVars->push_back(NewParm);
3886 }
3887
Douglas Gregor5499af42011-01-05 23:12:31 +00003888 // We're done with the pack expansion.
3889 continue;
3890 }
3891
3892 // We'll substitute the parameter now without expanding the pack
3893 // expansion.
3894 }
3895
3896 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003897 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3898 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003899 if (!NewParm)
3900 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003901
Douglas Gregordd472162011-01-07 00:20:55 +00003902 OutParamTypes.push_back(NewParm->getType());
3903 if (PVars)
3904 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003905 continue;
3906 }
John McCall58f10c32010-03-11 09:03:00 +00003907
3908 // Deal with the possibility that we don't have a parameter
3909 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003910 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003911 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003912 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003913 if (const PackExpansionType *Expansion
3914 = dyn_cast<PackExpansionType>(OldType)) {
3915 // We have a function parameter pack that may need to be expanded.
3916 QualType Pattern = Expansion->getPattern();
3917 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3918 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3919
3920 // Determine whether we should expand the parameter packs.
3921 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003922 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003923 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003924 Unexpanded.data(),
3925 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003926 ShouldExpand,
3927 RetainExpansion,
3928 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003929 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003930 }
3931
3932 if (ShouldExpand) {
3933 // Expand the function parameter pack into multiple, separate
3934 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003935 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003936 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3937 QualType NewType = getDerived().TransformType(Pattern);
3938 if (NewType.isNull())
3939 return true;
John McCall58f10c32010-03-11 09:03:00 +00003940
Douglas Gregordd472162011-01-07 00:20:55 +00003941 OutParamTypes.push_back(NewType);
3942 if (PVars)
3943 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003944 }
3945
3946 // We're done with the pack expansion.
3947 continue;
3948 }
3949
Douglas Gregor48d24112011-01-10 20:53:55 +00003950 // If we're supposed to retain a pack expansion, do so by temporarily
3951 // forgetting the partially-substituted parameter pack.
3952 if (RetainExpansion) {
3953 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3954 QualType NewType = getDerived().TransformType(Pattern);
3955 if (NewType.isNull())
3956 return true;
3957
3958 OutParamTypes.push_back(NewType);
3959 if (PVars)
3960 PVars->push_back(0);
3961 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003962
Douglas Gregor5499af42011-01-05 23:12:31 +00003963 // We'll substitute the parameter now without expanding the pack
3964 // expansion.
3965 OldType = Expansion->getPattern();
3966 IsPackExpansion = true;
3967 }
3968
3969 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3970 QualType NewType = getDerived().TransformType(OldType);
3971 if (NewType.isNull())
3972 return true;
3973
3974 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003975 NewType = getSema().Context.getPackExpansionType(NewType,
3976 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003977
Douglas Gregordd472162011-01-07 00:20:55 +00003978 OutParamTypes.push_back(NewType);
3979 if (PVars)
3980 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003981 }
3982
3983 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003984 }
John McCall58f10c32010-03-11 09:03:00 +00003985
3986template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003987QualType
John McCall550e0c22009-10-21 00:40:46 +00003988TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003989 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003990 // Transform the parameters and return type.
3991 //
3992 // We instantiate in source order, with the return type first followed by
3993 // the parameters, because users tend to expect this (even if they shouldn't
3994 // rely on it!).
3995 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003996 // When the function has a trailing return type, we instantiate the
3997 // parameters before the return type, since the return type can then refer
3998 // to the parameters themselves (via decltype, sizeof, etc.).
3999 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00004000 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00004001 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004002 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004003
Douglas Gregor7fb25412010-10-01 18:44:50 +00004004 QualType ResultType;
4005
4006 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004007 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4008 TL.getParmArray(),
4009 TL.getNumArgs(),
4010 TL.getTypePtr()->arg_type_begin(),
4011 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004012 return QualType();
4013
4014 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4015 if (ResultType.isNull())
4016 return QualType();
4017 }
4018 else {
4019 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4020 if (ResultType.isNull())
4021 return QualType();
4022
Douglas Gregordd472162011-01-07 00:20:55 +00004023 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4024 TL.getParmArray(),
4025 TL.getNumArgs(),
4026 TL.getTypePtr()->arg_type_begin(),
4027 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004028 return QualType();
4029 }
4030
John McCall550e0c22009-10-21 00:40:46 +00004031 QualType Result = TL.getType();
4032 if (getDerived().AlwaysRebuild() ||
4033 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004034 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004035 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4036 Result = getDerived().RebuildFunctionProtoType(ResultType,
4037 ParamTypes.data(),
4038 ParamTypes.size(),
4039 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004040 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004041 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004042 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004043 if (Result.isNull())
4044 return QualType();
4045 }
Mike Stump11289f42009-09-09 15:08:12 +00004046
John McCall550e0c22009-10-21 00:40:46 +00004047 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4048 NewTL.setLParenLoc(TL.getLParenLoc());
4049 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004050 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004051 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4052 NewTL.setArg(i, ParamDecls[i]);
4053
4054 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004055}
Mike Stump11289f42009-09-09 15:08:12 +00004056
Douglas Gregord6ff3322009-08-04 16:50:30 +00004057template<typename Derived>
4058QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004059 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004060 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004061 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004062 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4063 if (ResultType.isNull())
4064 return QualType();
4065
4066 QualType Result = TL.getType();
4067 if (getDerived().AlwaysRebuild() ||
4068 ResultType != T->getResultType())
4069 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4070
4071 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4072 NewTL.setLParenLoc(TL.getLParenLoc());
4073 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004074 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004075
4076 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004077}
Mike Stump11289f42009-09-09 15:08:12 +00004078
John McCallb96ec562009-12-04 22:46:56 +00004079template<typename Derived> QualType
4080TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004081 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004082 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004083 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004084 if (!D)
4085 return QualType();
4086
4087 QualType Result = TL.getType();
4088 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4089 Result = getDerived().RebuildUnresolvedUsingType(D);
4090 if (Result.isNull())
4091 return QualType();
4092 }
4093
4094 // We might get an arbitrary type spec type back. We should at
4095 // least always get a type spec type, though.
4096 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4097 NewTL.setNameLoc(TL.getNameLoc());
4098
4099 return Result;
4100}
4101
Douglas Gregord6ff3322009-08-04 16:50:30 +00004102template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004103QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004104 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004105 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004106 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004107 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4108 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004109 if (!Typedef)
4110 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004111
John McCall550e0c22009-10-21 00:40:46 +00004112 QualType Result = TL.getType();
4113 if (getDerived().AlwaysRebuild() ||
4114 Typedef != T->getDecl()) {
4115 Result = getDerived().RebuildTypedefType(Typedef);
4116 if (Result.isNull())
4117 return QualType();
4118 }
Mike Stump11289f42009-09-09 15:08:12 +00004119
John McCall550e0c22009-10-21 00:40:46 +00004120 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4121 NewTL.setNameLoc(TL.getNameLoc());
4122
4123 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004124}
Mike Stump11289f42009-09-09 15:08:12 +00004125
Douglas Gregord6ff3322009-08-04 16:50:30 +00004126template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004127QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004128 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004129 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004130 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004131
John McCalldadc5752010-08-24 06:29:42 +00004132 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004133 if (E.isInvalid())
4134 return QualType();
4135
John McCall550e0c22009-10-21 00:40:46 +00004136 QualType Result = TL.getType();
4137 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004138 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004139 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004140 if (Result.isNull())
4141 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004142 }
John McCall550e0c22009-10-21 00:40:46 +00004143 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004144
John McCall550e0c22009-10-21 00:40:46 +00004145 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004146 NewTL.setTypeofLoc(TL.getTypeofLoc());
4147 NewTL.setLParenLoc(TL.getLParenLoc());
4148 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004149
4150 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004151}
Mike Stump11289f42009-09-09 15:08:12 +00004152
4153template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004154QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004155 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004156 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4157 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4158 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004159 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004160
John McCall550e0c22009-10-21 00:40:46 +00004161 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004162 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4163 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004164 if (Result.isNull())
4165 return QualType();
4166 }
Mike Stump11289f42009-09-09 15:08:12 +00004167
John McCall550e0c22009-10-21 00:40:46 +00004168 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004169 NewTL.setTypeofLoc(TL.getTypeofLoc());
4170 NewTL.setLParenLoc(TL.getLParenLoc());
4171 NewTL.setRParenLoc(TL.getRParenLoc());
4172 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004173
4174 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004175}
Mike Stump11289f42009-09-09 15:08:12 +00004176
4177template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004178QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004179 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004180 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004181
Douglas Gregore922c772009-08-04 22:27:00 +00004182 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004183 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004184
John McCalldadc5752010-08-24 06:29:42 +00004185 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004186 if (E.isInvalid())
4187 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004188
John McCall550e0c22009-10-21 00:40:46 +00004189 QualType Result = TL.getType();
4190 if (getDerived().AlwaysRebuild() ||
4191 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004192 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004193 if (Result.isNull())
4194 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004195 }
John McCall550e0c22009-10-21 00:40:46 +00004196 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004197
John McCall550e0c22009-10-21 00:40:46 +00004198 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4199 NewTL.setNameLoc(TL.getNameLoc());
4200
4201 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004202}
4203
4204template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004205QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4206 AutoTypeLoc TL) {
4207 const AutoType *T = TL.getTypePtr();
4208 QualType OldDeduced = T->getDeducedType();
4209 QualType NewDeduced;
4210 if (!OldDeduced.isNull()) {
4211 NewDeduced = getDerived().TransformType(OldDeduced);
4212 if (NewDeduced.isNull())
4213 return QualType();
4214 }
4215
4216 QualType Result = TL.getType();
4217 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4218 Result = getDerived().RebuildAutoType(NewDeduced);
4219 if (Result.isNull())
4220 return QualType();
4221 }
4222
4223 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4224 NewTL.setNameLoc(TL.getNameLoc());
4225
4226 return Result;
4227}
4228
4229template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004230QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004231 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004232 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004233 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004234 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4235 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004236 if (!Record)
4237 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004238
John McCall550e0c22009-10-21 00:40:46 +00004239 QualType Result = TL.getType();
4240 if (getDerived().AlwaysRebuild() ||
4241 Record != T->getDecl()) {
4242 Result = getDerived().RebuildRecordType(Record);
4243 if (Result.isNull())
4244 return QualType();
4245 }
Mike Stump11289f42009-09-09 15:08:12 +00004246
John McCall550e0c22009-10-21 00:40:46 +00004247 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4248 NewTL.setNameLoc(TL.getNameLoc());
4249
4250 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004251}
Mike Stump11289f42009-09-09 15:08:12 +00004252
4253template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004254QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004255 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004256 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004257 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004258 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4259 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004260 if (!Enum)
4261 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004262
John McCall550e0c22009-10-21 00:40:46 +00004263 QualType Result = TL.getType();
4264 if (getDerived().AlwaysRebuild() ||
4265 Enum != T->getDecl()) {
4266 Result = getDerived().RebuildEnumType(Enum);
4267 if (Result.isNull())
4268 return QualType();
4269 }
Mike Stump11289f42009-09-09 15:08:12 +00004270
John McCall550e0c22009-10-21 00:40:46 +00004271 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4272 NewTL.setNameLoc(TL.getNameLoc());
4273
4274 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004275}
John McCallfcc33b02009-09-05 00:15:47 +00004276
John McCalle78aac42010-03-10 03:28:59 +00004277template<typename Derived>
4278QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4279 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004280 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004281 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4282 TL.getTypePtr()->getDecl());
4283 if (!D) return QualType();
4284
4285 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4286 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4287 return T;
4288}
4289
Douglas Gregord6ff3322009-08-04 16:50:30 +00004290template<typename Derived>
4291QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004292 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004293 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004294 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004295}
4296
Mike Stump11289f42009-09-09 15:08:12 +00004297template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004298QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004299 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004300 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004301 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004302}
4303
4304template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004305QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4306 TypeLocBuilder &TLB,
4307 SubstTemplateTypeParmPackTypeLoc TL) {
4308 return TransformTypeSpecType(TLB, TL);
4309}
4310
4311template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004312QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004313 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004314 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004315 const TemplateSpecializationType *T = TL.getTypePtr();
4316
Mike Stump11289f42009-09-09 15:08:12 +00004317 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004318 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004319 if (Template.isNull())
4320 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004321
John McCall31f82722010-11-12 08:19:04 +00004322 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4323}
4324
Douglas Gregorfe921a72010-12-20 23:36:19 +00004325namespace {
4326 /// \brief Simple iterator that traverses the template arguments in a
4327 /// container that provides a \c getArgLoc() member function.
4328 ///
4329 /// This iterator is intended to be used with the iterator form of
4330 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4331 template<typename ArgLocContainer>
4332 class TemplateArgumentLocContainerIterator {
4333 ArgLocContainer *Container;
4334 unsigned Index;
4335
4336 public:
4337 typedef TemplateArgumentLoc value_type;
4338 typedef TemplateArgumentLoc reference;
4339 typedef int difference_type;
4340 typedef std::input_iterator_tag iterator_category;
4341
4342 class pointer {
4343 TemplateArgumentLoc Arg;
4344
4345 public:
4346 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4347
4348 const TemplateArgumentLoc *operator->() const {
4349 return &Arg;
4350 }
4351 };
4352
4353
4354 TemplateArgumentLocContainerIterator() {}
4355
4356 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4357 unsigned Index)
4358 : Container(&Container), Index(Index) { }
4359
4360 TemplateArgumentLocContainerIterator &operator++() {
4361 ++Index;
4362 return *this;
4363 }
4364
4365 TemplateArgumentLocContainerIterator operator++(int) {
4366 TemplateArgumentLocContainerIterator Old(*this);
4367 ++(*this);
4368 return Old;
4369 }
4370
4371 TemplateArgumentLoc operator*() const {
4372 return Container->getArgLoc(Index);
4373 }
4374
4375 pointer operator->() const {
4376 return pointer(Container->getArgLoc(Index));
4377 }
4378
4379 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004380 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004381 return X.Container == Y.Container && X.Index == Y.Index;
4382 }
4383
4384 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004385 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004386 return !(X == Y);
4387 }
4388 };
4389}
4390
4391
John McCall31f82722010-11-12 08:19:04 +00004392template <typename Derived>
4393QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4394 TypeLocBuilder &TLB,
4395 TemplateSpecializationTypeLoc TL,
4396 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004397 TemplateArgumentListInfo NewTemplateArgs;
4398 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4399 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004400 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4401 ArgIterator;
4402 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4403 ArgIterator(TL, TL.getNumArgs()),
4404 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004405 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004406
John McCall0ad16662009-10-29 08:12:44 +00004407 // FIXME: maybe don't rebuild if all the template arguments are the same.
4408
4409 QualType Result =
4410 getDerived().RebuildTemplateSpecializationType(Template,
4411 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004412 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004413
4414 if (!Result.isNull()) {
4415 TemplateSpecializationTypeLoc NewTL
4416 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4417 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4418 NewTL.setLAngleLoc(TL.getLAngleLoc());
4419 NewTL.setRAngleLoc(TL.getRAngleLoc());
4420 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4421 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004422 }
Mike Stump11289f42009-09-09 15:08:12 +00004423
John McCall0ad16662009-10-29 08:12:44 +00004424 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004425}
Mike Stump11289f42009-09-09 15:08:12 +00004426
Douglas Gregor5a064722011-02-28 17:23:35 +00004427template <typename Derived>
4428QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4429 TypeLocBuilder &TLB,
4430 DependentTemplateSpecializationTypeLoc TL,
4431 TemplateName Template) {
4432 TemplateArgumentListInfo NewTemplateArgs;
4433 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4434 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4435 typedef TemplateArgumentLocContainerIterator<
4436 DependentTemplateSpecializationTypeLoc> ArgIterator;
4437 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4438 ArgIterator(TL, TL.getNumArgs()),
4439 NewTemplateArgs))
4440 return QualType();
4441
4442 // FIXME: maybe don't rebuild if all the template arguments are the same.
4443
4444 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4445 QualType Result
4446 = getSema().Context.getDependentTemplateSpecializationType(
4447 TL.getTypePtr()->getKeyword(),
4448 DTN->getQualifier(),
4449 DTN->getIdentifier(),
4450 NewTemplateArgs);
4451
4452 DependentTemplateSpecializationTypeLoc NewTL
4453 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4454 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004455
4456 // FIXME: Poor nested-name-specifier source-location information.
4457 CXXScopeSpec SS;
4458 SS.MakeTrivial(SemaRef.Context,
4459 DTN->getQualifier(), TL.getQualifierLoc().getSourceRange());
4460 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004461 NewTL.setNameLoc(TL.getNameLoc());
4462 NewTL.setLAngleLoc(TL.getLAngleLoc());
4463 NewTL.setRAngleLoc(TL.getRAngleLoc());
4464 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4465 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4466 return Result;
4467 }
4468
4469 QualType Result
4470 = getDerived().RebuildTemplateSpecializationType(Template,
4471 TL.getNameLoc(),
4472 NewTemplateArgs);
4473
4474 if (!Result.isNull()) {
4475 /// FIXME: Wrap this in an elaborated-type-specifier?
4476 TemplateSpecializationTypeLoc NewTL
4477 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4478 NewTL.setTemplateNameLoc(TL.getNameLoc());
4479 NewTL.setLAngleLoc(TL.getLAngleLoc());
4480 NewTL.setRAngleLoc(TL.getRAngleLoc());
4481 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4482 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4483 }
4484
4485 return Result;
4486}
4487
Mike Stump11289f42009-09-09 15:08:12 +00004488template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004489QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004490TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004491 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004492 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004493
Douglas Gregor844cb502011-03-01 18:12:44 +00004494 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004495 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004496 if (TL.getQualifierLoc()) {
4497 QualifierLoc
4498 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4499 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004500 return QualType();
4501 }
Mike Stump11289f42009-09-09 15:08:12 +00004502
John McCall31f82722010-11-12 08:19:04 +00004503 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4504 if (NamedT.isNull())
4505 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004506
John McCall550e0c22009-10-21 00:40:46 +00004507 QualType Result = TL.getType();
4508 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004509 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004510 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004511 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004512 T->getKeyword(),
4513 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004514 if (Result.isNull())
4515 return QualType();
4516 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004517
Abramo Bagnara6150c882010-05-11 21:36:43 +00004518 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004519 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004520 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004521 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004522}
Mike Stump11289f42009-09-09 15:08:12 +00004523
4524template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004525QualType TreeTransform<Derived>::TransformAttributedType(
4526 TypeLocBuilder &TLB,
4527 AttributedTypeLoc TL) {
4528 const AttributedType *oldType = TL.getTypePtr();
4529 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4530 if (modifiedType.isNull())
4531 return QualType();
4532
4533 QualType result = TL.getType();
4534
4535 // FIXME: dependent operand expressions?
4536 if (getDerived().AlwaysRebuild() ||
4537 modifiedType != oldType->getModifiedType()) {
4538 // TODO: this is really lame; we should really be rebuilding the
4539 // equivalent type from first principles.
4540 QualType equivalentType
4541 = getDerived().TransformType(oldType->getEquivalentType());
4542 if (equivalentType.isNull())
4543 return QualType();
4544 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4545 modifiedType,
4546 equivalentType);
4547 }
4548
4549 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4550 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4551 if (TL.hasAttrOperand())
4552 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4553 if (TL.hasAttrExprOperand())
4554 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4555 else if (TL.hasAttrEnumOperand())
4556 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4557
4558 return result;
4559}
4560
4561template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004562QualType
4563TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4564 ParenTypeLoc TL) {
4565 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4566 if (Inner.isNull())
4567 return QualType();
4568
4569 QualType Result = TL.getType();
4570 if (getDerived().AlwaysRebuild() ||
4571 Inner != TL.getInnerLoc().getType()) {
4572 Result = getDerived().RebuildParenType(Inner);
4573 if (Result.isNull())
4574 return QualType();
4575 }
4576
4577 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4578 NewTL.setLParenLoc(TL.getLParenLoc());
4579 NewTL.setRParenLoc(TL.getRParenLoc());
4580 return Result;
4581}
4582
4583template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004584QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004585 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004586 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004587
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004588 NestedNameSpecifierLoc QualifierLoc
4589 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4590 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004591 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004592
John McCallc392f372010-06-11 00:33:02 +00004593 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004594 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004595 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004596 QualifierLoc,
4597 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004598 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004599 if (Result.isNull())
4600 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004601
Abramo Bagnarad7548482010-05-19 21:37:53 +00004602 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4603 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004604 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4605
Abramo Bagnarad7548482010-05-19 21:37:53 +00004606 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4607 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004608 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004609 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004610 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4611 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004612 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004613 NewTL.setNameLoc(TL.getNameLoc());
4614 }
John McCall550e0c22009-10-21 00:40:46 +00004615 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004616}
Mike Stump11289f42009-09-09 15:08:12 +00004617
Douglas Gregord6ff3322009-08-04 16:50:30 +00004618template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004619QualType TreeTransform<Derived>::
4620 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004621 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004622 NestedNameSpecifierLoc QualifierLoc;
4623 if (TL.getQualifierLoc()) {
4624 QualifierLoc
4625 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4626 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004627 return QualType();
4628 }
4629
John McCall31f82722010-11-12 08:19:04 +00004630 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004631 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004632}
4633
4634template<typename Derived>
4635QualType TreeTransform<Derived>::
4636 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4637 DependentTemplateSpecializationTypeLoc TL,
4638 NestedNameSpecifier *NNS) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004639 // FIXME: This routine needs to go away.
John McCall424cec92011-01-19 06:33:43 +00004640 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004641
John McCallc392f372010-06-11 00:33:02 +00004642 TemplateArgumentListInfo NewTemplateArgs;
4643 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4644 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor14454802011-02-25 02:25:35 +00004645
4646 // FIXME: Nested-name-specifier source location info!
Douglas Gregorfe921a72010-12-20 23:36:19 +00004647 typedef TemplateArgumentLocContainerIterator<
4648 DependentTemplateSpecializationTypeLoc> ArgIterator;
4649 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4650 ArgIterator(TL, TL.getNumArgs()),
4651 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004652 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004653
Douglas Gregora5614c52010-09-08 23:56:00 +00004654 QualType Result
4655 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4656 NNS,
Douglas Gregora7a795b2011-03-01 20:11:18 +00004657 TL.getQualifierLoc().getSourceRange(),
Douglas Gregora5614c52010-09-08 23:56:00 +00004658 T->getIdentifier(),
4659 TL.getNameLoc(),
4660 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004661 if (Result.isNull())
4662 return QualType();
4663
4664 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4665 QualType NamedT = ElabT->getNamedType();
4666
4667 // Copy information relevant to the template specialization.
4668 TemplateSpecializationTypeLoc NamedTL
4669 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4670 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4671 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4672 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4673 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4674
4675 // Copy information relevant to the elaborated type.
4676 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4677 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004678
4679 // FIXME: DependentTemplateSpecializationType needs better source-location
4680 // info.
4681 NestedNameSpecifierLocBuilder Builder;
Douglas Gregora7a795b2011-03-01 20:11:18 +00004682 Builder.MakeTrivial(SemaRef.Context,
4683 NNS, TL.getQualifierLoc().getSourceRange());
Douglas Gregor844cb502011-03-01 18:12:44 +00004684 NewTL.setQualifierLoc(Builder.getWithLocInContext(SemaRef.Context));
John McCallc392f372010-06-11 00:33:02 +00004685 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004686 TypeLoc NewTL(Result, TL.getOpaqueData());
4687 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004688 }
4689 return Result;
4690}
4691
4692template<typename Derived>
Douglas Gregora7a795b2011-03-01 20:11:18 +00004693QualType TreeTransform<Derived>::
4694TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4695 DependentTemplateSpecializationTypeLoc TL,
4696 NestedNameSpecifierLoc QualifierLoc) {
4697 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4698
4699 TemplateArgumentListInfo NewTemplateArgs;
4700 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4701 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4702
4703 typedef TemplateArgumentLocContainerIterator<
4704 DependentTemplateSpecializationTypeLoc> ArgIterator;
4705 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4706 ArgIterator(TL, TL.getNumArgs()),
4707 NewTemplateArgs))
4708 return QualType();
4709
4710 QualType Result
4711 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4712 QualifierLoc,
4713 T->getIdentifier(),
4714 TL.getNameLoc(),
4715 NewTemplateArgs);
4716 if (Result.isNull())
4717 return QualType();
4718
4719 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4720 QualType NamedT = ElabT->getNamedType();
4721
4722 // Copy information relevant to the template specialization.
4723 TemplateSpecializationTypeLoc NamedTL
4724 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4725 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4726 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4727 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4728 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4729
4730 // Copy information relevant to the elaborated type.
4731 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4732 NewTL.setKeywordLoc(TL.getKeywordLoc());
4733 NewTL.setQualifierLoc(QualifierLoc);
4734 } else {
4735 TypeLoc NewTL(Result, TL.getOpaqueData());
4736 TLB.pushFullCopy(NewTL);
4737 }
4738 return Result;
4739}
4740
4741template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004742QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4743 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004744 QualType Pattern
4745 = getDerived().TransformType(TLB, TL.getPatternLoc());
4746 if (Pattern.isNull())
4747 return QualType();
4748
4749 QualType Result = TL.getType();
4750 if (getDerived().AlwaysRebuild() ||
4751 Pattern != TL.getPatternLoc().getType()) {
4752 Result = getDerived().RebuildPackExpansionType(Pattern,
4753 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004754 TL.getEllipsisLoc(),
4755 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004756 if (Result.isNull())
4757 return QualType();
4758 }
4759
4760 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4761 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4762 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004763}
4764
4765template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004766QualType
4767TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004768 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004769 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004770 TLB.pushFullCopy(TL);
4771 return TL.getType();
4772}
4773
4774template<typename Derived>
4775QualType
4776TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004777 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004778 // ObjCObjectType is never dependent.
4779 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004780 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004781}
Mike Stump11289f42009-09-09 15:08:12 +00004782
4783template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004784QualType
4785TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004786 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004787 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004788 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004789 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004790}
4791
Douglas Gregord6ff3322009-08-04 16:50:30 +00004792//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004793// Statement transformation
4794//===----------------------------------------------------------------------===//
4795template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004796StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004797TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004798 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004799}
4800
4801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004802StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004803TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4804 return getDerived().TransformCompoundStmt(S, false);
4805}
4806
4807template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004808StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004809TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004810 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004811 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004812 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004813 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004814 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4815 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004816 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004817 if (Result.isInvalid()) {
4818 // Immediately fail if this was a DeclStmt, since it's very
4819 // likely that this will cause problems for future statements.
4820 if (isa<DeclStmt>(*B))
4821 return StmtError();
4822
4823 // Otherwise, just keep processing substatements and fail later.
4824 SubStmtInvalid = true;
4825 continue;
4826 }
Mike Stump11289f42009-09-09 15:08:12 +00004827
Douglas Gregorebe10102009-08-20 07:17:43 +00004828 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4829 Statements.push_back(Result.takeAs<Stmt>());
4830 }
Mike Stump11289f42009-09-09 15:08:12 +00004831
John McCall1ababa62010-08-27 19:56:05 +00004832 if (SubStmtInvalid)
4833 return StmtError();
4834
Douglas Gregorebe10102009-08-20 07:17:43 +00004835 if (!getDerived().AlwaysRebuild() &&
4836 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004837 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004838
4839 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4840 move_arg(Statements),
4841 S->getRBracLoc(),
4842 IsStmtExpr);
4843}
Mike Stump11289f42009-09-09 15:08:12 +00004844
Douglas Gregorebe10102009-08-20 07:17:43 +00004845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004846StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004847TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004848 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004849 {
4850 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004851 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004852
Eli Friedman06577382009-11-19 03:14:00 +00004853 // Transform the left-hand case value.
4854 LHS = getDerived().TransformExpr(S->getLHS());
4855 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004856 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004857
Eli Friedman06577382009-11-19 03:14:00 +00004858 // Transform the right-hand case value (for the GNU case-range extension).
4859 RHS = getDerived().TransformExpr(S->getRHS());
4860 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004861 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004862 }
Mike Stump11289f42009-09-09 15:08:12 +00004863
Douglas Gregorebe10102009-08-20 07:17:43 +00004864 // Build the case statement.
4865 // Case statements are always rebuilt so that they will attached to their
4866 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004867 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004868 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004869 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004870 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004871 S->getColonLoc());
4872 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004873 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004874
Douglas Gregorebe10102009-08-20 07:17:43 +00004875 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004876 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004877 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004878 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004879
Douglas Gregorebe10102009-08-20 07:17:43 +00004880 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004881 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004882}
4883
4884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004885StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004886TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004887 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004888 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004889 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004890 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004891
Douglas Gregorebe10102009-08-20 07:17:43 +00004892 // Default statements are always rebuilt
4893 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004894 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004895}
Mike Stump11289f42009-09-09 15:08:12 +00004896
Douglas Gregorebe10102009-08-20 07:17:43 +00004897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004898StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004899TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004900 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004901 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004902 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004903
Chris Lattnercab02a62011-02-17 20:34:02 +00004904 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4905 S->getDecl());
4906 if (!LD)
4907 return StmtError();
4908
4909
Douglas Gregorebe10102009-08-20 07:17:43 +00004910 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004911 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004912 cast<LabelDecl>(LD), SourceLocation(),
4913 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004914}
Mike Stump11289f42009-09-09 15:08:12 +00004915
Douglas Gregorebe10102009-08-20 07:17:43 +00004916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004917StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004918TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004919 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004920 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004921 VarDecl *ConditionVar = 0;
4922 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004923 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004924 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004925 getDerived().TransformDefinition(
4926 S->getConditionVariable()->getLocation(),
4927 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004928 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004929 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004930 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004931 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004932
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004933 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004934 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004935
4936 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004937 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004938 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4939 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004940 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004941 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004942
John McCallb268a282010-08-23 23:25:46 +00004943 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004944 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004945 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004946
John McCallb268a282010-08-23 23:25:46 +00004947 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4948 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004949 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004950
Douglas Gregorebe10102009-08-20 07:17:43 +00004951 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004952 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004953 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004954 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004955
Douglas Gregorebe10102009-08-20 07:17:43 +00004956 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004957 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004958 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004959 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004960
Douglas Gregorebe10102009-08-20 07:17:43 +00004961 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004962 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004963 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004964 Then.get() == S->getThen() &&
4965 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004966 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004967
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004968 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004969 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004970 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004971}
4972
4973template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004974StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004975TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004976 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004977 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004978 VarDecl *ConditionVar = 0;
4979 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004980 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004981 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004982 getDerived().TransformDefinition(
4983 S->getConditionVariable()->getLocation(),
4984 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004985 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004986 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004987 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004988 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004989
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004990 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004991 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004992 }
Mike Stump11289f42009-09-09 15:08:12 +00004993
Douglas Gregorebe10102009-08-20 07:17:43 +00004994 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004995 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004996 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004997 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004998 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004999 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005000
Douglas Gregorebe10102009-08-20 07:17:43 +00005001 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005002 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005003 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005004 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005005
Douglas Gregorebe10102009-08-20 07:17:43 +00005006 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005007 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5008 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005009}
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregorebe10102009-08-20 07:17:43 +00005011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005012StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005013TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005014 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005015 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005016 VarDecl *ConditionVar = 0;
5017 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005018 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005019 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005020 getDerived().TransformDefinition(
5021 S->getConditionVariable()->getLocation(),
5022 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005023 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005024 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005025 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005026 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005027
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005028 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005029 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005030
5031 if (S->getCond()) {
5032 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005033 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5034 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005035 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005036 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005037 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005038 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005039 }
Mike Stump11289f42009-09-09 15:08:12 +00005040
John McCallb268a282010-08-23 23:25:46 +00005041 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5042 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005043 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005044
Douglas Gregorebe10102009-08-20 07:17:43 +00005045 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005046 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005047 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005048 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005049
Douglas Gregorebe10102009-08-20 07:17:43 +00005050 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005051 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005052 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005053 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005054 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005055
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005056 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005057 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005058}
Mike Stump11289f42009-09-09 15:08:12 +00005059
Douglas Gregorebe10102009-08-20 07:17:43 +00005060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005061StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005062TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005063 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005064 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005065 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005066 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005067
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005068 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005069 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005070 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005071 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005072
Douglas Gregorebe10102009-08-20 07:17:43 +00005073 if (!getDerived().AlwaysRebuild() &&
5074 Cond.get() == S->getCond() &&
5075 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005076 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005077
John McCallb268a282010-08-23 23:25:46 +00005078 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5079 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005080 S->getRParenLoc());
5081}
Mike Stump11289f42009-09-09 15:08:12 +00005082
Douglas Gregorebe10102009-08-20 07:17:43 +00005083template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005084StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005085TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005086 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005087 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005088 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005089 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005090
Douglas Gregorebe10102009-08-20 07:17:43 +00005091 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005092 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005093 VarDecl *ConditionVar = 0;
5094 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005095 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005096 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005097 getDerived().TransformDefinition(
5098 S->getConditionVariable()->getLocation(),
5099 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005100 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005101 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005102 } else {
5103 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005104
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005105 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005106 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005107
5108 if (S->getCond()) {
5109 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005110 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5111 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005112 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005113 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005114
John McCallb268a282010-08-23 23:25:46 +00005115 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005116 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005117 }
Mike Stump11289f42009-09-09 15:08:12 +00005118
John McCallb268a282010-08-23 23:25:46 +00005119 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5120 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005121 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005122
Douglas Gregorebe10102009-08-20 07:17:43 +00005123 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005124 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005125 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005126 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005127
John McCallb268a282010-08-23 23:25:46 +00005128 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5129 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005130 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005131
Douglas Gregorebe10102009-08-20 07:17:43 +00005132 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005133 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005134 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005135 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005136
Douglas Gregorebe10102009-08-20 07:17:43 +00005137 if (!getDerived().AlwaysRebuild() &&
5138 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005139 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005140 Inc.get() == S->getInc() &&
5141 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005142 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005143
Douglas Gregorebe10102009-08-20 07:17:43 +00005144 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005145 Init.get(), FullCond, ConditionVar,
5146 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005147}
5148
5149template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005150StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005151TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005152 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5153 S->getLabel());
5154 if (!LD)
5155 return StmtError();
5156
Douglas Gregorebe10102009-08-20 07:17:43 +00005157 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005158 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005159 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005160}
5161
5162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005163StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005164TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005165 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005166 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005167 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005168
Douglas Gregorebe10102009-08-20 07:17:43 +00005169 if (!getDerived().AlwaysRebuild() &&
5170 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005171 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005172
5173 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005174 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005175}
5176
5177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005178StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005179TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005180 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005181}
Mike Stump11289f42009-09-09 15:08:12 +00005182
Douglas Gregorebe10102009-08-20 07:17:43 +00005183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005184StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005185TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005186 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005187}
Mike Stump11289f42009-09-09 15:08:12 +00005188
Douglas Gregorebe10102009-08-20 07:17:43 +00005189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005190StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005191TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005192 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005193 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005194 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005195
Mike Stump11289f42009-09-09 15:08:12 +00005196 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005197 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005198 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005199}
Mike Stump11289f42009-09-09 15:08:12 +00005200
Douglas Gregorebe10102009-08-20 07:17:43 +00005201template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005202StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005203TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005204 bool DeclChanged = false;
5205 llvm::SmallVector<Decl *, 4> Decls;
5206 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5207 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005208 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5209 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005210 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005211 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005212
Douglas Gregorebe10102009-08-20 07:17:43 +00005213 if (Transformed != *D)
5214 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005215
Douglas Gregorebe10102009-08-20 07:17:43 +00005216 Decls.push_back(Transformed);
5217 }
Mike Stump11289f42009-09-09 15:08:12 +00005218
Douglas Gregorebe10102009-08-20 07:17:43 +00005219 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005220 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005221
5222 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005223 S->getStartLoc(), S->getEndLoc());
5224}
Mike Stump11289f42009-09-09 15:08:12 +00005225
Douglas Gregorebe10102009-08-20 07:17:43 +00005226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005227StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005228TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005229
John McCall37ad5512010-08-23 06:44:23 +00005230 ASTOwningVector<Expr*> Constraints(getSema());
5231 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005232 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005233
John McCalldadc5752010-08-24 06:29:42 +00005234 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005235 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005236
5237 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005238
Anders Carlssonaaeef072010-01-24 05:50:09 +00005239 // Go through the outputs.
5240 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005241 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005242
Anders Carlssonaaeef072010-01-24 05:50:09 +00005243 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005244 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005245
Anders Carlssonaaeef072010-01-24 05:50:09 +00005246 // Transform the output expr.
5247 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005248 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005249 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005250 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005251
Anders Carlssonaaeef072010-01-24 05:50:09 +00005252 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005253
John McCallb268a282010-08-23 23:25:46 +00005254 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005255 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005256
Anders Carlssonaaeef072010-01-24 05:50:09 +00005257 // Go through the inputs.
5258 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005259 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005260
Anders Carlssonaaeef072010-01-24 05:50:09 +00005261 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005262 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005263
Anders Carlssonaaeef072010-01-24 05:50:09 +00005264 // Transform the input expr.
5265 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005266 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005267 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005268 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005269
Anders Carlssonaaeef072010-01-24 05:50:09 +00005270 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005271
John McCallb268a282010-08-23 23:25:46 +00005272 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005273 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005274
Anders Carlssonaaeef072010-01-24 05:50:09 +00005275 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005276 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005277
5278 // Go through the clobbers.
5279 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005280 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005281
5282 // No need to transform the asm string literal.
5283 AsmString = SemaRef.Owned(S->getAsmString());
5284
5285 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5286 S->isSimple(),
5287 S->isVolatile(),
5288 S->getNumOutputs(),
5289 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005290 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005291 move_arg(Constraints),
5292 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005293 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005294 move_arg(Clobbers),
5295 S->getRParenLoc(),
5296 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005297}
5298
5299
5300template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005301StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005302TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005303 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005304 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005305 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005306 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005307
Douglas Gregor96c79492010-04-23 22:50:49 +00005308 // Transform the @catch statements (if present).
5309 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005310 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005311 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005312 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005313 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005314 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005315 if (Catch.get() != S->getCatchStmt(I))
5316 AnyCatchChanged = true;
5317 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005318 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005319
Douglas Gregor306de2f2010-04-22 23:59:56 +00005320 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005321 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005322 if (S->getFinallyStmt()) {
5323 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5324 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005325 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005326 }
5327
5328 // If nothing changed, just retain this statement.
5329 if (!getDerived().AlwaysRebuild() &&
5330 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005331 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005332 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005333 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005334
Douglas Gregor306de2f2010-04-22 23:59:56 +00005335 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005336 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5337 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005338}
Mike Stump11289f42009-09-09 15:08:12 +00005339
Douglas Gregorebe10102009-08-20 07:17:43 +00005340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005341StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005342TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005343 // Transform the @catch parameter, if there is one.
5344 VarDecl *Var = 0;
5345 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5346 TypeSourceInfo *TSInfo = 0;
5347 if (FromVar->getTypeSourceInfo()) {
5348 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5349 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005350 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005351 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005352
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005353 QualType T;
5354 if (TSInfo)
5355 T = TSInfo->getType();
5356 else {
5357 T = getDerived().TransformType(FromVar->getType());
5358 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005359 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005360 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005361
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005362 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5363 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005364 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005365 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005366
John McCalldadc5752010-08-24 06:29:42 +00005367 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005368 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005369 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005370
5371 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005372 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005373 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005374}
Mike Stump11289f42009-09-09 15:08:12 +00005375
Douglas Gregorebe10102009-08-20 07:17:43 +00005376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005377StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005378TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005379 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005380 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005381 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005382 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005383
Douglas Gregor306de2f2010-04-22 23:59:56 +00005384 // If nothing changed, just retain this statement.
5385 if (!getDerived().AlwaysRebuild() &&
5386 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005387 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005388
5389 // Build a new statement.
5390 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005391 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005392}
Mike Stump11289f42009-09-09 15:08:12 +00005393
Douglas Gregorebe10102009-08-20 07:17:43 +00005394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005395StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005396TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005397 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005398 if (S->getThrowExpr()) {
5399 Operand = getDerived().TransformExpr(S->getThrowExpr());
5400 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005401 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005402 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005403
Douglas Gregor2900c162010-04-22 21:44:01 +00005404 if (!getDerived().AlwaysRebuild() &&
5405 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005406 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005407
John McCallb268a282010-08-23 23:25:46 +00005408 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005409}
Mike Stump11289f42009-09-09 15:08:12 +00005410
Douglas Gregorebe10102009-08-20 07:17:43 +00005411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005412StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005413TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005414 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005415 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005416 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005417 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005418 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005419
Douglas Gregor6148de72010-04-22 22:01:21 +00005420 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005421 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005422 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005423 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005424
Douglas Gregor6148de72010-04-22 22:01:21 +00005425 // If nothing change, just retain the current statement.
5426 if (!getDerived().AlwaysRebuild() &&
5427 Object.get() == S->getSynchExpr() &&
5428 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005429 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005430
5431 // Build a new statement.
5432 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005433 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005434}
5435
5436template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005437StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005438TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005439 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005440 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005441 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005442 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005443 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005444
Douglas Gregorf68a5082010-04-22 23:10:45 +00005445 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005446 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005447 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005448 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005449
Douglas Gregorf68a5082010-04-22 23:10:45 +00005450 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005451 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005452 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005453 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005454
Douglas Gregorf68a5082010-04-22 23:10:45 +00005455 // If nothing changed, just retain this statement.
5456 if (!getDerived().AlwaysRebuild() &&
5457 Element.get() == S->getElement() &&
5458 Collection.get() == S->getCollection() &&
5459 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005460 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005461
Douglas Gregorf68a5082010-04-22 23:10:45 +00005462 // Build a new statement.
5463 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5464 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005465 Element.get(),
5466 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005467 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005468 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005469}
5470
5471
5472template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005473StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005474TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5475 // Transform the exception declaration, if any.
5476 VarDecl *Var = 0;
5477 if (S->getExceptionDecl()) {
5478 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005479 TypeSourceInfo *T = getDerived().TransformType(
5480 ExceptionDecl->getTypeSourceInfo());
5481 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005482 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005483
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005484 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005485 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005486 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005487 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005488 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005489 }
Mike Stump11289f42009-09-09 15:08:12 +00005490
Douglas Gregorebe10102009-08-20 07:17:43 +00005491 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005492 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005493 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005494 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005495
Douglas Gregorebe10102009-08-20 07:17:43 +00005496 if (!getDerived().AlwaysRebuild() &&
5497 !Var &&
5498 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005499 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005500
5501 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5502 Var,
John McCallb268a282010-08-23 23:25:46 +00005503 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005504}
Mike Stump11289f42009-09-09 15:08:12 +00005505
Douglas Gregorebe10102009-08-20 07:17:43 +00005506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005507StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005508TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5509 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005510 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005511 = getDerived().TransformCompoundStmt(S->getTryBlock());
5512 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005513 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005514
Douglas Gregorebe10102009-08-20 07:17:43 +00005515 // Transform the handlers.
5516 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005517 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005518 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005519 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005520 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5521 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005522 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005523
Douglas Gregorebe10102009-08-20 07:17:43 +00005524 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5525 Handlers.push_back(Handler.takeAs<Stmt>());
5526 }
Mike Stump11289f42009-09-09 15:08:12 +00005527
Douglas Gregorebe10102009-08-20 07:17:43 +00005528 if (!getDerived().AlwaysRebuild() &&
5529 TryBlock.get() == S->getTryBlock() &&
5530 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005531 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005532
John McCallb268a282010-08-23 23:25:46 +00005533 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005534 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005535}
Mike Stump11289f42009-09-09 15:08:12 +00005536
Douglas Gregorebe10102009-08-20 07:17:43 +00005537//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005538// Expression transformation
5539//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005541ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005542TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005543 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005544}
Mike Stump11289f42009-09-09 15:08:12 +00005545
5546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005547ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005548TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005549 NestedNameSpecifierLoc QualifierLoc;
5550 if (E->getQualifierLoc()) {
5551 QualifierLoc
5552 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5553 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005554 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005555 }
John McCallce546572009-12-08 09:08:17 +00005556
5557 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005558 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5559 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005560 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005561 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005562
John McCall815039a2010-08-17 21:27:17 +00005563 DeclarationNameInfo NameInfo = E->getNameInfo();
5564 if (NameInfo.getName()) {
5565 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5566 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005567 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005568 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005569
5570 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005571 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005572 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005573 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005574 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005575
5576 // Mark it referenced in the new context regardless.
5577 // FIXME: this is a bit instantiation-specific.
5578 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5579
John McCallc3007a22010-10-26 07:05:15 +00005580 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005581 }
John McCallce546572009-12-08 09:08:17 +00005582
5583 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005584 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005585 TemplateArgs = &TransArgs;
5586 TransArgs.setLAngleLoc(E->getLAngleLoc());
5587 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005588 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5589 E->getNumTemplateArgs(),
5590 TransArgs))
5591 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005592 }
5593
Douglas Gregorea972d32011-02-28 21:54:11 +00005594 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5595 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005596}
Mike Stump11289f42009-09-09 15:08:12 +00005597
Douglas Gregora16548e2009-08-11 05:31:07 +00005598template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005599ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005600TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005601 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005602}
Mike Stump11289f42009-09-09 15:08:12 +00005603
Douglas Gregora16548e2009-08-11 05:31:07 +00005604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005605ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005606TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005607 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005608}
Mike Stump11289f42009-09-09 15:08:12 +00005609
Douglas Gregora16548e2009-08-11 05:31:07 +00005610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005611ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005612TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005613 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005614}
Mike Stump11289f42009-09-09 15:08:12 +00005615
Douglas Gregora16548e2009-08-11 05:31:07 +00005616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005617ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005618TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005619 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005620}
Mike Stump11289f42009-09-09 15:08:12 +00005621
Douglas Gregora16548e2009-08-11 05:31:07 +00005622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005623ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005624TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005625 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005626}
5627
5628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005629ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005630TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005631 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005633 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005634
Douglas Gregora16548e2009-08-11 05:31:07 +00005635 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005636 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005637
John McCallb268a282010-08-23 23:25:46 +00005638 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 E->getRParen());
5640}
5641
Mike Stump11289f42009-09-09 15:08:12 +00005642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005643ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005644TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005645 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005648
Douglas Gregora16548e2009-08-11 05:31:07 +00005649 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005650 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregora16548e2009-08-11 05:31:07 +00005652 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5653 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005654 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005655}
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregora16548e2009-08-11 05:31:07 +00005657template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005658ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005659TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5660 // Transform the type.
5661 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5662 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005663 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005664
Douglas Gregor882211c2010-04-28 22:16:22 +00005665 // Transform all of the components into components similar to what the
5666 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005667 // FIXME: It would be slightly more efficient in the non-dependent case to
5668 // just map FieldDecls, rather than requiring the rebuilder to look for
5669 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005670 // template code that we don't care.
5671 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005672 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005673 typedef OffsetOfExpr::OffsetOfNode Node;
5674 llvm::SmallVector<Component, 4> Components;
5675 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5676 const Node &ON = E->getComponent(I);
5677 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005678 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005679 Comp.LocStart = ON.getRange().getBegin();
5680 Comp.LocEnd = ON.getRange().getEnd();
5681 switch (ON.getKind()) {
5682 case Node::Array: {
5683 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005684 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005685 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005686 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005687
Douglas Gregor882211c2010-04-28 22:16:22 +00005688 ExprChanged = ExprChanged || Index.get() != FromIndex;
5689 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005690 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005691 break;
5692 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005693
Douglas Gregor882211c2010-04-28 22:16:22 +00005694 case Node::Field:
5695 case Node::Identifier:
5696 Comp.isBrackets = false;
5697 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005698 if (!Comp.U.IdentInfo)
5699 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005700
Douglas Gregor882211c2010-04-28 22:16:22 +00005701 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005702
Douglas Gregord1702062010-04-29 00:18:15 +00005703 case Node::Base:
5704 // Will be recomputed during the rebuild.
5705 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005706 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005707
Douglas Gregor882211c2010-04-28 22:16:22 +00005708 Components.push_back(Comp);
5709 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005710
Douglas Gregor882211c2010-04-28 22:16:22 +00005711 // If nothing changed, retain the existing expression.
5712 if (!getDerived().AlwaysRebuild() &&
5713 Type == E->getTypeSourceInfo() &&
5714 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005715 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005716
Douglas Gregor882211c2010-04-28 22:16:22 +00005717 // Build a new offsetof expression.
5718 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5719 Components.data(), Components.size(),
5720 E->getRParenLoc());
5721}
5722
5723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005724ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005725TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5726 assert(getDerived().AlreadyTransformed(E->getType()) &&
5727 "opaque value expression requires transformation");
5728 return SemaRef.Owned(E);
5729}
5730
5731template<typename Derived>
5732ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005733TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005734 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005735 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005736
John McCallbcd03502009-12-07 02:54:59 +00005737 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005738 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005739 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005740
John McCall4c98fd82009-11-04 07:28:41 +00005741 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005742 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005743
John McCall4c98fd82009-11-04 07:28:41 +00005744 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005745 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005746 E->getSourceRange());
5747 }
Mike Stump11289f42009-09-09 15:08:12 +00005748
John McCalldadc5752010-08-24 06:29:42 +00005749 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005750 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005751 // C++0x [expr.sizeof]p1:
5752 // The operand is either an expression, which is an unevaluated operand
5753 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005754 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005755
Douglas Gregora16548e2009-08-11 05:31:07 +00005756 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5757 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005758 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005759
Douglas Gregora16548e2009-08-11 05:31:07 +00005760 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005761 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005762 }
Mike Stump11289f42009-09-09 15:08:12 +00005763
John McCallb268a282010-08-23 23:25:46 +00005764 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005765 E->isSizeOf(),
5766 E->getSourceRange());
5767}
Mike Stump11289f42009-09-09 15:08:12 +00005768
Douglas Gregora16548e2009-08-11 05:31:07 +00005769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005770ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005771TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005772 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005775
John McCalldadc5752010-08-24 06:29:42 +00005776 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005777 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005778 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005779
5780
Douglas Gregora16548e2009-08-11 05:31:07 +00005781 if (!getDerived().AlwaysRebuild() &&
5782 LHS.get() == E->getLHS() &&
5783 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005784 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005785
John McCallb268a282010-08-23 23:25:46 +00005786 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005787 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005788 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005789 E->getRBracketLoc());
5790}
Mike Stump11289f42009-09-09 15:08:12 +00005791
5792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005793ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005794TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005795 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005796 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005797 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005798 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005799
5800 // Transform arguments.
5801 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005802 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005803 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5804 &ArgChanged))
5805 return ExprError();
5806
Douglas Gregora16548e2009-08-11 05:31:07 +00005807 if (!getDerived().AlwaysRebuild() &&
5808 Callee.get() == E->getCallee() &&
5809 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005810 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005811
Douglas Gregora16548e2009-08-11 05:31:07 +00005812 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005813 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005814 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005815 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005816 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005817 E->getRParenLoc());
5818}
Mike Stump11289f42009-09-09 15:08:12 +00005819
5820template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005821ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005822TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005823 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005824 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005825 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005826
Douglas Gregorea972d32011-02-28 21:54:11 +00005827 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005828 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005829 QualifierLoc
5830 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5831
5832 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005833 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005834 }
Mike Stump11289f42009-09-09 15:08:12 +00005835
Eli Friedman2cfcef62009-12-04 06:40:45 +00005836 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005837 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5838 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005839 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005841
John McCall16df1e52010-03-30 21:47:33 +00005842 NamedDecl *FoundDecl = E->getFoundDecl();
5843 if (FoundDecl == E->getMemberDecl()) {
5844 FoundDecl = Member;
5845 } else {
5846 FoundDecl = cast_or_null<NamedDecl>(
5847 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5848 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005849 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005850 }
5851
Douglas Gregora16548e2009-08-11 05:31:07 +00005852 if (!getDerived().AlwaysRebuild() &&
5853 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005854 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005855 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005856 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005857 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005858
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005859 // Mark it referenced in the new context regardless.
5860 // FIXME: this is a bit instantiation-specific.
5861 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005862 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005863 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005864
John McCall6b51f282009-11-23 01:53:49 +00005865 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005866 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005867 TransArgs.setLAngleLoc(E->getLAngleLoc());
5868 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005869 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5870 E->getNumTemplateArgs(),
5871 TransArgs))
5872 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005873 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005874
Douglas Gregora16548e2009-08-11 05:31:07 +00005875 // FIXME: Bogus source location for the operator
5876 SourceLocation FakeOperatorLoc
5877 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5878
John McCall38836f02010-01-15 08:34:02 +00005879 // FIXME: to do this check properly, we will need to preserve the
5880 // first-qualifier-in-scope here, just in case we had a dependent
5881 // base (and therefore couldn't do the check) and a
5882 // nested-name-qualifier (and therefore could do the lookup).
5883 NamedDecl *FirstQualifierInScope = 0;
5884
John McCallb268a282010-08-23 23:25:46 +00005885 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005886 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005887 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005888 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005889 Member,
John McCall16df1e52010-03-30 21:47:33 +00005890 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005891 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005892 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005893 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005894}
Mike Stump11289f42009-09-09 15:08:12 +00005895
Douglas Gregora16548e2009-08-11 05:31:07 +00005896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005897ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005898TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005899 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005900 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005901 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005902
John McCalldadc5752010-08-24 06:29:42 +00005903 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005904 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005905 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005906
Douglas Gregora16548e2009-08-11 05:31:07 +00005907 if (!getDerived().AlwaysRebuild() &&
5908 LHS.get() == E->getLHS() &&
5909 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005910 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005911
Douglas Gregora16548e2009-08-11 05:31:07 +00005912 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005913 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005914}
5915
Mike Stump11289f42009-09-09 15:08:12 +00005916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005917ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005918TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005919 CompoundAssignOperator *E) {
5920 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005921}
Mike Stump11289f42009-09-09 15:08:12 +00005922
Douglas Gregora16548e2009-08-11 05:31:07 +00005923template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005924ExprResult TreeTransform<Derived>::
5925TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5926 // Just rebuild the common and RHS expressions and see whether we
5927 // get any changes.
5928
5929 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5930 if (commonExpr.isInvalid())
5931 return ExprError();
5932
5933 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5934 if (rhs.isInvalid())
5935 return ExprError();
5936
5937 if (!getDerived().AlwaysRebuild() &&
5938 commonExpr.get() == e->getCommon() &&
5939 rhs.get() == e->getFalseExpr())
5940 return SemaRef.Owned(e);
5941
5942 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5943 e->getQuestionLoc(),
5944 0,
5945 e->getColonLoc(),
5946 rhs.get());
5947}
5948
5949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005950ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005951TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005952 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005953 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005954 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005955
John McCalldadc5752010-08-24 06:29:42 +00005956 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005957 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005958 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005959
John McCalldadc5752010-08-24 06:29:42 +00005960 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005961 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005962 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005963
Douglas Gregora16548e2009-08-11 05:31:07 +00005964 if (!getDerived().AlwaysRebuild() &&
5965 Cond.get() == E->getCond() &&
5966 LHS.get() == E->getLHS() &&
5967 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005968 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005969
John McCallb268a282010-08-23 23:25:46 +00005970 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005971 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005972 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005973 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005974 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005975}
Mike Stump11289f42009-09-09 15:08:12 +00005976
5977template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005978ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005979TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005980 // Implicit casts are eliminated during transformation, since they
5981 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005982 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005983}
Mike Stump11289f42009-09-09 15:08:12 +00005984
Douglas Gregora16548e2009-08-11 05:31:07 +00005985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005986ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005987TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005988 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5989 if (!Type)
5990 return ExprError();
5991
John McCalldadc5752010-08-24 06:29:42 +00005992 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005993 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005994 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005995 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005996
Douglas Gregora16548e2009-08-11 05:31:07 +00005997 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005998 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005999 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006000 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006001
John McCall97513962010-01-15 18:39:57 +00006002 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006003 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006004 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006005 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006006}
Mike Stump11289f42009-09-09 15:08:12 +00006007
Douglas Gregora16548e2009-08-11 05:31:07 +00006008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006009ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006010TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006011 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6012 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6013 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006014 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006015
John McCalldadc5752010-08-24 06:29:42 +00006016 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006017 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006018 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006019
Douglas Gregora16548e2009-08-11 05:31:07 +00006020 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006021 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006022 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006023 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006024
John McCall5d7aa7f2010-01-19 22:33:45 +00006025 // Note: the expression type doesn't necessarily match the
6026 // type-as-written, but that's okay, because it should always be
6027 // derivable from the initializer.
6028
John McCalle15bbff2010-01-18 19:35:47 +00006029 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006030 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006031 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006032}
Mike Stump11289f42009-09-09 15:08:12 +00006033
Douglas Gregora16548e2009-08-11 05:31:07 +00006034template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006035ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006036TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006037 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006038 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006039 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregora16548e2009-08-11 05:31:07 +00006041 if (!getDerived().AlwaysRebuild() &&
6042 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006043 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006044
Douglas Gregora16548e2009-08-11 05:31:07 +00006045 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006046 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006047 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006048 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006049 E->getAccessorLoc(),
6050 E->getAccessor());
6051}
Mike Stump11289f42009-09-09 15:08:12 +00006052
Douglas Gregora16548e2009-08-11 05:31:07 +00006053template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006054ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006055TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006056 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006057
John McCall37ad5512010-08-23 06:44:23 +00006058 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006059 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6060 Inits, &InitChanged))
6061 return ExprError();
6062
Douglas Gregora16548e2009-08-11 05:31:07 +00006063 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006064 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006065
Douglas Gregora16548e2009-08-11 05:31:07 +00006066 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006067 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006068}
Mike Stump11289f42009-09-09 15:08:12 +00006069
Douglas Gregora16548e2009-08-11 05:31:07 +00006070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006072TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006073 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006074
Douglas Gregorebe10102009-08-20 07:17:43 +00006075 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006076 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006077 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006078 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006079
Douglas Gregorebe10102009-08-20 07:17:43 +00006080 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006081 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006082 bool ExprChanged = false;
6083 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6084 DEnd = E->designators_end();
6085 D != DEnd; ++D) {
6086 if (D->isFieldDesignator()) {
6087 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6088 D->getDotLoc(),
6089 D->getFieldLoc()));
6090 continue;
6091 }
Mike Stump11289f42009-09-09 15:08:12 +00006092
Douglas Gregora16548e2009-08-11 05:31:07 +00006093 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006094 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006095 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006096 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006097
6098 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006099 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006100
Douglas Gregora16548e2009-08-11 05:31:07 +00006101 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6102 ArrayExprs.push_back(Index.release());
6103 continue;
6104 }
Mike Stump11289f42009-09-09 15:08:12 +00006105
Douglas Gregora16548e2009-08-11 05:31:07 +00006106 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006107 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006108 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6109 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006110 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006111
John McCalldadc5752010-08-24 06:29:42 +00006112 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006113 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006114 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006115
6116 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006117 End.get(),
6118 D->getLBracketLoc(),
6119 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006120
Douglas Gregora16548e2009-08-11 05:31:07 +00006121 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6122 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006123
Douglas Gregora16548e2009-08-11 05:31:07 +00006124 ArrayExprs.push_back(Start.release());
6125 ArrayExprs.push_back(End.release());
6126 }
Mike Stump11289f42009-09-09 15:08:12 +00006127
Douglas Gregora16548e2009-08-11 05:31:07 +00006128 if (!getDerived().AlwaysRebuild() &&
6129 Init.get() == E->getInit() &&
6130 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006131 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006132
Douglas Gregora16548e2009-08-11 05:31:07 +00006133 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6134 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006135 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006136}
Mike Stump11289f42009-09-09 15:08:12 +00006137
Douglas Gregora16548e2009-08-11 05:31:07 +00006138template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006139ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006140TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006141 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006142 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006143
Douglas Gregor3da3c062009-10-28 00:29:27 +00006144 // FIXME: Will we ever have proper type location here? Will we actually
6145 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006146 QualType T = getDerived().TransformType(E->getType());
6147 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006148 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006149
Douglas Gregora16548e2009-08-11 05:31:07 +00006150 if (!getDerived().AlwaysRebuild() &&
6151 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006152 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006153
Douglas Gregora16548e2009-08-11 05:31:07 +00006154 return getDerived().RebuildImplicitValueInitExpr(T);
6155}
Mike Stump11289f42009-09-09 15:08:12 +00006156
Douglas Gregora16548e2009-08-11 05:31:07 +00006157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006159TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006160 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6161 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006162 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006163
John McCalldadc5752010-08-24 06:29:42 +00006164 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006165 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006166 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006167
Douglas Gregora16548e2009-08-11 05:31:07 +00006168 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006169 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006170 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006171 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006172
John McCallb268a282010-08-23 23:25:46 +00006173 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006174 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006175}
6176
6177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006178ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006179TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006180 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006181 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006182 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6183 &ArgumentChanged))
6184 return ExprError();
6185
Douglas Gregora16548e2009-08-11 05:31:07 +00006186 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6187 move_arg(Inits),
6188 E->getRParenLoc());
6189}
Mike Stump11289f42009-09-09 15:08:12 +00006190
Douglas Gregora16548e2009-08-11 05:31:07 +00006191/// \brief Transform an address-of-label expression.
6192///
6193/// By default, the transformation of an address-of-label expression always
6194/// rebuilds the expression, so that the label identifier can be resolved to
6195/// the corresponding label statement by semantic analysis.
6196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006197ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006198TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006199 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6200 E->getLabel());
6201 if (!LD)
6202 return ExprError();
6203
Douglas Gregora16548e2009-08-11 05:31:07 +00006204 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006205 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006206}
Mike Stump11289f42009-09-09 15:08:12 +00006207
6208template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006209ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006210TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006211 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006212 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6213 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006214 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006215
Douglas Gregora16548e2009-08-11 05:31:07 +00006216 if (!getDerived().AlwaysRebuild() &&
6217 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006218 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006219
6220 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006221 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006222 E->getRParenLoc());
6223}
Mike Stump11289f42009-09-09 15:08:12 +00006224
Douglas Gregora16548e2009-08-11 05:31:07 +00006225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006226ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006227TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006228 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006229 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006230 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006231
John McCalldadc5752010-08-24 06:29:42 +00006232 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006233 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006234 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006235
John McCalldadc5752010-08-24 06:29:42 +00006236 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006237 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006239
Douglas Gregora16548e2009-08-11 05:31:07 +00006240 if (!getDerived().AlwaysRebuild() &&
6241 Cond.get() == E->getCond() &&
6242 LHS.get() == E->getLHS() &&
6243 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006244 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006245
Douglas Gregora16548e2009-08-11 05:31:07 +00006246 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006247 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006248 E->getRParenLoc());
6249}
Mike Stump11289f42009-09-09 15:08:12 +00006250
Douglas Gregora16548e2009-08-11 05:31:07 +00006251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006252ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006253TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006254 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006255}
6256
6257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006258ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006259TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006260 switch (E->getOperator()) {
6261 case OO_New:
6262 case OO_Delete:
6263 case OO_Array_New:
6264 case OO_Array_Delete:
6265 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006266 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006267
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006268 case OO_Call: {
6269 // This is a call to an object's operator().
6270 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6271
6272 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006273 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006274 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006275 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006276
6277 // FIXME: Poor location information
6278 SourceLocation FakeLParenLoc
6279 = SemaRef.PP.getLocForEndOfToken(
6280 static_cast<Expr *>(Object.get())->getLocEnd());
6281
6282 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006283 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006284 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6285 Args))
6286 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006287
John McCallb268a282010-08-23 23:25:46 +00006288 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006289 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006290 E->getLocEnd());
6291 }
6292
6293#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6294 case OO_##Name:
6295#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6296#include "clang/Basic/OperatorKinds.def"
6297 case OO_Subscript:
6298 // Handled below.
6299 break;
6300
6301 case OO_Conditional:
6302 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006303 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006304
6305 case OO_None:
6306 case NUM_OVERLOADED_OPERATORS:
6307 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006308 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006309 }
6310
John McCalldadc5752010-08-24 06:29:42 +00006311 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006312 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006313 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006314
John McCalldadc5752010-08-24 06:29:42 +00006315 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006316 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006317 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006318
John McCalldadc5752010-08-24 06:29:42 +00006319 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006320 if (E->getNumArgs() == 2) {
6321 Second = getDerived().TransformExpr(E->getArg(1));
6322 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006323 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006324 }
Mike Stump11289f42009-09-09 15:08:12 +00006325
Douglas Gregora16548e2009-08-11 05:31:07 +00006326 if (!getDerived().AlwaysRebuild() &&
6327 Callee.get() == E->getCallee() &&
6328 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006329 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006330 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006331
Douglas Gregora16548e2009-08-11 05:31:07 +00006332 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6333 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006334 Callee.get(),
6335 First.get(),
6336 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006337}
Mike Stump11289f42009-09-09 15:08:12 +00006338
Douglas Gregora16548e2009-08-11 05:31:07 +00006339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006340ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006341TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6342 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006343}
Mike Stump11289f42009-09-09 15:08:12 +00006344
Douglas Gregora16548e2009-08-11 05:31:07 +00006345template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006346ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006347TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6348 // Transform the callee.
6349 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6350 if (Callee.isInvalid())
6351 return ExprError();
6352
6353 // Transform exec config.
6354 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6355 if (EC.isInvalid())
6356 return ExprError();
6357
6358 // Transform arguments.
6359 bool ArgChanged = false;
6360 ASTOwningVector<Expr*> Args(SemaRef);
6361 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6362 &ArgChanged))
6363 return ExprError();
6364
6365 if (!getDerived().AlwaysRebuild() &&
6366 Callee.get() == E->getCallee() &&
6367 !ArgChanged)
6368 return SemaRef.Owned(E);
6369
6370 // FIXME: Wrong source location information for the '('.
6371 SourceLocation FakeLParenLoc
6372 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6373 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6374 move_arg(Args),
6375 E->getRParenLoc(), EC.get());
6376}
6377
6378template<typename Derived>
6379ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006380TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006381 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6382 if (!Type)
6383 return ExprError();
6384
John McCalldadc5752010-08-24 06:29:42 +00006385 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006386 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006387 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006388 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006389
Douglas Gregora16548e2009-08-11 05:31:07 +00006390 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006391 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006392 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006393 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006394
Douglas Gregora16548e2009-08-11 05:31:07 +00006395 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006396 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006397 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6398 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6399 SourceLocation FakeRParenLoc
6400 = SemaRef.PP.getLocForEndOfToken(
6401 E->getSubExpr()->getSourceRange().getEnd());
6402 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006403 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006404 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006405 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006406 FakeRAngleLoc,
6407 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006408 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006409 FakeRParenLoc);
6410}
Mike Stump11289f42009-09-09 15:08:12 +00006411
Douglas Gregora16548e2009-08-11 05:31:07 +00006412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006413ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006414TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6415 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006416}
Mike Stump11289f42009-09-09 15:08:12 +00006417
6418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006420TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6421 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006422}
6423
Douglas Gregora16548e2009-08-11 05:31:07 +00006424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006425ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006426TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006427 CXXReinterpretCastExpr *E) {
6428 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006429}
Mike Stump11289f42009-09-09 15:08:12 +00006430
Douglas Gregora16548e2009-08-11 05:31:07 +00006431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006432ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006433TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6434 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006435}
Mike Stump11289f42009-09-09 15:08:12 +00006436
Douglas Gregora16548e2009-08-11 05:31:07 +00006437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006438ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006439TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006440 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006441 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6442 if (!Type)
6443 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006444
John McCalldadc5752010-08-24 06:29:42 +00006445 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006446 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006447 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006448 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006449
Douglas Gregora16548e2009-08-11 05:31:07 +00006450 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006451 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006452 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006453 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006454
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006455 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006456 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006457 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006458 E->getRParenLoc());
6459}
Mike Stump11289f42009-09-09 15:08:12 +00006460
Douglas Gregora16548e2009-08-11 05:31:07 +00006461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006462ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006463TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006464 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006465 TypeSourceInfo *TInfo
6466 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6467 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006468 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006469
Douglas Gregora16548e2009-08-11 05:31:07 +00006470 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006471 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006472 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006473
Douglas Gregor9da64192010-04-26 22:37:10 +00006474 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6475 E->getLocStart(),
6476 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006477 E->getLocEnd());
6478 }
Mike Stump11289f42009-09-09 15:08:12 +00006479
Douglas Gregora16548e2009-08-11 05:31:07 +00006480 // We don't know whether the expression is potentially evaluated until
6481 // after we perform semantic analysis, so the expression is potentially
6482 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006483 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006484 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006485
John McCalldadc5752010-08-24 06:29:42 +00006486 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006487 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006489
Douglas Gregora16548e2009-08-11 05:31:07 +00006490 if (!getDerived().AlwaysRebuild() &&
6491 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006492 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006493
Douglas Gregor9da64192010-04-26 22:37:10 +00006494 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6495 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006496 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006497 E->getLocEnd());
6498}
6499
6500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006501ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006502TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6503 if (E->isTypeOperand()) {
6504 TypeSourceInfo *TInfo
6505 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6506 if (!TInfo)
6507 return ExprError();
6508
6509 if (!getDerived().AlwaysRebuild() &&
6510 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006511 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006512
6513 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6514 E->getLocStart(),
6515 TInfo,
6516 E->getLocEnd());
6517 }
6518
6519 // We don't know whether the expression is potentially evaluated until
6520 // after we perform semantic analysis, so the expression is potentially
6521 // potentially evaluated.
6522 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6523
6524 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6525 if (SubExpr.isInvalid())
6526 return ExprError();
6527
6528 if (!getDerived().AlwaysRebuild() &&
6529 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006530 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006531
6532 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6533 E->getLocStart(),
6534 SubExpr.get(),
6535 E->getLocEnd());
6536}
6537
6538template<typename Derived>
6539ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006540TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006541 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006542}
Mike Stump11289f42009-09-09 15:08:12 +00006543
Douglas Gregora16548e2009-08-11 05:31:07 +00006544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006545ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006546TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006547 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006548 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006549}
Mike Stump11289f42009-09-09 15:08:12 +00006550
Douglas Gregora16548e2009-08-11 05:31:07 +00006551template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006552ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006553TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006554 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6555 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6556 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006557
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006558 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006559 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006560
Douglas Gregorb15af892010-01-07 23:12:05 +00006561 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006562}
Mike Stump11289f42009-09-09 15:08:12 +00006563
Douglas Gregora16548e2009-08-11 05:31:07 +00006564template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006565ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006566TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006567 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006568 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006569 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006570
Douglas Gregora16548e2009-08-11 05:31:07 +00006571 if (!getDerived().AlwaysRebuild() &&
6572 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006573 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006574
John McCallb268a282010-08-23 23:25:46 +00006575 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006576}
Mike Stump11289f42009-09-09 15:08:12 +00006577
Douglas Gregora16548e2009-08-11 05:31:07 +00006578template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006579ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006580TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006581 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006582 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6583 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006584 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006585 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006586
Chandler Carruth794da4c2010-02-08 06:42:49 +00006587 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006588 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006589 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006590
Douglas Gregor033f6752009-12-23 23:03:06 +00006591 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006592}
Mike Stump11289f42009-09-09 15:08:12 +00006593
Douglas Gregora16548e2009-08-11 05:31:07 +00006594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006595ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006596TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6597 CXXScalarValueInitExpr *E) {
6598 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6599 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006600 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006601
Douglas Gregora16548e2009-08-11 05:31:07 +00006602 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006603 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006604 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006605
Douglas Gregor2b88c112010-09-08 00:15:04 +00006606 return getDerived().RebuildCXXScalarValueInitExpr(T,
6607 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006608 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006609}
Mike Stump11289f42009-09-09 15:08:12 +00006610
Douglas Gregora16548e2009-08-11 05:31:07 +00006611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006612ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006613TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006614 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006615 TypeSourceInfo *AllocTypeInfo
6616 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6617 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006618 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006619
Douglas Gregora16548e2009-08-11 05:31:07 +00006620 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006621 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006622 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006623 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006624
Douglas Gregora16548e2009-08-11 05:31:07 +00006625 // Transform the placement arguments (if any).
6626 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006627 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006628 if (getDerived().TransformExprs(E->getPlacementArgs(),
6629 E->getNumPlacementArgs(), true,
6630 PlacementArgs, &ArgumentChanged))
6631 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006632
Douglas Gregorebe10102009-08-20 07:17:43 +00006633 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006634 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006635 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6636 ConstructorArgs, &ArgumentChanged))
6637 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006638
Douglas Gregord2d9da02010-02-26 00:38:10 +00006639 // Transform constructor, new operator, and delete operator.
6640 CXXConstructorDecl *Constructor = 0;
6641 if (E->getConstructor()) {
6642 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006643 getDerived().TransformDecl(E->getLocStart(),
6644 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006645 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006646 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006647 }
6648
6649 FunctionDecl *OperatorNew = 0;
6650 if (E->getOperatorNew()) {
6651 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006652 getDerived().TransformDecl(E->getLocStart(),
6653 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006654 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006655 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006656 }
6657
6658 FunctionDecl *OperatorDelete = 0;
6659 if (E->getOperatorDelete()) {
6660 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006661 getDerived().TransformDecl(E->getLocStart(),
6662 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006663 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006664 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006665 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006666
Douglas Gregora16548e2009-08-11 05:31:07 +00006667 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006668 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006669 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006670 Constructor == E->getConstructor() &&
6671 OperatorNew == E->getOperatorNew() &&
6672 OperatorDelete == E->getOperatorDelete() &&
6673 !ArgumentChanged) {
6674 // Mark any declarations we need as referenced.
6675 // FIXME: instantiation-specific.
6676 if (Constructor)
6677 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6678 if (OperatorNew)
6679 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6680 if (OperatorDelete)
6681 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006682 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006683 }
Mike Stump11289f42009-09-09 15:08:12 +00006684
Douglas Gregor0744ef62010-09-07 21:49:58 +00006685 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006686 if (!ArraySize.get()) {
6687 // If no array size was specified, but the new expression was
6688 // instantiated with an array type (e.g., "new T" where T is
6689 // instantiated with "int[4]"), extract the outer bound from the
6690 // array type as our array size. We do this with constant and
6691 // dependently-sized array types.
6692 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6693 if (!ArrayT) {
6694 // Do nothing
6695 } else if (const ConstantArrayType *ConsArrayT
6696 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006697 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006698 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6699 ConsArrayT->getSize(),
6700 SemaRef.Context.getSizeType(),
6701 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006702 AllocType = ConsArrayT->getElementType();
6703 } else if (const DependentSizedArrayType *DepArrayT
6704 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6705 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006706 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006707 AllocType = DepArrayT->getElementType();
6708 }
6709 }
6710 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006711
Douglas Gregora16548e2009-08-11 05:31:07 +00006712 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6713 E->isGlobalNew(),
6714 /*FIXME:*/E->getLocStart(),
6715 move_arg(PlacementArgs),
6716 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006717 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006718 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006719 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006720 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006721 /*FIXME:*/E->getLocStart(),
6722 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006723 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006724}
Mike Stump11289f42009-09-09 15:08:12 +00006725
Douglas Gregora16548e2009-08-11 05:31:07 +00006726template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006727ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006728TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006729 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006730 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006731 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006732
Douglas Gregord2d9da02010-02-26 00:38:10 +00006733 // Transform the delete operator, if known.
6734 FunctionDecl *OperatorDelete = 0;
6735 if (E->getOperatorDelete()) {
6736 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006737 getDerived().TransformDecl(E->getLocStart(),
6738 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006739 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006740 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006741 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006742
Douglas Gregora16548e2009-08-11 05:31:07 +00006743 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006744 Operand.get() == E->getArgument() &&
6745 OperatorDelete == E->getOperatorDelete()) {
6746 // Mark any declarations we need as referenced.
6747 // FIXME: instantiation-specific.
6748 if (OperatorDelete)
6749 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006750
6751 if (!E->getArgument()->isTypeDependent()) {
6752 QualType Destroyed = SemaRef.Context.getBaseElementType(
6753 E->getDestroyedType());
6754 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6755 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6756 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6757 SemaRef.LookupDestructor(Record));
6758 }
6759 }
6760
John McCallc3007a22010-10-26 07:05:15 +00006761 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006762 }
Mike Stump11289f42009-09-09 15:08:12 +00006763
Douglas Gregora16548e2009-08-11 05:31:07 +00006764 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6765 E->isGlobalDelete(),
6766 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006767 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006768}
Mike Stump11289f42009-09-09 15:08:12 +00006769
Douglas Gregora16548e2009-08-11 05:31:07 +00006770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006771ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006772TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006773 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006774 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006775 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006776 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006777
John McCallba7bf592010-08-24 05:47:05 +00006778 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006779 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006780 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006781 E->getOperatorLoc(),
6782 E->isArrow()? tok::arrow : tok::period,
6783 ObjectTypePtr,
6784 MayBePseudoDestructor);
6785 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006786 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006787
John McCallba7bf592010-08-24 05:47:05 +00006788 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006789 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6790 if (QualifierLoc) {
6791 QualifierLoc
6792 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6793 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006794 return ExprError();
6795 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006796 CXXScopeSpec SS;
6797 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006798
Douglas Gregor678f90d2010-02-25 01:56:36 +00006799 PseudoDestructorTypeStorage Destroyed;
6800 if (E->getDestroyedTypeInfo()) {
6801 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006802 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006803 ObjectType, 0,
6804 QualifierLoc.getNestedNameSpecifier());
Douglas Gregor678f90d2010-02-25 01:56:36 +00006805 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006806 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006807 Destroyed = DestroyedTypeInfo;
6808 } else if (ObjectType->isDependentType()) {
6809 // We aren't likely to be able to resolve the identifier down to a type
6810 // now anyway, so just retain the identifier.
6811 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6812 E->getDestroyedTypeLoc());
6813 } else {
6814 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006815 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006816 *E->getDestroyedTypeIdentifier(),
6817 E->getDestroyedTypeLoc(),
6818 /*Scope=*/0,
6819 SS, ObjectTypePtr,
6820 false);
6821 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006822 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006823
Douglas Gregor678f90d2010-02-25 01:56:36 +00006824 Destroyed
6825 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6826 E->getDestroyedTypeLoc());
6827 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006828
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006829 TypeSourceInfo *ScopeTypeInfo = 0;
6830 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006831 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006832 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006833 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006834 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006835
John McCallb268a282010-08-23 23:25:46 +00006836 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006837 E->getOperatorLoc(),
6838 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006839 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006840 ScopeTypeInfo,
6841 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006842 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006843 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006844}
Mike Stump11289f42009-09-09 15:08:12 +00006845
Douglas Gregorad8a3362009-09-04 17:36:40 +00006846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006847ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006848TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006849 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006850 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6851
6852 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6853 Sema::LookupOrdinaryName);
6854
6855 // Transform all the decls.
6856 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6857 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006858 NamedDecl *InstD = static_cast<NamedDecl*>(
6859 getDerived().TransformDecl(Old->getNameLoc(),
6860 *I));
John McCall84d87672009-12-10 09:41:52 +00006861 if (!InstD) {
6862 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6863 // This can happen because of dependent hiding.
6864 if (isa<UsingShadowDecl>(*I))
6865 continue;
6866 else
John McCallfaf5fb42010-08-26 23:41:50 +00006867 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006868 }
John McCalle66edc12009-11-24 19:00:30 +00006869
6870 // Expand using declarations.
6871 if (isa<UsingDecl>(InstD)) {
6872 UsingDecl *UD = cast<UsingDecl>(InstD);
6873 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6874 E = UD->shadow_end(); I != E; ++I)
6875 R.addDecl(*I);
6876 continue;
6877 }
6878
6879 R.addDecl(InstD);
6880 }
6881
6882 // Resolve a kind, but don't do any further analysis. If it's
6883 // ambiguous, the callee needs to deal with it.
6884 R.resolveKind();
6885
6886 // Rebuild the nested-name qualifier, if present.
6887 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006888 if (Old->getQualifierLoc()) {
6889 NestedNameSpecifierLoc QualifierLoc
6890 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6891 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006892 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006893
Douglas Gregor0da1d432011-02-28 20:01:57 +00006894 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006895 }
6896
Douglas Gregor9262f472010-04-27 18:19:34 +00006897 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006898 CXXRecordDecl *NamingClass
6899 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6900 Old->getNameLoc(),
6901 Old->getNamingClass()));
6902 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006903 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006904
Douglas Gregorda7be082010-04-27 16:10:10 +00006905 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006906 }
6907
6908 // If we have no template arguments, it's a normal declaration name.
6909 if (!Old->hasExplicitTemplateArgs())
6910 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6911
6912 // If we have template arguments, rebuild them, then rebuild the
6913 // templateid expression.
6914 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006915 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6916 Old->getNumTemplateArgs(),
6917 TransArgs))
6918 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006919
6920 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6921 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006922}
Mike Stump11289f42009-09-09 15:08:12 +00006923
Douglas Gregora16548e2009-08-11 05:31:07 +00006924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006925ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006926TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006927 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6928 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006930
Douglas Gregora16548e2009-08-11 05:31:07 +00006931 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006932 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006933 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006934
Mike Stump11289f42009-09-09 15:08:12 +00006935 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006936 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006937 T,
6938 E->getLocEnd());
6939}
Mike Stump11289f42009-09-09 15:08:12 +00006940
Douglas Gregora16548e2009-08-11 05:31:07 +00006941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006942ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006943TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6944 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6945 if (!LhsT)
6946 return ExprError();
6947
6948 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6949 if (!RhsT)
6950 return ExprError();
6951
6952 if (!getDerived().AlwaysRebuild() &&
6953 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6954 return SemaRef.Owned(E);
6955
6956 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6957 E->getLocStart(),
6958 LhsT, RhsT,
6959 E->getLocEnd());
6960}
6961
6962template<typename Derived>
6963ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006964TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006965 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006966 NestedNameSpecifierLoc QualifierLoc
6967 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6968 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006969 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006970
John McCall31f82722010-11-12 08:19:04 +00006971 // TODO: If this is a conversion-function-id, verify that the
6972 // destination type name (if present) resolves the same way after
6973 // instantiation as it did in the local scope.
6974
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006975 DeclarationNameInfo NameInfo
6976 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6977 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006978 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006979
John McCalle66edc12009-11-24 19:00:30 +00006980 if (!E->hasExplicitTemplateArgs()) {
6981 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006982 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006983 // Note: it is sufficient to compare the Name component of NameInfo:
6984 // if name has not changed, DNLoc has not changed either.
6985 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006986 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006987
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006988 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006989 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006990 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006991 }
John McCall6b51f282009-11-23 01:53:49 +00006992
6993 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006994 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6995 E->getNumTemplateArgs(),
6996 TransArgs))
6997 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006998
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006999 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007000 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007001 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007002}
7003
7004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007005ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007006TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007007 // CXXConstructExprs are always implicit, so when we have a
7008 // 1-argument construction we just transform that argument.
7009 if (E->getNumArgs() == 1 ||
7010 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7011 return getDerived().TransformExpr(E->getArg(0));
7012
Douglas Gregora16548e2009-08-11 05:31:07 +00007013 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7014
7015 QualType T = getDerived().TransformType(E->getType());
7016 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007017 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007018
7019 CXXConstructorDecl *Constructor
7020 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007021 getDerived().TransformDecl(E->getLocStart(),
7022 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007023 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007024 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007025
Douglas Gregora16548e2009-08-11 05:31:07 +00007026 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007027 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007028 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7029 &ArgumentChanged))
7030 return ExprError();
7031
Douglas Gregora16548e2009-08-11 05:31:07 +00007032 if (!getDerived().AlwaysRebuild() &&
7033 T == E->getType() &&
7034 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007035 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007036 // Mark the constructor as referenced.
7037 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007038 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007039 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007040 }
Mike Stump11289f42009-09-09 15:08:12 +00007041
Douglas Gregordb121ba2009-12-14 16:27:04 +00007042 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7043 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007044 move_arg(Args),
7045 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007046 E->getConstructionKind(),
7047 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007048}
Mike Stump11289f42009-09-09 15:08:12 +00007049
Douglas Gregora16548e2009-08-11 05:31:07 +00007050/// \brief Transform a C++ temporary-binding expression.
7051///
Douglas Gregor363b1512009-12-24 18:51:59 +00007052/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7053/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007055ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007056TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007057 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007058}
Mike Stump11289f42009-09-09 15:08:12 +00007059
John McCall5d413782010-12-06 08:20:24 +00007060/// \brief Transform a C++ expression that contains cleanups that should
7061/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007062///
John McCall5d413782010-12-06 08:20:24 +00007063/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007064/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007066ExprResult
John McCall5d413782010-12-06 08:20:24 +00007067TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007068 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007069}
Mike Stump11289f42009-09-09 15:08:12 +00007070
Douglas Gregora16548e2009-08-11 05:31:07 +00007071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007072ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007073TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007074 CXXTemporaryObjectExpr *E) {
7075 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7076 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007077 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007078
Douglas Gregora16548e2009-08-11 05:31:07 +00007079 CXXConstructorDecl *Constructor
7080 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007081 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007082 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007083 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007084 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007085
Douglas Gregora16548e2009-08-11 05:31:07 +00007086 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007087 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007088 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007089 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7090 &ArgumentChanged))
7091 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007092
Douglas Gregora16548e2009-08-11 05:31:07 +00007093 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007094 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007095 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007096 !ArgumentChanged) {
7097 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007098 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007099 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007100 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007101
7102 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7103 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007104 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007105 E->getLocEnd());
7106}
Mike Stump11289f42009-09-09 15:08:12 +00007107
Douglas Gregora16548e2009-08-11 05:31:07 +00007108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007109ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007110TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007111 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007112 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7113 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007114 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007115
Douglas Gregora16548e2009-08-11 05:31:07 +00007116 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007117 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007118 Args.reserve(E->arg_size());
7119 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7120 &ArgumentChanged))
7121 return ExprError();
7122
Douglas Gregora16548e2009-08-11 05:31:07 +00007123 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007124 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007125 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007126 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007127
Douglas Gregora16548e2009-08-11 05:31:07 +00007128 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007129 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007130 E->getLParenLoc(),
7131 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007132 E->getRParenLoc());
7133}
Mike Stump11289f42009-09-09 15:08:12 +00007134
Douglas Gregora16548e2009-08-11 05:31:07 +00007135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007136ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007137TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007138 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007139 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007140 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007141 Expr *OldBase;
7142 QualType BaseType;
7143 QualType ObjectType;
7144 if (!E->isImplicitAccess()) {
7145 OldBase = E->getBase();
7146 Base = getDerived().TransformExpr(OldBase);
7147 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007148 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007149
John McCall2d74de92009-12-01 22:10:20 +00007150 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007151 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007152 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007153 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007154 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007155 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007156 ObjectTy,
7157 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007158 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007159 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007160
John McCallba7bf592010-08-24 05:47:05 +00007161 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007162 BaseType = ((Expr*) Base.get())->getType();
7163 } else {
7164 OldBase = 0;
7165 BaseType = getDerived().TransformType(E->getBaseType());
7166 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7167 }
Mike Stump11289f42009-09-09 15:08:12 +00007168
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007169 // Transform the first part of the nested-name-specifier that qualifies
7170 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007171 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007172 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007173 E->getFirstQualifierFoundInScope(),
7174 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007175
Douglas Gregore16af532011-02-28 18:50:33 +00007176 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007177 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007178 QualifierLoc
7179 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7180 ObjectType,
7181 FirstQualifierInScope);
7182 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007183 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007184 }
Mike Stump11289f42009-09-09 15:08:12 +00007185
John McCall31f82722010-11-12 08:19:04 +00007186 // TODO: If this is a conversion-function-id, verify that the
7187 // destination type name (if present) resolves the same way after
7188 // instantiation as it did in the local scope.
7189
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007190 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007191 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007192 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007193 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007194
John McCall2d74de92009-12-01 22:10:20 +00007195 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007196 // This is a reference to a member without an explicitly-specified
7197 // template argument list. Optimize for this common case.
7198 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007199 Base.get() == OldBase &&
7200 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007201 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007202 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007203 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007204 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007205
John McCallb268a282010-08-23 23:25:46 +00007206 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007207 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007208 E->isArrow(),
7209 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007210 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007211 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007212 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007213 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007214 }
7215
John McCall6b51f282009-11-23 01:53:49 +00007216 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007217 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7218 E->getNumTemplateArgs(),
7219 TransArgs))
7220 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007221
John McCallb268a282010-08-23 23:25:46 +00007222 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007223 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007224 E->isArrow(),
7225 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007226 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007227 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007228 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007229 &TransArgs);
7230}
7231
7232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007234TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007235 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007236 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007237 QualType BaseType;
7238 if (!Old->isImplicitAccess()) {
7239 Base = getDerived().TransformExpr(Old->getBase());
7240 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007241 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007242 BaseType = ((Expr*) Base.get())->getType();
7243 } else {
7244 BaseType = getDerived().TransformType(Old->getBaseType());
7245 }
John McCall10eae182009-11-30 22:42:35 +00007246
Douglas Gregor0da1d432011-02-28 20:01:57 +00007247 NestedNameSpecifierLoc QualifierLoc;
7248 if (Old->getQualifierLoc()) {
7249 QualifierLoc
7250 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7251 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007252 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007253 }
7254
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007255 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007256 Sema::LookupOrdinaryName);
7257
7258 // Transform all the decls.
7259 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7260 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007261 NamedDecl *InstD = static_cast<NamedDecl*>(
7262 getDerived().TransformDecl(Old->getMemberLoc(),
7263 *I));
John McCall84d87672009-12-10 09:41:52 +00007264 if (!InstD) {
7265 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7266 // This can happen because of dependent hiding.
7267 if (isa<UsingShadowDecl>(*I))
7268 continue;
7269 else
John McCallfaf5fb42010-08-26 23:41:50 +00007270 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007271 }
John McCall10eae182009-11-30 22:42:35 +00007272
7273 // Expand using declarations.
7274 if (isa<UsingDecl>(InstD)) {
7275 UsingDecl *UD = cast<UsingDecl>(InstD);
7276 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7277 E = UD->shadow_end(); I != E; ++I)
7278 R.addDecl(*I);
7279 continue;
7280 }
7281
7282 R.addDecl(InstD);
7283 }
7284
7285 R.resolveKind();
7286
Douglas Gregor9262f472010-04-27 18:19:34 +00007287 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007288 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007289 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007290 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007291 Old->getMemberLoc(),
7292 Old->getNamingClass()));
7293 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007294 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007295
Douglas Gregorda7be082010-04-27 16:10:10 +00007296 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007297 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007298
John McCall10eae182009-11-30 22:42:35 +00007299 TemplateArgumentListInfo TransArgs;
7300 if (Old->hasExplicitTemplateArgs()) {
7301 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7302 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007303 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7304 Old->getNumTemplateArgs(),
7305 TransArgs))
7306 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007307 }
John McCall38836f02010-01-15 08:34:02 +00007308
7309 // FIXME: to do this check properly, we will need to preserve the
7310 // first-qualifier-in-scope here, just in case we had a dependent
7311 // base (and therefore couldn't do the check) and a
7312 // nested-name-qualifier (and therefore could do the lookup).
7313 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007314
John McCallb268a282010-08-23 23:25:46 +00007315 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007316 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007317 Old->getOperatorLoc(),
7318 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007319 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007320 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007321 R,
7322 (Old->hasExplicitTemplateArgs()
7323 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007324}
7325
7326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007327ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007328TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7329 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7330 if (SubExpr.isInvalid())
7331 return ExprError();
7332
7333 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007334 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007335
7336 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7337}
7338
7339template<typename Derived>
7340ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007341TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007342 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7343 if (Pattern.isInvalid())
7344 return ExprError();
7345
7346 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7347 return SemaRef.Owned(E);
7348
Douglas Gregorb8840002011-01-14 21:20:45 +00007349 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7350 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007351}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007352
7353template<typename Derived>
7354ExprResult
7355TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7356 // If E is not value-dependent, then nothing will change when we transform it.
7357 // Note: This is an instantiation-centric view.
7358 if (!E->isValueDependent())
7359 return SemaRef.Owned(E);
7360
7361 // Note: None of the implementations of TryExpandParameterPacks can ever
7362 // produce a diagnostic when given only a single unexpanded parameter pack,
7363 // so
7364 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7365 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007366 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007367 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007368 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7369 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007370 ShouldExpand, RetainExpansion,
7371 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007372 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007373
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007374 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007375 return SemaRef.Owned(E);
7376
7377 // We now know the length of the parameter pack, so build a new expression
7378 // that stores that length.
7379 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7380 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007381 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007382}
7383
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007384template<typename Derived>
7385ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007386TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7387 SubstNonTypeTemplateParmPackExpr *E) {
7388 // Default behavior is to do nothing with this transformation.
7389 return SemaRef.Owned(E);
7390}
7391
7392template<typename Derived>
7393ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007394TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007395 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007396}
7397
Mike Stump11289f42009-09-09 15:08:12 +00007398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007399ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007400TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007401 TypeSourceInfo *EncodedTypeInfo
7402 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7403 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007404 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007405
Douglas Gregora16548e2009-08-11 05:31:07 +00007406 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007407 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007408 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007409
7410 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007411 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007412 E->getRParenLoc());
7413}
Mike Stump11289f42009-09-09 15:08:12 +00007414
Douglas Gregora16548e2009-08-11 05:31:07 +00007415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007416ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007417TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007418 // Transform arguments.
7419 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007420 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007421 Args.reserve(E->getNumArgs());
7422 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7423 &ArgChanged))
7424 return ExprError();
7425
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007426 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7427 // Class message: transform the receiver type.
7428 TypeSourceInfo *ReceiverTypeInfo
7429 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7430 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007431 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007432
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007433 // If nothing changed, just retain the existing message send.
7434 if (!getDerived().AlwaysRebuild() &&
7435 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007436 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007437
7438 // Build a new class message send.
7439 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7440 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007441 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007442 E->getMethodDecl(),
7443 E->getLeftLoc(),
7444 move_arg(Args),
7445 E->getRightLoc());
7446 }
7447
7448 // Instance message: transform the receiver
7449 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7450 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007451 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007452 = getDerived().TransformExpr(E->getInstanceReceiver());
7453 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007454 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007455
7456 // If nothing changed, just retain the existing message send.
7457 if (!getDerived().AlwaysRebuild() &&
7458 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007459 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007460
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007461 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007462 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007463 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007464 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007465 E->getMethodDecl(),
7466 E->getLeftLoc(),
7467 move_arg(Args),
7468 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007469}
7470
Mike Stump11289f42009-09-09 15:08:12 +00007471template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007472ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007473TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007474 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007475}
7476
Mike Stump11289f42009-09-09 15:08:12 +00007477template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007478ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007479TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007480 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007481}
7482
Mike Stump11289f42009-09-09 15:08:12 +00007483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007484ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007485TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007486 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007487 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007488 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007489 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007490
7491 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007492
Douglas Gregord51d90d2010-04-26 20:11:03 +00007493 // If nothing changed, just retain the existing expression.
7494 if (!getDerived().AlwaysRebuild() &&
7495 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007496 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007497
John McCallb268a282010-08-23 23:25:46 +00007498 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007499 E->getLocation(),
7500 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007501}
7502
Mike Stump11289f42009-09-09 15:08:12 +00007503template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007504ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007505TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007506 // 'super' and types never change. Property never changes. Just
7507 // retain the existing expression.
7508 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007509 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007510
Douglas Gregor9faee212010-04-26 20:47:02 +00007511 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007512 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007513 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007514 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007515
Douglas Gregor9faee212010-04-26 20:47:02 +00007516 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007517
Douglas Gregor9faee212010-04-26 20:47:02 +00007518 // If nothing changed, just retain the existing expression.
7519 if (!getDerived().AlwaysRebuild() &&
7520 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007521 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007522
John McCallb7bd14f2010-12-02 01:19:52 +00007523 if (E->isExplicitProperty())
7524 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7525 E->getExplicitProperty(),
7526 E->getLocation());
7527
7528 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7529 E->getType(),
7530 E->getImplicitPropertyGetter(),
7531 E->getImplicitPropertySetter(),
7532 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007533}
7534
Mike Stump11289f42009-09-09 15:08:12 +00007535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007536ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007537TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007538 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007539 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007540 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007541 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007542
Douglas Gregord51d90d2010-04-26 20:11:03 +00007543 // If nothing changed, just retain the existing expression.
7544 if (!getDerived().AlwaysRebuild() &&
7545 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007546 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007547
John McCallb268a282010-08-23 23:25:46 +00007548 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007549 E->isArrow());
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>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007555 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007556 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007557 SubExprs.reserve(E->getNumSubExprs());
7558 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7559 SubExprs, &ArgumentChanged))
7560 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007561
Douglas Gregora16548e2009-08-11 05:31:07 +00007562 if (!getDerived().AlwaysRebuild() &&
7563 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007564 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007565
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7567 move_arg(SubExprs),
7568 E->getRParenLoc());
7569}
7570
Mike Stump11289f42009-09-09 15:08:12 +00007571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007572ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007573TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007574 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007575
John McCall490112f2011-02-04 18:33:18 +00007576 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7577 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7578
7579 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7580 llvm::SmallVector<ParmVarDecl*, 4> params;
7581 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007582
7583 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007584 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7585 oldBlock->param_begin(),
7586 oldBlock->param_size(),
7587 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007588 return true;
John McCall490112f2011-02-04 18:33:18 +00007589
7590 const FunctionType *exprFunctionType = E->getFunctionType();
7591 QualType exprResultType = exprFunctionType->getResultType();
7592 if (!exprResultType.isNull()) {
7593 if (!exprResultType->isDependentType())
7594 blockScope->ReturnType = exprResultType;
7595 else if (exprResultType != getSema().Context.DependentTy)
7596 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007597 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007598
7599 // If the return type has not been determined yet, leave it as a dependent
7600 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007601 if (blockScope->ReturnType.isNull())
7602 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007603
7604 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007605 if (blockScope->ReturnType->isObjCObjectType()) {
7606 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007607 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007608 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007609 return ExprError();
7610 }
John McCall3882ace2011-01-05 12:14:39 +00007611
John McCall490112f2011-02-04 18:33:18 +00007612 QualType functionType = getDerived().RebuildFunctionProtoType(
7613 blockScope->ReturnType,
7614 paramTypes.data(),
7615 paramTypes.size(),
7616 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007617 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007618 exprFunctionType->getExtInfo());
7619 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007620
7621 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007622 if (!params.empty())
7623 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007624
7625 // If the return type wasn't explicitly set, it will have been marked as a
7626 // dependent type (DependentTy); clear out the return type setting so
7627 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007628 if (blockScope->ReturnType == getSema().Context.DependentTy)
7629 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007630
John McCall3882ace2011-01-05 12:14:39 +00007631 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007632 StmtResult body = getDerived().TransformStmt(E->getBody());
7633 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007634 return ExprError();
7635
John McCall490112f2011-02-04 18:33:18 +00007636#ifndef NDEBUG
7637 // In builds with assertions, make sure that we captured everything we
7638 // captured before.
7639
7640 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7641
7642 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7643 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007644 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007645
7646 // Ignore parameter packs.
7647 if (isa<ParmVarDecl>(oldCapture) &&
7648 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7649 continue;
7650
7651 VarDecl *newCapture =
7652 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7653 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007654 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007655 }
7656#endif
7657
7658 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7659 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007660}
7661
Mike Stump11289f42009-09-09 15:08:12 +00007662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007663ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007664TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007665 ValueDecl *ND
7666 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7667 E->getDecl()));
7668 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007669 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007670
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007671 if (!getDerived().AlwaysRebuild() &&
7672 ND == E->getDecl()) {
7673 // Mark it referenced in the new context regardless.
7674 // FIXME: this is a bit instantiation-specific.
7675 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7676
John McCallc3007a22010-10-26 07:05:15 +00007677 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007678 }
7679
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007680 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007681 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007682 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007683}
Mike Stump11289f42009-09-09 15:08:12 +00007684
Douglas Gregora16548e2009-08-11 05:31:07 +00007685//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007686// Type reconstruction
7687//===----------------------------------------------------------------------===//
7688
Mike Stump11289f42009-09-09 15:08:12 +00007689template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007690QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7691 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007692 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007693 getDerived().getBaseEntity());
7694}
7695
Mike Stump11289f42009-09-09 15:08:12 +00007696template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007697QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7698 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007699 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007700 getDerived().getBaseEntity());
7701}
7702
Mike Stump11289f42009-09-09 15:08:12 +00007703template<typename Derived>
7704QualType
John McCall70dd5f62009-10-30 00:06:24 +00007705TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7706 bool WrittenAsLValue,
7707 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007708 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007709 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007710}
7711
7712template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007713QualType
John McCall70dd5f62009-10-30 00:06:24 +00007714TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7715 QualType ClassType,
7716 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007717 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007718 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007719}
7720
7721template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007722QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007723TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7724 ArrayType::ArraySizeModifier SizeMod,
7725 const llvm::APInt *Size,
7726 Expr *SizeExpr,
7727 unsigned IndexTypeQuals,
7728 SourceRange BracketsRange) {
7729 if (SizeExpr || !Size)
7730 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7731 IndexTypeQuals, BracketsRange,
7732 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007733
7734 QualType Types[] = {
7735 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7736 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7737 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007738 };
7739 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7740 QualType SizeType;
7741 for (unsigned I = 0; I != NumTypes; ++I)
7742 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7743 SizeType = Types[I];
7744 break;
7745 }
Mike Stump11289f42009-09-09 15:08:12 +00007746
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007747 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7748 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007749 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007750 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007751 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007752}
Mike Stump11289f42009-09-09 15:08:12 +00007753
Douglas Gregord6ff3322009-08-04 16:50:30 +00007754template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007755QualType
7756TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007757 ArrayType::ArraySizeModifier SizeMod,
7758 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007759 unsigned IndexTypeQuals,
7760 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007761 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007762 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007763}
7764
7765template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007766QualType
Mike Stump11289f42009-09-09 15:08:12 +00007767TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007768 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007769 unsigned IndexTypeQuals,
7770 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007771 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007772 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007773}
Mike Stump11289f42009-09-09 15:08:12 +00007774
Douglas Gregord6ff3322009-08-04 16:50:30 +00007775template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007776QualType
7777TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007778 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007779 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007780 unsigned IndexTypeQuals,
7781 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007782 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007783 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007784 IndexTypeQuals, BracketsRange);
7785}
7786
7787template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007788QualType
7789TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007790 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007791 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007792 unsigned IndexTypeQuals,
7793 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007794 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007795 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007796 IndexTypeQuals, BracketsRange);
7797}
7798
7799template<typename Derived>
7800QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007801 unsigned NumElements,
7802 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007803 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007804 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007805}
Mike Stump11289f42009-09-09 15:08:12 +00007806
Douglas Gregord6ff3322009-08-04 16:50:30 +00007807template<typename Derived>
7808QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7809 unsigned NumElements,
7810 SourceLocation AttributeLoc) {
7811 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7812 NumElements, true);
7813 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007814 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7815 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007816 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007817}
Mike Stump11289f42009-09-09 15:08:12 +00007818
Douglas Gregord6ff3322009-08-04 16:50:30 +00007819template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007820QualType
7821TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007822 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007823 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007824 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007825}
Mike Stump11289f42009-09-09 15:08:12 +00007826
Douglas Gregord6ff3322009-08-04 16:50:30 +00007827template<typename Derived>
7828QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007829 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007830 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007831 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007832 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007833 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007834 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007835 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007836 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007837 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007838 getDerived().getBaseEntity(),
7839 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007840}
Mike Stump11289f42009-09-09 15:08:12 +00007841
Douglas Gregord6ff3322009-08-04 16:50:30 +00007842template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007843QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7844 return SemaRef.Context.getFunctionNoProtoType(T);
7845}
7846
7847template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007848QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7849 assert(D && "no decl found");
7850 if (D->isInvalidDecl()) return QualType();
7851
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007852 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007853 TypeDecl *Ty;
7854 if (isa<UsingDecl>(D)) {
7855 UsingDecl *Using = cast<UsingDecl>(D);
7856 assert(Using->isTypeName() &&
7857 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7858
7859 // A valid resolved using typename decl points to exactly one type decl.
7860 assert(++Using->shadow_begin() == Using->shadow_end());
7861 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007862
John McCallb96ec562009-12-04 22:46:56 +00007863 } else {
7864 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7865 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7866 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7867 }
7868
7869 return SemaRef.Context.getTypeDeclType(Ty);
7870}
7871
7872template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007873QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7874 SourceLocation Loc) {
7875 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007876}
7877
7878template<typename Derived>
7879QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7880 return SemaRef.Context.getTypeOfType(Underlying);
7881}
7882
7883template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007884QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7885 SourceLocation Loc) {
7886 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007887}
7888
7889template<typename Derived>
7890QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007891 TemplateName Template,
7892 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007893 const TemplateArgumentListInfo &TemplateArgs) {
7894 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007895}
Mike Stump11289f42009-09-09 15:08:12 +00007896
Douglas Gregor1135c352009-08-06 05:28:30 +00007897template<typename Derived>
7898NestedNameSpecifier *
7899TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7900 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007901 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007902 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007903 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007904 CXXScopeSpec SS;
7905 // FIXME: The source location information is all wrong.
Douglas Gregor869ad452011-02-24 17:54:50 +00007906 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
Douglas Gregor90c99722011-02-24 00:17:56 +00007907 if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(),
7908 /*FIXME:*/Range.getEnd(),
7909 ObjectType, false,
7910 SS, FirstQualifierInScope,
7911 false))
7912 return 0;
7913
7914 return SS.getScopeRep();
Douglas Gregor1135c352009-08-06 05:28:30 +00007915}
7916
7917template<typename Derived>
7918NestedNameSpecifier *
7919TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7920 SourceRange Range,
7921 NamespaceDecl *NS) {
7922 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7923}
7924
7925template<typename Derived>
7926NestedNameSpecifier *
7927TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7928 SourceRange Range,
Douglas Gregor7b26ff92011-02-24 02:36:08 +00007929 NamespaceAliasDecl *Alias) {
7930 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias);
7931}
7932
7933template<typename Derived>
7934NestedNameSpecifier *
7935TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7936 SourceRange Range,
Douglas Gregor1135c352009-08-06 05:28:30 +00007937 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007938 QualType T) {
7939 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007940 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007941 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007942 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7943 T.getTypePtr());
7944 }
Mike Stump11289f42009-09-09 15:08:12 +00007945
Douglas Gregor1135c352009-08-06 05:28:30 +00007946 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7947 return 0;
7948}
Mike Stump11289f42009-09-09 15:08:12 +00007949
Douglas Gregor71dc5092009-08-06 06:41:21 +00007950template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007951TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007952TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7953 bool TemplateKW,
7954 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007955 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007956 Template);
7957}
7958
7959template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007960TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007961TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007962 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007963 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007964 QualType ObjectType,
7965 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007966 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007967 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007968 UnqualifiedId Name;
7969 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007970 Sema::TemplateTy Template;
7971 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7972 /*FIXME:*/getDerived().getBaseLocation(),
7973 SS,
7974 Name,
John McCallba7bf592010-08-24 05:47:05 +00007975 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007976 /*EnteringContext=*/false,
7977 Template);
John McCall31f82722010-11-12 08:19:04 +00007978 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007979}
Mike Stump11289f42009-09-09 15:08:12 +00007980
Douglas Gregora16548e2009-08-11 05:31:07 +00007981template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007982TemplateName
7983TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7984 OverloadedOperatorKind Operator,
7985 QualType ObjectType) {
7986 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007987 SS.MakeTrivial(SemaRef.Context, Qualifier, SourceRange(getDerived().getBaseLocation()));
Douglas Gregor71395fa2009-11-04 00:56:37 +00007988 UnqualifiedId Name;
7989 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7990 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7991 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007992 Sema::TemplateTy Template;
7993 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007994 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007995 SS,
7996 Name,
John McCallba7bf592010-08-24 05:47:05 +00007997 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007998 /*EnteringContext=*/false,
7999 Template);
8000 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008001}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008002
Douglas Gregor71395fa2009-11-04 00:56:37 +00008003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008004ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008005TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8006 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008007 Expr *OrigCallee,
8008 Expr *First,
8009 Expr *Second) {
8010 Expr *Callee = OrigCallee->IgnoreParenCasts();
8011 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008012
Douglas Gregora16548e2009-08-11 05:31:07 +00008013 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008014 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008015 if (!First->getType()->isOverloadableType() &&
8016 !Second->getType()->isOverloadableType())
8017 return getSema().CreateBuiltinArraySubscriptExpr(First,
8018 Callee->getLocStart(),
8019 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008020 } else if (Op == OO_Arrow) {
8021 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008022 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8023 } else if (Second == 0 || isPostIncDec) {
8024 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008025 // The argument is not of overloadable type, so try to create a
8026 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008027 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008028 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008029
John McCallb268a282010-08-23 23:25:46 +00008030 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008031 }
8032 } else {
John McCallb268a282010-08-23 23:25:46 +00008033 if (!First->getType()->isOverloadableType() &&
8034 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008035 // Neither of the arguments is an overloadable type, so try to
8036 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008037 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008038 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008039 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008040 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008041 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008042
Douglas Gregora16548e2009-08-11 05:31:07 +00008043 return move(Result);
8044 }
8045 }
Mike Stump11289f42009-09-09 15:08:12 +00008046
8047 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008048 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008049 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008050
John McCallb268a282010-08-23 23:25:46 +00008051 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008052 assert(ULE->requiresADL());
8053
8054 // FIXME: Do we have to check
8055 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008056 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008057 } else {
John McCallb268a282010-08-23 23:25:46 +00008058 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008059 }
Mike Stump11289f42009-09-09 15:08:12 +00008060
Douglas Gregora16548e2009-08-11 05:31:07 +00008061 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008062 Expr *Args[2] = { First, Second };
8063 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008064
Douglas Gregora16548e2009-08-11 05:31:07 +00008065 // Create the overloaded operator invocation for unary operators.
8066 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008067 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008068 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008069 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008070 }
Mike Stump11289f42009-09-09 15:08:12 +00008071
Sebastian Redladba46e2009-10-29 20:17:01 +00008072 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00008073 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00008074 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008075 First,
8076 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00008077
Douglas Gregora16548e2009-08-11 05:31:07 +00008078 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008079 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008080 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008081 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8082 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008083 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008084
Mike Stump11289f42009-09-09 15:08:12 +00008085 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008086}
Mike Stump11289f42009-09-09 15:08:12 +00008087
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008089ExprResult
John McCallb268a282010-08-23 23:25:46 +00008090TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008091 SourceLocation OperatorLoc,
8092 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008093 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008094 TypeSourceInfo *ScopeType,
8095 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008096 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008097 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008098 QualType BaseType = Base->getType();
8099 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008100 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008101 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008102 !BaseType->getAs<PointerType>()->getPointeeType()
8103 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008104 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008105 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008106 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008107 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008108 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008109 /*FIXME?*/true);
8110 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008111
Douglas Gregor678f90d2010-02-25 01:56:36 +00008112 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008113 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8114 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8115 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8116 NameInfo.setNamedTypeInfo(DestroyedType);
8117
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008118 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008119
John McCallb268a282010-08-23 23:25:46 +00008120 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008121 OperatorLoc, isArrow,
8122 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008123 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008124 /*TemplateArgs*/ 0);
8125}
8126
Douglas Gregord6ff3322009-08-04 16:50:30 +00008127} // end namespace clang
8128
8129#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H