blob: c45d02a56c6d3c00772164b46370cba29d9933e6 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000034#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000035#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000036#include <algorithm>
37
38namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000039using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000040
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// \brief A semantic tree transformation that allows one to transform one
42/// abstract syntax tree into another.
43///
Mike Stump11289f42009-09-09 15:08:12 +000044/// A new tree transformation is defined by creating a new subclass \c X of
45/// \c TreeTransform<X> and then overriding certain operations to provide
46/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000047/// instantiation is implemented as a tree transformation where the
48/// transformation of TemplateTypeParmType nodes involves substituting the
49/// template arguments for their corresponding template parameters; a similar
50/// transformation is performed for non-type template parameters and
51/// template template parameters.
52///
53/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000054/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000055/// override any of the transformation or rebuild operators by providing an
56/// operation with the same signature as the default implementation. The
57/// overridding function should not be virtual.
58///
59/// Semantic tree transformations are split into two stages, either of which
60/// can be replaced by a subclass. The "transform" step transforms an AST node
61/// or the parts of an AST node using the various transformation functions,
62/// then passes the pieces on to the "rebuild" step, which constructs a new AST
63/// node of the appropriate kind from the pieces. The default transformation
64/// routines recursively transform the operands to composite AST nodes (e.g.,
65/// the pointee type of a PointerType node) and, if any of those operand nodes
66/// were changed by the transformation, invokes the rebuild operation to create
67/// a new AST node.
68///
Mike Stump11289f42009-09-09 15:08:12 +000069/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000070/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000071/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// TransformTemplateName(), or TransformTemplateArgument() with entirely
73/// new implementations.
74///
75/// For more fine-grained transformations, subclasses can replace any of the
76/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000077/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000078/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000079/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// parameters. Additionally, subclasses can override the \c RebuildXXX
81/// functions to control how AST nodes are rebuilt when their operands change.
82/// By default, \c TreeTransform will invoke semantic analysis to rebuild
83/// AST nodes. However, certain other tree transformations (e.g, cloning) may
84/// be able to use more efficient rebuild steps.
85///
86/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000087/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000088/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
89/// operands have not changed (\c AlwaysRebuild()), and customize the
90/// default locations and entity names used for type-checking
91/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000092template<typename Derived>
93class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000094 /// \brief Private RAII object that helps us forget and then re-remember
95 /// the template argument corresponding to a partially-substituted parameter
96 /// pack.
97 class ForgetPartiallySubstitutedPackRAII {
98 Derived &Self;
99 TemplateArgument Old;
100
101 public:
102 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
103 Old = Self.ForgetPartiallySubstitutedPack();
104 }
105
106 ~ForgetPartiallySubstitutedPackRAII() {
107 Self.RememberPartiallySubstitutedPack(Old);
108 }
109 };
110
Douglas Gregord6ff3322009-08-04 16:50:30 +0000111protected:
112 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000113
Mike Stump11289f42009-09-09 15:08:12 +0000114public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000116 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000117
Douglas Gregord6ff3322009-08-04 16:50:30 +0000118 /// \brief Retrieves a reference to the derived class.
119 Derived &getDerived() { return static_cast<Derived&>(*this); }
120
121 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000122 const Derived &getDerived() const {
123 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 }
125
John McCalldadc5752010-08-24 06:29:42 +0000126 static inline ExprResult Owned(Expr *E) { return E; }
127 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000128
Douglas Gregord6ff3322009-08-04 16:50:30 +0000129 /// \brief Retrieves a reference to the semantic analysis object used for
130 /// this tree transform.
131 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000132
Douglas Gregord6ff3322009-08-04 16:50:30 +0000133 /// \brief Whether the transformation should always rebuild AST nodes, even
134 /// if none of the children have changed.
135 ///
136 /// Subclasses may override this function to specify when the transformation
137 /// should rebuild all AST nodes.
138 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Returns the location of the entity being transformed, if that
141 /// information was not available elsewhere in the AST.
142 ///
Mike Stump11289f42009-09-09 15:08:12 +0000143 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000144 /// provide an alternative implementation that provides better location
145 /// information.
146 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000147
Douglas Gregord6ff3322009-08-04 16:50:30 +0000148 /// \brief Returns the name of the entity being transformed, if that
149 /// information was not available elsewhere in the AST.
150 ///
151 /// By default, returns an empty name. Subclasses can provide an alternative
152 /// implementation with a more precise name.
153 DeclarationName getBaseEntity() { return DeclarationName(); }
154
Douglas Gregora16548e2009-08-11 05:31:07 +0000155 /// \brief Sets the "base" location and entity when that
156 /// information is known based on another transformation.
157 ///
158 /// By default, the source location and entity are ignored. Subclasses can
159 /// override this function to provide a customized implementation.
160 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000161
Douglas Gregora16548e2009-08-11 05:31:07 +0000162 /// \brief RAII object that temporarily sets the base location and entity
163 /// used for reporting diagnostics in types.
164 class TemporaryBase {
165 TreeTransform &Self;
166 SourceLocation OldLocation;
167 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000168
Douglas Gregora16548e2009-08-11 05:31:07 +0000169 public:
170 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000171 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 OldLocation = Self.getDerived().getBaseLocation();
173 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000174
175 if (Location.isValid())
176 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000177 }
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 ~TemporaryBase() {
180 Self.getDerived().setBase(OldLocation, OldEntity);
181 }
182 };
Mike Stump11289f42009-09-09 15:08:12 +0000183
184 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// transformed.
186 ///
187 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000188 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000189 /// not change. For example, template instantiation need not traverse
190 /// non-dependent types.
191 bool AlreadyTransformed(QualType T) {
192 return T.isNull();
193 }
194
Douglas Gregord196a582009-12-14 19:27:10 +0000195 /// \brief Determine whether the given call argument should be dropped, e.g.,
196 /// because it is a default argument.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine to
199 /// determine which kinds of call arguments get dropped. By default,
200 /// CXXDefaultArgument nodes are dropped (prior to transformation).
201 bool DropCallArgument(Expr *E) {
202 return E->isDefaultArgument();
203 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000204
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000205 /// \brief Determine whether we should expand a pack expansion with the
206 /// given set of parameter packs into separate arguments by repeatedly
207 /// transforming the pattern.
208 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000209 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000210 /// Subclasses can override this routine to provide different behavior.
211 ///
212 /// \param EllipsisLoc The location of the ellipsis that identifies the
213 /// pack expansion.
214 ///
215 /// \param PatternRange The source range that covers the entire pattern of
216 /// the pack expansion.
217 ///
218 /// \param Unexpanded The set of unexpanded parameter packs within the
219 /// pattern.
220 ///
221 /// \param NumUnexpanded The number of unexpanded parameter packs in
222 /// \p Unexpanded.
223 ///
224 /// \param ShouldExpand Will be set to \c true if the transformer should
225 /// expand the corresponding pack expansions into separate arguments. When
226 /// set, \c NumExpansions must also be set.
227 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000228 /// \param RetainExpansion Whether the caller should add an unexpanded
229 /// pack expansion after all of the expanded arguments. This is used
230 /// when extending explicitly-specified template argument packs per
231 /// C++0x [temp.arg.explicit]p9.
232 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000233 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000234 /// the expanded form of the corresponding pack expansion. This is both an
235 /// input and an output parameter, which can be set by the caller if the
236 /// number of expansions is known a priori (e.g., due to a prior substitution)
237 /// and will be set by the callee when the number of expansions is known.
238 /// The callee must set this value when \c ShouldExpand is \c true; it may
239 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 ///
241 /// \returns true if an error occurred (e.g., because the parameter packs
242 /// are to be instantiated with arguments of different lengths), false
243 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
244 /// must be set.
245 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
246 SourceRange PatternRange,
247 const UnexpandedParameterPack *Unexpanded,
248 unsigned NumUnexpanded,
249 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 /// \brief "Forget" about the partially-substituted pack template argument,
257 /// when performing an instantiation that must preserve the parameter pack
258 /// use.
259 ///
260 /// This routine is meant to be overridden by the template instantiator.
261 TemplateArgument ForgetPartiallySubstitutedPack() {
262 return TemplateArgument();
263 }
264
265 /// \brief "Remember" the partially-substituted pack template argument
266 /// after performing an instantiation that must preserve the parameter pack
267 /// use.
268 ///
269 /// This routine is meant to be overridden by the template instantiator.
270 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271
Douglas Gregorf3010112011-01-07 16:43:16 +0000272 /// \brief Note to the derived class when a function parameter pack is
273 /// being expanded.
274 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
275
Douglas Gregord6ff3322009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCall550e0c22009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000280 /// function. This is expensive, but we don't mind, because
281 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000286
John McCall550e0c22009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
John McCall550e0c22009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by delegating to the
291 /// appropriate TransformXXXType to build a new type. Subclasses
292 /// may override this function (to take over all type
293 /// transformations) or some set of the TransformXXXType functions
294 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000296
297 /// \brief Transform the given type-with-location into a new
298 /// type, collecting location information in the given builder
299 /// as necessary.
300 ///
John McCall31f82722010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000302
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000304 ///
Mike Stump11289f42009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000306 /// appropriate TransformXXXStmt function to transform a specific kind of
307 /// statement or the TransformExpr() function to transform an expression.
308 /// Subclasses may override this function to transform statements using some
309 /// other mechanism.
310 ///
311 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000313
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000316 /// By default, this routine transforms an expression by delegating to the
317 /// appropriate TransformXXXExpr function to build a new expression.
318 /// Subclasses may override this function to transform expressions using some
319 /// other mechanism.
320 ///
321 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000323
Douglas Gregora3efea12011-01-03 19:04:46 +0000324 /// \brief Transform the given list of expressions.
325 ///
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
331 ///
332 /// \param Inputs The set of expressions to be transformed.
333 ///
334 /// \param NumInputs The number of expressions in \c Inputs.
335 ///
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
338 /// be.
339 ///
340 /// \param Outputs The transformed input expressions will be added to this
341 /// vector.
342 ///
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
345 ///
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
348 llvm::SmallVectorImpl<Expr *> &Outputs,
349 bool *ArgChanged = 0);
350
Douglas Gregord6ff3322009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000354 /// By default, acts as the identity function on declarations. Subclasses
355 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump11289f42009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000364 }
Mike Stump11289f42009-09-09 15:08:12 +0000365
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000366 /// \brief Transform the given declaration, which was the first part of a
367 /// nested-name-specifier in a member access expression.
368 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000370 /// identifier in a nested-name-specifier of a member access expression, e.g.,
371 /// the \c T in \c x->T::member
372 ///
373 /// By default, invokes TransformDecl() to transform the declaration.
374 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000377 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000378
Douglas Gregor14454802011-02-25 02:25:35 +0000379 /// \brief Transform the given nested-name-specifier with source-location
380 /// information.
381 ///
382 /// By default, transforms all of the types and declarations within the
383 /// nested-name-specifier. Subclasses may override this function to provide
384 /// alternate behavior.
385 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386 NestedNameSpecifierLoc NNS,
387 QualType ObjectType = QualType(),
388 NamedDecl *FirstQualifierInScope = 0);
389
Douglas Gregorf816bd72009-09-03 22:13:48 +0000390 /// \brief Transform the given declaration name.
391 ///
392 /// By default, transforms the types of conversion function, constructor,
393 /// and destructor names and then (if needed) rebuilds the declaration name.
394 /// Identifiers and selectors are returned unmodified. Sublcasses may
395 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000398
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000400 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000401 /// \param SS The nested-name-specifier that qualifies the template
402 /// name. This nested-name-specifier must already have been transformed.
403 ///
404 /// \param Name The template name to transform.
405 ///
406 /// \param NameLoc The source location of the template name.
407 ///
408 /// \param ObjectType If we're translating a template name within a member
409 /// access expression, this is the type of the object whose member template
410 /// is being referenced.
411 ///
412 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413 /// also refers to a name within the current (lexical) scope, this is the
414 /// declaration it refers to.
415 ///
416 /// By default, transforms the template name by transforming the declarations
417 /// and nested-name-specifiers that occur within the template name.
418 /// Subclasses may override this function to provide alternate behavior.
419 TemplateName TransformTemplateName(CXXScopeSpec &SS,
420 TemplateName Name,
421 SourceLocation NameLoc,
422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
424
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump11289f42009-09-09 15:08:12 +0000427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000431 ///
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
435
Douglas Gregor62e06f22010-12-20 17:31:10 +0000436 /// \brief Transform the given set of template arguments.
437 ///
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
441 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
445 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000446 /// \param Inputs The set of template arguments to be transformed.
447 ///
448 /// \param NumInputs The number of template arguments in \p Inputs.
449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000459
460 /// \brief Transform the given set of template arguments.
461 ///
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
465 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000466 /// \param First An iterator to the first template argument.
467 ///
468 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000469 ///
470 /// \param Outputs The set of transformed template arguments output by this
471 /// routine.
472 ///
473 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000478
John McCall0ad16662009-10-29 08:12:44 +0000479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
482
John McCallbcd03502009-12-07 02:54:59 +0000483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump11289f42009-09-09 15:08:12 +0000488
John McCall550e0c22009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493
John Wiegley1c0675e2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall31f82722010-11-12 08:19:04 +0000497 QualType
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
501
502 QualType
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall58f10c32010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000523 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000524 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000534
John McCall31f82722010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000536
John McCalldadc5752010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000539
Douglas Gregorebe10102009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000546
Douglas Gregord6ff3322009-08-04 16:50:30 +0000547 /// \brief Build a new pointer type given its pointee type.
548 ///
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump11289f42009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558
John McCall70dd5f62009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 ///
John McCall70dd5f62009-10-30 00:06:24 +0000561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000564 ///
John McCall70dd5f62009-10-30 00:06:24 +0000565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
568 bool LValue,
569 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000570
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
573 ///
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000578
Douglas Gregord6ff3322009-08-04 16:50:30 +0000579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
581 /// qualifiers.
582 ///
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
589 Expr *SizeExpr,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000592
Douglas Gregord6ff3322009-08-04 16:50:30 +0000593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000603
Douglas Gregord6ff3322009-08-04 16:50:30 +0000604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000613
Mike Stump11289f42009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump11289f42009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626 /// size modifier, size expression, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
635
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000643
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000653 /// given the element type and number of elements.
654 ///
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new function type.
662 ///
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000671
John McCall550e0c22009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCallb96ec562009-12-04 22:46:56 +0000675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
678
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681 return SemaRef.Context.getTypeDeclType(Typedef);
682 }
683
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
687 }
688
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
692 }
John McCallfcc33b02009-09-05 00:15:47 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000699
Mike Stump11289f42009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Mike Stump11289f42009-09-09 15:08:12 +0000705 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 ///
707 /// By default, performs semantic analysis when building the decltype type.
708 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000709 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000710
Richard Smith30482bc2011-02-20 03:19:35 +0000711 /// \brief Build a new C++0x auto type.
712 ///
713 /// By default, builds a new AutoType with the given deduced type.
714 QualType RebuildAutoType(QualType Deduced) {
715 return SemaRef.Context.getAutoType(Deduced);
716 }
717
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 /// \brief Build a new template specialization type.
719 ///
720 /// By default, performs semantic analysis when building the template
721 /// specialization type. Subclasses may override this routine to provide
722 /// different behavior.
723 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000724 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000725 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000726
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000727 /// \brief Build a new parenthesized type.
728 ///
729 /// By default, builds a new ParenType type from the inner type.
730 /// Subclasses may override this routine to provide different behavior.
731 QualType RebuildParenType(QualType InnerType) {
732 return SemaRef.Context.getParenType(InnerType);
733 }
734
Douglas Gregord6ff3322009-08-04 16:50:30 +0000735 /// \brief Build a new qualified name type.
736 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000737 /// By default, builds a new ElaboratedType type from the keyword,
738 /// the nested-name-specifier and the named type.
739 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000740 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
741 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000742 NestedNameSpecifierLoc QualifierLoc,
743 QualType Named) {
744 return SemaRef.Context.getElaboratedType(Keyword,
745 QualifierLoc.getNestedNameSpecifier(),
746 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000747 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748
749 /// \brief Build a new typename type that refers to a template-id.
750 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000751 /// By default, builds a new DependentNameType type from the
752 /// nested-name-specifier and the given type. Subclasses may override
753 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000754 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000755 ElaboratedTypeKeyword Keyword,
756 NestedNameSpecifierLoc QualifierLoc,
757 const IdentifierInfo *Name,
758 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000759 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000760 // Rebuild the template name.
761 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000762 CXXScopeSpec SS;
763 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000764 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000765 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000766
767 if (InstName.isNull())
768 return QualType();
769
770 // If it's still dependent, make a dependent specialization.
771 if (InstName.getAsDependentTemplateName())
772 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
773 QualifierLoc.getNestedNameSpecifier(),
774 Name,
775 Args);
776
777 // Otherwise, make an elaborated type wrapping a non-dependent
778 // specialization.
779 QualType T =
780 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
781 if (T.isNull()) return QualType();
782
783 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
784 return T;
785
786 return SemaRef.Context.getElaboratedType(Keyword,
787 QualifierLoc.getNestedNameSpecifier(),
788 T);
789 }
790
Douglas Gregord6ff3322009-08-04 16:50:30 +0000791 /// \brief Build a new typename type that refers to an identifier.
792 ///
793 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000794 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000795 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000796 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000797 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000798 NestedNameSpecifierLoc QualifierLoc,
799 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000800 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000801 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000802 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000803
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000804 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000805 // If the name is still dependent, just build a new dependent name type.
806 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000807 return SemaRef.Context.getDependentNameType(Keyword,
808 QualifierLoc.getNestedNameSpecifier(),
809 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000810 }
811
Abramo Bagnara6150c882010-05-11 21:36:43 +0000812 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000813 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000814 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000815
816 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
817
Abramo Bagnarad7548482010-05-19 21:37:53 +0000818 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000819 // into a non-dependent elaborated-type-specifier. Find the tag we're
820 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000821 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000822 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
823 if (!DC)
824 return QualType();
825
John McCallbf8c5192010-05-27 06:40:31 +0000826 if (SemaRef.RequireCompleteDeclContext(SS, DC))
827 return QualType();
828
Douglas Gregore677daf2010-03-31 22:19:08 +0000829 TagDecl *Tag = 0;
830 SemaRef.LookupQualifiedName(Result, DC);
831 switch (Result.getResultKind()) {
832 case LookupResult::NotFound:
833 case LookupResult::NotFoundInCurrentInstantiation:
834 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000835
Douglas Gregore677daf2010-03-31 22:19:08 +0000836 case LookupResult::Found:
837 Tag = Result.getAsSingle<TagDecl>();
838 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000839
Douglas Gregore677daf2010-03-31 22:19:08 +0000840 case LookupResult::FoundOverloaded:
841 case LookupResult::FoundUnresolvedValue:
842 llvm_unreachable("Tag lookup cannot find non-tags");
843 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000844
Douglas Gregore677daf2010-03-31 22:19:08 +0000845 case LookupResult::Ambiguous:
846 // Let the LookupResult structure handle ambiguities.
847 return QualType();
848 }
849
850 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000851 // Check where the name exists but isn't a tag type and use that to emit
852 // better diagnostics.
853 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
854 SemaRef.LookupQualifiedName(Result, DC);
855 switch (Result.getResultKind()) {
856 case LookupResult::Found:
857 case LookupResult::FoundOverloaded:
858 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000859 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000860 unsigned Kind = 0;
861 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000862 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
863 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000864 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
865 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
866 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000867 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000868 default:
869 // FIXME: Would be nice to highlight just the source range.
870 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
871 << Kind << Id << DC;
872 break;
873 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000874 return QualType();
875 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000876
Abramo Bagnarad7548482010-05-19 21:37:53 +0000877 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
878 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000879 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
880 return QualType();
881 }
882
883 // Build the elaborated-type-specifier type.
884 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000885 return SemaRef.Context.getElaboratedType(Keyword,
886 QualifierLoc.getNestedNameSpecifier(),
887 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000888 }
Mike Stump11289f42009-09-09 15:08:12 +0000889
Douglas Gregor822d0302011-01-12 17:07:58 +0000890 /// \brief Build a new pack expansion type.
891 ///
892 /// By default, builds a new PackExpansionType type from the given pattern.
893 /// Subclasses may override this routine to provide different behavior.
894 QualType RebuildPackExpansionType(QualType Pattern,
895 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000896 SourceLocation EllipsisLoc,
897 llvm::Optional<unsigned> NumExpansions) {
898 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
899 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000900 }
901
Douglas Gregor71dc5092009-08-06 06:41:21 +0000902 /// \brief Build a new template name given a nested name specifier, a flag
903 /// indicating whether the "template" keyword was provided, and the template
904 /// that the template name refers to.
905 ///
906 /// By default, builds the new template name directly. Subclasses may override
907 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000908 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000909 bool TemplateKW,
910 TemplateDecl *Template);
911
Douglas Gregor71dc5092009-08-06 06:41:21 +0000912 /// \brief Build a new template name given a nested name specifier and the
913 /// name that is referred to as a template.
914 ///
915 /// By default, performs semantic analysis to determine whether the name can
916 /// be resolved to a specific template, then builds the appropriate kind of
917 /// template name. Subclasses may override this routine to provide different
918 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000919 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
920 const IdentifierInfo &Name,
921 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000922 QualType ObjectType,
923 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000924
Douglas Gregor71395fa2009-11-04 00:56:37 +0000925 /// \brief Build a new template name given a nested name specifier and the
926 /// overloaded operator name that is referred to as a template.
927 ///
928 /// By default, performs semantic analysis to determine whether the name can
929 /// be resolved to a specific template, then builds the appropriate kind of
930 /// template name. Subclasses may override this routine to provide different
931 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000932 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000933 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000934 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000935 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000936
937 /// \brief Build a new template name given a template template parameter pack
938 /// and the
939 ///
940 /// By default, performs semantic analysis to determine whether the name can
941 /// be resolved to a specific template, then builds the appropriate kind of
942 /// template name. Subclasses may override this routine to provide different
943 /// behavior.
944 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
945 const TemplateArgument &ArgPack) {
946 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
947 }
948
Douglas Gregorebe10102009-08-20 07:17:43 +0000949 /// \brief Build a new compound statement.
950 ///
951 /// By default, performs semantic analysis to build the new statement.
952 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000953 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000954 MultiStmtArg Statements,
955 SourceLocation RBraceLoc,
956 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000957 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000958 IsStmtExpr);
959 }
960
961 /// \brief Build a new case statement.
962 ///
963 /// By default, performs semantic analysis to build the new statement.
964 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000965 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000966 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000967 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000968 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000969 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000970 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000971 ColonLoc);
972 }
Mike Stump11289f42009-09-09 15:08:12 +0000973
Douglas Gregorebe10102009-08-20 07:17:43 +0000974 /// \brief Attach the body to a new case statement.
975 ///
976 /// By default, performs semantic analysis to build the new statement.
977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000978 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000979 getSema().ActOnCaseStmtBody(S, Body);
980 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000981 }
Mike Stump11289f42009-09-09 15:08:12 +0000982
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 /// \brief Build a new default statement.
984 ///
985 /// By default, performs semantic analysis to build the new statement.
986 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000987 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000988 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000989 Stmt *SubStmt) {
990 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000991 /*CurScope=*/0);
992 }
Mike Stump11289f42009-09-09 15:08:12 +0000993
Douglas Gregorebe10102009-08-20 07:17:43 +0000994 /// \brief Build a new label statement.
995 ///
996 /// By default, performs semantic analysis to build the new statement.
997 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +0000998 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
999 SourceLocation ColonLoc, Stmt *SubStmt) {
1000 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001001 }
Mike Stump11289f42009-09-09 15:08:12 +00001002
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 /// \brief Build a new "if" statement.
1004 ///
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001007 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001008 VarDecl *CondVar, Stmt *Then,
1009 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001010 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001011 }
Mike Stump11289f42009-09-09 15:08:12 +00001012
Douglas Gregorebe10102009-08-20 07:17:43 +00001013 /// \brief Start building a new switch statement.
1014 ///
1015 /// By default, performs semantic analysis to build the new statement.
1016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001017 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001018 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001019 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001020 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001021 }
Mike Stump11289f42009-09-09 15:08:12 +00001022
Douglas Gregorebe10102009-08-20 07:17:43 +00001023 /// \brief Attach the body to the switch statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001027 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001028 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001029 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001030 }
1031
1032 /// \brief Build a new while statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001036 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1037 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001038 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001039 }
Mike Stump11289f42009-09-09 15:08:12 +00001040
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 /// \brief Build a new do-while statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001046 SourceLocation WhileLoc, SourceLocation LParenLoc,
1047 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001048 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1049 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 }
1051
1052 /// \brief Build a new for statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001056 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1057 Stmt *Init, Sema::FullExprArg Cond,
1058 VarDecl *CondVar, Sema::FullExprArg Inc,
1059 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001060 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001061 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 }
Mike Stump11289f42009-09-09 15:08:12 +00001063
Douglas Gregorebe10102009-08-20 07:17:43 +00001064 /// \brief Build a new goto statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001068 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1069 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001070 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001071 }
1072
1073 /// \brief Build a new indirect goto statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001077 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001078 SourceLocation StarLoc,
1079 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001080 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 }
Mike Stump11289f42009-09-09 15:08:12 +00001082
Douglas Gregorebe10102009-08-20 07:17:43 +00001083 /// \brief Build a new return statement.
1084 ///
1085 /// By default, performs semantic analysis to build the new statement.
1086 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001087 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001088 return getSema().ActOnReturnStmt(ReturnLoc, Result);
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 Build a new declaration 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 RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001096 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001097 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001098 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1099 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 }
Mike Stump11289f42009-09-09 15:08:12 +00001101
Anders Carlssonaaeef072010-01-24 05:50:09 +00001102 /// \brief Build a new inline asm statement.
1103 ///
1104 /// By default, performs semantic analysis to build the new statement.
1105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001106 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001107 bool IsSimple,
1108 bool IsVolatile,
1109 unsigned NumOutputs,
1110 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001111 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001112 MultiExprArg Constraints,
1113 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001114 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001115 MultiExprArg Clobbers,
1116 SourceLocation RParenLoc,
1117 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001118 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001119 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001120 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001121 RParenLoc, MSAsm);
1122 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001123
1124 /// \brief Build a new Objective-C @try statement.
1125 ///
1126 /// By default, performs semantic analysis to build the new statement.
1127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001128 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001129 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001130 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001131 Stmt *Finally) {
1132 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1133 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001134 }
1135
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001136 /// \brief Rebuild an Objective-C exception declaration.
1137 ///
1138 /// By default, performs semantic analysis to build the new declaration.
1139 /// Subclasses may override this routine to provide different behavior.
1140 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1141 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001142 return getSema().BuildObjCExceptionDecl(TInfo, T,
1143 ExceptionDecl->getInnerLocStart(),
1144 ExceptionDecl->getLocation(),
1145 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001146 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001147
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001148 /// \brief Build a new Objective-C @catch statement.
1149 ///
1150 /// By default, performs semantic analysis to build the new statement.
1151 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001152 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001153 SourceLocation RParenLoc,
1154 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001155 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001156 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001157 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001158 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001159
Douglas Gregor306de2f2010-04-22 23:59:56 +00001160 /// \brief Build a new Objective-C @finally statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001165 Stmt *Body) {
1166 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001167 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001168
Douglas Gregor6148de72010-04-22 22:01:21 +00001169 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001170 ///
1171 /// By default, performs semantic analysis to build the new statement.
1172 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001173 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001174 Expr *Operand) {
1175 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001176 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001177
Douglas Gregor6148de72010-04-22 22:01:21 +00001178 /// \brief Build a new Objective-C @synchronized statement.
1179 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001180 /// By default, performs semantic analysis to build the new statement.
1181 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001182 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001183 Expr *Object,
1184 Stmt *Body) {
1185 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1186 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001187 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001188
1189 /// \brief Build a new Objective-C fast enumeration statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001193 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001194 SourceLocation LParenLoc,
1195 Stmt *Element,
1196 Expr *Collection,
1197 SourceLocation RParenLoc,
1198 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001199 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001200 Element,
1201 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001202 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001203 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001204 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001205
Douglas Gregorebe10102009-08-20 07:17:43 +00001206 /// \brief Build a new C++ exception declaration.
1207 ///
1208 /// By default, performs semantic analysis to build the new decaration.
1209 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001210 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001211 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001212 SourceLocation StartLoc,
1213 SourceLocation IdLoc,
1214 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001215 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1216 StartLoc, IdLoc, Id);
1217 if (Var)
1218 getSema().CurContext->addDecl(Var);
1219 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 }
1221
1222 /// \brief Build a new C++ catch statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001226 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001227 VarDecl *ExceptionDecl,
1228 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001229 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1230 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001231 }
Mike Stump11289f42009-09-09 15:08:12 +00001232
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 /// \brief Build a new C++ try statement.
1234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001237 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001238 Stmt *TryBlock,
1239 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001240 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001241 }
Mike Stump11289f42009-09-09 15:08:12 +00001242
Richard Smith02e85f32011-04-14 22:09:26 +00001243 /// \brief Build a new C++0x range-based for statement.
1244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
1247 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1248 SourceLocation ColonLoc,
1249 Stmt *Range, Stmt *BeginEnd,
1250 Expr *Cond, Expr *Inc,
1251 Stmt *LoopVar,
1252 SourceLocation RParenLoc) {
1253 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1254 Cond, Inc, LoopVar, RParenLoc);
1255 }
1256
1257 /// \brief Attach body to a C++0x range-based for statement.
1258 ///
1259 /// By default, performs semantic analysis to finish the new statement.
1260 /// Subclasses may override this routine to provide different behavior.
1261 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1262 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1263 }
1264
John Wiegley1c0675e2011-04-28 01:08:34 +00001265 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1266 SourceLocation TryLoc,
1267 Stmt *TryBlock,
1268 Stmt *Handler) {
1269 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1270 }
1271
1272 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1273 Expr *FilterExpr,
1274 Stmt *Block) {
1275 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1276 }
1277
1278 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1279 Stmt *Block) {
1280 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1281 }
1282
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 /// \brief Build a new expression that references a declaration.
1284 ///
1285 /// By default, performs semantic analysis to build the new expression.
1286 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001287 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001288 LookupResult &R,
1289 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001290 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1291 }
1292
1293
1294 /// \brief Build a new expression that references a declaration.
1295 ///
1296 /// By default, performs semantic analysis to build the new expression.
1297 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001298 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001299 ValueDecl *VD,
1300 const DeclarationNameInfo &NameInfo,
1301 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001302 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001303 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001304
1305 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001306
1307 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 }
Mike Stump11289f42009-09-09 15:08:12 +00001309
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001311 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001314 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001316 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 }
1318
Douglas Gregorad8a3362009-09-04 17:36:40 +00001319 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001323 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001324 SourceLocation OperatorLoc,
1325 bool isArrow,
1326 CXXScopeSpec &SS,
1327 TypeSourceInfo *ScopeType,
1328 SourceLocation CCLoc,
1329 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001330 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// \brief Build a new unary operator expression.
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 RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001337 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001338 Expr *SubExpr) {
1339 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Douglas Gregor882211c2010-04-28 22:16:22 +00001342 /// \brief Build a new builtin offsetof expression.
1343 ///
1344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001346 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001347 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001348 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001349 unsigned NumComponents,
1350 SourceLocation RParenLoc) {
1351 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1352 NumComponents, RParenLoc);
1353 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001354
Peter Collingbournee190dee2011-03-11 19:24:49 +00001355 /// \brief Build a new sizeof, alignof or vec_step expression with a
1356 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001357 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 /// By default, performs semantic analysis to build the new expression.
1359 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001360 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1361 SourceLocation OpLoc,
1362 UnaryExprOrTypeTrait ExprKind,
1363 SourceRange R) {
1364 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 }
1366
Peter Collingbournee190dee2011-03-11 19:24:49 +00001367 /// \brief Build a new sizeof, alignof or vec step expression with an
1368 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001369 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001370 /// By default, performs semantic analysis to build the new expression.
1371 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001372 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1373 UnaryExprOrTypeTrait ExprKind,
1374 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001375 ExprResult Result
Peter Collingbournee190dee2011-03-11 19:24:49 +00001376 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001378 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001379
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 return move(Result);
1381 }
Mike Stump11289f42009-09-09 15:08:12 +00001382
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001384 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 /// By default, performs semantic analysis to build the new expression.
1386 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001387 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001388 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001389 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001391 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1392 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 RBracketLoc);
1394 }
1395
1396 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001397 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 /// By default, performs semantic analysis to build the new expression.
1399 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001400 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001402 SourceLocation RParenLoc,
1403 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001404 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001405 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 }
1407
1408 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001409 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 /// By default, performs semantic analysis to build the new expression.
1411 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001412 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001413 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001414 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001415 const DeclarationNameInfo &MemberNameInfo,
1416 ValueDecl *Member,
1417 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001418 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001419 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001420 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001421 // We have a reference to an unnamed field. This is always the
1422 // base of an anonymous struct/union member access, i.e. the
1423 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001424 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001425 assert(Member->getType()->isRecordType() &&
1426 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001427
John Wiegley01296292011-04-08 18:41:53 +00001428 ExprResult BaseResult =
1429 getSema().PerformObjectMemberConversion(Base,
1430 QualifierLoc.getNestedNameSpecifier(),
1431 FoundDecl, Member);
1432 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001433 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001434 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001435 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001436 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001437 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001438 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001439 cast<FieldDecl>(Member)->getType(),
1440 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001441 return getSema().Owned(ME);
1442 }
Mike Stump11289f42009-09-09 15:08:12 +00001443
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001444 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001445 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001446
John Wiegley01296292011-04-08 18:41:53 +00001447 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1448 if (BaseResult.isInvalid())
1449 return ExprError();
1450 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001451 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001452
John McCall16df1e52010-03-30 21:47:33 +00001453 // FIXME: this involves duplicating earlier analysis in a lot of
1454 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001455 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001456 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001457 R.resolveKind();
1458
John McCallb268a282010-08-23 23:25:46 +00001459 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001460 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001461 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 }
Mike Stump11289f42009-09-09 15:08:12 +00001463
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001465 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 /// By default, performs semantic analysis to build the new expression.
1467 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001468 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001469 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001470 Expr *LHS, Expr *RHS) {
1471 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 }
1473
1474 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001475 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001478 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001479 SourceLocation QuestionLoc,
1480 Expr *LHS,
1481 SourceLocation ColonLoc,
1482 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001483 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1484 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 }
1486
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001488 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 /// By default, performs semantic analysis to build the new expression.
1490 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001491 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001492 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001494 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001495 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001496 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 }
Mike Stump11289f42009-09-09 15:08:12 +00001498
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001500 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 /// By default, performs semantic analysis to build the new expression.
1502 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001503 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001504 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001506 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001507 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001508 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 }
Mike Stump11289f42009-09-09 15:08:12 +00001510
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001512 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001515 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 SourceLocation OpLoc,
1517 SourceLocation AccessorLoc,
1518 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001519
John McCall10eae182009-11-30 22:42:35 +00001520 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001521 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001522 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001523 OpLoc, /*IsArrow*/ false,
1524 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001525 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001526 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 }
Mike Stump11289f42009-09-09 15:08:12 +00001528
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001530 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 /// By default, performs semantic analysis to build the new expression.
1532 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001533 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001535 SourceLocation RBraceLoc,
1536 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001537 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001538 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1539 if (Result.isInvalid() || ResultTy->isDependentType())
1540 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001541
Douglas Gregord3d93062009-11-09 17:16:50 +00001542 // Patch in the result type we were given, which may have been computed
1543 // when the initial InitListExpr was built.
1544 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1545 ILE->setType(ResultTy);
1546 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 }
Mike Stump11289f42009-09-09 15:08:12 +00001548
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001550 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001553 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 MultiExprArg ArrayExprs,
1555 SourceLocation EqualOrColonLoc,
1556 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001557 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001558 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001560 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001562 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001563
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 ArrayExprs.release();
1565 return move(Result);
1566 }
Mike Stump11289f42009-09-09 15:08:12 +00001567
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001569 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 /// By default, builds the implicit value initialization without performing
1571 /// any semantic analysis. Subclasses may override this routine to provide
1572 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001573 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1575 }
Mike Stump11289f42009-09-09 15:08:12 +00001576
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001578 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001581 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001582 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001583 SourceLocation RParenLoc) {
1584 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001585 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001586 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 }
1588
1589 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001590 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 /// By default, performs semantic analysis to build the new expression.
1592 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001593 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 MultiExprArg SubExprs,
1595 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001596 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001597 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001598 }
Mike Stump11289f42009-09-09 15:08:12 +00001599
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001601 ///
1602 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 /// rather than attempting to map the label statement itself.
1604 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001605 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001606 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001607 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 }
Mike Stump11289f42009-09-09 15:08:12 +00001609
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001611 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 /// By default, performs semantic analysis to build the new expression.
1613 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001614 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001615 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001617 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 }
Mike Stump11289f42009-09-09 15:08:12 +00001619
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 /// \brief Build a new __builtin_choose_expr expression.
1621 ///
1622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001624 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001625 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 SourceLocation RParenLoc) {
1627 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001628 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 RParenLoc);
1630 }
Mike Stump11289f42009-09-09 15:08:12 +00001631
Peter Collingbourne91147592011-04-15 00:35:48 +00001632 /// \brief Build a new generic selection expression.
1633 ///
1634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
1636 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1637 SourceLocation DefaultLoc,
1638 SourceLocation RParenLoc,
1639 Expr *ControllingExpr,
1640 TypeSourceInfo **Types,
1641 Expr **Exprs,
1642 unsigned NumAssocs) {
1643 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1644 ControllingExpr, Types, Exprs,
1645 NumAssocs);
1646 }
1647
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 /// \brief Build a new overloaded operator call expression.
1649 ///
1650 /// By default, performs semantic analysis to build the new expression.
1651 /// The semantic analysis provides the behavior of template instantiation,
1652 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001653 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 /// argument-dependent lookup, etc. Subclasses may override this routine to
1655 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001656 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001658 Expr *Callee,
1659 Expr *First,
1660 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001661
1662 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 /// reinterpret_cast.
1664 ///
1665 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001666 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001668 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 Stmt::StmtClass Class,
1670 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001671 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 SourceLocation RAngleLoc,
1673 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001674 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 SourceLocation RParenLoc) {
1676 switch (Class) {
1677 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001678 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001679 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001680 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001681
1682 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001683 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001684 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001685 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001686
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001688 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001689 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001690 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001692
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001694 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001695 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001696 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001697
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 default:
1699 assert(false && "Invalid C++ named cast");
1700 break;
1701 }
Mike Stump11289f42009-09-09 15:08:12 +00001702
John McCallfaf5fb42010-08-26 23:41:50 +00001703 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 }
Mike Stump11289f42009-09-09 15:08:12 +00001705
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 /// \brief Build a new C++ static_cast expression.
1707 ///
1708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001710 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001712 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 SourceLocation RAngleLoc,
1714 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001715 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001716 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001717 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001718 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001719 SourceRange(LAngleLoc, RAngleLoc),
1720 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 }
1722
1723 /// \brief Build a new C++ dynamic_cast expression.
1724 ///
1725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001727 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001729 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 SourceLocation RAngleLoc,
1731 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001732 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001733 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001734 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001735 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001736 SourceRange(LAngleLoc, RAngleLoc),
1737 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 }
1739
1740 /// \brief Build a new C++ reinterpret_cast expression.
1741 ///
1742 /// By default, performs semantic analysis to build the new expression.
1743 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001744 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001746 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001747 SourceLocation RAngleLoc,
1748 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001749 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001750 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001751 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001752 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001753 SourceRange(LAngleLoc, RAngleLoc),
1754 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 }
1756
1757 /// \brief Build a new C++ const_cast expression.
1758 ///
1759 /// By default, performs semantic analysis to build the new expression.
1760 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001761 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001763 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 SourceLocation RAngleLoc,
1765 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001766 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001768 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001769 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001770 SourceRange(LAngleLoc, RAngleLoc),
1771 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 }
Mike Stump11289f42009-09-09 15:08:12 +00001773
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 /// \brief Build a new C++ functional-style cast expression.
1775 ///
1776 /// By default, performs semantic analysis to build the new expression.
1777 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001778 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1779 SourceLocation LParenLoc,
1780 Expr *Sub,
1781 SourceLocation RParenLoc) {
1782 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001783 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001784 RParenLoc);
1785 }
Mike Stump11289f42009-09-09 15:08:12 +00001786
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 /// \brief Build a new C++ typeid(type) expression.
1788 ///
1789 /// By default, performs semantic analysis to build the new expression.
1790 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001791 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001792 SourceLocation TypeidLoc,
1793 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001795 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001796 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 }
Mike Stump11289f42009-09-09 15:08:12 +00001798
Francois Pichet9f4f2072010-09-08 12:20:18 +00001799
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 /// \brief Build a new C++ typeid(expr) expression.
1801 ///
1802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001805 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001806 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001808 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001809 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001810 }
1811
Francois Pichet9f4f2072010-09-08 12:20:18 +00001812 /// \brief Build a new C++ __uuidof(type) expression.
1813 ///
1814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
1816 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1817 SourceLocation TypeidLoc,
1818 TypeSourceInfo *Operand,
1819 SourceLocation RParenLoc) {
1820 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1821 RParenLoc);
1822 }
1823
1824 /// \brief Build a new C++ __uuidof(expr) expression.
1825 ///
1826 /// By default, performs semantic analysis to build the new expression.
1827 /// Subclasses may override this routine to provide different behavior.
1828 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1829 SourceLocation TypeidLoc,
1830 Expr *Operand,
1831 SourceLocation RParenLoc) {
1832 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1833 RParenLoc);
1834 }
1835
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 /// \brief Build a new C++ "this" expression.
1837 ///
1838 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001839 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001841 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001842 QualType ThisType,
1843 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001845 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1846 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001847 }
1848
1849 /// \brief Build a new C++ throw expression.
1850 ///
1851 /// By default, performs semantic analysis to build the new expression.
1852 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001853 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001854 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001855 }
1856
1857 /// \brief Build a new C++ default-argument expression.
1858 ///
1859 /// By default, builds a new default-argument expression, which does not
1860 /// require any semantic analysis. Subclasses may override this routine to
1861 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001862 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001863 ParmVarDecl *Param) {
1864 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1865 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001866 }
1867
1868 /// \brief Build a new C++ zero-initialization expression.
1869 ///
1870 /// By default, performs semantic analysis to build the new expression.
1871 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001872 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1873 SourceLocation LParenLoc,
1874 SourceLocation RParenLoc) {
1875 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001876 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001877 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 }
Mike Stump11289f42009-09-09 15:08:12 +00001879
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 /// \brief Build a new C++ "new" expression.
1881 ///
1882 /// By default, performs semantic analysis to build the new expression.
1883 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001884 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001885 bool UseGlobal,
1886 SourceLocation PlacementLParen,
1887 MultiExprArg PlacementArgs,
1888 SourceLocation PlacementRParen,
1889 SourceRange TypeIdParens,
1890 QualType AllocatedType,
1891 TypeSourceInfo *AllocatedTypeInfo,
1892 Expr *ArraySize,
1893 SourceLocation ConstructorLParen,
1894 MultiExprArg ConstructorArgs,
1895 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001896 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 PlacementLParen,
1898 move(PlacementArgs),
1899 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001900 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001901 AllocatedType,
1902 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001903 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 ConstructorLParen,
1905 move(ConstructorArgs),
1906 ConstructorRParen);
1907 }
Mike Stump11289f42009-09-09 15:08:12 +00001908
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 /// \brief Build a new C++ "delete" expression.
1910 ///
1911 /// By default, performs semantic analysis to build the new expression.
1912 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001913 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 bool IsGlobalDelete,
1915 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001916 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001918 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 }
Mike Stump11289f42009-09-09 15:08:12 +00001920
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 /// \brief Build a new unary type trait expression.
1922 ///
1923 /// By default, performs semantic analysis to build the new expression.
1924 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001925 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001926 SourceLocation StartLoc,
1927 TypeSourceInfo *T,
1928 SourceLocation RParenLoc) {
1929 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 }
1931
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001932 /// \brief Build a new binary type trait expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
1936 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1937 SourceLocation StartLoc,
1938 TypeSourceInfo *LhsT,
1939 TypeSourceInfo *RhsT,
1940 SourceLocation RParenLoc) {
1941 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1942 }
1943
John Wiegley6242b6a2011-04-28 00:16:57 +00001944 /// \brief Build a new array type trait expression.
1945 ///
1946 /// By default, performs semantic analysis to build the new expression.
1947 /// Subclasses may override this routine to provide different behavior.
1948 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1949 SourceLocation StartLoc,
1950 TypeSourceInfo *TSInfo,
1951 Expr *DimExpr,
1952 SourceLocation RParenLoc) {
1953 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1954 }
1955
John Wiegleyf9f65842011-04-25 06:54:41 +00001956 /// \brief Build a new expression trait expression.
1957 ///
1958 /// By default, performs semantic analysis to build the new expression.
1959 /// Subclasses may override this routine to provide different behavior.
1960 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1961 SourceLocation StartLoc,
1962 Expr *Queried,
1963 SourceLocation RParenLoc) {
1964 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1965 }
1966
Mike Stump11289f42009-09-09 15:08:12 +00001967 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 /// expression.
1969 ///
1970 /// By default, performs semantic analysis to build the new expression.
1971 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001972 ExprResult RebuildDependentScopeDeclRefExpr(
1973 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001974 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001975 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001977 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001978
1979 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001980 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001981 *TemplateArgs);
1982
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001983 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 }
1985
1986 /// \brief Build a new template-id expression.
1987 ///
1988 /// By default, performs semantic analysis to build the new expression.
1989 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001990 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001991 LookupResult &R,
1992 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001993 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001994 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 }
1996
1997 /// \brief Build a new object-construction expression.
1998 ///
1999 /// By default, performs semantic analysis to build the new expression.
2000 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002001 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002002 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 CXXConstructorDecl *Constructor,
2004 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002005 MultiExprArg Args,
2006 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002007 CXXConstructExpr::ConstructionKind ConstructKind,
2008 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002009 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002010 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002011 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002012 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002013
Douglas Gregordb121ba2009-12-14 16:27:04 +00002014 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002015 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00002016 RequiresZeroInit, ConstructKind,
2017 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 }
2019
2020 /// \brief Build a new object-construction expression.
2021 ///
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002024 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2025 SourceLocation LParenLoc,
2026 MultiExprArg Args,
2027 SourceLocation RParenLoc) {
2028 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 LParenLoc,
2030 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002031 RParenLoc);
2032 }
2033
2034 /// \brief Build a new object-construction expression.
2035 ///
2036 /// By default, performs semantic analysis to build the new expression.
2037 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002038 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2039 SourceLocation LParenLoc,
2040 MultiExprArg Args,
2041 SourceLocation RParenLoc) {
2042 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 LParenLoc,
2044 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 RParenLoc);
2046 }
Mike Stump11289f42009-09-09 15:08:12 +00002047
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 /// \brief Build a new member reference expression.
2049 ///
2050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002052 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002053 QualType BaseType,
2054 bool IsArrow,
2055 SourceLocation OperatorLoc,
2056 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002057 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002058 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002059 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002060 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002061 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002062
John McCallb268a282010-08-23 23:25:46 +00002063 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002064 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002065 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002066 MemberNameInfo,
2067 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002068 }
2069
John McCall10eae182009-11-30 22:42:35 +00002070 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002071 ///
2072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002074 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002075 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002076 SourceLocation OperatorLoc,
2077 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002078 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002079 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002080 LookupResult &R,
2081 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002082 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002083 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002084
John McCallb268a282010-08-23 23:25:46 +00002085 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002086 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002087 SS, FirstQualifierInScope,
2088 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002089 }
Mike Stump11289f42009-09-09 15:08:12 +00002090
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002091 /// \brief Build a new noexcept expression.
2092 ///
2093 /// By default, performs semantic analysis to build the new expression.
2094 /// Subclasses may override this routine to provide different behavior.
2095 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2096 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2097 }
2098
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002099 /// \brief Build a new expression to compute the length of a parameter pack.
2100 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2101 SourceLocation PackLoc,
2102 SourceLocation RParenLoc,
2103 unsigned Length) {
2104 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2105 OperatorLoc, Pack, PackLoc,
2106 RParenLoc, Length);
2107 }
2108
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 /// \brief Build a new Objective-C @encode expression.
2110 ///
2111 /// By default, performs semantic analysis to build the new expression.
2112 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002113 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002114 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002115 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002116 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002118 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002119
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002120 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002121 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002122 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002123 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002124 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002125 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002126 MultiExprArg Args,
2127 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002128 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2129 ReceiverTypeInfo->getType(),
2130 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002131 Sel, Method, LBracLoc, SelectorLoc,
2132 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002133 }
2134
2135 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002136 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002137 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002138 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002139 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002140 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002141 MultiExprArg Args,
2142 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002143 return SemaRef.BuildInstanceMessage(Receiver,
2144 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002145 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002146 Sel, Method, LBracLoc, SelectorLoc,
2147 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002148 }
2149
Douglas Gregord51d90d2010-04-26 20:11:03 +00002150 /// \brief Build a new Objective-C ivar reference expression.
2151 ///
2152 /// By default, performs semantic analysis to build the new expression.
2153 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002154 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002155 SourceLocation IvarLoc,
2156 bool IsArrow, bool IsFreeIvar) {
2157 // FIXME: We lose track of the IsFreeIvar bit.
2158 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002159 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002160 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2161 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002162 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002163 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002164 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002165 false);
John Wiegley01296292011-04-08 18:41:53 +00002166 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002167 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002168
Douglas Gregord51d90d2010-04-26 20:11:03 +00002169 if (Result.get())
2170 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002171
John Wiegley01296292011-04-08 18:41:53 +00002172 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002173 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002174 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002175 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002176 /*TemplateArgs=*/0);
2177 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002178
2179 /// \brief Build a new Objective-C property reference expression.
2180 ///
2181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002184 ObjCPropertyDecl *Property,
2185 SourceLocation PropertyLoc) {
2186 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002187 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002188 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2189 Sema::LookupMemberName);
2190 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002191 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002192 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002193 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002194 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002195 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002196
Douglas Gregor9faee212010-04-26 20:47:02 +00002197 if (Result.get())
2198 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002199
John Wiegley01296292011-04-08 18:41:53 +00002200 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002201 /*FIXME:*/PropertyLoc, IsArrow,
2202 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002203 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002204 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002205 /*TemplateArgs=*/0);
2206 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002207
John McCallb7bd14f2010-12-02 01:19:52 +00002208 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002209 ///
2210 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002211 /// Subclasses may override this routine to provide different behavior.
2212 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2213 ObjCMethodDecl *Getter,
2214 ObjCMethodDecl *Setter,
2215 SourceLocation PropertyLoc) {
2216 // Since these expressions can only be value-dependent, we do not
2217 // need to perform semantic analysis again.
2218 return Owned(
2219 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2220 VK_LValue, OK_ObjCProperty,
2221 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002222 }
2223
Douglas Gregord51d90d2010-04-26 20:11:03 +00002224 /// \brief Build a new Objective-C "isa" expression.
2225 ///
2226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002228 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002229 bool IsArrow) {
2230 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002231 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002232 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2233 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002234 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002235 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002236 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002237 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002238 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002239
Douglas Gregord51d90d2010-04-26 20:11:03 +00002240 if (Result.get())
2241 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002242
John Wiegley01296292011-04-08 18:41:53 +00002243 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002244 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002245 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002246 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002247 /*TemplateArgs=*/0);
2248 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002249
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 /// \brief Build a new shuffle vector expression.
2251 ///
2252 /// By default, performs semantic analysis to build the new expression.
2253 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002254 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002255 MultiExprArg SubExprs,
2256 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002258 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2260 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2261 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2262 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002263
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 // Build a reference to the __builtin_shufflevector builtin
2265 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002266 ExprResult Callee
2267 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2268 VK_LValue, BuiltinLoc));
2269 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2270 if (Callee.isInvalid())
2271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002272
2273 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 unsigned NumSubExprs = SubExprs.size();
2275 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002276 ExprResult TheCall = SemaRef.Owned(
2277 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002279 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002280 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002281 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002282
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002284 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 }
John McCall31f82722010-11-12 08:19:04 +00002286
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002287 /// \brief Build a new template argument pack expansion.
2288 ///
2289 /// By default, performs semantic analysis to build a new pack expansion
2290 /// for a template argument. Subclasses may override this routine to provide
2291 /// different behavior.
2292 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002293 SourceLocation EllipsisLoc,
2294 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002295 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002296 case TemplateArgument::Expression: {
2297 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002298 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2299 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002300 if (Result.isInvalid())
2301 return TemplateArgumentLoc();
2302
2303 return TemplateArgumentLoc(Result.get(), Result.get());
2304 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002305
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002306 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002307 return TemplateArgumentLoc(TemplateArgument(
2308 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002309 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002310 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002311 Pattern.getTemplateNameLoc(),
2312 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002313
2314 case TemplateArgument::Null:
2315 case TemplateArgument::Integral:
2316 case TemplateArgument::Declaration:
2317 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002318 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002319 llvm_unreachable("Pack expansion pattern has no parameter packs");
2320
2321 case TemplateArgument::Type:
2322 if (TypeSourceInfo *Expansion
2323 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002324 EllipsisLoc,
2325 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002326 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2327 Expansion);
2328 break;
2329 }
2330
2331 return TemplateArgumentLoc();
2332 }
2333
Douglas Gregor968f23a2011-01-03 19:31:53 +00002334 /// \brief Build a new expression pack expansion.
2335 ///
2336 /// By default, performs semantic analysis to build a new pack expansion
2337 /// for an expression. Subclasses may override this routine to provide
2338 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002339 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2340 llvm::Optional<unsigned> NumExpansions) {
2341 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002342 }
2343
John McCall31f82722010-11-12 08:19:04 +00002344private:
Douglas Gregor14454802011-02-25 02:25:35 +00002345 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2346 QualType ObjectType,
2347 NamedDecl *FirstQualifierInScope,
2348 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002349
2350 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2351 QualType ObjectType,
2352 NamedDecl *FirstQualifierInScope,
2353 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002354};
Douglas Gregora16548e2009-08-11 05:31:07 +00002355
Douglas Gregorebe10102009-08-20 07:17:43 +00002356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002357StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002358 if (!S)
2359 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002360
Douglas Gregorebe10102009-08-20 07:17:43 +00002361 switch (S->getStmtClass()) {
2362 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002363
Douglas Gregorebe10102009-08-20 07:17:43 +00002364 // Transform individual statement nodes
2365#define STMT(Node, Parent) \
2366 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002367#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002368#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002369#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002370
Douglas Gregorebe10102009-08-20 07:17:43 +00002371 // Transform expressions by calling TransformExpr.
2372#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002373#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002374#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002375#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002376 {
John McCalldadc5752010-08-24 06:29:42 +00002377 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002378 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002379 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002380
John McCallb268a282010-08-23 23:25:46 +00002381 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002382 }
Mike Stump11289f42009-09-09 15:08:12 +00002383 }
2384
John McCallc3007a22010-10-26 07:05:15 +00002385 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002386}
Mike Stump11289f42009-09-09 15:08:12 +00002387
2388
Douglas Gregore922c772009-08-04 22:27:00 +00002389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002390ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002391 if (!E)
2392 return SemaRef.Owned(E);
2393
2394 switch (E->getStmtClass()) {
2395 case Stmt::NoStmtClass: break;
2396#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002397#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002398#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002399 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002400#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002401 }
2402
John McCallc3007a22010-10-26 07:05:15 +00002403 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002404}
2405
2406template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002407bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2408 unsigned NumInputs,
2409 bool IsCall,
2410 llvm::SmallVectorImpl<Expr *> &Outputs,
2411 bool *ArgChanged) {
2412 for (unsigned I = 0; I != NumInputs; ++I) {
2413 // If requested, drop call arguments that need to be dropped.
2414 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2415 if (ArgChanged)
2416 *ArgChanged = true;
2417
2418 break;
2419 }
2420
Douglas Gregor968f23a2011-01-03 19:31:53 +00002421 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2422 Expr *Pattern = Expansion->getPattern();
2423
2424 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2425 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2426 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2427
2428 // Determine whether the set of unexpanded parameter packs can and should
2429 // be expanded.
2430 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002431 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002432 llvm::Optional<unsigned> OrigNumExpansions
2433 = Expansion->getNumExpansions();
2434 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002435 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2436 Pattern->getSourceRange(),
2437 Unexpanded.data(),
2438 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002439 Expand, RetainExpansion,
2440 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002441 return true;
2442
2443 if (!Expand) {
2444 // The transform has determined that we should perform a simple
2445 // transformation on the pack expansion, producing another pack
2446 // expansion.
2447 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2448 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2449 if (OutPattern.isInvalid())
2450 return true;
2451
2452 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002453 Expansion->getEllipsisLoc(),
2454 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002455 if (Out.isInvalid())
2456 return true;
2457
2458 if (ArgChanged)
2459 *ArgChanged = true;
2460 Outputs.push_back(Out.get());
2461 continue;
2462 }
2463
2464 // The transform has determined that we should perform an elementwise
2465 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002466 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002467 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2468 ExprResult Out = getDerived().TransformExpr(Pattern);
2469 if (Out.isInvalid())
2470 return true;
2471
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002472 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002473 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2474 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002475 if (Out.isInvalid())
2476 return true;
2477 }
2478
Douglas Gregor968f23a2011-01-03 19:31:53 +00002479 if (ArgChanged)
2480 *ArgChanged = true;
2481 Outputs.push_back(Out.get());
2482 }
2483
2484 continue;
2485 }
2486
Douglas Gregora3efea12011-01-03 19:04:46 +00002487 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2488 if (Result.isInvalid())
2489 return true;
2490
2491 if (Result.get() != Inputs[I] && ArgChanged)
2492 *ArgChanged = true;
2493
2494 Outputs.push_back(Result.get());
2495 }
2496
2497 return false;
2498}
2499
2500template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002501NestedNameSpecifierLoc
2502TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2503 NestedNameSpecifierLoc NNS,
2504 QualType ObjectType,
2505 NamedDecl *FirstQualifierInScope) {
2506 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2507 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2508 Qualifier = Qualifier.getPrefix())
2509 Qualifiers.push_back(Qualifier);
2510
2511 CXXScopeSpec SS;
2512 while (!Qualifiers.empty()) {
2513 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2514 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2515
2516 switch (QNNS->getKind()) {
2517 case NestedNameSpecifier::Identifier:
2518 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2519 *QNNS->getAsIdentifier(),
2520 Q.getLocalBeginLoc(),
2521 Q.getLocalEndLoc(),
2522 ObjectType, false, SS,
2523 FirstQualifierInScope, false))
2524 return NestedNameSpecifierLoc();
2525
2526 break;
2527
2528 case NestedNameSpecifier::Namespace: {
2529 NamespaceDecl *NS
2530 = cast_or_null<NamespaceDecl>(
2531 getDerived().TransformDecl(
2532 Q.getLocalBeginLoc(),
2533 QNNS->getAsNamespace()));
2534 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2535 break;
2536 }
2537
2538 case NestedNameSpecifier::NamespaceAlias: {
2539 NamespaceAliasDecl *Alias
2540 = cast_or_null<NamespaceAliasDecl>(
2541 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2542 QNNS->getAsNamespaceAlias()));
2543 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2544 Q.getLocalEndLoc());
2545 break;
2546 }
2547
2548 case NestedNameSpecifier::Global:
2549 // There is no meaningful transformation that one could perform on the
2550 // global scope.
2551 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2552 break;
2553
2554 case NestedNameSpecifier::TypeSpecWithTemplate:
2555 case NestedNameSpecifier::TypeSpec: {
2556 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2557 FirstQualifierInScope, SS);
2558
2559 if (!TL)
2560 return NestedNameSpecifierLoc();
2561
2562 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2563 (SemaRef.getLangOptions().CPlusPlus0x &&
2564 TL.getType()->isEnumeralType())) {
2565 assert(!TL.getType().hasLocalQualifiers() &&
2566 "Can't get cv-qualifiers here");
2567 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2568 Q.getLocalEndLoc());
2569 break;
2570 }
Richard Trieude756fb2011-05-07 01:36:37 +00002571 // If the nested-name-specifier is an invalid type def, don't emit an
2572 // error because a previous error should have already been emitted.
2573 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2574 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2575 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2576 << TL.getType() << SS.getRange();
2577 }
Douglas Gregor14454802011-02-25 02:25:35 +00002578 return NestedNameSpecifierLoc();
2579 }
Douglas Gregore16af532011-02-28 18:50:33 +00002580 }
Douglas Gregor14454802011-02-25 02:25:35 +00002581
Douglas Gregore16af532011-02-28 18:50:33 +00002582 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002583 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002584 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002585 }
2586
2587 // Don't rebuild the nested-name-specifier if we don't have to.
2588 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2589 !getDerived().AlwaysRebuild())
2590 return NNS;
2591
2592 // If we can re-use the source-location data from the original
2593 // nested-name-specifier, do so.
2594 if (SS.location_size() == NNS.getDataLength() &&
2595 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2596 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2597
2598 // Allocate new nested-name-specifier location information.
2599 return SS.getWithLocInContext(SemaRef.Context);
2600}
2601
2602template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002603DeclarationNameInfo
2604TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002605::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002606 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002607 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002608 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002609
2610 switch (Name.getNameKind()) {
2611 case DeclarationName::Identifier:
2612 case DeclarationName::ObjCZeroArgSelector:
2613 case DeclarationName::ObjCOneArgSelector:
2614 case DeclarationName::ObjCMultiArgSelector:
2615 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002616 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002617 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002618 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002619
Douglas Gregorf816bd72009-09-03 22:13:48 +00002620 case DeclarationName::CXXConstructorName:
2621 case DeclarationName::CXXDestructorName:
2622 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002623 TypeSourceInfo *NewTInfo;
2624 CanQualType NewCanTy;
2625 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002626 NewTInfo = getDerived().TransformType(OldTInfo);
2627 if (!NewTInfo)
2628 return DeclarationNameInfo();
2629 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002630 }
2631 else {
2632 NewTInfo = 0;
2633 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002634 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002635 if (NewT.isNull())
2636 return DeclarationNameInfo();
2637 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2638 }
Mike Stump11289f42009-09-09 15:08:12 +00002639
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002640 DeclarationName NewName
2641 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2642 NewCanTy);
2643 DeclarationNameInfo NewNameInfo(NameInfo);
2644 NewNameInfo.setName(NewName);
2645 NewNameInfo.setNamedTypeInfo(NewTInfo);
2646 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002647 }
Mike Stump11289f42009-09-09 15:08:12 +00002648 }
2649
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002650 assert(0 && "Unknown name kind.");
2651 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002652}
2653
2654template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002655TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002656TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2657 TemplateName Name,
2658 SourceLocation NameLoc,
2659 QualType ObjectType,
2660 NamedDecl *FirstQualifierInScope) {
2661 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2662 TemplateDecl *Template = QTN->getTemplateDecl();
2663 assert(Template && "qualified template name must refer to a template");
2664
2665 TemplateDecl *TransTemplate
2666 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2667 Template));
2668 if (!TransTemplate)
2669 return TemplateName();
2670
2671 if (!getDerived().AlwaysRebuild() &&
2672 SS.getScopeRep() == QTN->getQualifier() &&
2673 TransTemplate == Template)
2674 return Name;
2675
2676 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2677 TransTemplate);
2678 }
2679
2680 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2681 if (SS.getScopeRep()) {
2682 // These apply to the scope specifier, not the template.
2683 ObjectType = QualType();
2684 FirstQualifierInScope = 0;
2685 }
2686
2687 if (!getDerived().AlwaysRebuild() &&
2688 SS.getScopeRep() == DTN->getQualifier() &&
2689 ObjectType.isNull())
2690 return Name;
2691
2692 if (DTN->isIdentifier()) {
2693 return getDerived().RebuildTemplateName(SS,
2694 *DTN->getIdentifier(),
2695 NameLoc,
2696 ObjectType,
2697 FirstQualifierInScope);
2698 }
2699
2700 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2701 ObjectType);
2702 }
2703
2704 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2705 TemplateDecl *TransTemplate
2706 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2707 Template));
2708 if (!TransTemplate)
2709 return TemplateName();
2710
2711 if (!getDerived().AlwaysRebuild() &&
2712 TransTemplate == Template)
2713 return Name;
2714
2715 return TemplateName(TransTemplate);
2716 }
2717
2718 if (SubstTemplateTemplateParmPackStorage *SubstPack
2719 = Name.getAsSubstTemplateTemplateParmPack()) {
2720 TemplateTemplateParmDecl *TransParam
2721 = cast_or_null<TemplateTemplateParmDecl>(
2722 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2723 if (!TransParam)
2724 return TemplateName();
2725
2726 if (!getDerived().AlwaysRebuild() &&
2727 TransParam == SubstPack->getParameterPack())
2728 return Name;
2729
2730 return getDerived().RebuildTemplateName(TransParam,
2731 SubstPack->getArgumentPack());
2732 }
2733
2734 // These should be getting filtered out before they reach the AST.
2735 llvm_unreachable("overloaded function decl survived to here");
2736 return TemplateName();
2737}
2738
2739template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002740void TreeTransform<Derived>::InventTemplateArgumentLoc(
2741 const TemplateArgument &Arg,
2742 TemplateArgumentLoc &Output) {
2743 SourceLocation Loc = getDerived().getBaseLocation();
2744 switch (Arg.getKind()) {
2745 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002746 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002747 break;
2748
2749 case TemplateArgument::Type:
2750 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002751 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002752
John McCall0ad16662009-10-29 08:12:44 +00002753 break;
2754
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002755 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002756 case TemplateArgument::TemplateExpansion: {
2757 NestedNameSpecifierLocBuilder Builder;
2758 TemplateName Template = Arg.getAsTemplate();
2759 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2760 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2761 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2762 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2763
2764 if (Arg.getKind() == TemplateArgument::Template)
2765 Output = TemplateArgumentLoc(Arg,
2766 Builder.getWithLocInContext(SemaRef.Context),
2767 Loc);
2768 else
2769 Output = TemplateArgumentLoc(Arg,
2770 Builder.getWithLocInContext(SemaRef.Context),
2771 Loc, Loc);
2772
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002773 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002774 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002775
John McCall0ad16662009-10-29 08:12:44 +00002776 case TemplateArgument::Expression:
2777 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2778 break;
2779
2780 case TemplateArgument::Declaration:
2781 case TemplateArgument::Integral:
2782 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002783 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002784 break;
2785 }
2786}
2787
2788template<typename Derived>
2789bool TreeTransform<Derived>::TransformTemplateArgument(
2790 const TemplateArgumentLoc &Input,
2791 TemplateArgumentLoc &Output) {
2792 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002793 switch (Arg.getKind()) {
2794 case TemplateArgument::Null:
2795 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002796 Output = Input;
2797 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002798
Douglas Gregore922c772009-08-04 22:27:00 +00002799 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002800 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002801 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002802 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002803
2804 DI = getDerived().TransformType(DI);
2805 if (!DI) return true;
2806
2807 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2808 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002809 }
Mike Stump11289f42009-09-09 15:08:12 +00002810
Douglas Gregore922c772009-08-04 22:27:00 +00002811 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002812 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002813 DeclarationName Name;
2814 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2815 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002816 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002817 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002818 if (!D) return true;
2819
John McCall0d07eb32009-10-29 18:45:58 +00002820 Expr *SourceExpr = Input.getSourceDeclExpression();
2821 if (SourceExpr) {
2822 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002823 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002824 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002825 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002826 }
2827
2828 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002829 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002830 }
Mike Stump11289f42009-09-09 15:08:12 +00002831
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002832 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002833 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2834 if (QualifierLoc) {
2835 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2836 if (!QualifierLoc)
2837 return true;
2838 }
2839
Douglas Gregordf846d12011-03-02 18:46:51 +00002840 CXXScopeSpec SS;
2841 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002842 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002843 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2844 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002845 if (Template.isNull())
2846 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002847
Douglas Gregor9d802122011-03-02 17:09:35 +00002848 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002849 Input.getTemplateNameLoc());
2850 return false;
2851 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002852
2853 case TemplateArgument::TemplateExpansion:
2854 llvm_unreachable("Caller should expand pack expansions");
2855
Douglas Gregore922c772009-08-04 22:27:00 +00002856 case TemplateArgument::Expression: {
2857 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002858 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002859 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002860
John McCall0ad16662009-10-29 08:12:44 +00002861 Expr *InputExpr = Input.getSourceExpression();
2862 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2863
Chris Lattnercdb591a2011-04-25 20:37:58 +00002864 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002865 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002866 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002867 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002868 }
Mike Stump11289f42009-09-09 15:08:12 +00002869
Douglas Gregore922c772009-08-04 22:27:00 +00002870 case TemplateArgument::Pack: {
2871 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2872 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002873 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002874 AEnd = Arg.pack_end();
2875 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002876
John McCall0ad16662009-10-29 08:12:44 +00002877 // FIXME: preserve source information here when we start
2878 // caring about parameter packs.
2879
John McCall0d07eb32009-10-29 18:45:58 +00002880 TemplateArgumentLoc InputArg;
2881 TemplateArgumentLoc OutputArg;
2882 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2883 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002884 return true;
2885
John McCall0d07eb32009-10-29 18:45:58 +00002886 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002887 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002888
2889 TemplateArgument *TransformedArgsPtr
2890 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2891 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2892 TransformedArgsPtr);
2893 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2894 TransformedArgs.size()),
2895 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002896 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002897 }
2898 }
Mike Stump11289f42009-09-09 15:08:12 +00002899
Douglas Gregore922c772009-08-04 22:27:00 +00002900 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002901 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002902}
2903
Douglas Gregorfe921a72010-12-20 23:36:19 +00002904/// \brief Iterator adaptor that invents template argument location information
2905/// for each of the template arguments in its underlying iterator.
2906template<typename Derived, typename InputIterator>
2907class TemplateArgumentLocInventIterator {
2908 TreeTransform<Derived> &Self;
2909 InputIterator Iter;
2910
2911public:
2912 typedef TemplateArgumentLoc value_type;
2913 typedef TemplateArgumentLoc reference;
2914 typedef typename std::iterator_traits<InputIterator>::difference_type
2915 difference_type;
2916 typedef std::input_iterator_tag iterator_category;
2917
2918 class pointer {
2919 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002920
Douglas Gregorfe921a72010-12-20 23:36:19 +00002921 public:
2922 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2923
2924 const TemplateArgumentLoc *operator->() const { return &Arg; }
2925 };
2926
2927 TemplateArgumentLocInventIterator() { }
2928
2929 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2930 InputIterator Iter)
2931 : Self(Self), Iter(Iter) { }
2932
2933 TemplateArgumentLocInventIterator &operator++() {
2934 ++Iter;
2935 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002936 }
2937
Douglas Gregorfe921a72010-12-20 23:36:19 +00002938 TemplateArgumentLocInventIterator operator++(int) {
2939 TemplateArgumentLocInventIterator Old(*this);
2940 ++(*this);
2941 return Old;
2942 }
2943
2944 reference operator*() const {
2945 TemplateArgumentLoc Result;
2946 Self.InventTemplateArgumentLoc(*Iter, Result);
2947 return Result;
2948 }
2949
2950 pointer operator->() const { return pointer(**this); }
2951
2952 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2953 const TemplateArgumentLocInventIterator &Y) {
2954 return X.Iter == Y.Iter;
2955 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002956
Douglas Gregorfe921a72010-12-20 23:36:19 +00002957 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2958 const TemplateArgumentLocInventIterator &Y) {
2959 return X.Iter != Y.Iter;
2960 }
2961};
2962
Douglas Gregor42cafa82010-12-20 17:42:22 +00002963template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002964template<typename InputIterator>
2965bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2966 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002967 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002968 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002969 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002970 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002971
2972 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2973 // Unpack argument packs, which we translate them into separate
2974 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002975 // FIXME: We could do much better if we could guarantee that the
2976 // TemplateArgumentLocInfo for the pack expansion would be usable for
2977 // all of the template arguments in the argument pack.
2978 typedef TemplateArgumentLocInventIterator<Derived,
2979 TemplateArgument::pack_iterator>
2980 PackLocIterator;
2981 if (TransformTemplateArguments(PackLocIterator(*this,
2982 In.getArgument().pack_begin()),
2983 PackLocIterator(*this,
2984 In.getArgument().pack_end()),
2985 Outputs))
2986 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002987
2988 continue;
2989 }
2990
2991 if (In.getArgument().isPackExpansion()) {
2992 // We have a pack expansion, for which we will be substituting into
2993 // the pattern.
2994 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002995 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002996 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002997 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2998 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002999
3000 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3001 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3002 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3003
3004 // Determine whether the set of unexpanded parameter packs can and should
3005 // be expanded.
3006 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003007 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003008 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003009 if (getDerived().TryExpandParameterPacks(Ellipsis,
3010 Pattern.getSourceRange(),
3011 Unexpanded.data(),
3012 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003013 Expand,
3014 RetainExpansion,
3015 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003016 return true;
3017
3018 if (!Expand) {
3019 // The transform has determined that we should perform a simple
3020 // transformation on the pack expansion, producing another pack
3021 // expansion.
3022 TemplateArgumentLoc OutPattern;
3023 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3024 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3025 return true;
3026
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003027 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3028 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003029 if (Out.getArgument().isNull())
3030 return true;
3031
3032 Outputs.addArgument(Out);
3033 continue;
3034 }
3035
3036 // The transform has determined that we should perform an elementwise
3037 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003038 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003039 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3040
3041 if (getDerived().TransformTemplateArgument(Pattern, Out))
3042 return true;
3043
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003044 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003045 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3046 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003047 if (Out.getArgument().isNull())
3048 return true;
3049 }
3050
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003051 Outputs.addArgument(Out);
3052 }
3053
Douglas Gregor48d24112011-01-10 20:53:55 +00003054 // If we're supposed to retain a pack expansion, do so by temporarily
3055 // forgetting the partially-substituted parameter pack.
3056 if (RetainExpansion) {
3057 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3058
3059 if (getDerived().TransformTemplateArgument(Pattern, Out))
3060 return true;
3061
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003062 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3063 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003064 if (Out.getArgument().isNull())
3065 return true;
3066
3067 Outputs.addArgument(Out);
3068 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003069
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003070 continue;
3071 }
3072
3073 // The simple case:
3074 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003075 return true;
3076
3077 Outputs.addArgument(Out);
3078 }
3079
3080 return false;
3081
3082}
3083
Douglas Gregord6ff3322009-08-04 16:50:30 +00003084//===----------------------------------------------------------------------===//
3085// Type transformation
3086//===----------------------------------------------------------------------===//
3087
3088template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003089QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003090 if (getDerived().AlreadyTransformed(T))
3091 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003092
John McCall550e0c22009-10-21 00:40:46 +00003093 // Temporary workaround. All of these transformations should
3094 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003095 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3096 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003097
John McCall31f82722010-11-12 08:19:04 +00003098 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003099
John McCall550e0c22009-10-21 00:40:46 +00003100 if (!NewDI)
3101 return QualType();
3102
3103 return NewDI->getType();
3104}
3105
3106template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003107TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003108 if (getDerived().AlreadyTransformed(DI->getType()))
3109 return DI;
3110
3111 TypeLocBuilder TLB;
3112
3113 TypeLoc TL = DI->getTypeLoc();
3114 TLB.reserve(TL.getFullDataSize());
3115
John McCall31f82722010-11-12 08:19:04 +00003116 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003117 if (Result.isNull())
3118 return 0;
3119
John McCallbcd03502009-12-07 02:54:59 +00003120 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003121}
3122
3123template<typename Derived>
3124QualType
John McCall31f82722010-11-12 08:19:04 +00003125TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003126 switch (T.getTypeLocClass()) {
3127#define ABSTRACT_TYPELOC(CLASS, PARENT)
3128#define TYPELOC(CLASS, PARENT) \
3129 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003130 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003131#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003132 }
Mike Stump11289f42009-09-09 15:08:12 +00003133
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003134 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003135 return QualType();
3136}
3137
3138/// FIXME: By default, this routine adds type qualifiers only to types
3139/// that can have qualifiers, and silently suppresses those qualifiers
3140/// that are not permitted (e.g., qualifiers on reference or function
3141/// types). This is the right thing for template instantiation, but
3142/// probably not for other clients.
3143template<typename Derived>
3144QualType
3145TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003146 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003147 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003148
John McCall31f82722010-11-12 08:19:04 +00003149 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003150 if (Result.isNull())
3151 return QualType();
3152
3153 // Silently suppress qualifiers if the result type can't be qualified.
3154 // FIXME: this is the right thing for template instantiation, but
3155 // probably not for other clients.
3156 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003157 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003158
John McCallcb0f89a2010-06-05 06:41:15 +00003159 if (!Quals.empty()) {
3160 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3161 TLB.push<QualifiedTypeLoc>(Result);
3162 // No location information to preserve.
3163 }
John McCall550e0c22009-10-21 00:40:46 +00003164
3165 return Result;
3166}
3167
Douglas Gregor14454802011-02-25 02:25:35 +00003168template<typename Derived>
3169TypeLoc
3170TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3171 QualType ObjectType,
3172 NamedDecl *UnqualLookup,
3173 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003174 QualType T = TL.getType();
3175 if (getDerived().AlreadyTransformed(T))
3176 return TL;
3177
3178 TypeLocBuilder TLB;
3179 QualType Result;
3180
3181 if (isa<TemplateSpecializationType>(T)) {
3182 TemplateSpecializationTypeLoc SpecTL
3183 = cast<TemplateSpecializationTypeLoc>(TL);
3184
3185 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003186 getDerived().TransformTemplateName(SS,
3187 SpecTL.getTypePtr()->getTemplateName(),
3188 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003189 ObjectType, UnqualLookup);
3190 if (Template.isNull())
3191 return TypeLoc();
3192
3193 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3194 Template);
3195 } else if (isa<DependentTemplateSpecializationType>(T)) {
3196 DependentTemplateSpecializationTypeLoc SpecTL
3197 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3198
Douglas Gregor5a064722011-02-28 17:23:35 +00003199 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003200 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003201 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003202 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003203 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003204 if (Template.isNull())
3205 return TypeLoc();
3206
Douglas Gregor14454802011-02-25 02:25:35 +00003207 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003208 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003209 Template,
3210 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003211 } else {
3212 // Nothing special needs to be done for these.
3213 Result = getDerived().TransformType(TLB, TL);
3214 }
3215
3216 if (Result.isNull())
3217 return TypeLoc();
3218
3219 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3220}
3221
Douglas Gregor579c15f2011-03-02 18:32:08 +00003222template<typename Derived>
3223TypeSourceInfo *
3224TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3225 QualType ObjectType,
3226 NamedDecl *UnqualLookup,
3227 CXXScopeSpec &SS) {
3228 // FIXME: Painfully copy-paste from the above!
3229
3230 QualType T = TSInfo->getType();
3231 if (getDerived().AlreadyTransformed(T))
3232 return TSInfo;
3233
3234 TypeLocBuilder TLB;
3235 QualType Result;
3236
3237 TypeLoc TL = TSInfo->getTypeLoc();
3238 if (isa<TemplateSpecializationType>(T)) {
3239 TemplateSpecializationTypeLoc SpecTL
3240 = cast<TemplateSpecializationTypeLoc>(TL);
3241
3242 TemplateName Template
3243 = getDerived().TransformTemplateName(SS,
3244 SpecTL.getTypePtr()->getTemplateName(),
3245 SpecTL.getTemplateNameLoc(),
3246 ObjectType, UnqualLookup);
3247 if (Template.isNull())
3248 return 0;
3249
3250 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3251 Template);
3252 } else if (isa<DependentTemplateSpecializationType>(T)) {
3253 DependentTemplateSpecializationTypeLoc SpecTL
3254 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3255
3256 TemplateName Template
3257 = getDerived().RebuildTemplateName(SS,
3258 *SpecTL.getTypePtr()->getIdentifier(),
3259 SpecTL.getNameLoc(),
3260 ObjectType, UnqualLookup);
3261 if (Template.isNull())
3262 return 0;
3263
3264 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3265 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003266 Template,
3267 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003268 } else {
3269 // Nothing special needs to be done for these.
3270 Result = getDerived().TransformType(TLB, TL);
3271 }
3272
3273 if (Result.isNull())
3274 return 0;
3275
3276 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3277}
3278
John McCall550e0c22009-10-21 00:40:46 +00003279template <class TyLoc> static inline
3280QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3281 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3282 NewT.setNameLoc(T.getNameLoc());
3283 return T.getType();
3284}
3285
John McCall550e0c22009-10-21 00:40:46 +00003286template<typename Derived>
3287QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003288 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003289 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3290 NewT.setBuiltinLoc(T.getBuiltinLoc());
3291 if (T.needsExtraLocalData())
3292 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3293 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003294}
Mike Stump11289f42009-09-09 15:08:12 +00003295
Douglas Gregord6ff3322009-08-04 16:50:30 +00003296template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003297QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003298 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003299 // FIXME: recurse?
3300 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003301}
Mike Stump11289f42009-09-09 15:08:12 +00003302
Douglas Gregord6ff3322009-08-04 16:50:30 +00003303template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003304QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003305 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003306 QualType PointeeType
3307 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003308 if (PointeeType.isNull())
3309 return QualType();
3310
3311 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003312 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003313 // A dependent pointer type 'T *' has is being transformed such
3314 // that an Objective-C class type is being replaced for 'T'. The
3315 // resulting pointer type is an ObjCObjectPointerType, not a
3316 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003317 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003318
John McCall8b07ec22010-05-15 11:32:37 +00003319 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3320 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003321 return Result;
3322 }
John McCall31f82722010-11-12 08:19:04 +00003323
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003324 if (getDerived().AlwaysRebuild() ||
3325 PointeeType != TL.getPointeeLoc().getType()) {
3326 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3327 if (Result.isNull())
3328 return QualType();
3329 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003330
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003331 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3332 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003333 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003334}
Mike Stump11289f42009-09-09 15:08:12 +00003335
3336template<typename Derived>
3337QualType
John McCall550e0c22009-10-21 00:40:46 +00003338TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003339 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003340 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003341 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3342 if (PointeeType.isNull())
3343 return QualType();
3344
3345 QualType Result = TL.getType();
3346 if (getDerived().AlwaysRebuild() ||
3347 PointeeType != TL.getPointeeLoc().getType()) {
3348 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003349 TL.getSigilLoc());
3350 if (Result.isNull())
3351 return QualType();
3352 }
3353
Douglas Gregor049211a2010-04-22 16:50:51 +00003354 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003355 NewT.setSigilLoc(TL.getSigilLoc());
3356 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003357}
3358
John McCall70dd5f62009-10-30 00:06:24 +00003359/// Transforms a reference type. Note that somewhat paradoxically we
3360/// don't care whether the type itself is an l-value type or an r-value
3361/// type; we only care if the type was *written* as an l-value type
3362/// or an r-value type.
3363template<typename Derived>
3364QualType
3365TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003366 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003367 const ReferenceType *T = TL.getTypePtr();
3368
3369 // Note that this works with the pointee-as-written.
3370 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3371 if (PointeeType.isNull())
3372 return QualType();
3373
3374 QualType Result = TL.getType();
3375 if (getDerived().AlwaysRebuild() ||
3376 PointeeType != T->getPointeeTypeAsWritten()) {
3377 Result = getDerived().RebuildReferenceType(PointeeType,
3378 T->isSpelledAsLValue(),
3379 TL.getSigilLoc());
3380 if (Result.isNull())
3381 return QualType();
3382 }
3383
3384 // r-value references can be rebuilt as l-value references.
3385 ReferenceTypeLoc NewTL;
3386 if (isa<LValueReferenceType>(Result))
3387 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3388 else
3389 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3390 NewTL.setSigilLoc(TL.getSigilLoc());
3391
3392 return Result;
3393}
3394
Mike Stump11289f42009-09-09 15:08:12 +00003395template<typename Derived>
3396QualType
John McCall550e0c22009-10-21 00:40:46 +00003397TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003398 LValueReferenceTypeLoc TL) {
3399 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003400}
3401
Mike Stump11289f42009-09-09 15:08:12 +00003402template<typename Derived>
3403QualType
John McCall550e0c22009-10-21 00:40:46 +00003404TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003405 RValueReferenceTypeLoc TL) {
3406 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003407}
Mike Stump11289f42009-09-09 15:08:12 +00003408
Douglas Gregord6ff3322009-08-04 16:50:30 +00003409template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003410QualType
John McCall550e0c22009-10-21 00:40:46 +00003411TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003412 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003413 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003414 if (PointeeType.isNull())
3415 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003416
Abramo Bagnara509357842011-03-05 14:42:21 +00003417 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3418 TypeSourceInfo* NewClsTInfo = 0;
3419 if (OldClsTInfo) {
3420 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3421 if (!NewClsTInfo)
3422 return QualType();
3423 }
3424
3425 const MemberPointerType *T = TL.getTypePtr();
3426 QualType OldClsType = QualType(T->getClass(), 0);
3427 QualType NewClsType;
3428 if (NewClsTInfo)
3429 NewClsType = NewClsTInfo->getType();
3430 else {
3431 NewClsType = getDerived().TransformType(OldClsType);
3432 if (NewClsType.isNull())
3433 return QualType();
3434 }
Mike Stump11289f42009-09-09 15:08:12 +00003435
John McCall550e0c22009-10-21 00:40:46 +00003436 QualType Result = TL.getType();
3437 if (getDerived().AlwaysRebuild() ||
3438 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003439 NewClsType != OldClsType) {
3440 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003441 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003442 if (Result.isNull())
3443 return QualType();
3444 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003445
John McCall550e0c22009-10-21 00:40:46 +00003446 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3447 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003448 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003449
3450 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003451}
3452
Mike Stump11289f42009-09-09 15:08:12 +00003453template<typename Derived>
3454QualType
John McCall550e0c22009-10-21 00:40:46 +00003455TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003456 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003457 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003458 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003459 if (ElementType.isNull())
3460 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003461
John McCall550e0c22009-10-21 00:40:46 +00003462 QualType Result = TL.getType();
3463 if (getDerived().AlwaysRebuild() ||
3464 ElementType != T->getElementType()) {
3465 Result = getDerived().RebuildConstantArrayType(ElementType,
3466 T->getSizeModifier(),
3467 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003468 T->getIndexTypeCVRQualifiers(),
3469 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003470 if (Result.isNull())
3471 return QualType();
3472 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003473
John McCall550e0c22009-10-21 00:40:46 +00003474 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3475 NewTL.setLBracketLoc(TL.getLBracketLoc());
3476 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003477
John McCall550e0c22009-10-21 00:40:46 +00003478 Expr *Size = TL.getSizeExpr();
3479 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003480 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003481 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3482 }
3483 NewTL.setSizeExpr(Size);
3484
3485 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003486}
Mike Stump11289f42009-09-09 15:08:12 +00003487
Douglas Gregord6ff3322009-08-04 16:50:30 +00003488template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003489QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003490 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003491 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003492 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003493 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003494 if (ElementType.isNull())
3495 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003496
John McCall550e0c22009-10-21 00:40:46 +00003497 QualType Result = TL.getType();
3498 if (getDerived().AlwaysRebuild() ||
3499 ElementType != T->getElementType()) {
3500 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003501 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003502 T->getIndexTypeCVRQualifiers(),
3503 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003504 if (Result.isNull())
3505 return QualType();
3506 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003507
John McCall550e0c22009-10-21 00:40:46 +00003508 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3509 NewTL.setLBracketLoc(TL.getLBracketLoc());
3510 NewTL.setRBracketLoc(TL.getRBracketLoc());
3511 NewTL.setSizeExpr(0);
3512
3513 return Result;
3514}
3515
3516template<typename Derived>
3517QualType
3518TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003519 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003520 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003521 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3522 if (ElementType.isNull())
3523 return QualType();
3524
3525 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003526 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003527
John McCalldadc5752010-08-24 06:29:42 +00003528 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003529 = getDerived().TransformExpr(T->getSizeExpr());
3530 if (SizeResult.isInvalid())
3531 return QualType();
3532
John McCallb268a282010-08-23 23:25:46 +00003533 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003534
3535 QualType Result = TL.getType();
3536 if (getDerived().AlwaysRebuild() ||
3537 ElementType != T->getElementType() ||
3538 Size != T->getSizeExpr()) {
3539 Result = getDerived().RebuildVariableArrayType(ElementType,
3540 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003541 Size,
John McCall550e0c22009-10-21 00:40:46 +00003542 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003543 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003544 if (Result.isNull())
3545 return QualType();
3546 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003547
John McCall550e0c22009-10-21 00:40:46 +00003548 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3549 NewTL.setLBracketLoc(TL.getLBracketLoc());
3550 NewTL.setRBracketLoc(TL.getRBracketLoc());
3551 NewTL.setSizeExpr(Size);
3552
3553 return Result;
3554}
3555
3556template<typename Derived>
3557QualType
3558TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003559 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003560 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003561 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3562 if (ElementType.isNull())
3563 return QualType();
3564
3565 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003566 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003567
John McCall33ddac02011-01-19 10:06:00 +00003568 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3569 Expr *origSize = TL.getSizeExpr();
3570 if (!origSize) origSize = T->getSizeExpr();
3571
3572 ExprResult sizeResult
3573 = getDerived().TransformExpr(origSize);
3574 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003575 return QualType();
3576
John McCall33ddac02011-01-19 10:06:00 +00003577 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003578
3579 QualType Result = TL.getType();
3580 if (getDerived().AlwaysRebuild() ||
3581 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003582 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003583 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3584 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003585 size,
John McCall550e0c22009-10-21 00:40:46 +00003586 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003587 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003588 if (Result.isNull())
3589 return QualType();
3590 }
John McCall550e0c22009-10-21 00:40:46 +00003591
3592 // We might have any sort of array type now, but fortunately they
3593 // all have the same location layout.
3594 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3595 NewTL.setLBracketLoc(TL.getLBracketLoc());
3596 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003597 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003598
3599 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003600}
Mike Stump11289f42009-09-09 15:08:12 +00003601
3602template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003603QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003604 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003605 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003606 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003607
3608 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003609 QualType ElementType = getDerived().TransformType(T->getElementType());
3610 if (ElementType.isNull())
3611 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003612
Douglas Gregore922c772009-08-04 22:27:00 +00003613 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003614 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003615
John McCalldadc5752010-08-24 06:29:42 +00003616 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003617 if (Size.isInvalid())
3618 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003619
John McCall550e0c22009-10-21 00:40:46 +00003620 QualType Result = TL.getType();
3621 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003622 ElementType != T->getElementType() ||
3623 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003624 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003625 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003626 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003627 if (Result.isNull())
3628 return QualType();
3629 }
John McCall550e0c22009-10-21 00:40:46 +00003630
3631 // Result might be dependent or not.
3632 if (isa<DependentSizedExtVectorType>(Result)) {
3633 DependentSizedExtVectorTypeLoc NewTL
3634 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3635 NewTL.setNameLoc(TL.getNameLoc());
3636 } else {
3637 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3638 NewTL.setNameLoc(TL.getNameLoc());
3639 }
3640
3641 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003642}
Mike Stump11289f42009-09-09 15:08:12 +00003643
3644template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003645QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003646 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003647 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003648 QualType ElementType = getDerived().TransformType(T->getElementType());
3649 if (ElementType.isNull())
3650 return QualType();
3651
John McCall550e0c22009-10-21 00:40:46 +00003652 QualType Result = TL.getType();
3653 if (getDerived().AlwaysRebuild() ||
3654 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003655 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003656 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003657 if (Result.isNull())
3658 return QualType();
3659 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003660
John McCall550e0c22009-10-21 00:40:46 +00003661 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3662 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003663
John McCall550e0c22009-10-21 00:40:46 +00003664 return Result;
3665}
3666
3667template<typename Derived>
3668QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003669 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003670 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003671 QualType ElementType = getDerived().TransformType(T->getElementType());
3672 if (ElementType.isNull())
3673 return QualType();
3674
3675 QualType Result = TL.getType();
3676 if (getDerived().AlwaysRebuild() ||
3677 ElementType != T->getElementType()) {
3678 Result = getDerived().RebuildExtVectorType(ElementType,
3679 T->getNumElements(),
3680 /*FIXME*/ SourceLocation());
3681 if (Result.isNull())
3682 return QualType();
3683 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003684
John McCall550e0c22009-10-21 00:40:46 +00003685 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3686 NewTL.setNameLoc(TL.getNameLoc());
3687
3688 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003689}
Mike Stump11289f42009-09-09 15:08:12 +00003690
3691template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003692ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003693TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003694 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003695 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003696 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003697 TypeSourceInfo *NewDI = 0;
3698
3699 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3700 // If we're substituting into a pack expansion type and we know the
3701 TypeLoc OldTL = OldDI->getTypeLoc();
3702 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3703
3704 TypeLocBuilder TLB;
3705 TypeLoc NewTL = OldDI->getTypeLoc();
3706 TLB.reserve(NewTL.getFullDataSize());
3707
3708 QualType Result = getDerived().TransformType(TLB,
3709 OldExpansionTL.getPatternLoc());
3710 if (Result.isNull())
3711 return 0;
3712
3713 Result = RebuildPackExpansionType(Result,
3714 OldExpansionTL.getPatternLoc().getSourceRange(),
3715 OldExpansionTL.getEllipsisLoc(),
3716 NumExpansions);
3717 if (Result.isNull())
3718 return 0;
3719
3720 PackExpansionTypeLoc NewExpansionTL
3721 = TLB.push<PackExpansionTypeLoc>(Result);
3722 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3723 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3724 } else
3725 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003726 if (!NewDI)
3727 return 0;
3728
John McCall8fb0d9d2011-05-01 22:35:37 +00003729 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003730 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003731
3732 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3733 OldParm->getDeclContext(),
3734 OldParm->getInnerLocStart(),
3735 OldParm->getLocation(),
3736 OldParm->getIdentifier(),
3737 NewDI->getType(),
3738 NewDI,
3739 OldParm->getStorageClass(),
3740 OldParm->getStorageClassAsWritten(),
3741 /* DefArg */ NULL);
3742 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3743 OldParm->getFunctionScopeIndex() + indexAdjustment);
3744 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003745}
3746
3747template<typename Derived>
3748bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003749 TransformFunctionTypeParams(SourceLocation Loc,
3750 ParmVarDecl **Params, unsigned NumParams,
3751 const QualType *ParamTypes,
3752 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3753 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003754 int indexAdjustment = 0;
3755
Douglas Gregordd472162011-01-07 00:20:55 +00003756 for (unsigned i = 0; i != NumParams; ++i) {
3757 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003758 assert(OldParm->getFunctionScopeIndex() == i);
3759
Douglas Gregor715e4612011-01-14 22:40:04 +00003760 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003761 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003762 if (OldParm->isParameterPack()) {
3763 // We have a function parameter pack that may need to be expanded.
3764 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003765
Douglas Gregor5499af42011-01-05 23:12:31 +00003766 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003767 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3768 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3769 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3770 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003771 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3772
Douglas Gregor5499af42011-01-05 23:12:31 +00003773 // Determine whether we should expand the parameter packs.
3774 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003775 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003776 llvm::Optional<unsigned> OrigNumExpansions
3777 = ExpansionTL.getTypePtr()->getNumExpansions();
3778 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003779 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3780 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003781 Unexpanded.data(),
3782 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003783 ShouldExpand,
3784 RetainExpansion,
3785 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003786 return true;
3787 }
3788
3789 if (ShouldExpand) {
3790 // Expand the function parameter pack into multiple, separate
3791 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003792 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003793 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003794 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3795 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003796 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003797 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003798 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003799 if (!NewParm)
3800 return true;
3801
Douglas Gregordd472162011-01-07 00:20:55 +00003802 OutParamTypes.push_back(NewParm->getType());
3803 if (PVars)
3804 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003805 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003806
3807 // If we're supposed to retain a pack expansion, do so by temporarily
3808 // forgetting the partially-substituted parameter pack.
3809 if (RetainExpansion) {
3810 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3811 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003812 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003813 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003814 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003815 if (!NewParm)
3816 return true;
3817
3818 OutParamTypes.push_back(NewParm->getType());
3819 if (PVars)
3820 PVars->push_back(NewParm);
3821 }
3822
John McCall8fb0d9d2011-05-01 22:35:37 +00003823 // The next parameter should have the same adjustment as the
3824 // last thing we pushed, but we post-incremented indexAdjustment
3825 // on every push. Also, if we push nothing, the adjustment should
3826 // go down by one.
3827 indexAdjustment--;
3828
Douglas Gregor5499af42011-01-05 23:12:31 +00003829 // We're done with the pack expansion.
3830 continue;
3831 }
3832
3833 // We'll substitute the parameter now without expanding the pack
3834 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003835 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3836 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003837 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003838 NumExpansions);
3839 } else {
3840 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003841 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003842 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003843 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003844
John McCall58f10c32010-03-11 09:03:00 +00003845 if (!NewParm)
3846 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003847
Douglas Gregordd472162011-01-07 00:20:55 +00003848 OutParamTypes.push_back(NewParm->getType());
3849 if (PVars)
3850 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003851 continue;
3852 }
John McCall58f10c32010-03-11 09:03:00 +00003853
3854 // Deal with the possibility that we don't have a parameter
3855 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003856 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003857 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003858 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003859 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003860 if (const PackExpansionType *Expansion
3861 = dyn_cast<PackExpansionType>(OldType)) {
3862 // We have a function parameter pack that may need to be expanded.
3863 QualType Pattern = Expansion->getPattern();
3864 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3865 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3866
3867 // Determine whether we should expand the parameter packs.
3868 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003869 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003870 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003871 Unexpanded.data(),
3872 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003873 ShouldExpand,
3874 RetainExpansion,
3875 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003876 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003877 }
3878
3879 if (ShouldExpand) {
3880 // Expand the function parameter pack into multiple, separate
3881 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003882 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003883 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3884 QualType NewType = getDerived().TransformType(Pattern);
3885 if (NewType.isNull())
3886 return true;
John McCall58f10c32010-03-11 09:03:00 +00003887
Douglas Gregordd472162011-01-07 00:20:55 +00003888 OutParamTypes.push_back(NewType);
3889 if (PVars)
3890 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003891 }
3892
3893 // We're done with the pack expansion.
3894 continue;
3895 }
3896
Douglas Gregor48d24112011-01-10 20:53:55 +00003897 // If we're supposed to retain a pack expansion, do so by temporarily
3898 // forgetting the partially-substituted parameter pack.
3899 if (RetainExpansion) {
3900 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3901 QualType NewType = getDerived().TransformType(Pattern);
3902 if (NewType.isNull())
3903 return true;
3904
3905 OutParamTypes.push_back(NewType);
3906 if (PVars)
3907 PVars->push_back(0);
3908 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003909
Douglas Gregor5499af42011-01-05 23:12:31 +00003910 // We'll substitute the parameter now without expanding the pack
3911 // expansion.
3912 OldType = Expansion->getPattern();
3913 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003914 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3915 NewType = getDerived().TransformType(OldType);
3916 } else {
3917 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003918 }
3919
Douglas Gregor5499af42011-01-05 23:12:31 +00003920 if (NewType.isNull())
3921 return true;
3922
3923 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003924 NewType = getSema().Context.getPackExpansionType(NewType,
3925 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003926
Douglas Gregordd472162011-01-07 00:20:55 +00003927 OutParamTypes.push_back(NewType);
3928 if (PVars)
3929 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003930 }
3931
John McCall8fb0d9d2011-05-01 22:35:37 +00003932#ifndef NDEBUG
3933 if (PVars) {
3934 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3935 if (ParmVarDecl *parm = (*PVars)[i])
3936 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00003937 }
John McCall8fb0d9d2011-05-01 22:35:37 +00003938#endif
3939
3940 return false;
3941}
John McCall58f10c32010-03-11 09:03:00 +00003942
3943template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003944QualType
John McCall550e0c22009-10-21 00:40:46 +00003945TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003946 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003947 // Transform the parameters and return type.
3948 //
3949 // We instantiate in source order, with the return type first followed by
3950 // the parameters, because users tend to expect this (even if they shouldn't
3951 // rely on it!).
3952 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003953 // When the function has a trailing return type, we instantiate the
3954 // parameters before the return type, since the return type can then refer
3955 // to the parameters themselves (via decltype, sizeof, etc.).
3956 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003957 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003958 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003959 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003960
Douglas Gregor7fb25412010-10-01 18:44:50 +00003961 QualType ResultType;
3962
3963 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003964 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3965 TL.getParmArray(),
3966 TL.getNumArgs(),
3967 TL.getTypePtr()->arg_type_begin(),
3968 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003969 return QualType();
3970
3971 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3972 if (ResultType.isNull())
3973 return QualType();
3974 }
3975 else {
3976 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3977 if (ResultType.isNull())
3978 return QualType();
3979
Douglas Gregordd472162011-01-07 00:20:55 +00003980 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3981 TL.getParmArray(),
3982 TL.getNumArgs(),
3983 TL.getTypePtr()->arg_type_begin(),
3984 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003985 return QualType();
3986 }
3987
John McCall550e0c22009-10-21 00:40:46 +00003988 QualType Result = TL.getType();
3989 if (getDerived().AlwaysRebuild() ||
3990 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003991 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003992 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3993 Result = getDerived().RebuildFunctionProtoType(ResultType,
3994 ParamTypes.data(),
3995 ParamTypes.size(),
3996 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003997 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003998 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003999 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004000 if (Result.isNull())
4001 return QualType();
4002 }
Mike Stump11289f42009-09-09 15:08:12 +00004003
John McCall550e0c22009-10-21 00:40:46 +00004004 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004005 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4006 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004007 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004008 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4009 NewTL.setArg(i, ParamDecls[i]);
4010
4011 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004012}
Mike Stump11289f42009-09-09 15:08:12 +00004013
Douglas Gregord6ff3322009-08-04 16:50:30 +00004014template<typename Derived>
4015QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004016 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004017 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004018 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004019 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4020 if (ResultType.isNull())
4021 return QualType();
4022
4023 QualType Result = TL.getType();
4024 if (getDerived().AlwaysRebuild() ||
4025 ResultType != T->getResultType())
4026 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4027
4028 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004029 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4030 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004031 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004032
4033 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004034}
Mike Stump11289f42009-09-09 15:08:12 +00004035
John McCallb96ec562009-12-04 22:46:56 +00004036template<typename Derived> QualType
4037TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004038 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004039 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004040 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004041 if (!D)
4042 return QualType();
4043
4044 QualType Result = TL.getType();
4045 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4046 Result = getDerived().RebuildUnresolvedUsingType(D);
4047 if (Result.isNull())
4048 return QualType();
4049 }
4050
4051 // We might get an arbitrary type spec type back. We should at
4052 // least always get a type spec type, though.
4053 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4054 NewTL.setNameLoc(TL.getNameLoc());
4055
4056 return Result;
4057}
4058
Douglas Gregord6ff3322009-08-04 16:50:30 +00004059template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004060QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004061 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004062 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004063 TypedefNameDecl *Typedef
4064 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4065 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004066 if (!Typedef)
4067 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004068
John McCall550e0c22009-10-21 00:40:46 +00004069 QualType Result = TL.getType();
4070 if (getDerived().AlwaysRebuild() ||
4071 Typedef != T->getDecl()) {
4072 Result = getDerived().RebuildTypedefType(Typedef);
4073 if (Result.isNull())
4074 return QualType();
4075 }
Mike Stump11289f42009-09-09 15:08:12 +00004076
John McCall550e0c22009-10-21 00:40:46 +00004077 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4078 NewTL.setNameLoc(TL.getNameLoc());
4079
4080 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004081}
Mike Stump11289f42009-09-09 15:08:12 +00004082
Douglas Gregord6ff3322009-08-04 16:50:30 +00004083template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004084QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004085 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004086 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004087 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004088
John McCalldadc5752010-08-24 06:29:42 +00004089 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004090 if (E.isInvalid())
4091 return QualType();
4092
John McCall550e0c22009-10-21 00:40:46 +00004093 QualType Result = TL.getType();
4094 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004095 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004096 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004097 if (Result.isNull())
4098 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004099 }
John McCall550e0c22009-10-21 00:40:46 +00004100 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004101
John McCall550e0c22009-10-21 00:40:46 +00004102 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004103 NewTL.setTypeofLoc(TL.getTypeofLoc());
4104 NewTL.setLParenLoc(TL.getLParenLoc());
4105 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004106
4107 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004108}
Mike Stump11289f42009-09-09 15:08:12 +00004109
4110template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004111QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004112 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004113 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4114 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4115 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004116 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004117
John McCall550e0c22009-10-21 00:40:46 +00004118 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004119 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4120 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004121 if (Result.isNull())
4122 return QualType();
4123 }
Mike Stump11289f42009-09-09 15:08:12 +00004124
John McCall550e0c22009-10-21 00:40:46 +00004125 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004126 NewTL.setTypeofLoc(TL.getTypeofLoc());
4127 NewTL.setLParenLoc(TL.getLParenLoc());
4128 NewTL.setRParenLoc(TL.getRParenLoc());
4129 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004130
4131 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004132}
Mike Stump11289f42009-09-09 15:08:12 +00004133
4134template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004135QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004136 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004137 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004138
Douglas Gregore922c772009-08-04 22:27:00 +00004139 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004140 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004141
John McCalldadc5752010-08-24 06:29:42 +00004142 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004143 if (E.isInvalid())
4144 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004145
John McCall550e0c22009-10-21 00:40:46 +00004146 QualType Result = TL.getType();
4147 if (getDerived().AlwaysRebuild() ||
4148 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004149 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004150 if (Result.isNull())
4151 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004152 }
John McCall550e0c22009-10-21 00:40:46 +00004153 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004154
John McCall550e0c22009-10-21 00:40:46 +00004155 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4156 NewTL.setNameLoc(TL.getNameLoc());
4157
4158 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004159}
4160
4161template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004162QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4163 AutoTypeLoc TL) {
4164 const AutoType *T = TL.getTypePtr();
4165 QualType OldDeduced = T->getDeducedType();
4166 QualType NewDeduced;
4167 if (!OldDeduced.isNull()) {
4168 NewDeduced = getDerived().TransformType(OldDeduced);
4169 if (NewDeduced.isNull())
4170 return QualType();
4171 }
4172
4173 QualType Result = TL.getType();
4174 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4175 Result = getDerived().RebuildAutoType(NewDeduced);
4176 if (Result.isNull())
4177 return QualType();
4178 }
4179
4180 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4181 NewTL.setNameLoc(TL.getNameLoc());
4182
4183 return Result;
4184}
4185
4186template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004187QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004188 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004189 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004190 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004191 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4192 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004193 if (!Record)
4194 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004195
John McCall550e0c22009-10-21 00:40:46 +00004196 QualType Result = TL.getType();
4197 if (getDerived().AlwaysRebuild() ||
4198 Record != T->getDecl()) {
4199 Result = getDerived().RebuildRecordType(Record);
4200 if (Result.isNull())
4201 return QualType();
4202 }
Mike Stump11289f42009-09-09 15:08:12 +00004203
John McCall550e0c22009-10-21 00:40:46 +00004204 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4205 NewTL.setNameLoc(TL.getNameLoc());
4206
4207 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004208}
Mike Stump11289f42009-09-09 15:08:12 +00004209
4210template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004211QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004212 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004213 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004214 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004215 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4216 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004217 if (!Enum)
4218 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004219
John McCall550e0c22009-10-21 00:40:46 +00004220 QualType Result = TL.getType();
4221 if (getDerived().AlwaysRebuild() ||
4222 Enum != T->getDecl()) {
4223 Result = getDerived().RebuildEnumType(Enum);
4224 if (Result.isNull())
4225 return QualType();
4226 }
Mike Stump11289f42009-09-09 15:08:12 +00004227
John McCall550e0c22009-10-21 00:40:46 +00004228 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4229 NewTL.setNameLoc(TL.getNameLoc());
4230
4231 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004232}
John McCallfcc33b02009-09-05 00:15:47 +00004233
John McCalle78aac42010-03-10 03:28:59 +00004234template<typename Derived>
4235QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4236 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004237 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004238 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4239 TL.getTypePtr()->getDecl());
4240 if (!D) return QualType();
4241
4242 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4243 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4244 return T;
4245}
4246
Douglas Gregord6ff3322009-08-04 16:50:30 +00004247template<typename Derived>
4248QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004249 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004250 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004251 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004252}
4253
Mike Stump11289f42009-09-09 15:08:12 +00004254template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004255QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004256 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004257 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004258 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4259
4260 // Substitute into the replacement type, which itself might involve something
4261 // that needs to be transformed. This only tends to occur with default
4262 // template arguments of template template parameters.
4263 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4264 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4265 if (Replacement.isNull())
4266 return QualType();
4267
4268 // Always canonicalize the replacement type.
4269 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4270 QualType Result
4271 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4272 Replacement);
4273
4274 // Propagate type-source information.
4275 SubstTemplateTypeParmTypeLoc NewTL
4276 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4277 NewTL.setNameLoc(TL.getNameLoc());
4278 return Result;
4279
John McCallcebee162009-10-18 09:09:24 +00004280}
4281
4282template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004283QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4284 TypeLocBuilder &TLB,
4285 SubstTemplateTypeParmPackTypeLoc TL) {
4286 return TransformTypeSpecType(TLB, TL);
4287}
4288
4289template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004290QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004291 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004292 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004293 const TemplateSpecializationType *T = TL.getTypePtr();
4294
Douglas Gregordf846d12011-03-02 18:46:51 +00004295 // The nested-name-specifier never matters in a TemplateSpecializationType,
4296 // because we can't have a dependent nested-name-specifier anyway.
4297 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004298 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004299 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4300 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004301 if (Template.isNull())
4302 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004303
John McCall31f82722010-11-12 08:19:04 +00004304 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4305}
4306
Douglas Gregorfe921a72010-12-20 23:36:19 +00004307namespace {
4308 /// \brief Simple iterator that traverses the template arguments in a
4309 /// container that provides a \c getArgLoc() member function.
4310 ///
4311 /// This iterator is intended to be used with the iterator form of
4312 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4313 template<typename ArgLocContainer>
4314 class TemplateArgumentLocContainerIterator {
4315 ArgLocContainer *Container;
4316 unsigned Index;
4317
4318 public:
4319 typedef TemplateArgumentLoc value_type;
4320 typedef TemplateArgumentLoc reference;
4321 typedef int difference_type;
4322 typedef std::input_iterator_tag iterator_category;
4323
4324 class pointer {
4325 TemplateArgumentLoc Arg;
4326
4327 public:
4328 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4329
4330 const TemplateArgumentLoc *operator->() const {
4331 return &Arg;
4332 }
4333 };
4334
4335
4336 TemplateArgumentLocContainerIterator() {}
4337
4338 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4339 unsigned Index)
4340 : Container(&Container), Index(Index) { }
4341
4342 TemplateArgumentLocContainerIterator &operator++() {
4343 ++Index;
4344 return *this;
4345 }
4346
4347 TemplateArgumentLocContainerIterator operator++(int) {
4348 TemplateArgumentLocContainerIterator Old(*this);
4349 ++(*this);
4350 return Old;
4351 }
4352
4353 TemplateArgumentLoc operator*() const {
4354 return Container->getArgLoc(Index);
4355 }
4356
4357 pointer operator->() const {
4358 return pointer(Container->getArgLoc(Index));
4359 }
4360
4361 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004362 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004363 return X.Container == Y.Container && X.Index == Y.Index;
4364 }
4365
4366 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004367 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004368 return !(X == Y);
4369 }
4370 };
4371}
4372
4373
John McCall31f82722010-11-12 08:19:04 +00004374template <typename Derived>
4375QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4376 TypeLocBuilder &TLB,
4377 TemplateSpecializationTypeLoc TL,
4378 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004379 TemplateArgumentListInfo NewTemplateArgs;
4380 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4381 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004382 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4383 ArgIterator;
4384 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4385 ArgIterator(TL, TL.getNumArgs()),
4386 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004387 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004388
John McCall0ad16662009-10-29 08:12:44 +00004389 // FIXME: maybe don't rebuild if all the template arguments are the same.
4390
4391 QualType Result =
4392 getDerived().RebuildTemplateSpecializationType(Template,
4393 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004394 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004395
4396 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004397 // Specializations of template template parameters are represented as
4398 // TemplateSpecializationTypes, and substitution of type alias templates
4399 // within a dependent context can transform them into
4400 // DependentTemplateSpecializationTypes.
4401 if (isa<DependentTemplateSpecializationType>(Result)) {
4402 DependentTemplateSpecializationTypeLoc NewTL
4403 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4404 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4405 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4406 NewTL.setNameLoc(TL.getTemplateNameLoc());
4407 NewTL.setLAngleLoc(TL.getLAngleLoc());
4408 NewTL.setRAngleLoc(TL.getRAngleLoc());
4409 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4410 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4411 return Result;
4412 }
4413
John McCall0ad16662009-10-29 08:12:44 +00004414 TemplateSpecializationTypeLoc NewTL
4415 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4416 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4417 NewTL.setLAngleLoc(TL.getLAngleLoc());
4418 NewTL.setRAngleLoc(TL.getRAngleLoc());
4419 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4420 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004421 }
Mike Stump11289f42009-09-09 15:08:12 +00004422
John McCall0ad16662009-10-29 08:12:44 +00004423 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004424}
Mike Stump11289f42009-09-09 15:08:12 +00004425
Douglas Gregor5a064722011-02-28 17:23:35 +00004426template <typename Derived>
4427QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4428 TypeLocBuilder &TLB,
4429 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004430 TemplateName Template,
4431 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004432 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
Douglas Gregora7a795b2011-03-01 20:11:18 +00004456 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004457 NewTL.setNameLoc(TL.getNameLoc());
4458 NewTL.setLAngleLoc(TL.getLAngleLoc());
4459 NewTL.setRAngleLoc(TL.getRAngleLoc());
4460 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4461 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4462 return Result;
4463 }
4464
4465 QualType Result
4466 = getDerived().RebuildTemplateSpecializationType(Template,
4467 TL.getNameLoc(),
4468 NewTemplateArgs);
4469
4470 if (!Result.isNull()) {
4471 /// FIXME: Wrap this in an elaborated-type-specifier?
4472 TemplateSpecializationTypeLoc NewTL
4473 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4474 NewTL.setTemplateNameLoc(TL.getNameLoc());
4475 NewTL.setLAngleLoc(TL.getLAngleLoc());
4476 NewTL.setRAngleLoc(TL.getRAngleLoc());
4477 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4478 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4479 }
4480
4481 return Result;
4482}
4483
Mike Stump11289f42009-09-09 15:08:12 +00004484template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004485QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004486TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004487 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004488 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004489
Douglas Gregor844cb502011-03-01 18:12:44 +00004490 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004491 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004492 if (TL.getQualifierLoc()) {
4493 QualifierLoc
4494 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4495 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004496 return QualType();
4497 }
Mike Stump11289f42009-09-09 15:08:12 +00004498
John McCall31f82722010-11-12 08:19:04 +00004499 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4500 if (NamedT.isNull())
4501 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004502
Richard Smith3f1b5d02011-05-05 21:57:07 +00004503 // C++0x [dcl.type.elab]p2:
4504 // If the identifier resolves to a typedef-name or the simple-template-id
4505 // resolves to an alias template specialization, the
4506 // elaborated-type-specifier is ill-formed.
4507 if (const TemplateSpecializationType *TST =
4508 NamedT->getAs<TemplateSpecializationType>()) {
4509 TemplateName Template = TST->getTemplateName();
4510 if (TypeAliasTemplateDecl *TAT =
4511 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4512 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4513 diag::err_tag_reference_non_tag) << 4;
4514 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4515 }
4516 }
4517
John McCall550e0c22009-10-21 00:40:46 +00004518 QualType Result = TL.getType();
4519 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004520 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004521 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004522 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004523 T->getKeyword(),
4524 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004525 if (Result.isNull())
4526 return QualType();
4527 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004528
Abramo Bagnara6150c882010-05-11 21:36:43 +00004529 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004530 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004531 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004532 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004533}
Mike Stump11289f42009-09-09 15:08:12 +00004534
4535template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004536QualType TreeTransform<Derived>::TransformAttributedType(
4537 TypeLocBuilder &TLB,
4538 AttributedTypeLoc TL) {
4539 const AttributedType *oldType = TL.getTypePtr();
4540 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4541 if (modifiedType.isNull())
4542 return QualType();
4543
4544 QualType result = TL.getType();
4545
4546 // FIXME: dependent operand expressions?
4547 if (getDerived().AlwaysRebuild() ||
4548 modifiedType != oldType->getModifiedType()) {
4549 // TODO: this is really lame; we should really be rebuilding the
4550 // equivalent type from first principles.
4551 QualType equivalentType
4552 = getDerived().TransformType(oldType->getEquivalentType());
4553 if (equivalentType.isNull())
4554 return QualType();
4555 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4556 modifiedType,
4557 equivalentType);
4558 }
4559
4560 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4561 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4562 if (TL.hasAttrOperand())
4563 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4564 if (TL.hasAttrExprOperand())
4565 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4566 else if (TL.hasAttrEnumOperand())
4567 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4568
4569 return result;
4570}
4571
4572template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004573QualType
4574TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4575 ParenTypeLoc TL) {
4576 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4577 if (Inner.isNull())
4578 return QualType();
4579
4580 QualType Result = TL.getType();
4581 if (getDerived().AlwaysRebuild() ||
4582 Inner != TL.getInnerLoc().getType()) {
4583 Result = getDerived().RebuildParenType(Inner);
4584 if (Result.isNull())
4585 return QualType();
4586 }
4587
4588 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4589 NewTL.setLParenLoc(TL.getLParenLoc());
4590 NewTL.setRParenLoc(TL.getRParenLoc());
4591 return Result;
4592}
4593
4594template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004595QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004596 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004597 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004598
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004599 NestedNameSpecifierLoc QualifierLoc
4600 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4601 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004602 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004603
John McCallc392f372010-06-11 00:33:02 +00004604 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004605 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004606 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004607 QualifierLoc,
4608 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004609 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004610 if (Result.isNull())
4611 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004612
Abramo Bagnarad7548482010-05-19 21:37:53 +00004613 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4614 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004615 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4616
Abramo Bagnarad7548482010-05-19 21:37:53 +00004617 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4618 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004619 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004620 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004621 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4622 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004623 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004624 NewTL.setNameLoc(TL.getNameLoc());
4625 }
John McCall550e0c22009-10-21 00:40:46 +00004626 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004627}
Mike Stump11289f42009-09-09 15:08:12 +00004628
Douglas Gregord6ff3322009-08-04 16:50:30 +00004629template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004630QualType TreeTransform<Derived>::
4631 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004632 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004633 NestedNameSpecifierLoc QualifierLoc;
4634 if (TL.getQualifierLoc()) {
4635 QualifierLoc
4636 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4637 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004638 return QualType();
4639 }
4640
John McCall31f82722010-11-12 08:19:04 +00004641 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004642 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004643}
4644
4645template<typename Derived>
4646QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004647TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4648 DependentTemplateSpecializationTypeLoc TL,
4649 NestedNameSpecifierLoc QualifierLoc) {
4650 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4651
4652 TemplateArgumentListInfo NewTemplateArgs;
4653 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4654 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4655
4656 typedef TemplateArgumentLocContainerIterator<
4657 DependentTemplateSpecializationTypeLoc> ArgIterator;
4658 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4659 ArgIterator(TL, TL.getNumArgs()),
4660 NewTemplateArgs))
4661 return QualType();
4662
4663 QualType Result
4664 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4665 QualifierLoc,
4666 T->getIdentifier(),
4667 TL.getNameLoc(),
4668 NewTemplateArgs);
4669 if (Result.isNull())
4670 return QualType();
4671
4672 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4673 QualType NamedT = ElabT->getNamedType();
4674
4675 // Copy information relevant to the template specialization.
4676 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004677 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004678 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004679 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4680 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004681 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004682 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004683
4684 // Copy information relevant to the elaborated type.
4685 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4686 NewTL.setKeywordLoc(TL.getKeywordLoc());
4687 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004688 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4689 DependentTemplateSpecializationTypeLoc SpecTL
4690 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004691 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004692 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004693 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004694 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4695 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004696 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004697 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004698 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004699 TemplateSpecializationTypeLoc SpecTL
4700 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004701 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004702 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4703 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004704 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004705 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004706 }
4707 return Result;
4708}
4709
4710template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004711QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4712 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004713 QualType Pattern
4714 = getDerived().TransformType(TLB, TL.getPatternLoc());
4715 if (Pattern.isNull())
4716 return QualType();
4717
4718 QualType Result = TL.getType();
4719 if (getDerived().AlwaysRebuild() ||
4720 Pattern != TL.getPatternLoc().getType()) {
4721 Result = getDerived().RebuildPackExpansionType(Pattern,
4722 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004723 TL.getEllipsisLoc(),
4724 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004725 if (Result.isNull())
4726 return QualType();
4727 }
4728
4729 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4730 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4731 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004732}
4733
4734template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004735QualType
4736TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004737 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004738 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004739 TLB.pushFullCopy(TL);
4740 return TL.getType();
4741}
4742
4743template<typename Derived>
4744QualType
4745TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004746 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004747 // ObjCObjectType is never dependent.
4748 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004749 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004750}
Mike Stump11289f42009-09-09 15:08:12 +00004751
4752template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004753QualType
4754TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004755 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004756 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004757 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004758 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004759}
4760
Douglas Gregord6ff3322009-08-04 16:50:30 +00004761//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004762// Statement transformation
4763//===----------------------------------------------------------------------===//
4764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004765StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004766TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004767 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004768}
4769
4770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004771StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004772TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4773 return getDerived().TransformCompoundStmt(S, false);
4774}
4775
4776template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004777StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004778TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004779 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004780 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004781 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004782 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004783 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4784 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004785 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004786 if (Result.isInvalid()) {
4787 // Immediately fail if this was a DeclStmt, since it's very
4788 // likely that this will cause problems for future statements.
4789 if (isa<DeclStmt>(*B))
4790 return StmtError();
4791
4792 // Otherwise, just keep processing substatements and fail later.
4793 SubStmtInvalid = true;
4794 continue;
4795 }
Mike Stump11289f42009-09-09 15:08:12 +00004796
Douglas Gregorebe10102009-08-20 07:17:43 +00004797 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4798 Statements.push_back(Result.takeAs<Stmt>());
4799 }
Mike Stump11289f42009-09-09 15:08:12 +00004800
John McCall1ababa62010-08-27 19:56:05 +00004801 if (SubStmtInvalid)
4802 return StmtError();
4803
Douglas Gregorebe10102009-08-20 07:17:43 +00004804 if (!getDerived().AlwaysRebuild() &&
4805 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004806 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004807
4808 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4809 move_arg(Statements),
4810 S->getRBracLoc(),
4811 IsStmtExpr);
4812}
Mike Stump11289f42009-09-09 15:08:12 +00004813
Douglas Gregorebe10102009-08-20 07:17:43 +00004814template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004815StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004816TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004817 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004818 {
4819 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004820 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004821
Eli Friedman06577382009-11-19 03:14:00 +00004822 // Transform the left-hand case value.
4823 LHS = getDerived().TransformExpr(S->getLHS());
4824 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004825 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004826
Eli Friedman06577382009-11-19 03:14:00 +00004827 // Transform the right-hand case value (for the GNU case-range extension).
4828 RHS = getDerived().TransformExpr(S->getRHS());
4829 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004830 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004831 }
Mike Stump11289f42009-09-09 15:08:12 +00004832
Douglas Gregorebe10102009-08-20 07:17:43 +00004833 // Build the case statement.
4834 // Case statements are always rebuilt so that they will attached to their
4835 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004836 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004837 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004838 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004839 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004840 S->getColonLoc());
4841 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004842 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004843
Douglas Gregorebe10102009-08-20 07:17:43 +00004844 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004845 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004846 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004847 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004848
Douglas Gregorebe10102009-08-20 07:17:43 +00004849 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004850 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004851}
4852
4853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004854StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004855TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004856 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004857 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004858 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004859 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004860
Douglas Gregorebe10102009-08-20 07:17:43 +00004861 // Default statements are always rebuilt
4862 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004863 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004864}
Mike Stump11289f42009-09-09 15:08:12 +00004865
Douglas Gregorebe10102009-08-20 07:17:43 +00004866template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004867StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004868TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004869 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004870 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004871 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004872
Chris Lattnercab02a62011-02-17 20:34:02 +00004873 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4874 S->getDecl());
4875 if (!LD)
4876 return StmtError();
4877
4878
Douglas Gregorebe10102009-08-20 07:17:43 +00004879 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004880 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004881 cast<LabelDecl>(LD), SourceLocation(),
4882 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004883}
Mike Stump11289f42009-09-09 15:08:12 +00004884
Douglas Gregorebe10102009-08-20 07:17:43 +00004885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004886StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004887TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004888 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004889 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004890 VarDecl *ConditionVar = 0;
4891 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004892 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004893 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004894 getDerived().TransformDefinition(
4895 S->getConditionVariable()->getLocation(),
4896 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004897 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004898 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004899 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004900 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004901
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004902 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004903 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004904
4905 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004906 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004907 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4908 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004909 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004910 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004911
John McCallb268a282010-08-23 23:25:46 +00004912 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004913 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004914 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004915
John McCallb268a282010-08-23 23:25:46 +00004916 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4917 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004918 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004919
Douglas Gregorebe10102009-08-20 07:17:43 +00004920 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004921 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004922 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004923 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004924
Douglas Gregorebe10102009-08-20 07:17:43 +00004925 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004926 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004927 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004928 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004929
Douglas Gregorebe10102009-08-20 07:17:43 +00004930 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004931 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004932 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004933 Then.get() == S->getThen() &&
4934 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004935 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004936
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004937 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004938 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004939 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004940}
4941
4942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004943StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004944TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004945 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004946 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004947 VarDecl *ConditionVar = 0;
4948 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004949 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004950 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004951 getDerived().TransformDefinition(
4952 S->getConditionVariable()->getLocation(),
4953 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004954 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004955 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004956 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004957 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004958
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004959 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004960 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004961 }
Mike Stump11289f42009-09-09 15:08:12 +00004962
Douglas Gregorebe10102009-08-20 07:17:43 +00004963 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004964 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004965 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004966 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004967 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004968 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004969
Douglas Gregorebe10102009-08-20 07:17:43 +00004970 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004971 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004972 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004973 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004974
Douglas Gregorebe10102009-08-20 07:17:43 +00004975 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004976 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4977 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004978}
Mike Stump11289f42009-09-09 15:08:12 +00004979
Douglas Gregorebe10102009-08-20 07:17:43 +00004980template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004981StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004982TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004983 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004984 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004985 VarDecl *ConditionVar = 0;
4986 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004987 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004988 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004989 getDerived().TransformDefinition(
4990 S->getConditionVariable()->getLocation(),
4991 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004992 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004993 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004994 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004995 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004996
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004997 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004998 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004999
5000 if (S->getCond()) {
5001 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005002 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5003 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005004 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005005 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005006 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005007 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005008 }
Mike Stump11289f42009-09-09 15:08:12 +00005009
John McCallb268a282010-08-23 23:25:46 +00005010 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5011 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005012 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005013
Douglas Gregorebe10102009-08-20 07:17:43 +00005014 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005015 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005016 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005017 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005018
Douglas Gregorebe10102009-08-20 07:17:43 +00005019 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005020 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005021 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005022 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005023 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005024
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005025 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005026 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005027}
Mike Stump11289f42009-09-09 15:08:12 +00005028
Douglas Gregorebe10102009-08-20 07:17:43 +00005029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005030StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005031TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005032 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005033 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005034 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005035 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005036
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005037 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005038 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005039 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005040 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005041
Douglas Gregorebe10102009-08-20 07:17:43 +00005042 if (!getDerived().AlwaysRebuild() &&
5043 Cond.get() == S->getCond() &&
5044 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005045 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005046
John McCallb268a282010-08-23 23:25:46 +00005047 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5048 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005049 S->getRParenLoc());
5050}
Mike Stump11289f42009-09-09 15:08:12 +00005051
Douglas Gregorebe10102009-08-20 07:17:43 +00005052template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005053StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005054TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005055 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005056 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005057 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005058 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005059
Douglas Gregorebe10102009-08-20 07:17:43 +00005060 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005061 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005062 VarDecl *ConditionVar = 0;
5063 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005064 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005065 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005066 getDerived().TransformDefinition(
5067 S->getConditionVariable()->getLocation(),
5068 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005069 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005070 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005071 } else {
5072 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005073
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005074 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005075 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005076
5077 if (S->getCond()) {
5078 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005079 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5080 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005081 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005082 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005083
John McCallb268a282010-08-23 23:25:46 +00005084 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005085 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005086 }
Mike Stump11289f42009-09-09 15:08:12 +00005087
John McCallb268a282010-08-23 23:25:46 +00005088 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5089 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005090 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005091
Douglas Gregorebe10102009-08-20 07:17:43 +00005092 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005093 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005094 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005095 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005096
John McCallb268a282010-08-23 23:25:46 +00005097 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5098 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005099 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005100
Douglas Gregorebe10102009-08-20 07:17:43 +00005101 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005102 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005103 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005104 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005105
Douglas Gregorebe10102009-08-20 07:17:43 +00005106 if (!getDerived().AlwaysRebuild() &&
5107 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005108 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005109 Inc.get() == S->getInc() &&
5110 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005111 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005112
Douglas Gregorebe10102009-08-20 07:17:43 +00005113 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005114 Init.get(), FullCond, ConditionVar,
5115 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005116}
5117
5118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005119StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005120TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005121 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5122 S->getLabel());
5123 if (!LD)
5124 return StmtError();
5125
Douglas Gregorebe10102009-08-20 07:17:43 +00005126 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005127 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005128 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005129}
5130
5131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005132StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005133TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005134 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005135 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005136 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005137
Douglas Gregorebe10102009-08-20 07:17:43 +00005138 if (!getDerived().AlwaysRebuild() &&
5139 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005140 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005141
5142 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005143 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005144}
5145
5146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005147StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005148TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005149 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005150}
Mike Stump11289f42009-09-09 15:08:12 +00005151
Douglas Gregorebe10102009-08-20 07:17:43 +00005152template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005153StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005154TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005155 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005156}
Mike Stump11289f42009-09-09 15:08:12 +00005157
Douglas Gregorebe10102009-08-20 07:17:43 +00005158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005159StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005160TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005161 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005162 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005163 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005164
Mike Stump11289f42009-09-09 15:08:12 +00005165 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005166 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005167 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005168}
Mike Stump11289f42009-09-09 15:08:12 +00005169
Douglas Gregorebe10102009-08-20 07:17:43 +00005170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005171StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005172TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005173 bool DeclChanged = false;
5174 llvm::SmallVector<Decl *, 4> Decls;
5175 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5176 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005177 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5178 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005179 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005180 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005181
Douglas Gregorebe10102009-08-20 07:17:43 +00005182 if (Transformed != *D)
5183 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005184
Douglas Gregorebe10102009-08-20 07:17:43 +00005185 Decls.push_back(Transformed);
5186 }
Mike Stump11289f42009-09-09 15:08:12 +00005187
Douglas Gregorebe10102009-08-20 07:17:43 +00005188 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005189 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005190
5191 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005192 S->getStartLoc(), S->getEndLoc());
5193}
Mike Stump11289f42009-09-09 15:08:12 +00005194
Douglas Gregorebe10102009-08-20 07:17:43 +00005195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005196StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005197TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005198
John McCall37ad5512010-08-23 06:44:23 +00005199 ASTOwningVector<Expr*> Constraints(getSema());
5200 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005201 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005202
John McCalldadc5752010-08-24 06:29:42 +00005203 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005204 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005205
5206 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005207
Anders Carlssonaaeef072010-01-24 05:50:09 +00005208 // Go through the outputs.
5209 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005210 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005211
Anders Carlssonaaeef072010-01-24 05:50:09 +00005212 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005213 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005214
Anders Carlssonaaeef072010-01-24 05:50:09 +00005215 // Transform the output expr.
5216 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005217 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005218 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005219 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005220
Anders Carlssonaaeef072010-01-24 05:50:09 +00005221 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005222
John McCallb268a282010-08-23 23:25:46 +00005223 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005224 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005225
Anders Carlssonaaeef072010-01-24 05:50:09 +00005226 // Go through the inputs.
5227 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005228 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005229
Anders Carlssonaaeef072010-01-24 05:50:09 +00005230 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005231 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005232
Anders Carlssonaaeef072010-01-24 05:50:09 +00005233 // Transform the input expr.
5234 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005235 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005236 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005237 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005238
Anders Carlssonaaeef072010-01-24 05:50:09 +00005239 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005240
John McCallb268a282010-08-23 23:25:46 +00005241 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005242 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005243
Anders Carlssonaaeef072010-01-24 05:50:09 +00005244 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005245 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005246
5247 // Go through the clobbers.
5248 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005249 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005250
5251 // No need to transform the asm string literal.
5252 AsmString = SemaRef.Owned(S->getAsmString());
5253
5254 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5255 S->isSimple(),
5256 S->isVolatile(),
5257 S->getNumOutputs(),
5258 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005259 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005260 move_arg(Constraints),
5261 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005262 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005263 move_arg(Clobbers),
5264 S->getRParenLoc(),
5265 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005266}
5267
5268
5269template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005270StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005271TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005272 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005273 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005274 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005275 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005276
Douglas Gregor96c79492010-04-23 22:50:49 +00005277 // Transform the @catch statements (if present).
5278 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005279 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005280 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005281 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005282 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005283 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005284 if (Catch.get() != S->getCatchStmt(I))
5285 AnyCatchChanged = true;
5286 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005287 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005288
Douglas Gregor306de2f2010-04-22 23:59:56 +00005289 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005290 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005291 if (S->getFinallyStmt()) {
5292 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5293 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005294 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005295 }
5296
5297 // If nothing changed, just retain this statement.
5298 if (!getDerived().AlwaysRebuild() &&
5299 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005300 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005301 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005302 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005303
Douglas Gregor306de2f2010-04-22 23:59:56 +00005304 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005305 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5306 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005307}
Mike Stump11289f42009-09-09 15:08:12 +00005308
Douglas Gregorebe10102009-08-20 07:17:43 +00005309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005310StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005311TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005312 // Transform the @catch parameter, if there is one.
5313 VarDecl *Var = 0;
5314 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5315 TypeSourceInfo *TSInfo = 0;
5316 if (FromVar->getTypeSourceInfo()) {
5317 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5318 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005319 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005320 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005321
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005322 QualType T;
5323 if (TSInfo)
5324 T = TSInfo->getType();
5325 else {
5326 T = getDerived().TransformType(FromVar->getType());
5327 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005328 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005329 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005330
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005331 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5332 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005333 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005334 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005335
John McCalldadc5752010-08-24 06:29:42 +00005336 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005337 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005338 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005339
5340 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005341 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005342 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005343}
Mike Stump11289f42009-09-09 15:08:12 +00005344
Douglas Gregorebe10102009-08-20 07:17:43 +00005345template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005346StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005347TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005348 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005349 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005350 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005351 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005352
Douglas Gregor306de2f2010-04-22 23:59:56 +00005353 // If nothing changed, just retain this statement.
5354 if (!getDerived().AlwaysRebuild() &&
5355 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005356 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005357
5358 // Build a new statement.
5359 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005360 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005361}
Mike Stump11289f42009-09-09 15:08:12 +00005362
Douglas Gregorebe10102009-08-20 07:17:43 +00005363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005364StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005365TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005366 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005367 if (S->getThrowExpr()) {
5368 Operand = getDerived().TransformExpr(S->getThrowExpr());
5369 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005370 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005371 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005372
Douglas Gregor2900c162010-04-22 21:44:01 +00005373 if (!getDerived().AlwaysRebuild() &&
5374 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005375 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005376
John McCallb268a282010-08-23 23:25:46 +00005377 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005378}
Mike Stump11289f42009-09-09 15:08:12 +00005379
Douglas Gregorebe10102009-08-20 07:17:43 +00005380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005381StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005382TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005383 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005384 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005385 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005386 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005387 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005388
Douglas Gregor6148de72010-04-22 22:01:21 +00005389 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005390 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005391 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005392 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005393
Douglas Gregor6148de72010-04-22 22:01:21 +00005394 // If nothing change, just retain the current statement.
5395 if (!getDerived().AlwaysRebuild() &&
5396 Object.get() == S->getSynchExpr() &&
5397 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005398 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005399
5400 // Build a new statement.
5401 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005402 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005403}
5404
5405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005406StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005407TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005408 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005409 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005410 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005411 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005412 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005413
Douglas Gregorf68a5082010-04-22 23:10:45 +00005414 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005415 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005416 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005417 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005418
Douglas Gregorf68a5082010-04-22 23:10:45 +00005419 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005420 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005421 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005422 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005423
Douglas Gregorf68a5082010-04-22 23:10:45 +00005424 // If nothing changed, just retain this statement.
5425 if (!getDerived().AlwaysRebuild() &&
5426 Element.get() == S->getElement() &&
5427 Collection.get() == S->getCollection() &&
5428 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005429 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005430
Douglas Gregorf68a5082010-04-22 23:10:45 +00005431 // Build a new statement.
5432 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5433 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005434 Element.get(),
5435 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005436 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005437 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005438}
5439
5440
5441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005442StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005443TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5444 // Transform the exception declaration, if any.
5445 VarDecl *Var = 0;
5446 if (S->getExceptionDecl()) {
5447 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005448 TypeSourceInfo *T = getDerived().TransformType(
5449 ExceptionDecl->getTypeSourceInfo());
5450 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005451 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005452
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005453 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005454 ExceptionDecl->getInnerLocStart(),
5455 ExceptionDecl->getLocation(),
5456 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005457 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005458 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005459 }
Mike Stump11289f42009-09-09 15:08:12 +00005460
Douglas Gregorebe10102009-08-20 07:17:43 +00005461 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005462 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005463 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005464 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005465
Douglas Gregorebe10102009-08-20 07:17:43 +00005466 if (!getDerived().AlwaysRebuild() &&
5467 !Var &&
5468 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005469 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005470
5471 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5472 Var,
John McCallb268a282010-08-23 23:25:46 +00005473 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005474}
Mike Stump11289f42009-09-09 15:08:12 +00005475
Douglas Gregorebe10102009-08-20 07:17:43 +00005476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005477StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005478TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5479 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005480 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005481 = getDerived().TransformCompoundStmt(S->getTryBlock());
5482 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005483 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005484
Douglas Gregorebe10102009-08-20 07:17:43 +00005485 // Transform the handlers.
5486 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005487 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005488 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005489 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005490 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5491 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005492 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregorebe10102009-08-20 07:17:43 +00005494 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5495 Handlers.push_back(Handler.takeAs<Stmt>());
5496 }
Mike Stump11289f42009-09-09 15:08:12 +00005497
Douglas Gregorebe10102009-08-20 07:17:43 +00005498 if (!getDerived().AlwaysRebuild() &&
5499 TryBlock.get() == S->getTryBlock() &&
5500 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005501 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005502
John McCallb268a282010-08-23 23:25:46 +00005503 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005504 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005505}
Mike Stump11289f42009-09-09 15:08:12 +00005506
Richard Smith02e85f32011-04-14 22:09:26 +00005507template<typename Derived>
5508StmtResult
5509TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5510 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5511 if (Range.isInvalid())
5512 return StmtError();
5513
5514 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5515 if (BeginEnd.isInvalid())
5516 return StmtError();
5517
5518 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5519 if (Cond.isInvalid())
5520 return StmtError();
5521
5522 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5523 if (Inc.isInvalid())
5524 return StmtError();
5525
5526 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5527 if (LoopVar.isInvalid())
5528 return StmtError();
5529
5530 StmtResult NewStmt = S;
5531 if (getDerived().AlwaysRebuild() ||
5532 Range.get() != S->getRangeStmt() ||
5533 BeginEnd.get() != S->getBeginEndStmt() ||
5534 Cond.get() != S->getCond() ||
5535 Inc.get() != S->getInc() ||
5536 LoopVar.get() != S->getLoopVarStmt())
5537 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5538 S->getColonLoc(), Range.get(),
5539 BeginEnd.get(), Cond.get(),
5540 Inc.get(), LoopVar.get(),
5541 S->getRParenLoc());
5542
5543 StmtResult Body = getDerived().TransformStmt(S->getBody());
5544 if (Body.isInvalid())
5545 return StmtError();
5546
5547 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5548 // it now so we have a new statement to attach the body to.
5549 if (Body.get() != S->getBody() && NewStmt.get() == S)
5550 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5551 S->getColonLoc(), Range.get(),
5552 BeginEnd.get(), Cond.get(),
5553 Inc.get(), LoopVar.get(),
5554 S->getRParenLoc());
5555
5556 if (NewStmt.get() == S)
5557 return SemaRef.Owned(S);
5558
5559 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5560}
5561
John Wiegley1c0675e2011-04-28 01:08:34 +00005562template<typename Derived>
5563StmtResult
5564TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5565 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5566 if(TryBlock.isInvalid()) return StmtError();
5567
5568 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5569 if(!getDerived().AlwaysRebuild() &&
5570 TryBlock.get() == S->getTryBlock() &&
5571 Handler.get() == S->getHandler())
5572 return SemaRef.Owned(S);
5573
5574 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5575 S->getTryLoc(),
5576 TryBlock.take(),
5577 Handler.take());
5578}
5579
5580template<typename Derived>
5581StmtResult
5582TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5583 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5584 if(Block.isInvalid()) return StmtError();
5585
5586 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5587 Block.take());
5588}
5589
5590template<typename Derived>
5591StmtResult
5592TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5593 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5594 if(FilterExpr.isInvalid()) return StmtError();
5595
5596 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5597 if(Block.isInvalid()) return StmtError();
5598
5599 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5600 FilterExpr.take(),
5601 Block.take());
5602}
5603
5604template<typename Derived>
5605StmtResult
5606TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5607 if(isa<SEHFinallyStmt>(Handler))
5608 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5609 else
5610 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5611}
5612
Douglas Gregorebe10102009-08-20 07:17:43 +00005613//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005614// Expression transformation
5615//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005617ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005618TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *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
5622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005623ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005624TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005625 NestedNameSpecifierLoc QualifierLoc;
5626 if (E->getQualifierLoc()) {
5627 QualifierLoc
5628 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5629 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005630 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005631 }
John McCallce546572009-12-08 09:08:17 +00005632
5633 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005634 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5635 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005636 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005637 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005638
John McCall815039a2010-08-17 21:27:17 +00005639 DeclarationNameInfo NameInfo = E->getNameInfo();
5640 if (NameInfo.getName()) {
5641 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5642 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005643 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005644 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005645
5646 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005647 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005648 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005649 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005650 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005651
5652 // Mark it referenced in the new context regardless.
5653 // FIXME: this is a bit instantiation-specific.
5654 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5655
John McCallc3007a22010-10-26 07:05:15 +00005656 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005657 }
John McCallce546572009-12-08 09:08:17 +00005658
5659 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005660 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005661 TemplateArgs = &TransArgs;
5662 TransArgs.setLAngleLoc(E->getLAngleLoc());
5663 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005664 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5665 E->getNumTemplateArgs(),
5666 TransArgs))
5667 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005668 }
5669
Douglas Gregorea972d32011-02-28 21:54:11 +00005670 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5671 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005672}
Mike Stump11289f42009-09-09 15:08:12 +00005673
Douglas Gregora16548e2009-08-11 05:31:07 +00005674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005675ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005676TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005677 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005678}
Mike Stump11289f42009-09-09 15:08:12 +00005679
Douglas Gregora16548e2009-08-11 05:31:07 +00005680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005681ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005682TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005683 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005684}
Mike Stump11289f42009-09-09 15:08:12 +00005685
Douglas Gregora16548e2009-08-11 05:31:07 +00005686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005687ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005688TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005689 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005690}
Mike Stump11289f42009-09-09 15:08:12 +00005691
Douglas Gregora16548e2009-08-11 05:31:07 +00005692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005694TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005695 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005696}
Mike Stump11289f42009-09-09 15:08:12 +00005697
Douglas Gregora16548e2009-08-11 05:31:07 +00005698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005699ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005700TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005701 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005702}
5703
5704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005705ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005706TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5707 ExprResult ControllingExpr =
5708 getDerived().TransformExpr(E->getControllingExpr());
5709 if (ControllingExpr.isInvalid())
5710 return ExprError();
5711
5712 llvm::SmallVector<Expr *, 4> AssocExprs;
5713 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5714 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5715 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5716 if (TS) {
5717 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5718 if (!AssocType)
5719 return ExprError();
5720 AssocTypes.push_back(AssocType);
5721 } else {
5722 AssocTypes.push_back(0);
5723 }
5724
5725 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5726 if (AssocExpr.isInvalid())
5727 return ExprError();
5728 AssocExprs.push_back(AssocExpr.release());
5729 }
5730
5731 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5732 E->getDefaultLoc(),
5733 E->getRParenLoc(),
5734 ControllingExpr.release(),
5735 AssocTypes.data(),
5736 AssocExprs.data(),
5737 E->getNumAssocs());
5738}
5739
5740template<typename Derived>
5741ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005742TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005743 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005744 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005745 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005746
Douglas Gregora16548e2009-08-11 05:31:07 +00005747 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005748 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005749
John McCallb268a282010-08-23 23:25:46 +00005750 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005751 E->getRParen());
5752}
5753
Mike Stump11289f42009-09-09 15:08:12 +00005754template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005755ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005756TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005757 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005758 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005759 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005760
Douglas Gregora16548e2009-08-11 05:31:07 +00005761 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005762 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005763
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5765 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005766 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005767}
Mike Stump11289f42009-09-09 15:08:12 +00005768
Douglas Gregora16548e2009-08-11 05:31:07 +00005769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005770ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005771TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5772 // Transform the type.
5773 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5774 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005775 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005776
Douglas Gregor882211c2010-04-28 22:16:22 +00005777 // Transform all of the components into components similar to what the
5778 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005779 // FIXME: It would be slightly more efficient in the non-dependent case to
5780 // just map FieldDecls, rather than requiring the rebuilder to look for
5781 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005782 // template code that we don't care.
5783 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005784 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005785 typedef OffsetOfExpr::OffsetOfNode Node;
5786 llvm::SmallVector<Component, 4> Components;
5787 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5788 const Node &ON = E->getComponent(I);
5789 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005790 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005791 Comp.LocStart = ON.getSourceRange().getBegin();
5792 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005793 switch (ON.getKind()) {
5794 case Node::Array: {
5795 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005796 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005797 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005798 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005799
Douglas Gregor882211c2010-04-28 22:16:22 +00005800 ExprChanged = ExprChanged || Index.get() != FromIndex;
5801 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005802 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005803 break;
5804 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005805
Douglas Gregor882211c2010-04-28 22:16:22 +00005806 case Node::Field:
5807 case Node::Identifier:
5808 Comp.isBrackets = false;
5809 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005810 if (!Comp.U.IdentInfo)
5811 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005812
Douglas Gregor882211c2010-04-28 22:16:22 +00005813 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005814
Douglas Gregord1702062010-04-29 00:18:15 +00005815 case Node::Base:
5816 // Will be recomputed during the rebuild.
5817 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005818 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005819
Douglas Gregor882211c2010-04-28 22:16:22 +00005820 Components.push_back(Comp);
5821 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005822
Douglas Gregor882211c2010-04-28 22:16:22 +00005823 // If nothing changed, retain the existing expression.
5824 if (!getDerived().AlwaysRebuild() &&
5825 Type == E->getTypeSourceInfo() &&
5826 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005827 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005828
Douglas Gregor882211c2010-04-28 22:16:22 +00005829 // Build a new offsetof expression.
5830 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5831 Components.data(), Components.size(),
5832 E->getRParenLoc());
5833}
5834
5835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005836ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005837TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5838 assert(getDerived().AlreadyTransformed(E->getType()) &&
5839 "opaque value expression requires transformation");
5840 return SemaRef.Owned(E);
5841}
5842
5843template<typename Derived>
5844ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005845TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5846 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005847 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005848 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005849
John McCallbcd03502009-12-07 02:54:59 +00005850 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005851 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005852 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005853
John McCall4c98fd82009-11-04 07:28:41 +00005854 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005855 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005856
Peter Collingbournee190dee2011-03-11 19:24:49 +00005857 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5858 E->getKind(),
5859 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005860 }
Mike Stump11289f42009-09-09 15:08:12 +00005861
John McCalldadc5752010-08-24 06:29:42 +00005862 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005863 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005864 // C++0x [expr.sizeof]p1:
5865 // The operand is either an expression, which is an unevaluated operand
5866 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005867 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005868
Douglas Gregora16548e2009-08-11 05:31:07 +00005869 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5870 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005871 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005872
Douglas Gregora16548e2009-08-11 05:31:07 +00005873 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005874 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005875 }
Mike Stump11289f42009-09-09 15:08:12 +00005876
Peter Collingbournee190dee2011-03-11 19:24:49 +00005877 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5878 E->getOperatorLoc(),
5879 E->getKind(),
5880 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005881}
Mike Stump11289f42009-09-09 15:08:12 +00005882
Douglas Gregora16548e2009-08-11 05:31:07 +00005883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005884ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005885TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005886 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005887 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005889
John McCalldadc5752010-08-24 06:29:42 +00005890 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005891 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005892 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005893
5894
Douglas Gregora16548e2009-08-11 05:31:07 +00005895 if (!getDerived().AlwaysRebuild() &&
5896 LHS.get() == E->getLHS() &&
5897 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005898 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005899
John McCallb268a282010-08-23 23:25:46 +00005900 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005901 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005902 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005903 E->getRBracketLoc());
5904}
Mike Stump11289f42009-09-09 15:08:12 +00005905
5906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005907ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005908TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005909 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005910 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005911 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005912 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005913
5914 // Transform arguments.
5915 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005916 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005917 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5918 &ArgChanged))
5919 return ExprError();
5920
Douglas Gregora16548e2009-08-11 05:31:07 +00005921 if (!getDerived().AlwaysRebuild() &&
5922 Callee.get() == E->getCallee() &&
5923 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005924 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005925
Douglas Gregora16548e2009-08-11 05:31:07 +00005926 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005927 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005928 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005929 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005930 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005931 E->getRParenLoc());
5932}
Mike Stump11289f42009-09-09 15:08:12 +00005933
5934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005935ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005936TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005937 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005938 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005939 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005940
Douglas Gregorea972d32011-02-28 21:54:11 +00005941 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005942 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005943 QualifierLoc
5944 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5945
5946 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005947 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005948 }
Mike Stump11289f42009-09-09 15:08:12 +00005949
Eli Friedman2cfcef62009-12-04 06:40:45 +00005950 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005951 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5952 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005953 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005954 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005955
John McCall16df1e52010-03-30 21:47:33 +00005956 NamedDecl *FoundDecl = E->getFoundDecl();
5957 if (FoundDecl == E->getMemberDecl()) {
5958 FoundDecl = Member;
5959 } else {
5960 FoundDecl = cast_or_null<NamedDecl>(
5961 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5962 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005963 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005964 }
5965
Douglas Gregora16548e2009-08-11 05:31:07 +00005966 if (!getDerived().AlwaysRebuild() &&
5967 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005968 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005969 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005970 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005971 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005972
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005973 // Mark it referenced in the new context regardless.
5974 // FIXME: this is a bit instantiation-specific.
5975 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005976 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005977 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005978
John McCall6b51f282009-11-23 01:53:49 +00005979 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005980 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005981 TransArgs.setLAngleLoc(E->getLAngleLoc());
5982 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005983 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5984 E->getNumTemplateArgs(),
5985 TransArgs))
5986 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005987 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005988
Douglas Gregora16548e2009-08-11 05:31:07 +00005989 // FIXME: Bogus source location for the operator
5990 SourceLocation FakeOperatorLoc
5991 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5992
John McCall38836f02010-01-15 08:34:02 +00005993 // FIXME: to do this check properly, we will need to preserve the
5994 // first-qualifier-in-scope here, just in case we had a dependent
5995 // base (and therefore couldn't do the check) and a
5996 // nested-name-qualifier (and therefore could do the lookup).
5997 NamedDecl *FirstQualifierInScope = 0;
5998
John McCallb268a282010-08-23 23:25:46 +00005999 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006000 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006001 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006002 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006003 Member,
John McCall16df1e52010-03-30 21:47:33 +00006004 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006005 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006006 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006007 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006008}
Mike Stump11289f42009-09-09 15:08:12 +00006009
Douglas Gregora16548e2009-08-11 05:31:07 +00006010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006011ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006012TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006013 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006015 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006016
John McCalldadc5752010-08-24 06:29:42 +00006017 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006018 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006019 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006020
Douglas Gregora16548e2009-08-11 05:31:07 +00006021 if (!getDerived().AlwaysRebuild() &&
6022 LHS.get() == E->getLHS() &&
6023 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006024 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006025
Douglas Gregora16548e2009-08-11 05:31:07 +00006026 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006027 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006028}
6029
Mike Stump11289f42009-09-09 15:08:12 +00006030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006031ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006032TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006033 CompoundAssignOperator *E) {
6034 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006035}
Mike Stump11289f42009-09-09 15:08:12 +00006036
Douglas Gregora16548e2009-08-11 05:31:07 +00006037template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006038ExprResult TreeTransform<Derived>::
6039TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6040 // Just rebuild the common and RHS expressions and see whether we
6041 // get any changes.
6042
6043 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6044 if (commonExpr.isInvalid())
6045 return ExprError();
6046
6047 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6048 if (rhs.isInvalid())
6049 return ExprError();
6050
6051 if (!getDerived().AlwaysRebuild() &&
6052 commonExpr.get() == e->getCommon() &&
6053 rhs.get() == e->getFalseExpr())
6054 return SemaRef.Owned(e);
6055
6056 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6057 e->getQuestionLoc(),
6058 0,
6059 e->getColonLoc(),
6060 rhs.get());
6061}
6062
6063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006064ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006065TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006066 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006067 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006068 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006069
John McCalldadc5752010-08-24 06:29:42 +00006070 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006071 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006073
John McCalldadc5752010-08-24 06:29:42 +00006074 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006075 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006076 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006077
Douglas Gregora16548e2009-08-11 05:31:07 +00006078 if (!getDerived().AlwaysRebuild() &&
6079 Cond.get() == E->getCond() &&
6080 LHS.get() == E->getLHS() &&
6081 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006082 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006083
John McCallb268a282010-08-23 23:25:46 +00006084 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006085 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006086 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006087 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006088 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006089}
Mike Stump11289f42009-09-09 15:08:12 +00006090
6091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006093TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006094 // Implicit casts are eliminated during transformation, since they
6095 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006096 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006097}
Mike Stump11289f42009-09-09 15:08:12 +00006098
Douglas Gregora16548e2009-08-11 05:31:07 +00006099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006101TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006102 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6103 if (!Type)
6104 return ExprError();
6105
John McCalldadc5752010-08-24 06:29:42 +00006106 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006107 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006108 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006109 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006110
Douglas Gregora16548e2009-08-11 05:31:07 +00006111 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006112 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006113 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006114 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006115
John McCall97513962010-01-15 18:39:57 +00006116 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006117 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006118 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006119 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006120}
Mike Stump11289f42009-09-09 15:08:12 +00006121
Douglas Gregora16548e2009-08-11 05:31:07 +00006122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006123ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006124TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006125 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6126 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6127 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006128 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006129
John McCalldadc5752010-08-24 06:29:42 +00006130 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006131 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006133
Douglas Gregora16548e2009-08-11 05:31:07 +00006134 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006135 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006136 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006137 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006138
John McCall5d7aa7f2010-01-19 22:33:45 +00006139 // Note: the expression type doesn't necessarily match the
6140 // type-as-written, but that's okay, because it should always be
6141 // derivable from the initializer.
6142
John McCalle15bbff2010-01-18 19:35:47 +00006143 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006144 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006145 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006146}
Mike Stump11289f42009-09-09 15:08:12 +00006147
Douglas Gregora16548e2009-08-11 05:31:07 +00006148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006150TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006151 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006152 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006153 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006154
Douglas Gregora16548e2009-08-11 05:31:07 +00006155 if (!getDerived().AlwaysRebuild() &&
6156 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006157 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006158
Douglas Gregora16548e2009-08-11 05:31:07 +00006159 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006160 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006161 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006162 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006163 E->getAccessorLoc(),
6164 E->getAccessor());
6165}
Mike Stump11289f42009-09-09 15:08:12 +00006166
Douglas Gregora16548e2009-08-11 05:31:07 +00006167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006168ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006169TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006170 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006171
John McCall37ad5512010-08-23 06:44:23 +00006172 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006173 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6174 Inits, &InitChanged))
6175 return ExprError();
6176
Douglas Gregora16548e2009-08-11 05:31:07 +00006177 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006178 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006179
Douglas Gregora16548e2009-08-11 05:31:07 +00006180 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006181 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006182}
Mike Stump11289f42009-09-09 15:08:12 +00006183
Douglas Gregora16548e2009-08-11 05:31:07 +00006184template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006185ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006186TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006187 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006188
Douglas Gregorebe10102009-08-20 07:17:43 +00006189 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006190 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006191 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006192 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006193
Douglas Gregorebe10102009-08-20 07:17:43 +00006194 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006195 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006196 bool ExprChanged = false;
6197 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6198 DEnd = E->designators_end();
6199 D != DEnd; ++D) {
6200 if (D->isFieldDesignator()) {
6201 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6202 D->getDotLoc(),
6203 D->getFieldLoc()));
6204 continue;
6205 }
Mike Stump11289f42009-09-09 15:08:12 +00006206
Douglas Gregora16548e2009-08-11 05:31:07 +00006207 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006208 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006209 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006210 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006211
6212 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006213 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006214
Douglas Gregora16548e2009-08-11 05:31:07 +00006215 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6216 ArrayExprs.push_back(Index.release());
6217 continue;
6218 }
Mike Stump11289f42009-09-09 15:08:12 +00006219
Douglas Gregora16548e2009-08-11 05:31:07 +00006220 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006221 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006222 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6223 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006224 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006225
John McCalldadc5752010-08-24 06:29:42 +00006226 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006227 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006228 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006229
6230 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006231 End.get(),
6232 D->getLBracketLoc(),
6233 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006234
Douglas Gregora16548e2009-08-11 05:31:07 +00006235 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6236 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006237
Douglas Gregora16548e2009-08-11 05:31:07 +00006238 ArrayExprs.push_back(Start.release());
6239 ArrayExprs.push_back(End.release());
6240 }
Mike Stump11289f42009-09-09 15:08:12 +00006241
Douglas Gregora16548e2009-08-11 05:31:07 +00006242 if (!getDerived().AlwaysRebuild() &&
6243 Init.get() == E->getInit() &&
6244 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006245 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006246
Douglas Gregora16548e2009-08-11 05:31:07 +00006247 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6248 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006249 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006250}
Mike Stump11289f42009-09-09 15:08:12 +00006251
Douglas Gregora16548e2009-08-11 05:31:07 +00006252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006253ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006254TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006255 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006256 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006257
Douglas Gregor3da3c062009-10-28 00:29:27 +00006258 // FIXME: Will we ever have proper type location here? Will we actually
6259 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006260 QualType T = getDerived().TransformType(E->getType());
6261 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006262 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006263
Douglas Gregora16548e2009-08-11 05:31:07 +00006264 if (!getDerived().AlwaysRebuild() &&
6265 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006266 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006267
Douglas Gregora16548e2009-08-11 05:31:07 +00006268 return getDerived().RebuildImplicitValueInitExpr(T);
6269}
Mike Stump11289f42009-09-09 15:08:12 +00006270
Douglas Gregora16548e2009-08-11 05:31:07 +00006271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006273TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006274 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6275 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006276 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006277
John McCalldadc5752010-08-24 06:29:42 +00006278 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006279 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006280 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006281
Douglas Gregora16548e2009-08-11 05:31:07 +00006282 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006283 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006284 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006285 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006286
John McCallb268a282010-08-23 23:25:46 +00006287 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006288 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006289}
6290
6291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006292ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006293TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006294 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006295 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006296 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6297 &ArgumentChanged))
6298 return ExprError();
6299
Douglas Gregora16548e2009-08-11 05:31:07 +00006300 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6301 move_arg(Inits),
6302 E->getRParenLoc());
6303}
Mike Stump11289f42009-09-09 15:08:12 +00006304
Douglas Gregora16548e2009-08-11 05:31:07 +00006305/// \brief Transform an address-of-label expression.
6306///
6307/// By default, the transformation of an address-of-label expression always
6308/// rebuilds the expression, so that the label identifier can be resolved to
6309/// the corresponding label statement by semantic analysis.
6310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006311ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006312TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006313 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6314 E->getLabel());
6315 if (!LD)
6316 return ExprError();
6317
Douglas Gregora16548e2009-08-11 05:31:07 +00006318 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006319 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006320}
Mike Stump11289f42009-09-09 15:08:12 +00006321
6322template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006323ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006324TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006325 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006326 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6327 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006328 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006329
Douglas Gregora16548e2009-08-11 05:31:07 +00006330 if (!getDerived().AlwaysRebuild() &&
6331 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006332 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006333
6334 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006335 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006336 E->getRParenLoc());
6337}
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>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006342 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006343 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006345
John McCalldadc5752010-08-24 06:29:42 +00006346 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006347 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006348 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006349
John McCalldadc5752010-08-24 06:29:42 +00006350 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006351 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006353
Douglas Gregora16548e2009-08-11 05:31:07 +00006354 if (!getDerived().AlwaysRebuild() &&
6355 Cond.get() == E->getCond() &&
6356 LHS.get() == E->getLHS() &&
6357 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006358 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006359
Douglas Gregora16548e2009-08-11 05:31:07 +00006360 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006361 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006362 E->getRParenLoc());
6363}
Mike Stump11289f42009-09-09 15:08:12 +00006364
Douglas Gregora16548e2009-08-11 05:31:07 +00006365template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006366ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006367TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006368 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006369}
6370
6371template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006372ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006373TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006374 switch (E->getOperator()) {
6375 case OO_New:
6376 case OO_Delete:
6377 case OO_Array_New:
6378 case OO_Array_Delete:
6379 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006380 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006381
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006382 case OO_Call: {
6383 // This is a call to an object's operator().
6384 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6385
6386 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006387 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006388 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006389 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006390
6391 // FIXME: Poor location information
6392 SourceLocation FakeLParenLoc
6393 = SemaRef.PP.getLocForEndOfToken(
6394 static_cast<Expr *>(Object.get())->getLocEnd());
6395
6396 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006397 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006398 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6399 Args))
6400 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006401
John McCallb268a282010-08-23 23:25:46 +00006402 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006403 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006404 E->getLocEnd());
6405 }
6406
6407#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6408 case OO_##Name:
6409#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6410#include "clang/Basic/OperatorKinds.def"
6411 case OO_Subscript:
6412 // Handled below.
6413 break;
6414
6415 case OO_Conditional:
6416 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006417 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006418
6419 case OO_None:
6420 case NUM_OVERLOADED_OPERATORS:
6421 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006422 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006423 }
6424
John McCalldadc5752010-08-24 06:29:42 +00006425 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006426 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006427 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006428
John McCalldadc5752010-08-24 06:29:42 +00006429 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006430 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006431 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006432
John McCalldadc5752010-08-24 06:29:42 +00006433 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006434 if (E->getNumArgs() == 2) {
6435 Second = getDerived().TransformExpr(E->getArg(1));
6436 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006437 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 }
Mike Stump11289f42009-09-09 15:08:12 +00006439
Douglas Gregora16548e2009-08-11 05:31:07 +00006440 if (!getDerived().AlwaysRebuild() &&
6441 Callee.get() == E->getCallee() &&
6442 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006443 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006444 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006445
Douglas Gregora16548e2009-08-11 05:31:07 +00006446 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6447 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006448 Callee.get(),
6449 First.get(),
6450 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006451}
Mike Stump11289f42009-09-09 15:08:12 +00006452
Douglas Gregora16548e2009-08-11 05:31:07 +00006453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006454ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006455TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6456 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006457}
Mike Stump11289f42009-09-09 15:08:12 +00006458
Douglas Gregora16548e2009-08-11 05:31:07 +00006459template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006460ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006461TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6462 // Transform the callee.
6463 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6464 if (Callee.isInvalid())
6465 return ExprError();
6466
6467 // Transform exec config.
6468 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6469 if (EC.isInvalid())
6470 return ExprError();
6471
6472 // Transform arguments.
6473 bool ArgChanged = false;
6474 ASTOwningVector<Expr*> Args(SemaRef);
6475 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6476 &ArgChanged))
6477 return ExprError();
6478
6479 if (!getDerived().AlwaysRebuild() &&
6480 Callee.get() == E->getCallee() &&
6481 !ArgChanged)
6482 return SemaRef.Owned(E);
6483
6484 // FIXME: Wrong source location information for the '('.
6485 SourceLocation FakeLParenLoc
6486 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6487 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6488 move_arg(Args),
6489 E->getRParenLoc(), EC.get());
6490}
6491
6492template<typename Derived>
6493ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006494TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006495 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6496 if (!Type)
6497 return ExprError();
6498
John McCalldadc5752010-08-24 06:29:42 +00006499 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006500 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006501 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006502 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006503
Douglas Gregora16548e2009-08-11 05:31:07 +00006504 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006505 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006506 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006507 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006508
Douglas Gregora16548e2009-08-11 05:31:07 +00006509 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006510 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006511 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6512 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6513 SourceLocation FakeRParenLoc
6514 = SemaRef.PP.getLocForEndOfToken(
6515 E->getSubExpr()->getSourceRange().getEnd());
6516 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006517 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006518 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006519 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006520 FakeRAngleLoc,
6521 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006522 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006523 FakeRParenLoc);
6524}
Mike Stump11289f42009-09-09 15:08:12 +00006525
Douglas Gregora16548e2009-08-11 05:31:07 +00006526template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006527ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006528TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6529 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006530}
Mike Stump11289f42009-09-09 15:08:12 +00006531
6532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006533ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006534TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6535 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006536}
6537
Douglas Gregora16548e2009-08-11 05:31:07 +00006538template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006539ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006540TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006541 CXXReinterpretCastExpr *E) {
6542 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006543}
Mike Stump11289f42009-09-09 15:08:12 +00006544
Douglas Gregora16548e2009-08-11 05:31:07 +00006545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006546ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006547TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6548 return getDerived().TransformCXXNamedCastExpr(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
Douglas Gregora16548e2009-08-11 05:31:07 +00006553TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006554 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006555 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6556 if (!Type)
6557 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006558
John McCalldadc5752010-08-24 06:29:42 +00006559 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006560 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006561 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006562 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006563
Douglas Gregora16548e2009-08-11 05:31:07 +00006564 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006565 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006566 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006567 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006568
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006569 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006570 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006571 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006572 E->getRParenLoc());
6573}
Mike Stump11289f42009-09-09 15:08:12 +00006574
Douglas Gregora16548e2009-08-11 05:31:07 +00006575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006576ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006577TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006578 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006579 TypeSourceInfo *TInfo
6580 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6581 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006582 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006583
Douglas Gregora16548e2009-08-11 05:31:07 +00006584 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006585 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006586 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006587
Douglas Gregor9da64192010-04-26 22:37:10 +00006588 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6589 E->getLocStart(),
6590 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006591 E->getLocEnd());
6592 }
Mike Stump11289f42009-09-09 15:08:12 +00006593
Douglas Gregora16548e2009-08-11 05:31:07 +00006594 // We don't know whether the expression is potentially evaluated until
6595 // after we perform semantic analysis, so the expression is potentially
6596 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006597 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006598 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006599
John McCalldadc5752010-08-24 06:29:42 +00006600 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006601 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006602 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006603
Douglas Gregora16548e2009-08-11 05:31:07 +00006604 if (!getDerived().AlwaysRebuild() &&
6605 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006606 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006607
Douglas Gregor9da64192010-04-26 22:37:10 +00006608 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6609 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006610 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006611 E->getLocEnd());
6612}
6613
6614template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006615ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006616TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6617 if (E->isTypeOperand()) {
6618 TypeSourceInfo *TInfo
6619 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6620 if (!TInfo)
6621 return ExprError();
6622
6623 if (!getDerived().AlwaysRebuild() &&
6624 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006625 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006626
Douglas Gregor69735112011-03-06 17:40:41 +00006627 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006628 E->getLocStart(),
6629 TInfo,
6630 E->getLocEnd());
6631 }
6632
6633 // We don't know whether the expression is potentially evaluated until
6634 // after we perform semantic analysis, so the expression is potentially
6635 // potentially evaluated.
6636 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6637
6638 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6639 if (SubExpr.isInvalid())
6640 return ExprError();
6641
6642 if (!getDerived().AlwaysRebuild() &&
6643 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006644 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006645
6646 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6647 E->getLocStart(),
6648 SubExpr.get(),
6649 E->getLocEnd());
6650}
6651
6652template<typename Derived>
6653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006654TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006655 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006656}
Mike Stump11289f42009-09-09 15:08:12 +00006657
Douglas Gregora16548e2009-08-11 05:31:07 +00006658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006659ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006660TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006661 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006662 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006663}
Mike Stump11289f42009-09-09 15:08:12 +00006664
Douglas Gregora16548e2009-08-11 05:31:07 +00006665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006666ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006667TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006668 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6669 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6670 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006671
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006672 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006673 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006674
Douglas Gregorb15af892010-01-07 23:12:05 +00006675 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006676}
Mike Stump11289f42009-09-09 15:08:12 +00006677
Douglas Gregora16548e2009-08-11 05:31:07 +00006678template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006679ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006680TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006681 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006683 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006684
Douglas Gregora16548e2009-08-11 05:31:07 +00006685 if (!getDerived().AlwaysRebuild() &&
6686 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006687 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006688
John McCallb268a282010-08-23 23:25:46 +00006689 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006690}
Mike Stump11289f42009-09-09 15:08:12 +00006691
Douglas Gregora16548e2009-08-11 05:31:07 +00006692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006694TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006695 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006696 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6697 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006698 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006699 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006700
Chandler Carruth794da4c2010-02-08 06:42:49 +00006701 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006702 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006703 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006704
Douglas Gregor033f6752009-12-23 23:03:06 +00006705 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006706}
Mike Stump11289f42009-09-09 15:08:12 +00006707
Douglas Gregora16548e2009-08-11 05:31:07 +00006708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006709ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006710TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6711 CXXScalarValueInitExpr *E) {
6712 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6713 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006714 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006715
Douglas Gregora16548e2009-08-11 05:31:07 +00006716 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006717 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006718 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006719
Douglas Gregor2b88c112010-09-08 00:15:04 +00006720 return getDerived().RebuildCXXScalarValueInitExpr(T,
6721 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006722 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006723}
Mike Stump11289f42009-09-09 15:08:12 +00006724
Douglas Gregora16548e2009-08-11 05:31:07 +00006725template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006726ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006727TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006728 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006729 TypeSourceInfo *AllocTypeInfo
6730 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6731 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006733
Douglas Gregora16548e2009-08-11 05:31:07 +00006734 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006735 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006736 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006737 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006738
Douglas Gregora16548e2009-08-11 05:31:07 +00006739 // Transform the placement arguments (if any).
6740 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006741 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006742 if (getDerived().TransformExprs(E->getPlacementArgs(),
6743 E->getNumPlacementArgs(), true,
6744 PlacementArgs, &ArgumentChanged))
6745 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006746
Douglas Gregorebe10102009-08-20 07:17:43 +00006747 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006748 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006749 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6750 ConstructorArgs, &ArgumentChanged))
6751 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006752
Douglas Gregord2d9da02010-02-26 00:38:10 +00006753 // Transform constructor, new operator, and delete operator.
6754 CXXConstructorDecl *Constructor = 0;
6755 if (E->getConstructor()) {
6756 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006757 getDerived().TransformDecl(E->getLocStart(),
6758 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006759 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006760 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006761 }
6762
6763 FunctionDecl *OperatorNew = 0;
6764 if (E->getOperatorNew()) {
6765 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006766 getDerived().TransformDecl(E->getLocStart(),
6767 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006768 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006769 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006770 }
6771
6772 FunctionDecl *OperatorDelete = 0;
6773 if (E->getOperatorDelete()) {
6774 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006775 getDerived().TransformDecl(E->getLocStart(),
6776 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006777 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006778 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006779 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006780
Douglas Gregora16548e2009-08-11 05:31:07 +00006781 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006782 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006783 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006784 Constructor == E->getConstructor() &&
6785 OperatorNew == E->getOperatorNew() &&
6786 OperatorDelete == E->getOperatorDelete() &&
6787 !ArgumentChanged) {
6788 // Mark any declarations we need as referenced.
6789 // FIXME: instantiation-specific.
6790 if (Constructor)
6791 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6792 if (OperatorNew)
6793 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6794 if (OperatorDelete)
6795 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006796 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006797 }
Mike Stump11289f42009-09-09 15:08:12 +00006798
Douglas Gregor0744ef62010-09-07 21:49:58 +00006799 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006800 if (!ArraySize.get()) {
6801 // If no array size was specified, but the new expression was
6802 // instantiated with an array type (e.g., "new T" where T is
6803 // instantiated with "int[4]"), extract the outer bound from the
6804 // array type as our array size. We do this with constant and
6805 // dependently-sized array types.
6806 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6807 if (!ArrayT) {
6808 // Do nothing
6809 } else if (const ConstantArrayType *ConsArrayT
6810 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006811 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006812 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6813 ConsArrayT->getSize(),
6814 SemaRef.Context.getSizeType(),
6815 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006816 AllocType = ConsArrayT->getElementType();
6817 } else if (const DependentSizedArrayType *DepArrayT
6818 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6819 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006820 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006821 AllocType = DepArrayT->getElementType();
6822 }
6823 }
6824 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006825
Douglas Gregora16548e2009-08-11 05:31:07 +00006826 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6827 E->isGlobalNew(),
6828 /*FIXME:*/E->getLocStart(),
6829 move_arg(PlacementArgs),
6830 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006831 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006832 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006833 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006834 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006835 /*FIXME:*/E->getLocStart(),
6836 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006837 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006838}
Mike Stump11289f42009-09-09 15:08:12 +00006839
Douglas Gregora16548e2009-08-11 05:31:07 +00006840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006841ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006842TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006843 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006844 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006846
Douglas Gregord2d9da02010-02-26 00:38:10 +00006847 // Transform the delete operator, if known.
6848 FunctionDecl *OperatorDelete = 0;
6849 if (E->getOperatorDelete()) {
6850 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006851 getDerived().TransformDecl(E->getLocStart(),
6852 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006853 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006854 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006855 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006856
Douglas Gregora16548e2009-08-11 05:31:07 +00006857 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006858 Operand.get() == E->getArgument() &&
6859 OperatorDelete == E->getOperatorDelete()) {
6860 // Mark any declarations we need as referenced.
6861 // FIXME: instantiation-specific.
6862 if (OperatorDelete)
6863 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006864
6865 if (!E->getArgument()->isTypeDependent()) {
6866 QualType Destroyed = SemaRef.Context.getBaseElementType(
6867 E->getDestroyedType());
6868 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6869 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6870 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6871 SemaRef.LookupDestructor(Record));
6872 }
6873 }
6874
John McCallc3007a22010-10-26 07:05:15 +00006875 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006876 }
Mike Stump11289f42009-09-09 15:08:12 +00006877
Douglas Gregora16548e2009-08-11 05:31:07 +00006878 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6879 E->isGlobalDelete(),
6880 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006881 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006882}
Mike Stump11289f42009-09-09 15:08:12 +00006883
Douglas Gregora16548e2009-08-11 05:31:07 +00006884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006885ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006886TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006887 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006888 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006889 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006890 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006891
John McCallba7bf592010-08-24 05:47:05 +00006892 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006893 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006894 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006895 E->getOperatorLoc(),
6896 E->isArrow()? tok::arrow : tok::period,
6897 ObjectTypePtr,
6898 MayBePseudoDestructor);
6899 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006900 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006901
John McCallba7bf592010-08-24 05:47:05 +00006902 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006903 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6904 if (QualifierLoc) {
6905 QualifierLoc
6906 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6907 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006908 return ExprError();
6909 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006910 CXXScopeSpec SS;
6911 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006912
Douglas Gregor678f90d2010-02-25 01:56:36 +00006913 PseudoDestructorTypeStorage Destroyed;
6914 if (E->getDestroyedTypeInfo()) {
6915 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006916 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006917 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006918 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006919 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006920 Destroyed = DestroyedTypeInfo;
6921 } else if (ObjectType->isDependentType()) {
6922 // We aren't likely to be able to resolve the identifier down to a type
6923 // now anyway, so just retain the identifier.
6924 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6925 E->getDestroyedTypeLoc());
6926 } else {
6927 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006928 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006929 *E->getDestroyedTypeIdentifier(),
6930 E->getDestroyedTypeLoc(),
6931 /*Scope=*/0,
6932 SS, ObjectTypePtr,
6933 false);
6934 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006935 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006936
Douglas Gregor678f90d2010-02-25 01:56:36 +00006937 Destroyed
6938 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6939 E->getDestroyedTypeLoc());
6940 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006941
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006942 TypeSourceInfo *ScopeTypeInfo = 0;
6943 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006944 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006945 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006946 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006947 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006948
John McCallb268a282010-08-23 23:25:46 +00006949 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006950 E->getOperatorLoc(),
6951 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006952 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006953 ScopeTypeInfo,
6954 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006955 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006956 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006957}
Mike Stump11289f42009-09-09 15:08:12 +00006958
Douglas Gregorad8a3362009-09-04 17:36:40 +00006959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006960ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006961TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006962 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006963 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6964 Sema::LookupOrdinaryName);
6965
6966 // Transform all the decls.
6967 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6968 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006969 NamedDecl *InstD = static_cast<NamedDecl*>(
6970 getDerived().TransformDecl(Old->getNameLoc(),
6971 *I));
John McCall84d87672009-12-10 09:41:52 +00006972 if (!InstD) {
6973 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6974 // This can happen because of dependent hiding.
6975 if (isa<UsingShadowDecl>(*I))
6976 continue;
6977 else
John McCallfaf5fb42010-08-26 23:41:50 +00006978 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006979 }
John McCalle66edc12009-11-24 19:00:30 +00006980
6981 // Expand using declarations.
6982 if (isa<UsingDecl>(InstD)) {
6983 UsingDecl *UD = cast<UsingDecl>(InstD);
6984 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6985 E = UD->shadow_end(); I != E; ++I)
6986 R.addDecl(*I);
6987 continue;
6988 }
6989
6990 R.addDecl(InstD);
6991 }
6992
6993 // Resolve a kind, but don't do any further analysis. If it's
6994 // ambiguous, the callee needs to deal with it.
6995 R.resolveKind();
6996
6997 // Rebuild the nested-name qualifier, if present.
6998 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006999 if (Old->getQualifierLoc()) {
7000 NestedNameSpecifierLoc QualifierLoc
7001 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7002 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007003 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007004
Douglas Gregor0da1d432011-02-28 20:01:57 +00007005 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007006 }
7007
Douglas Gregor9262f472010-04-27 18:19:34 +00007008 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007009 CXXRecordDecl *NamingClass
7010 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7011 Old->getNameLoc(),
7012 Old->getNamingClass()));
7013 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007014 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007015
Douglas Gregorda7be082010-04-27 16:10:10 +00007016 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007017 }
7018
7019 // If we have no template arguments, it's a normal declaration name.
7020 if (!Old->hasExplicitTemplateArgs())
7021 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7022
7023 // If we have template arguments, rebuild them, then rebuild the
7024 // templateid expression.
7025 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007026 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7027 Old->getNumTemplateArgs(),
7028 TransArgs))
7029 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007030
7031 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7032 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007033}
Mike Stump11289f42009-09-09 15:08:12 +00007034
Douglas Gregora16548e2009-08-11 05:31:07 +00007035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007036ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007037TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007038 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7039 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007040 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007041
Douglas Gregora16548e2009-08-11 05:31:07 +00007042 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007043 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007044 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007045
Mike Stump11289f42009-09-09 15:08:12 +00007046 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007047 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007048 T,
7049 E->getLocEnd());
7050}
Mike Stump11289f42009-09-09 15:08:12 +00007051
Douglas Gregora16548e2009-08-11 05:31:07 +00007052template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007053ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007054TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7055 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7056 if (!LhsT)
7057 return ExprError();
7058
7059 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7060 if (!RhsT)
7061 return ExprError();
7062
7063 if (!getDerived().AlwaysRebuild() &&
7064 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7065 return SemaRef.Owned(E);
7066
7067 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7068 E->getLocStart(),
7069 LhsT, RhsT,
7070 E->getLocEnd());
7071}
7072
7073template<typename Derived>
7074ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007075TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7076 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7077 if (!T)
7078 return ExprError();
7079
7080 if (!getDerived().AlwaysRebuild() &&
7081 T == E->getQueriedTypeSourceInfo())
7082 return SemaRef.Owned(E);
7083
7084 ExprResult SubExpr;
7085 {
7086 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7087 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7088 if (SubExpr.isInvalid())
7089 return ExprError();
7090
7091 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7092 return SemaRef.Owned(E);
7093 }
7094
7095 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7096 E->getLocStart(),
7097 T,
7098 SubExpr.get(),
7099 E->getLocEnd());
7100}
7101
7102template<typename Derived>
7103ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007104TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7105 ExprResult SubExpr;
7106 {
7107 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7108 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7109 if (SubExpr.isInvalid())
7110 return ExprError();
7111
7112 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7113 return SemaRef.Owned(E);
7114 }
7115
7116 return getDerived().RebuildExpressionTrait(
7117 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7118}
7119
7120template<typename Derived>
7121ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007122TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007123 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007124 NestedNameSpecifierLoc QualifierLoc
7125 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7126 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007128
John McCall31f82722010-11-12 08:19:04 +00007129 // TODO: If this is a conversion-function-id, verify that the
7130 // destination type name (if present) resolves the same way after
7131 // instantiation as it did in the local scope.
7132
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007133 DeclarationNameInfo NameInfo
7134 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7135 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007136 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007137
John McCalle66edc12009-11-24 19:00:30 +00007138 if (!E->hasExplicitTemplateArgs()) {
7139 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007140 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007141 // Note: it is sufficient to compare the Name component of NameInfo:
7142 // if name has not changed, DNLoc has not changed either.
7143 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007144 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007145
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007146 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007147 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007148 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007149 }
John McCall6b51f282009-11-23 01:53:49 +00007150
7151 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007152 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7153 E->getNumTemplateArgs(),
7154 TransArgs))
7155 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007156
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007157 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007158 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007159 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007160}
7161
7162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007163ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007164TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007165 // CXXConstructExprs are always implicit, so when we have a
7166 // 1-argument construction we just transform that argument.
7167 if (E->getNumArgs() == 1 ||
7168 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7169 return getDerived().TransformExpr(E->getArg(0));
7170
Douglas Gregora16548e2009-08-11 05:31:07 +00007171 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7172
7173 QualType T = getDerived().TransformType(E->getType());
7174 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007175 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007176
7177 CXXConstructorDecl *Constructor
7178 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007179 getDerived().TransformDecl(E->getLocStart(),
7180 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007181 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007182 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007183
Douglas Gregora16548e2009-08-11 05:31:07 +00007184 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007185 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007186 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7187 &ArgumentChanged))
7188 return ExprError();
7189
Douglas Gregora16548e2009-08-11 05:31:07 +00007190 if (!getDerived().AlwaysRebuild() &&
7191 T == E->getType() &&
7192 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007193 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007194 // Mark the constructor as referenced.
7195 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007196 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007197 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007198 }
Mike Stump11289f42009-09-09 15:08:12 +00007199
Douglas Gregordb121ba2009-12-14 16:27:04 +00007200 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7201 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007202 move_arg(Args),
7203 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007204 E->getConstructionKind(),
7205 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007206}
Mike Stump11289f42009-09-09 15:08:12 +00007207
Douglas Gregora16548e2009-08-11 05:31:07 +00007208/// \brief Transform a C++ temporary-binding expression.
7209///
Douglas Gregor363b1512009-12-24 18:51:59 +00007210/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7211/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007213ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007214TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007215 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007216}
Mike Stump11289f42009-09-09 15:08:12 +00007217
John McCall5d413782010-12-06 08:20:24 +00007218/// \brief Transform a C++ expression that contains cleanups that should
7219/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007220///
John McCall5d413782010-12-06 08:20:24 +00007221/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007222/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007223template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007224ExprResult
John McCall5d413782010-12-06 08:20:24 +00007225TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007226 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007227}
Mike Stump11289f42009-09-09 15:08:12 +00007228
Douglas Gregora16548e2009-08-11 05:31:07 +00007229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007230ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007231TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007232 CXXTemporaryObjectExpr *E) {
7233 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7234 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007236
Douglas Gregora16548e2009-08-11 05:31:07 +00007237 CXXConstructorDecl *Constructor
7238 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007239 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007240 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007241 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007242 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007243
Douglas Gregora16548e2009-08-11 05:31:07 +00007244 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007245 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007246 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007247 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7248 &ArgumentChanged))
7249 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007250
Douglas Gregora16548e2009-08-11 05:31:07 +00007251 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007252 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007253 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007254 !ArgumentChanged) {
7255 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007256 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007257 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007258 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007259
7260 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7261 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007262 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007263 E->getLocEnd());
7264}
Mike Stump11289f42009-09-09 15:08:12 +00007265
Douglas Gregora16548e2009-08-11 05:31:07 +00007266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007267ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007268TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007269 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007270 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7271 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007273
Douglas Gregora16548e2009-08-11 05:31:07 +00007274 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007275 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007276 Args.reserve(E->arg_size());
7277 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7278 &ArgumentChanged))
7279 return ExprError();
7280
Douglas Gregora16548e2009-08-11 05:31:07 +00007281 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007282 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007283 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007284 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007285
Douglas Gregora16548e2009-08-11 05:31:07 +00007286 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007287 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007288 E->getLParenLoc(),
7289 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007290 E->getRParenLoc());
7291}
Mike Stump11289f42009-09-09 15:08:12 +00007292
Douglas Gregora16548e2009-08-11 05:31:07 +00007293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007294ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007295TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007296 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007297 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007298 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007299 Expr *OldBase;
7300 QualType BaseType;
7301 QualType ObjectType;
7302 if (!E->isImplicitAccess()) {
7303 OldBase = E->getBase();
7304 Base = getDerived().TransformExpr(OldBase);
7305 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007306 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007307
John McCall2d74de92009-12-01 22:10:20 +00007308 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007309 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007310 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007311 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007312 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007313 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007314 ObjectTy,
7315 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007316 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007317 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007318
John McCallba7bf592010-08-24 05:47:05 +00007319 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007320 BaseType = ((Expr*) Base.get())->getType();
7321 } else {
7322 OldBase = 0;
7323 BaseType = getDerived().TransformType(E->getBaseType());
7324 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7325 }
Mike Stump11289f42009-09-09 15:08:12 +00007326
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007327 // Transform the first part of the nested-name-specifier that qualifies
7328 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007329 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007330 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007331 E->getFirstQualifierFoundInScope(),
7332 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007333
Douglas Gregore16af532011-02-28 18:50:33 +00007334 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007335 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007336 QualifierLoc
7337 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7338 ObjectType,
7339 FirstQualifierInScope);
7340 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007341 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007342 }
Mike Stump11289f42009-09-09 15:08:12 +00007343
John McCall31f82722010-11-12 08:19:04 +00007344 // TODO: If this is a conversion-function-id, verify that the
7345 // destination type name (if present) resolves the same way after
7346 // instantiation as it did in the local scope.
7347
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007348 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007349 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007350 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007351 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007352
John McCall2d74de92009-12-01 22:10:20 +00007353 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007354 // This is a reference to a member without an explicitly-specified
7355 // template argument list. Optimize for this common case.
7356 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007357 Base.get() == OldBase &&
7358 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007359 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007360 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007361 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007362 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007363
John McCallb268a282010-08-23 23:25:46 +00007364 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007365 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007366 E->isArrow(),
7367 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007368 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007369 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007370 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007371 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007372 }
7373
John McCall6b51f282009-11-23 01:53:49 +00007374 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007375 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7376 E->getNumTemplateArgs(),
7377 TransArgs))
7378 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007379
John McCallb268a282010-08-23 23:25:46 +00007380 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007381 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007382 E->isArrow(),
7383 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007384 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007385 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007386 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007387 &TransArgs);
7388}
7389
7390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007391ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007392TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007393 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007394 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007395 QualType BaseType;
7396 if (!Old->isImplicitAccess()) {
7397 Base = getDerived().TransformExpr(Old->getBase());
7398 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007399 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007400 BaseType = ((Expr*) Base.get())->getType();
7401 } else {
7402 BaseType = getDerived().TransformType(Old->getBaseType());
7403 }
John McCall10eae182009-11-30 22:42:35 +00007404
Douglas Gregor0da1d432011-02-28 20:01:57 +00007405 NestedNameSpecifierLoc QualifierLoc;
7406 if (Old->getQualifierLoc()) {
7407 QualifierLoc
7408 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7409 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007410 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007411 }
7412
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007413 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007414 Sema::LookupOrdinaryName);
7415
7416 // Transform all the decls.
7417 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7418 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007419 NamedDecl *InstD = static_cast<NamedDecl*>(
7420 getDerived().TransformDecl(Old->getMemberLoc(),
7421 *I));
John McCall84d87672009-12-10 09:41:52 +00007422 if (!InstD) {
7423 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7424 // This can happen because of dependent hiding.
7425 if (isa<UsingShadowDecl>(*I))
7426 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007427 else {
7428 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007429 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007430 }
John McCall84d87672009-12-10 09:41:52 +00007431 }
John McCall10eae182009-11-30 22:42:35 +00007432
7433 // Expand using declarations.
7434 if (isa<UsingDecl>(InstD)) {
7435 UsingDecl *UD = cast<UsingDecl>(InstD);
7436 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7437 E = UD->shadow_end(); I != E; ++I)
7438 R.addDecl(*I);
7439 continue;
7440 }
7441
7442 R.addDecl(InstD);
7443 }
7444
7445 R.resolveKind();
7446
Douglas Gregor9262f472010-04-27 18:19:34 +00007447 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007448 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007449 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007450 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007451 Old->getMemberLoc(),
7452 Old->getNamingClass()));
7453 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007454 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007455
Douglas Gregorda7be082010-04-27 16:10:10 +00007456 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007457 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007458
John McCall10eae182009-11-30 22:42:35 +00007459 TemplateArgumentListInfo TransArgs;
7460 if (Old->hasExplicitTemplateArgs()) {
7461 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7462 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007463 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7464 Old->getNumTemplateArgs(),
7465 TransArgs))
7466 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007467 }
John McCall38836f02010-01-15 08:34:02 +00007468
7469 // FIXME: to do this check properly, we will need to preserve the
7470 // first-qualifier-in-scope here, just in case we had a dependent
7471 // base (and therefore couldn't do the check) and a
7472 // nested-name-qualifier (and therefore could do the lookup).
7473 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007474
John McCallb268a282010-08-23 23:25:46 +00007475 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007476 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007477 Old->getOperatorLoc(),
7478 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007479 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007480 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007481 R,
7482 (Old->hasExplicitTemplateArgs()
7483 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007484}
7485
7486template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007487ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007488TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7489 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7490 if (SubExpr.isInvalid())
7491 return ExprError();
7492
7493 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007494 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007495
7496 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7497}
7498
7499template<typename Derived>
7500ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007501TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007502 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7503 if (Pattern.isInvalid())
7504 return ExprError();
7505
7506 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7507 return SemaRef.Owned(E);
7508
Douglas Gregorb8840002011-01-14 21:20:45 +00007509 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7510 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007511}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007512
7513template<typename Derived>
7514ExprResult
7515TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7516 // If E is not value-dependent, then nothing will change when we transform it.
7517 // Note: This is an instantiation-centric view.
7518 if (!E->isValueDependent())
7519 return SemaRef.Owned(E);
7520
7521 // Note: None of the implementations of TryExpandParameterPacks can ever
7522 // produce a diagnostic when given only a single unexpanded parameter pack,
7523 // so
7524 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7525 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007526 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007527 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007528 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7529 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007530 ShouldExpand, RetainExpansion,
7531 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007532 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007533
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007534 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007535 return SemaRef.Owned(E);
7536
7537 // We now know the length of the parameter pack, so build a new expression
7538 // that stores that length.
7539 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7540 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007541 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007542}
7543
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007544template<typename Derived>
7545ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007546TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7547 SubstNonTypeTemplateParmPackExpr *E) {
7548 // Default behavior is to do nothing with this transformation.
7549 return SemaRef.Owned(E);
7550}
7551
7552template<typename Derived>
7553ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007554TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007555 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007556}
7557
Mike Stump11289f42009-09-09 15:08:12 +00007558template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007559ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007560TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007561 TypeSourceInfo *EncodedTypeInfo
7562 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7563 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007565
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007567 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007568 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007569
7570 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007571 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007572 E->getRParenLoc());
7573}
Mike Stump11289f42009-09-09 15:08:12 +00007574
Douglas Gregora16548e2009-08-11 05:31:07 +00007575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007576ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007577TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007578 // Transform arguments.
7579 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007580 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007581 Args.reserve(E->getNumArgs());
7582 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7583 &ArgChanged))
7584 return ExprError();
7585
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007586 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7587 // Class message: transform the receiver type.
7588 TypeSourceInfo *ReceiverTypeInfo
7589 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7590 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007591 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007592
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007593 // If nothing changed, just retain the existing message send.
7594 if (!getDerived().AlwaysRebuild() &&
7595 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007596 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007597
7598 // Build a new class message send.
7599 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7600 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007601 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007602 E->getMethodDecl(),
7603 E->getLeftLoc(),
7604 move_arg(Args),
7605 E->getRightLoc());
7606 }
7607
7608 // Instance message: transform the receiver
7609 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7610 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007611 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007612 = getDerived().TransformExpr(E->getInstanceReceiver());
7613 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007614 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007615
7616 // If nothing changed, just retain the existing message send.
7617 if (!getDerived().AlwaysRebuild() &&
7618 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007619 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007620
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007621 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007622 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007623 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007624 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007625 E->getMethodDecl(),
7626 E->getLeftLoc(),
7627 move_arg(Args),
7628 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007629}
7630
Mike Stump11289f42009-09-09 15:08:12 +00007631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007632ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007633TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007634 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007635}
7636
Mike Stump11289f42009-09-09 15:08:12 +00007637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007638ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007639TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007640 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007641}
7642
Mike Stump11289f42009-09-09 15:08:12 +00007643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007644ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007645TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007646 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007647 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007648 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007649 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007650
7651 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007652
Douglas Gregord51d90d2010-04-26 20:11:03 +00007653 // If nothing changed, just retain the existing expression.
7654 if (!getDerived().AlwaysRebuild() &&
7655 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007656 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007657
John McCallb268a282010-08-23 23:25:46 +00007658 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007659 E->getLocation(),
7660 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007661}
7662
Mike Stump11289f42009-09-09 15:08:12 +00007663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007665TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007666 // 'super' and types never change. Property never changes. Just
7667 // retain the existing expression.
7668 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007669 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007670
Douglas Gregor9faee212010-04-26 20:47:02 +00007671 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007672 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007673 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007674 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007675
Douglas Gregor9faee212010-04-26 20:47:02 +00007676 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007677
Douglas Gregor9faee212010-04-26 20:47:02 +00007678 // If nothing changed, just retain the existing expression.
7679 if (!getDerived().AlwaysRebuild() &&
7680 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007681 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007682
John McCallb7bd14f2010-12-02 01:19:52 +00007683 if (E->isExplicitProperty())
7684 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7685 E->getExplicitProperty(),
7686 E->getLocation());
7687
7688 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7689 E->getType(),
7690 E->getImplicitPropertyGetter(),
7691 E->getImplicitPropertySetter(),
7692 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007693}
7694
Mike Stump11289f42009-09-09 15:08:12 +00007695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007696ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007697TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007698 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007699 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007700 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007701 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007702
Douglas Gregord51d90d2010-04-26 20:11:03 +00007703 // If nothing changed, just retain the existing expression.
7704 if (!getDerived().AlwaysRebuild() &&
7705 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007706 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007707
John McCallb268a282010-08-23 23:25:46 +00007708 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007709 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007710}
7711
Mike Stump11289f42009-09-09 15:08:12 +00007712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007713ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007714TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007715 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007716 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007717 SubExprs.reserve(E->getNumSubExprs());
7718 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7719 SubExprs, &ArgumentChanged))
7720 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007721
Douglas Gregora16548e2009-08-11 05:31:07 +00007722 if (!getDerived().AlwaysRebuild() &&
7723 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007724 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007725
Douglas Gregora16548e2009-08-11 05:31:07 +00007726 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7727 move_arg(SubExprs),
7728 E->getRParenLoc());
7729}
7730
Mike Stump11289f42009-09-09 15:08:12 +00007731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007732ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007733TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007734 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007735
John McCall490112f2011-02-04 18:33:18 +00007736 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7737 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7738
7739 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00007740 // We built a new blockScopeInfo in call to ActOnBlockStart
7741 // in above, CapturesCXXThis need be set here from the block
7742 // expression.
7743 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7744
John McCall490112f2011-02-04 18:33:18 +00007745 llvm::SmallVector<ParmVarDecl*, 4> params;
7746 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007747
7748 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007749 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7750 oldBlock->param_begin(),
7751 oldBlock->param_size(),
7752 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007753 return true;
John McCall490112f2011-02-04 18:33:18 +00007754
7755 const FunctionType *exprFunctionType = E->getFunctionType();
7756 QualType exprResultType = exprFunctionType->getResultType();
7757 if (!exprResultType.isNull()) {
7758 if (!exprResultType->isDependentType())
7759 blockScope->ReturnType = exprResultType;
7760 else if (exprResultType != getSema().Context.DependentTy)
7761 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007762 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007763
7764 // If the return type has not been determined yet, leave it as a dependent
7765 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007766 if (blockScope->ReturnType.isNull())
7767 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007768
7769 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007770 if (blockScope->ReturnType->isObjCObjectType()) {
7771 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007772 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007773 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007774 return ExprError();
7775 }
John McCall3882ace2011-01-05 12:14:39 +00007776
John McCall490112f2011-02-04 18:33:18 +00007777 QualType functionType = getDerived().RebuildFunctionProtoType(
7778 blockScope->ReturnType,
7779 paramTypes.data(),
7780 paramTypes.size(),
7781 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007782 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007783 exprFunctionType->getExtInfo());
7784 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007785
7786 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007787 if (!params.empty())
7788 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007789
7790 // If the return type wasn't explicitly set, it will have been marked as a
7791 // dependent type (DependentTy); clear out the return type setting so
7792 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007793 if (blockScope->ReturnType == getSema().Context.DependentTy)
7794 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007795
John McCall3882ace2011-01-05 12:14:39 +00007796 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007797 StmtResult body = getDerived().TransformStmt(E->getBody());
7798 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007799 return ExprError();
7800
John McCall490112f2011-02-04 18:33:18 +00007801#ifndef NDEBUG
7802 // In builds with assertions, make sure that we captured everything we
7803 // captured before.
7804
John McCall490112f2011-02-04 18:33:18 +00007805 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7806 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007807 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007808
7809 // Ignore parameter packs.
7810 if (isa<ParmVarDecl>(oldCapture) &&
7811 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7812 continue;
7813
7814 VarDecl *newCapture =
7815 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7816 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007817 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007818 }
7819#endif
7820
7821 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7822 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007823}
7824
Mike Stump11289f42009-09-09 15:08:12 +00007825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007826ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007827TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007828 ValueDecl *ND
7829 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7830 E->getDecl()));
7831 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007832 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007833
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007834 if (!getDerived().AlwaysRebuild() &&
7835 ND == E->getDecl()) {
7836 // Mark it referenced in the new context regardless.
7837 // FIXME: this is a bit instantiation-specific.
7838 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7839
John McCallc3007a22010-10-26 07:05:15 +00007840 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007841 }
7842
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007843 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007844 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007845 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007846}
Mike Stump11289f42009-09-09 15:08:12 +00007847
Douglas Gregora16548e2009-08-11 05:31:07 +00007848//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007849// Type reconstruction
7850//===----------------------------------------------------------------------===//
7851
Mike Stump11289f42009-09-09 15:08:12 +00007852template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007853QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7854 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007855 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007856 getDerived().getBaseEntity());
7857}
7858
Mike Stump11289f42009-09-09 15:08:12 +00007859template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007860QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7861 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007862 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007863 getDerived().getBaseEntity());
7864}
7865
Mike Stump11289f42009-09-09 15:08:12 +00007866template<typename Derived>
7867QualType
John McCall70dd5f62009-10-30 00:06:24 +00007868TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7869 bool WrittenAsLValue,
7870 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007871 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007872 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007873}
7874
7875template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007876QualType
John McCall70dd5f62009-10-30 00:06:24 +00007877TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7878 QualType ClassType,
7879 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007880 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007881 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007882}
7883
7884template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007885QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007886TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7887 ArrayType::ArraySizeModifier SizeMod,
7888 const llvm::APInt *Size,
7889 Expr *SizeExpr,
7890 unsigned IndexTypeQuals,
7891 SourceRange BracketsRange) {
7892 if (SizeExpr || !Size)
7893 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7894 IndexTypeQuals, BracketsRange,
7895 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007896
7897 QualType Types[] = {
7898 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7899 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7900 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007901 };
7902 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7903 QualType SizeType;
7904 for (unsigned I = 0; I != NumTypes; ++I)
7905 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7906 SizeType = Types[I];
7907 break;
7908 }
Mike Stump11289f42009-09-09 15:08:12 +00007909
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007910 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7911 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007912 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007913 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007914 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007915}
Mike Stump11289f42009-09-09 15:08:12 +00007916
Douglas Gregord6ff3322009-08-04 16:50:30 +00007917template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007918QualType
7919TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007920 ArrayType::ArraySizeModifier SizeMod,
7921 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007922 unsigned IndexTypeQuals,
7923 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007924 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007925 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007926}
7927
7928template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007929QualType
Mike Stump11289f42009-09-09 15:08:12 +00007930TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007931 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007932 unsigned IndexTypeQuals,
7933 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007934 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007935 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007936}
Mike Stump11289f42009-09-09 15:08:12 +00007937
Douglas Gregord6ff3322009-08-04 16:50:30 +00007938template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007939QualType
7940TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007941 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007942 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007943 unsigned IndexTypeQuals,
7944 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007945 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007946 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007947 IndexTypeQuals, BracketsRange);
7948}
7949
7950template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007951QualType
7952TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007953 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007954 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007955 unsigned IndexTypeQuals,
7956 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007957 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007958 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007959 IndexTypeQuals, BracketsRange);
7960}
7961
7962template<typename Derived>
7963QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007964 unsigned NumElements,
7965 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007966 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007967 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007968}
Mike Stump11289f42009-09-09 15:08:12 +00007969
Douglas Gregord6ff3322009-08-04 16:50:30 +00007970template<typename Derived>
7971QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7972 unsigned NumElements,
7973 SourceLocation AttributeLoc) {
7974 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7975 NumElements, true);
7976 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007977 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7978 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007979 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007980}
Mike Stump11289f42009-09-09 15:08:12 +00007981
Douglas Gregord6ff3322009-08-04 16:50:30 +00007982template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007983QualType
7984TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007985 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007986 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007987 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007988}
Mike Stump11289f42009-09-09 15:08:12 +00007989
Douglas Gregord6ff3322009-08-04 16:50:30 +00007990template<typename Derived>
7991QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007992 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007993 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007994 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007995 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007996 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007997 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007998 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007999 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008000 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008001 getDerived().getBaseEntity(),
8002 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008003}
Mike Stump11289f42009-09-09 15:08:12 +00008004
Douglas Gregord6ff3322009-08-04 16:50:30 +00008005template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008006QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8007 return SemaRef.Context.getFunctionNoProtoType(T);
8008}
8009
8010template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008011QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8012 assert(D && "no decl found");
8013 if (D->isInvalidDecl()) return QualType();
8014
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008015 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008016 TypeDecl *Ty;
8017 if (isa<UsingDecl>(D)) {
8018 UsingDecl *Using = cast<UsingDecl>(D);
8019 assert(Using->isTypeName() &&
8020 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8021
8022 // A valid resolved using typename decl points to exactly one type decl.
8023 assert(++Using->shadow_begin() == Using->shadow_end());
8024 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008025
John McCallb96ec562009-12-04 22:46:56 +00008026 } else {
8027 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8028 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8029 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8030 }
8031
8032 return SemaRef.Context.getTypeDeclType(Ty);
8033}
8034
8035template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008036QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8037 SourceLocation Loc) {
8038 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008039}
8040
8041template<typename Derived>
8042QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8043 return SemaRef.Context.getTypeOfType(Underlying);
8044}
8045
8046template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008047QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8048 SourceLocation Loc) {
8049 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008050}
8051
8052template<typename Derived>
8053QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008054 TemplateName Template,
8055 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008056 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008057 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008058}
Mike Stump11289f42009-09-09 15:08:12 +00008059
Douglas Gregor1135c352009-08-06 05:28:30 +00008060template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008061TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008062TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008063 bool TemplateKW,
8064 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008065 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008066 Template);
8067}
8068
8069template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008070TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008071TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8072 const IdentifierInfo &Name,
8073 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008074 QualType ObjectType,
8075 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008076 UnqualifiedId TemplateName;
8077 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008078 Sema::TemplateTy Template;
8079 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008080 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008081 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008082 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008083 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008084 /*EnteringContext=*/false,
8085 Template);
John McCall31f82722010-11-12 08:19:04 +00008086 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008087}
Mike Stump11289f42009-09-09 15:08:12 +00008088
Douglas Gregora16548e2009-08-11 05:31:07 +00008089template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008090TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008091TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008092 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008093 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008094 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008095 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008096 // FIXME: Bogus location information.
8097 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8098 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008099 Sema::TemplateTy Template;
8100 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008101 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008102 SS,
8103 Name,
John McCallba7bf592010-08-24 05:47:05 +00008104 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008105 /*EnteringContext=*/false,
8106 Template);
8107 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008108}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008109
Douglas Gregor71395fa2009-11-04 00:56:37 +00008110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008111ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008112TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8113 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008114 Expr *OrigCallee,
8115 Expr *First,
8116 Expr *Second) {
8117 Expr *Callee = OrigCallee->IgnoreParenCasts();
8118 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008119
Douglas Gregora16548e2009-08-11 05:31:07 +00008120 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008121 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008122 if (!First->getType()->isOverloadableType() &&
8123 !Second->getType()->isOverloadableType())
8124 return getSema().CreateBuiltinArraySubscriptExpr(First,
8125 Callee->getLocStart(),
8126 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008127 } else if (Op == OO_Arrow) {
8128 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008129 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8130 } else if (Second == 0 || isPostIncDec) {
8131 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008132 // The argument is not of overloadable type, so try to create a
8133 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008134 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008135 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008136
John McCallb268a282010-08-23 23:25:46 +00008137 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008138 }
8139 } else {
John McCallb268a282010-08-23 23:25:46 +00008140 if (!First->getType()->isOverloadableType() &&
8141 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008142 // Neither of the arguments is an overloadable type, so try to
8143 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008144 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008145 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008146 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008147 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008148 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008149
Douglas Gregora16548e2009-08-11 05:31:07 +00008150 return move(Result);
8151 }
8152 }
Mike Stump11289f42009-09-09 15:08:12 +00008153
8154 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008155 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008156 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008157
John McCallb268a282010-08-23 23:25:46 +00008158 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008159 assert(ULE->requiresADL());
8160
8161 // FIXME: Do we have to check
8162 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008163 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008164 } else {
John McCallb268a282010-08-23 23:25:46 +00008165 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008166 }
Mike Stump11289f42009-09-09 15:08:12 +00008167
Douglas Gregora16548e2009-08-11 05:31:07 +00008168 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008169 Expr *Args[2] = { First, Second };
8170 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008171
Douglas Gregora16548e2009-08-11 05:31:07 +00008172 // Create the overloaded operator invocation for unary operators.
8173 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008174 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008175 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008176 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 }
Mike Stump11289f42009-09-09 15:08:12 +00008178
Sebastian Redladba46e2009-10-29 20:17:01 +00008179 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00008180 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00008181 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008182 First,
8183 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00008184
Douglas Gregora16548e2009-08-11 05:31:07 +00008185 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008186 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008187 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008188 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8189 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008190 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008191
Mike Stump11289f42009-09-09 15:08:12 +00008192 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008193}
Mike Stump11289f42009-09-09 15:08:12 +00008194
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008196ExprResult
John McCallb268a282010-08-23 23:25:46 +00008197TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008198 SourceLocation OperatorLoc,
8199 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008200 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008201 TypeSourceInfo *ScopeType,
8202 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008203 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008204 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008205 QualType BaseType = Base->getType();
8206 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008207 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008208 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008209 !BaseType->getAs<PointerType>()->getPointeeType()
8210 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008211 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008212 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008213 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008214 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008215 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008216 /*FIXME?*/true);
8217 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008218
Douglas Gregor678f90d2010-02-25 01:56:36 +00008219 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008220 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8221 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8222 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8223 NameInfo.setNamedTypeInfo(DestroyedType);
8224
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008225 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008226
John McCallb268a282010-08-23 23:25:46 +00008227 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008228 OperatorLoc, isArrow,
8229 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008230 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008231 /*TemplateArgs*/ 0);
8232}
8233
Douglas Gregord6ff3322009-08-04 16:50:30 +00008234} // end namespace clang
8235
8236#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H