blob: d33e7a5c4c490711100e5652f4556fe0334aa106 [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
Alexis Hunte852b102011-05-24 22:41:36 +0000705 /// \brief Build a new unary transform type.
706 QualType RebuildUnaryTransformType(QualType BaseType,
707 UnaryTransformType::UTTKind UKind,
708 SourceLocation Loc);
709
Mike Stump11289f42009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 ///
712 /// By default, performs semantic analysis when building the decltype type.
713 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000715
Richard Smith30482bc2011-02-20 03:19:35 +0000716 /// \brief Build a new C++0x auto type.
717 ///
718 /// By default, builds a new AutoType with the given deduced type.
719 QualType RebuildAutoType(QualType Deduced) {
720 return SemaRef.Context.getAutoType(Deduced);
721 }
722
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// \brief Build a new template specialization type.
724 ///
725 /// By default, performs semantic analysis when building the template
726 /// specialization type. Subclasses may override this routine to provide
727 /// different behavior.
728 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000731
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000732 /// \brief Build a new parenthesized type.
733 ///
734 /// By default, builds a new ParenType type from the inner type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildParenType(QualType InnerType) {
737 return SemaRef.Context.getParenType(InnerType);
738 }
739
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000742 /// By default, builds a new ElaboratedType type from the keyword,
743 /// the nested-name-specifier and the named type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000752 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000756 /// By default, builds a new DependentNameType type from the
757 /// nested-name-specifier and the given type. Subclasses may override
758 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000771
772 if (InstName.isNull())
773 return QualType();
774
775 // If it's still dependent, make a dependent specialization.
776 if (InstName.getAsDependentTemplateName())
777 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
779 Name,
780 Args);
781
782 // Otherwise, make an elaborated type wrapping a non-dependent
783 // specialization.
784 QualType T =
785 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
786 if (T.isNull()) return QualType();
787
788 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
789 return T;
790
791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
793 T);
794 }
795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new typename type that refers to an identifier.
797 ///
798 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000808
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000810 // If the name is still dependent, just build a new dependent name type.
811 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara6150c882010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarad7548482010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCallbf8c5192010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregore677daf2010-03-31 22:19:08 +0000834 TagDecl *Tag = 0;
835 SemaRef.LookupQualifiedName(Result, DC);
836 switch (Result.getResultKind()) {
837 case LookupResult::NotFound:
838 case LookupResult::NotFoundInCurrentInstantiation:
839 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000840
Douglas Gregore677daf2010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000844
Douglas Gregore677daf2010-03-31 22:19:08 +0000845 case LookupResult::FoundOverloaded:
846 case LookupResult::FoundUnresolvedValue:
847 llvm_unreachable("Tag lookup cannot find non-tags");
848 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000849
Douglas Gregore677daf2010-03-31 22:19:08 +0000850 case LookupResult::Ambiguous:
851 // Let the LookupResult structure handle ambiguities.
852 return QualType();
853 }
854
855 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000856 // Check where the name exists but isn't a tag type and use that to emit
857 // better diagnostics.
858 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859 SemaRef.LookupQualifiedName(Result, DC);
860 switch (Result.getResultKind()) {
861 case LookupResult::Found:
862 case LookupResult::FoundOverloaded:
863 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000872 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000873 default:
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876 << Kind << Id << DC;
877 break;
878 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000881
Richard Trieucaa33d32011-06-10 03:11:26 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000885 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
886 return QualType();
887 }
888
889 // Build the elaborated-type-specifier type.
890 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
893 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000894 }
Mike Stump11289f42009-09-09 15:08:12 +0000895
Douglas Gregor822d0302011-01-12 17:07:58 +0000896 /// \brief Build a new pack expansion type.
897 ///
898 /// By default, builds a new PackExpansionType type from the given pattern.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildPackExpansionType(QualType Pattern,
901 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000906 }
907
Douglas Gregor71dc5092009-08-06 06:41:21 +0000908 /// \brief Build a new template name given a nested name specifier, a flag
909 /// indicating whether the "template" keyword was provided, and the template
910 /// that the template name refers to.
911 ///
912 /// By default, builds the new template name directly. Subclasses may override
913 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000914 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000915 bool TemplateKW,
916 TemplateDecl *Template);
917
Douglas Gregor71dc5092009-08-06 06:41:21 +0000918 /// \brief Build a new template name given a nested name specifier and the
919 /// name that is referred to as a template.
920 ///
921 /// By default, performs semantic analysis to determine whether the name can
922 /// be resolved to a specific template, then builds the appropriate kind of
923 /// template name. Subclasses may override this routine to provide different
924 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000925 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
926 const IdentifierInfo &Name,
927 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000928 QualType ObjectType,
929 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000930
Douglas Gregor71395fa2009-11-04 00:56:37 +0000931 /// \brief Build a new template name given a nested name specifier and the
932 /// overloaded operator name that is referred to as a template.
933 ///
934 /// By default, performs semantic analysis to determine whether the name can
935 /// be resolved to a specific template, then builds the appropriate kind of
936 /// template name. Subclasses may override this routine to provide different
937 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000938 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000939 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000940 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000941 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000942
943 /// \brief Build a new template name given a template template parameter pack
944 /// and the
945 ///
946 /// By default, performs semantic analysis to determine whether the name can
947 /// be resolved to a specific template, then builds the appropriate kind of
948 /// template name. Subclasses may override this routine to provide different
949 /// behavior.
950 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
951 const TemplateArgument &ArgPack) {
952 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
953 }
954
Douglas Gregorebe10102009-08-20 07:17:43 +0000955 /// \brief Build a new compound statement.
956 ///
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000959 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000960 MultiStmtArg Statements,
961 SourceLocation RBraceLoc,
962 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000963 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000964 IsStmtExpr);
965 }
966
967 /// \brief Build a new case statement.
968 ///
969 /// By default, performs semantic analysis to build the new statement.
970 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000971 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000972 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000973 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000974 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000975 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000976 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000977 ColonLoc);
978 }
Mike Stump11289f42009-09-09 15:08:12 +0000979
Douglas Gregorebe10102009-08-20 07:17:43 +0000980 /// \brief Attach the body to a new case statement.
981 ///
982 /// By default, performs semantic analysis to build the new statement.
983 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000984 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000985 getSema().ActOnCaseStmtBody(S, Body);
986 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 }
Mike Stump11289f42009-09-09 15:08:12 +0000988
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 /// \brief Build a new default statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000993 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000994 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000995 Stmt *SubStmt) {
996 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000997 /*CurScope=*/0);
998 }
Mike Stump11289f42009-09-09 15:08:12 +0000999
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 /// \brief Build a new label statement.
1001 ///
1002 /// By default, performs semantic analysis to build the new statement.
1003 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001004 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1005 SourceLocation ColonLoc, Stmt *SubStmt) {
1006 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001007 }
Mike Stump11289f42009-09-09 15:08:12 +00001008
Douglas Gregorebe10102009-08-20 07:17:43 +00001009 /// \brief Build a new "if" statement.
1010 ///
1011 /// By default, performs semantic analysis to build the new statement.
1012 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001013 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001014 VarDecl *CondVar, Stmt *Then,
1015 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001016 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001017 }
Mike Stump11289f42009-09-09 15:08:12 +00001018
Douglas Gregorebe10102009-08-20 07:17:43 +00001019 /// \brief Start building a new switch statement.
1020 ///
1021 /// By default, performs semantic analysis to build the new statement.
1022 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001023 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001024 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001025 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001026 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001027 }
Mike Stump11289f42009-09-09 15:08:12 +00001028
Douglas Gregorebe10102009-08-20 07:17:43 +00001029 /// \brief Attach the body to the switch statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001033 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001034 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001035 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001036 }
1037
1038 /// \brief Build a new while statement.
1039 ///
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001042 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1043 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001044 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001045 }
Mike Stump11289f42009-09-09 15:08:12 +00001046
Douglas Gregorebe10102009-08-20 07:17:43 +00001047 /// \brief Build a new do-while statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001051 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001052 SourceLocation WhileLoc, SourceLocation LParenLoc,
1053 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001054 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1055 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001056 }
1057
1058 /// \brief Build a new for statement.
1059 ///
1060 /// By default, performs semantic analysis to build the new statement.
1061 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001062 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1063 Stmt *Init, Sema::FullExprArg Cond,
1064 VarDecl *CondVar, Sema::FullExprArg Inc,
1065 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001066 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001067 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 }
Mike Stump11289f42009-09-09 15:08:12 +00001069
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 /// \brief Build a new goto statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001074 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1075 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001076 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001077 }
1078
1079 /// \brief Build a new indirect goto statement.
1080 ///
1081 /// By default, performs semantic analysis to build the new statement.
1082 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001083 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001084 SourceLocation StarLoc,
1085 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001086 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 }
Mike Stump11289f42009-09-09 15:08:12 +00001088
Douglas Gregorebe10102009-08-20 07:17:43 +00001089 /// \brief Build a new return statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001093 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001094 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 }
Mike Stump11289f42009-09-09 15:08:12 +00001096
Douglas Gregorebe10102009-08-20 07:17:43 +00001097 /// \brief Build a new declaration statement.
1098 ///
1099 /// By default, performs semantic analysis to build the new statement.
1100 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001101 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001102 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001103 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001104 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1105 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001106 }
Mike Stump11289f42009-09-09 15:08:12 +00001107
Anders Carlssonaaeef072010-01-24 05:50:09 +00001108 /// \brief Build a new inline asm statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001112 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001113 bool IsSimple,
1114 bool IsVolatile,
1115 unsigned NumOutputs,
1116 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001117 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001118 MultiExprArg Constraints,
1119 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001120 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001121 MultiExprArg Clobbers,
1122 SourceLocation RParenLoc,
1123 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001124 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001125 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001126 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001127 RParenLoc, MSAsm);
1128 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001129
1130 /// \brief Build a new Objective-C @try statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001134 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001135 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001136 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001137 Stmt *Finally) {
1138 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1139 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001140 }
1141
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001142 /// \brief Rebuild an Objective-C exception declaration.
1143 ///
1144 /// By default, performs semantic analysis to build the new declaration.
1145 /// Subclasses may override this routine to provide different behavior.
1146 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1147 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001148 return getSema().BuildObjCExceptionDecl(TInfo, T,
1149 ExceptionDecl->getInnerLocStart(),
1150 ExceptionDecl->getLocation(),
1151 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001152 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001153
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001154 /// \brief Build a new Objective-C @catch statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001158 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001159 SourceLocation RParenLoc,
1160 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001161 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001162 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001163 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001164 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001165
Douglas Gregor306de2f2010-04-22 23:59:56 +00001166 /// \brief Build a new Objective-C @finally statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001170 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001171 Stmt *Body) {
1172 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001173 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001174
Douglas Gregor6148de72010-04-22 22:01:21 +00001175 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001180 Expr *Operand) {
1181 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001182 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001183
Douglas Gregor6148de72010-04-22 22:01:21 +00001184 /// \brief Build a new Objective-C @synchronized statement.
1185 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001186 /// By default, performs semantic analysis to build the new statement.
1187 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001188 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001189 Expr *Object,
1190 Stmt *Body) {
1191 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1192 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001193 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001194
John McCall31168b02011-06-15 23:02:42 +00001195 /// \brief Build a new Objective-C @autoreleasepool statement.
1196 ///
1197 /// By default, performs semantic analysis to build the new statement.
1198 /// Subclasses may override this routine to provide different behavior.
1199 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1200 Stmt *Body) {
1201 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1202 }
1203
1204
Douglas Gregorf68a5082010-04-22 23:10:45 +00001205 /// \brief Build a new Objective-C fast enumeration statement.
1206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001209 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001210 SourceLocation LParenLoc,
1211 Stmt *Element,
1212 Expr *Collection,
1213 SourceLocation RParenLoc,
1214 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001215 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001216 Element,
1217 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001218 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001219 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001220 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001221
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 /// \brief Build a new C++ exception declaration.
1223 ///
1224 /// By default, performs semantic analysis to build the new decaration.
1225 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001226 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001227 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001228 SourceLocation StartLoc,
1229 SourceLocation IdLoc,
1230 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001231 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1232 StartLoc, IdLoc, Id);
1233 if (Var)
1234 getSema().CurContext->addDecl(Var);
1235 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001236 }
1237
1238 /// \brief Build a new C++ catch statement.
1239 ///
1240 /// By default, performs semantic analysis to build the new statement.
1241 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001242 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001243 VarDecl *ExceptionDecl,
1244 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001245 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1246 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001247 }
Mike Stump11289f42009-09-09 15:08:12 +00001248
Douglas Gregorebe10102009-08-20 07:17:43 +00001249 /// \brief Build a new C++ try statement.
1250 ///
1251 /// By default, performs semantic analysis to build the new statement.
1252 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001253 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001254 Stmt *TryBlock,
1255 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001256 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Richard Smith02e85f32011-04-14 22:09:26 +00001259 /// \brief Build a new C++0x range-based for statement.
1260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
1263 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1264 SourceLocation ColonLoc,
1265 Stmt *Range, Stmt *BeginEnd,
1266 Expr *Cond, Expr *Inc,
1267 Stmt *LoopVar,
1268 SourceLocation RParenLoc) {
1269 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1270 Cond, Inc, LoopVar, RParenLoc);
1271 }
1272
1273 /// \brief Attach body to a C++0x range-based for statement.
1274 ///
1275 /// By default, performs semantic analysis to finish the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
1277 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1278 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1279 }
1280
John Wiegley1c0675e2011-04-28 01:08:34 +00001281 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1282 SourceLocation TryLoc,
1283 Stmt *TryBlock,
1284 Stmt *Handler) {
1285 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1286 }
1287
1288 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1289 Expr *FilterExpr,
1290 Stmt *Block) {
1291 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1292 }
1293
1294 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1295 Stmt *Block) {
1296 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1297 }
1298
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 /// \brief Build a new expression that references a declaration.
1300 ///
1301 /// By default, performs semantic analysis to build the new expression.
1302 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001303 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001304 LookupResult &R,
1305 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001306 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1307 }
1308
1309
1310 /// \brief Build a new expression that references a declaration.
1311 ///
1312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001314 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001315 ValueDecl *VD,
1316 const DeclarationNameInfo &NameInfo,
1317 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001318 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001319 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001320
1321 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001322
1323 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 }
Mike Stump11289f42009-09-09 15:08:12 +00001325
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001327 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 /// By default, performs semantic analysis to build the new expression.
1329 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001330 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001332 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 }
1334
Douglas Gregorad8a3362009-09-04 17:36:40 +00001335 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001336 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001337 /// By default, performs semantic analysis to build the new expression.
1338 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001339 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001340 SourceLocation OperatorLoc,
1341 bool isArrow,
1342 CXXScopeSpec &SS,
1343 TypeSourceInfo *ScopeType,
1344 SourceLocation CCLoc,
1345 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001346 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001347
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001349 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 /// By default, performs semantic analysis to build the new expression.
1351 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001352 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001353 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001354 Expr *SubExpr) {
1355 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001356 }
Mike Stump11289f42009-09-09 15:08:12 +00001357
Douglas Gregor882211c2010-04-28 22:16:22 +00001358 /// \brief Build a new builtin offsetof expression.
1359 ///
1360 /// By default, performs semantic analysis to build the new expression.
1361 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001362 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001363 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001364 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001365 unsigned NumComponents,
1366 SourceLocation RParenLoc) {
1367 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1368 NumComponents, RParenLoc);
1369 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001370
Peter Collingbournee190dee2011-03-11 19:24:49 +00001371 /// \brief Build a new sizeof, alignof or vec_step expression with a
1372 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001373 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 /// By default, performs semantic analysis to build the new expression.
1375 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001376 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1377 SourceLocation OpLoc,
1378 UnaryExprOrTypeTrait ExprKind,
1379 SourceRange R) {
1380 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001381 }
1382
Peter Collingbournee190dee2011-03-11 19:24:49 +00001383 /// \brief Build a new sizeof, alignof or vec step expression with an
1384 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001385 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 /// By default, performs semantic analysis to build the new expression.
1387 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001388 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1389 UnaryExprOrTypeTrait ExprKind,
1390 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001391 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001392 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001394 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001395
Douglas Gregora16548e2009-08-11 05:31:07 +00001396 return move(Result);
1397 }
Mike Stump11289f42009-09-09 15:08:12 +00001398
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001400 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 /// By default, performs semantic analysis to build the new expression.
1402 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001403 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001405 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001407 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1408 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 RBracketLoc);
1410 }
1411
1412 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001413 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001416 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001418 SourceLocation RParenLoc,
1419 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001420 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001421 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 }
1423
1424 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001425 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001428 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001429 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001430 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001431 const DeclarationNameInfo &MemberNameInfo,
1432 ValueDecl *Member,
1433 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001434 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001435 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001436 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001437 // We have a reference to an unnamed field. This is always the
1438 // base of an anonymous struct/union member access, i.e. the
1439 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001440 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001441 assert(Member->getType()->isRecordType() &&
1442 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001443
John Wiegley01296292011-04-08 18:41:53 +00001444 ExprResult BaseResult =
1445 getSema().PerformObjectMemberConversion(Base,
1446 QualifierLoc.getNestedNameSpecifier(),
1447 FoundDecl, Member);
1448 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001449 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001450 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001451 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001452 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001453 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001454 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001455 cast<FieldDecl>(Member)->getType(),
1456 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001457 return getSema().Owned(ME);
1458 }
Mike Stump11289f42009-09-09 15:08:12 +00001459
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001460 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001461 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001462
John Wiegley01296292011-04-08 18:41:53 +00001463 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1464 if (BaseResult.isInvalid())
1465 return ExprError();
1466 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001467 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001468
John McCall16df1e52010-03-30 21:47:33 +00001469 // FIXME: this involves duplicating earlier analysis in a lot of
1470 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001471 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001472 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001473 R.resolveKind();
1474
John McCallb268a282010-08-23 23:25:46 +00001475 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001476 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001477 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 }
Mike Stump11289f42009-09-09 15:08:12 +00001479
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001481 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001484 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001485 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001486 Expr *LHS, Expr *RHS) {
1487 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001488 }
1489
1490 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001491 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 /// By default, performs semantic analysis to build the new expression.
1493 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001494 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001495 SourceLocation QuestionLoc,
1496 Expr *LHS,
1497 SourceLocation ColonLoc,
1498 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001499 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1500 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 }
1502
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001504 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001507 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001508 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001510 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001511 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001512 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 }
Mike Stump11289f42009-09-09 15:08:12 +00001514
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001516 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001519 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001520 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001522 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001523 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001524 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 }
Mike Stump11289f42009-09-09 15:08:12 +00001526
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001528 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 /// By default, performs semantic analysis to build the new expression.
1530 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001531 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 SourceLocation OpLoc,
1533 SourceLocation AccessorLoc,
1534 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001535
John McCall10eae182009-11-30 22:42:35 +00001536 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001537 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001538 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001539 OpLoc, /*IsArrow*/ false,
1540 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001541 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001542 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 }
Mike Stump11289f42009-09-09 15:08:12 +00001544
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001546 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001549 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001551 SourceLocation RBraceLoc,
1552 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001553 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001554 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1555 if (Result.isInvalid() || ResultTy->isDependentType())
1556 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001557
Douglas Gregord3d93062009-11-09 17:16:50 +00001558 // Patch in the result type we were given, which may have been computed
1559 // when the initial InitListExpr was built.
1560 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1561 ILE->setType(ResultTy);
1562 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 }
Mike Stump11289f42009-09-09 15:08:12 +00001564
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001566 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 /// By default, performs semantic analysis to build the new expression.
1568 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001569 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 MultiExprArg ArrayExprs,
1571 SourceLocation EqualOrColonLoc,
1572 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001573 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001574 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001576 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001578 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001579
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 ArrayExprs.release();
1581 return move(Result);
1582 }
Mike Stump11289f42009-09-09 15:08:12 +00001583
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001585 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 /// By default, builds the implicit value initialization without performing
1587 /// any semantic analysis. Subclasses may override this routine to provide
1588 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001589 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1591 }
Mike Stump11289f42009-09-09 15:08:12 +00001592
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001594 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001597 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001598 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001599 SourceLocation RParenLoc) {
1600 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001601 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001602 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 }
1604
1605 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001606 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001609 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 MultiExprArg SubExprs,
1611 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001612 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001613 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 }
Mike Stump11289f42009-09-09 15:08:12 +00001615
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001617 ///
1618 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 /// rather than attempting to map the label statement itself.
1620 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001621 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001622 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001623 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 }
Mike Stump11289f42009-09-09 15:08:12 +00001625
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001627 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001630 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001631 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001633 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 }
Mike Stump11289f42009-09-09 15:08:12 +00001635
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 /// \brief Build a new __builtin_choose_expr expression.
1637 ///
1638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001640 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001641 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 SourceLocation RParenLoc) {
1643 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001644 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 RParenLoc);
1646 }
Mike Stump11289f42009-09-09 15:08:12 +00001647
Peter Collingbourne91147592011-04-15 00:35:48 +00001648 /// \brief Build a new generic selection expression.
1649 ///
1650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
1652 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1653 SourceLocation DefaultLoc,
1654 SourceLocation RParenLoc,
1655 Expr *ControllingExpr,
1656 TypeSourceInfo **Types,
1657 Expr **Exprs,
1658 unsigned NumAssocs) {
1659 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1660 ControllingExpr, Types, Exprs,
1661 NumAssocs);
1662 }
1663
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 /// \brief Build a new overloaded operator call expression.
1665 ///
1666 /// By default, performs semantic analysis to build the new expression.
1667 /// The semantic analysis provides the behavior of template instantiation,
1668 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001669 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 /// argument-dependent lookup, etc. Subclasses may override this routine to
1671 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001672 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001674 Expr *Callee,
1675 Expr *First,
1676 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001677
1678 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 /// reinterpret_cast.
1680 ///
1681 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001682 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001684 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 Stmt::StmtClass Class,
1686 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001687 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 SourceLocation RAngleLoc,
1689 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001690 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 SourceLocation RParenLoc) {
1692 switch (Class) {
1693 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001694 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001695 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001696 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001697
1698 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001699 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001700 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001701 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001702
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001704 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001705 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001706 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001708
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001710 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001711 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001712 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001713
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 default:
1715 assert(false && "Invalid C++ named cast");
1716 break;
1717 }
Mike Stump11289f42009-09-09 15:08:12 +00001718
John McCallfaf5fb42010-08-26 23:41:50 +00001719 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 }
Mike Stump11289f42009-09-09 15:08:12 +00001721
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 /// \brief Build a new C++ static_cast expression.
1723 ///
1724 /// By default, performs semantic analysis to build the new expression.
1725 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001726 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001728 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 SourceLocation RAngleLoc,
1730 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001731 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001733 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001734 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001735 SourceRange(LAngleLoc, RAngleLoc),
1736 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 }
1738
1739 /// \brief Build a new C++ dynamic_cast expression.
1740 ///
1741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001743 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001745 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 SourceLocation RAngleLoc,
1747 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001748 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001750 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001751 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001752 SourceRange(LAngleLoc, RAngleLoc),
1753 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 }
1755
1756 /// \brief Build a new C++ reinterpret_cast expression.
1757 ///
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001760 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001762 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 SourceLocation RAngleLoc,
1764 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001765 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001767 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001768 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001769 SourceRange(LAngleLoc, RAngleLoc),
1770 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 }
1772
1773 /// \brief Build a new C++ const_cast expression.
1774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001777 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001779 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 SourceLocation RAngleLoc,
1781 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001782 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001784 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001785 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001786 SourceRange(LAngleLoc, RAngleLoc),
1787 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 }
Mike Stump11289f42009-09-09 15:08:12 +00001789
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 /// \brief Build a new C++ functional-style cast expression.
1791 ///
1792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001794 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1795 SourceLocation LParenLoc,
1796 Expr *Sub,
1797 SourceLocation RParenLoc) {
1798 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001799 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 RParenLoc);
1801 }
Mike Stump11289f42009-09-09 15:08:12 +00001802
Douglas Gregora16548e2009-08-11 05:31:07 +00001803 /// \brief Build a new C++ typeid(type) expression.
1804 ///
1805 /// By default, performs semantic analysis to build the new expression.
1806 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001807 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001808 SourceLocation TypeidLoc,
1809 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001811 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001812 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 }
Mike Stump11289f42009-09-09 15:08:12 +00001814
Francois Pichet9f4f2072010-09-08 12:20:18 +00001815
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 /// \brief Build a new C++ typeid(expr) expression.
1817 ///
1818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001820 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001821 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001822 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001824 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001825 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001826 }
1827
Francois Pichet9f4f2072010-09-08 12:20:18 +00001828 /// \brief Build a new C++ __uuidof(type) expression.
1829 ///
1830 /// By default, performs semantic analysis to build the new expression.
1831 /// Subclasses may override this routine to provide different behavior.
1832 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1833 SourceLocation TypeidLoc,
1834 TypeSourceInfo *Operand,
1835 SourceLocation RParenLoc) {
1836 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1837 RParenLoc);
1838 }
1839
1840 /// \brief Build a new C++ __uuidof(expr) expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
1844 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1845 SourceLocation TypeidLoc,
1846 Expr *Operand,
1847 SourceLocation RParenLoc) {
1848 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1849 RParenLoc);
1850 }
1851
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 /// \brief Build a new C++ "this" expression.
1853 ///
1854 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001855 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001856 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001857 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001858 QualType ThisType,
1859 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001860 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001861 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1862 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 }
1864
1865 /// \brief Build a new C++ throw expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001869 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001870 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 }
1872
1873 /// \brief Build a new C++ default-argument expression.
1874 ///
1875 /// By default, builds a new default-argument expression, which does not
1876 /// require any semantic analysis. Subclasses may override this routine to
1877 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001878 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001879 ParmVarDecl *Param) {
1880 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1881 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001882 }
1883
1884 /// \brief Build a new C++ zero-initialization expression.
1885 ///
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001888 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1889 SourceLocation LParenLoc,
1890 SourceLocation RParenLoc) {
1891 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001892 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001893 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 }
Mike Stump11289f42009-09-09 15:08:12 +00001895
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 /// \brief Build a new C++ "new" expression.
1897 ///
1898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001900 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001901 bool UseGlobal,
1902 SourceLocation PlacementLParen,
1903 MultiExprArg PlacementArgs,
1904 SourceLocation PlacementRParen,
1905 SourceRange TypeIdParens,
1906 QualType AllocatedType,
1907 TypeSourceInfo *AllocatedTypeInfo,
1908 Expr *ArraySize,
1909 SourceLocation ConstructorLParen,
1910 MultiExprArg ConstructorArgs,
1911 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001912 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 PlacementLParen,
1914 move(PlacementArgs),
1915 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001916 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001917 AllocatedType,
1918 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001919 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 ConstructorLParen,
1921 move(ConstructorArgs),
1922 ConstructorRParen);
1923 }
Mike Stump11289f42009-09-09 15:08:12 +00001924
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 /// \brief Build a new C++ "delete" expression.
1926 ///
1927 /// By default, performs semantic analysis to build the new expression.
1928 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001929 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 bool IsGlobalDelete,
1931 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001932 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001934 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 }
Mike Stump11289f42009-09-09 15:08:12 +00001936
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 /// \brief Build a new unary type trait expression.
1938 ///
1939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001941 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001942 SourceLocation StartLoc,
1943 TypeSourceInfo *T,
1944 SourceLocation RParenLoc) {
1945 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 }
1947
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001948 /// \brief Build a new binary type trait expression.
1949 ///
1950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
1952 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1953 SourceLocation StartLoc,
1954 TypeSourceInfo *LhsT,
1955 TypeSourceInfo *RhsT,
1956 SourceLocation RParenLoc) {
1957 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1958 }
1959
John Wiegley6242b6a2011-04-28 00:16:57 +00001960 /// \brief Build a new array type trait expression.
1961 ///
1962 /// By default, performs semantic analysis to build the new expression.
1963 /// Subclasses may override this routine to provide different behavior.
1964 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1965 SourceLocation StartLoc,
1966 TypeSourceInfo *TSInfo,
1967 Expr *DimExpr,
1968 SourceLocation RParenLoc) {
1969 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1970 }
1971
John Wiegleyf9f65842011-04-25 06:54:41 +00001972 /// \brief Build a new expression trait expression.
1973 ///
1974 /// By default, performs semantic analysis to build the new expression.
1975 /// Subclasses may override this routine to provide different behavior.
1976 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1977 SourceLocation StartLoc,
1978 Expr *Queried,
1979 SourceLocation RParenLoc) {
1980 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1981 }
1982
Mike Stump11289f42009-09-09 15:08:12 +00001983 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 /// expression.
1985 ///
1986 /// By default, performs semantic analysis to build the new expression.
1987 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001988 ExprResult RebuildDependentScopeDeclRefExpr(
1989 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001990 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001991 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001993 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001994
1995 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001996 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001997 *TemplateArgs);
1998
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001999 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 }
2001
2002 /// \brief Build a new template-id expression.
2003 ///
2004 /// By default, performs semantic analysis to build the new expression.
2005 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002006 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00002007 LookupResult &R,
2008 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00002009 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00002010 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 }
2012
2013 /// \brief Build a new object-construction expression.
2014 ///
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002017 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002018 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 CXXConstructorDecl *Constructor,
2020 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002021 MultiExprArg Args,
2022 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002023 CXXConstructExpr::ConstructionKind ConstructKind,
2024 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002025 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002026 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002027 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002028 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002029
Douglas Gregordb121ba2009-12-14 16:27:04 +00002030 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002031 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00002032 RequiresZeroInit, ConstructKind,
2033 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 }
2035
2036 /// \brief Build a new object-construction expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002040 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2041 SourceLocation LParenLoc,
2042 MultiExprArg Args,
2043 SourceLocation RParenLoc) {
2044 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 LParenLoc,
2046 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 RParenLoc);
2048 }
2049
2050 /// \brief Build a new object-construction expression.
2051 ///
2052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002054 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2055 SourceLocation LParenLoc,
2056 MultiExprArg Args,
2057 SourceLocation RParenLoc) {
2058 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 LParenLoc,
2060 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 RParenLoc);
2062 }
Mike Stump11289f42009-09-09 15:08:12 +00002063
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 /// \brief Build a new member reference expression.
2065 ///
2066 /// By default, performs semantic analysis to build the new expression.
2067 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002068 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002069 QualType BaseType,
2070 bool IsArrow,
2071 SourceLocation OperatorLoc,
2072 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002073 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002074 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002075 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002077 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002078
John McCallb268a282010-08-23 23:25:46 +00002079 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002080 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002081 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002082 MemberNameInfo,
2083 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 }
2085
John McCall10eae182009-11-30 22:42:35 +00002086 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002090 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002091 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002092 SourceLocation OperatorLoc,
2093 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002094 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002095 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002096 LookupResult &R,
2097 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002098 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002099 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002100
John McCallb268a282010-08-23 23:25:46 +00002101 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002102 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002103 SS, FirstQualifierInScope,
2104 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002105 }
Mike Stump11289f42009-09-09 15:08:12 +00002106
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002107 /// \brief Build a new noexcept expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
2111 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2112 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2113 }
2114
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002115 /// \brief Build a new expression to compute the length of a parameter pack.
2116 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2117 SourceLocation PackLoc,
2118 SourceLocation RParenLoc,
2119 unsigned Length) {
2120 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2121 OperatorLoc, Pack, PackLoc,
2122 RParenLoc, Length);
2123 }
2124
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 /// \brief Build a new Objective-C @encode expression.
2126 ///
2127 /// By default, performs semantic analysis to build the new expression.
2128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002129 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002130 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002132 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002134 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002135
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002136 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002138 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002139 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002140 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002141 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002142 MultiExprArg Args,
2143 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002144 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2145 ReceiverTypeInfo->getType(),
2146 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002147 Sel, Method, LBracLoc, SelectorLoc,
2148 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002149 }
2150
2151 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002152 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002153 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002154 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002155 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002156 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002157 MultiExprArg Args,
2158 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002159 return SemaRef.BuildInstanceMessage(Receiver,
2160 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002161 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002162 Sel, Method, LBracLoc, SelectorLoc,
2163 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002164 }
2165
Douglas Gregord51d90d2010-04-26 20:11:03 +00002166 /// \brief Build a new Objective-C ivar reference expression.
2167 ///
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002170 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002171 SourceLocation IvarLoc,
2172 bool IsArrow, bool IsFreeIvar) {
2173 // FIXME: We lose track of the IsFreeIvar bit.
2174 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002175 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002176 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2177 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002178 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002179 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002180 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002181 false);
John Wiegley01296292011-04-08 18:41:53 +00002182 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002183 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002184
Douglas Gregord51d90d2010-04-26 20:11:03 +00002185 if (Result.get())
2186 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002187
John Wiegley01296292011-04-08 18:41:53 +00002188 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002189 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002190 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002191 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002192 /*TemplateArgs=*/0);
2193 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002194
2195 /// \brief Build a new Objective-C property reference expression.
2196 ///
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002199 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002200 ObjCPropertyDecl *Property,
2201 SourceLocation PropertyLoc) {
2202 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002203 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002204 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2205 Sema::LookupMemberName);
2206 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002207 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002208 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002209 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002210 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002211 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002212
Douglas Gregor9faee212010-04-26 20:47:02 +00002213 if (Result.get())
2214 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002215
John Wiegley01296292011-04-08 18:41:53 +00002216 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002217 /*FIXME:*/PropertyLoc, IsArrow,
2218 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002219 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002220 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002221 /*TemplateArgs=*/0);
2222 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002223
John McCallb7bd14f2010-12-02 01:19:52 +00002224 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002225 ///
2226 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002227 /// Subclasses may override this routine to provide different behavior.
2228 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2229 ObjCMethodDecl *Getter,
2230 ObjCMethodDecl *Setter,
2231 SourceLocation PropertyLoc) {
2232 // Since these expressions can only be value-dependent, we do not
2233 // need to perform semantic analysis again.
2234 return Owned(
2235 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2236 VK_LValue, OK_ObjCProperty,
2237 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002238 }
2239
Douglas Gregord51d90d2010-04-26 20:11:03 +00002240 /// \brief Build a new Objective-C "isa" expression.
2241 ///
2242 /// By default, performs semantic analysis to build the new expression.
2243 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002244 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002245 bool IsArrow) {
2246 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002247 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002248 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2249 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002250 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002251 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002252 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002253 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002254 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002255
Douglas Gregord51d90d2010-04-26 20:11:03 +00002256 if (Result.get())
2257 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002258
John Wiegley01296292011-04-08 18:41:53 +00002259 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002260 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002261 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002262 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002263 /*TemplateArgs=*/0);
2264 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002265
Douglas Gregora16548e2009-08-11 05:31:07 +00002266 /// \brief Build a new shuffle vector expression.
2267 ///
2268 /// By default, performs semantic analysis to build the new expression.
2269 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002270 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002271 MultiExprArg SubExprs,
2272 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002273 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002274 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2276 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2277 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2278 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002279
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 // Build a reference to the __builtin_shufflevector builtin
2281 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002282 ExprResult Callee
2283 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2284 VK_LValue, BuiltinLoc));
2285 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2286 if (Callee.isInvalid())
2287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002288
2289 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 unsigned NumSubExprs = SubExprs.size();
2291 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002292 ExprResult TheCall = SemaRef.Owned(
2293 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002294 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002295 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002296 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002297 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002298
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002300 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 }
John McCall31f82722010-11-12 08:19:04 +00002302
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002303 /// \brief Build a new template argument pack expansion.
2304 ///
2305 /// By default, performs semantic analysis to build a new pack expansion
2306 /// for a template argument. Subclasses may override this routine to provide
2307 /// different behavior.
2308 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002309 SourceLocation EllipsisLoc,
2310 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002311 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002312 case TemplateArgument::Expression: {
2313 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002314 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2315 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002316 if (Result.isInvalid())
2317 return TemplateArgumentLoc();
2318
2319 return TemplateArgumentLoc(Result.get(), Result.get());
2320 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002321
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002322 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002323 return TemplateArgumentLoc(TemplateArgument(
2324 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002325 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002326 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002327 Pattern.getTemplateNameLoc(),
2328 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002329
2330 case TemplateArgument::Null:
2331 case TemplateArgument::Integral:
2332 case TemplateArgument::Declaration:
2333 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002334 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002335 llvm_unreachable("Pack expansion pattern has no parameter packs");
2336
2337 case TemplateArgument::Type:
2338 if (TypeSourceInfo *Expansion
2339 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002340 EllipsisLoc,
2341 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002342 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2343 Expansion);
2344 break;
2345 }
2346
2347 return TemplateArgumentLoc();
2348 }
2349
Douglas Gregor968f23a2011-01-03 19:31:53 +00002350 /// \brief Build a new expression pack expansion.
2351 ///
2352 /// By default, performs semantic analysis to build a new pack expansion
2353 /// for an expression. Subclasses may override this routine to provide
2354 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002355 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2356 llvm::Optional<unsigned> NumExpansions) {
2357 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002358 }
2359
John McCall31f82722010-11-12 08:19:04 +00002360private:
Douglas Gregor14454802011-02-25 02:25:35 +00002361 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2362 QualType ObjectType,
2363 NamedDecl *FirstQualifierInScope,
2364 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002365
2366 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2367 QualType ObjectType,
2368 NamedDecl *FirstQualifierInScope,
2369 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002370};
Douglas Gregora16548e2009-08-11 05:31:07 +00002371
Douglas Gregorebe10102009-08-20 07:17:43 +00002372template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002373StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002374 if (!S)
2375 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002376
Douglas Gregorebe10102009-08-20 07:17:43 +00002377 switch (S->getStmtClass()) {
2378 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002379
Douglas Gregorebe10102009-08-20 07:17:43 +00002380 // Transform individual statement nodes
2381#define STMT(Node, Parent) \
2382 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002383#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002384#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002385#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002386
Douglas Gregorebe10102009-08-20 07:17:43 +00002387 // Transform expressions by calling TransformExpr.
2388#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002389#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002390#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002391#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002392 {
John McCalldadc5752010-08-24 06:29:42 +00002393 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002394 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002395 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002396
John McCallb268a282010-08-23 23:25:46 +00002397 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002398 }
Mike Stump11289f42009-09-09 15:08:12 +00002399 }
2400
John McCallc3007a22010-10-26 07:05:15 +00002401 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002402}
Mike Stump11289f42009-09-09 15:08:12 +00002403
2404
Douglas Gregore922c772009-08-04 22:27:00 +00002405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002406ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 if (!E)
2408 return SemaRef.Owned(E);
2409
2410 switch (E->getStmtClass()) {
2411 case Stmt::NoStmtClass: break;
2412#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002413#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002414#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002415 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002416#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002417 }
2418
John McCallc3007a22010-10-26 07:05:15 +00002419 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002420}
2421
2422template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002423bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2424 unsigned NumInputs,
2425 bool IsCall,
2426 llvm::SmallVectorImpl<Expr *> &Outputs,
2427 bool *ArgChanged) {
2428 for (unsigned I = 0; I != NumInputs; ++I) {
2429 // If requested, drop call arguments that need to be dropped.
2430 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2431 if (ArgChanged)
2432 *ArgChanged = true;
2433
2434 break;
2435 }
2436
Douglas Gregor968f23a2011-01-03 19:31:53 +00002437 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2438 Expr *Pattern = Expansion->getPattern();
2439
2440 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2441 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2442 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2443
2444 // Determine whether the set of unexpanded parameter packs can and should
2445 // be expanded.
2446 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002447 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002448 llvm::Optional<unsigned> OrigNumExpansions
2449 = Expansion->getNumExpansions();
2450 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002451 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2452 Pattern->getSourceRange(),
2453 Unexpanded.data(),
2454 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002455 Expand, RetainExpansion,
2456 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002457 return true;
2458
2459 if (!Expand) {
2460 // The transform has determined that we should perform a simple
2461 // transformation on the pack expansion, producing another pack
2462 // expansion.
2463 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2464 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2465 if (OutPattern.isInvalid())
2466 return true;
2467
2468 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002469 Expansion->getEllipsisLoc(),
2470 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002471 if (Out.isInvalid())
2472 return true;
2473
2474 if (ArgChanged)
2475 *ArgChanged = true;
2476 Outputs.push_back(Out.get());
2477 continue;
2478 }
2479
2480 // The transform has determined that we should perform an elementwise
2481 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002482 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002483 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2484 ExprResult Out = getDerived().TransformExpr(Pattern);
2485 if (Out.isInvalid())
2486 return true;
2487
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002488 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002489 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2490 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002491 if (Out.isInvalid())
2492 return true;
2493 }
2494
Douglas Gregor968f23a2011-01-03 19:31:53 +00002495 if (ArgChanged)
2496 *ArgChanged = true;
2497 Outputs.push_back(Out.get());
2498 }
2499
2500 continue;
2501 }
2502
Douglas Gregora3efea12011-01-03 19:04:46 +00002503 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2504 if (Result.isInvalid())
2505 return true;
2506
2507 if (Result.get() != Inputs[I] && ArgChanged)
2508 *ArgChanged = true;
2509
2510 Outputs.push_back(Result.get());
2511 }
2512
2513 return false;
2514}
2515
2516template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002517NestedNameSpecifierLoc
2518TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2519 NestedNameSpecifierLoc NNS,
2520 QualType ObjectType,
2521 NamedDecl *FirstQualifierInScope) {
2522 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2523 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2524 Qualifier = Qualifier.getPrefix())
2525 Qualifiers.push_back(Qualifier);
2526
2527 CXXScopeSpec SS;
2528 while (!Qualifiers.empty()) {
2529 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2530 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2531
2532 switch (QNNS->getKind()) {
2533 case NestedNameSpecifier::Identifier:
2534 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2535 *QNNS->getAsIdentifier(),
2536 Q.getLocalBeginLoc(),
2537 Q.getLocalEndLoc(),
2538 ObjectType, false, SS,
2539 FirstQualifierInScope, false))
2540 return NestedNameSpecifierLoc();
2541
2542 break;
2543
2544 case NestedNameSpecifier::Namespace: {
2545 NamespaceDecl *NS
2546 = cast_or_null<NamespaceDecl>(
2547 getDerived().TransformDecl(
2548 Q.getLocalBeginLoc(),
2549 QNNS->getAsNamespace()));
2550 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2551 break;
2552 }
2553
2554 case NestedNameSpecifier::NamespaceAlias: {
2555 NamespaceAliasDecl *Alias
2556 = cast_or_null<NamespaceAliasDecl>(
2557 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2558 QNNS->getAsNamespaceAlias()));
2559 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2560 Q.getLocalEndLoc());
2561 break;
2562 }
2563
2564 case NestedNameSpecifier::Global:
2565 // There is no meaningful transformation that one could perform on the
2566 // global scope.
2567 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2568 break;
2569
2570 case NestedNameSpecifier::TypeSpecWithTemplate:
2571 case NestedNameSpecifier::TypeSpec: {
2572 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2573 FirstQualifierInScope, SS);
2574
2575 if (!TL)
2576 return NestedNameSpecifierLoc();
2577
2578 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2579 (SemaRef.getLangOptions().CPlusPlus0x &&
2580 TL.getType()->isEnumeralType())) {
2581 assert(!TL.getType().hasLocalQualifiers() &&
2582 "Can't get cv-qualifiers here");
2583 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2584 Q.getLocalEndLoc());
2585 break;
2586 }
Richard Trieude756fb2011-05-07 01:36:37 +00002587 // If the nested-name-specifier is an invalid type def, don't emit an
2588 // error because a previous error should have already been emitted.
2589 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2590 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2591 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2592 << TL.getType() << SS.getRange();
2593 }
Douglas Gregor14454802011-02-25 02:25:35 +00002594 return NestedNameSpecifierLoc();
2595 }
Douglas Gregore16af532011-02-28 18:50:33 +00002596 }
Douglas Gregor14454802011-02-25 02:25:35 +00002597
Douglas Gregore16af532011-02-28 18:50:33 +00002598 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002599 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002600 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002601 }
2602
2603 // Don't rebuild the nested-name-specifier if we don't have to.
2604 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2605 !getDerived().AlwaysRebuild())
2606 return NNS;
2607
2608 // If we can re-use the source-location data from the original
2609 // nested-name-specifier, do so.
2610 if (SS.location_size() == NNS.getDataLength() &&
2611 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2612 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2613
2614 // Allocate new nested-name-specifier location information.
2615 return SS.getWithLocInContext(SemaRef.Context);
2616}
2617
2618template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002619DeclarationNameInfo
2620TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002621::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002622 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002623 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002624 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002625
2626 switch (Name.getNameKind()) {
2627 case DeclarationName::Identifier:
2628 case DeclarationName::ObjCZeroArgSelector:
2629 case DeclarationName::ObjCOneArgSelector:
2630 case DeclarationName::ObjCMultiArgSelector:
2631 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002632 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002633 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002634 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002635
Douglas Gregorf816bd72009-09-03 22:13:48 +00002636 case DeclarationName::CXXConstructorName:
2637 case DeclarationName::CXXDestructorName:
2638 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002639 TypeSourceInfo *NewTInfo;
2640 CanQualType NewCanTy;
2641 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002642 NewTInfo = getDerived().TransformType(OldTInfo);
2643 if (!NewTInfo)
2644 return DeclarationNameInfo();
2645 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002646 }
2647 else {
2648 NewTInfo = 0;
2649 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002650 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002651 if (NewT.isNull())
2652 return DeclarationNameInfo();
2653 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2654 }
Mike Stump11289f42009-09-09 15:08:12 +00002655
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002656 DeclarationName NewName
2657 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2658 NewCanTy);
2659 DeclarationNameInfo NewNameInfo(NameInfo);
2660 NewNameInfo.setName(NewName);
2661 NewNameInfo.setNamedTypeInfo(NewTInfo);
2662 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002663 }
Mike Stump11289f42009-09-09 15:08:12 +00002664 }
2665
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002666 assert(0 && "Unknown name kind.");
2667 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002668}
2669
2670template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002671TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002672TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2673 TemplateName Name,
2674 SourceLocation NameLoc,
2675 QualType ObjectType,
2676 NamedDecl *FirstQualifierInScope) {
2677 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2678 TemplateDecl *Template = QTN->getTemplateDecl();
2679 assert(Template && "qualified template name must refer to a template");
2680
2681 TemplateDecl *TransTemplate
2682 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2683 Template));
2684 if (!TransTemplate)
2685 return TemplateName();
2686
2687 if (!getDerived().AlwaysRebuild() &&
2688 SS.getScopeRep() == QTN->getQualifier() &&
2689 TransTemplate == Template)
2690 return Name;
2691
2692 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2693 TransTemplate);
2694 }
2695
2696 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2697 if (SS.getScopeRep()) {
2698 // These apply to the scope specifier, not the template.
2699 ObjectType = QualType();
2700 FirstQualifierInScope = 0;
2701 }
2702
2703 if (!getDerived().AlwaysRebuild() &&
2704 SS.getScopeRep() == DTN->getQualifier() &&
2705 ObjectType.isNull())
2706 return Name;
2707
2708 if (DTN->isIdentifier()) {
2709 return getDerived().RebuildTemplateName(SS,
2710 *DTN->getIdentifier(),
2711 NameLoc,
2712 ObjectType,
2713 FirstQualifierInScope);
2714 }
2715
2716 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2717 ObjectType);
2718 }
2719
2720 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2721 TemplateDecl *TransTemplate
2722 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2723 Template));
2724 if (!TransTemplate)
2725 return TemplateName();
2726
2727 if (!getDerived().AlwaysRebuild() &&
2728 TransTemplate == Template)
2729 return Name;
2730
2731 return TemplateName(TransTemplate);
2732 }
2733
2734 if (SubstTemplateTemplateParmPackStorage *SubstPack
2735 = Name.getAsSubstTemplateTemplateParmPack()) {
2736 TemplateTemplateParmDecl *TransParam
2737 = cast_or_null<TemplateTemplateParmDecl>(
2738 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2739 if (!TransParam)
2740 return TemplateName();
2741
2742 if (!getDerived().AlwaysRebuild() &&
2743 TransParam == SubstPack->getParameterPack())
2744 return Name;
2745
2746 return getDerived().RebuildTemplateName(TransParam,
2747 SubstPack->getArgumentPack());
2748 }
2749
2750 // These should be getting filtered out before they reach the AST.
2751 llvm_unreachable("overloaded function decl survived to here");
2752 return TemplateName();
2753}
2754
2755template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002756void TreeTransform<Derived>::InventTemplateArgumentLoc(
2757 const TemplateArgument &Arg,
2758 TemplateArgumentLoc &Output) {
2759 SourceLocation Loc = getDerived().getBaseLocation();
2760 switch (Arg.getKind()) {
2761 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002762 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002763 break;
2764
2765 case TemplateArgument::Type:
2766 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002767 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002768
John McCall0ad16662009-10-29 08:12:44 +00002769 break;
2770
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002771 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002772 case TemplateArgument::TemplateExpansion: {
2773 NestedNameSpecifierLocBuilder Builder;
2774 TemplateName Template = Arg.getAsTemplate();
2775 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2776 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2777 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2778 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2779
2780 if (Arg.getKind() == TemplateArgument::Template)
2781 Output = TemplateArgumentLoc(Arg,
2782 Builder.getWithLocInContext(SemaRef.Context),
2783 Loc);
2784 else
2785 Output = TemplateArgumentLoc(Arg,
2786 Builder.getWithLocInContext(SemaRef.Context),
2787 Loc, Loc);
2788
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002789 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002790 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002791
John McCall0ad16662009-10-29 08:12:44 +00002792 case TemplateArgument::Expression:
2793 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2794 break;
2795
2796 case TemplateArgument::Declaration:
2797 case TemplateArgument::Integral:
2798 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002799 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002800 break;
2801 }
2802}
2803
2804template<typename Derived>
2805bool TreeTransform<Derived>::TransformTemplateArgument(
2806 const TemplateArgumentLoc &Input,
2807 TemplateArgumentLoc &Output) {
2808 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002809 switch (Arg.getKind()) {
2810 case TemplateArgument::Null:
2811 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002812 Output = Input;
2813 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002814
Douglas Gregore922c772009-08-04 22:27:00 +00002815 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002816 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002817 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002818 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002819
2820 DI = getDerived().TransformType(DI);
2821 if (!DI) return true;
2822
2823 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2824 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002825 }
Mike Stump11289f42009-09-09 15:08:12 +00002826
Douglas Gregore922c772009-08-04 22:27:00 +00002827 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002828 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002829 DeclarationName Name;
2830 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2831 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002832 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002833 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002834 if (!D) return true;
2835
John McCall0d07eb32009-10-29 18:45:58 +00002836 Expr *SourceExpr = Input.getSourceDeclExpression();
2837 if (SourceExpr) {
2838 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002839 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002840 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002841 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002842 }
2843
2844 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002845 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002846 }
Mike Stump11289f42009-09-09 15:08:12 +00002847
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002848 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002849 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2850 if (QualifierLoc) {
2851 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2852 if (!QualifierLoc)
2853 return true;
2854 }
2855
Douglas Gregordf846d12011-03-02 18:46:51 +00002856 CXXScopeSpec SS;
2857 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002858 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002859 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2860 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002861 if (Template.isNull())
2862 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002863
Douglas Gregor9d802122011-03-02 17:09:35 +00002864 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002865 Input.getTemplateNameLoc());
2866 return false;
2867 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002868
2869 case TemplateArgument::TemplateExpansion:
2870 llvm_unreachable("Caller should expand pack expansions");
2871
Douglas Gregore922c772009-08-04 22:27:00 +00002872 case TemplateArgument::Expression: {
2873 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002874 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002875 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002876
John McCall0ad16662009-10-29 08:12:44 +00002877 Expr *InputExpr = Input.getSourceExpression();
2878 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2879
Chris Lattnercdb591a2011-04-25 20:37:58 +00002880 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002881 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002882 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002883 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002884 }
Mike Stump11289f42009-09-09 15:08:12 +00002885
Douglas Gregore922c772009-08-04 22:27:00 +00002886 case TemplateArgument::Pack: {
2887 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2888 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002889 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002890 AEnd = Arg.pack_end();
2891 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002892
John McCall0ad16662009-10-29 08:12:44 +00002893 // FIXME: preserve source information here when we start
2894 // caring about parameter packs.
2895
John McCall0d07eb32009-10-29 18:45:58 +00002896 TemplateArgumentLoc InputArg;
2897 TemplateArgumentLoc OutputArg;
2898 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2899 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002900 return true;
2901
John McCall0d07eb32009-10-29 18:45:58 +00002902 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002903 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002904
2905 TemplateArgument *TransformedArgsPtr
2906 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2907 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2908 TransformedArgsPtr);
2909 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2910 TransformedArgs.size()),
2911 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002912 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002913 }
2914 }
Mike Stump11289f42009-09-09 15:08:12 +00002915
Douglas Gregore922c772009-08-04 22:27:00 +00002916 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002917 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002918}
2919
Douglas Gregorfe921a72010-12-20 23:36:19 +00002920/// \brief Iterator adaptor that invents template argument location information
2921/// for each of the template arguments in its underlying iterator.
2922template<typename Derived, typename InputIterator>
2923class TemplateArgumentLocInventIterator {
2924 TreeTransform<Derived> &Self;
2925 InputIterator Iter;
2926
2927public:
2928 typedef TemplateArgumentLoc value_type;
2929 typedef TemplateArgumentLoc reference;
2930 typedef typename std::iterator_traits<InputIterator>::difference_type
2931 difference_type;
2932 typedef std::input_iterator_tag iterator_category;
2933
2934 class pointer {
2935 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002936
Douglas Gregorfe921a72010-12-20 23:36:19 +00002937 public:
2938 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2939
2940 const TemplateArgumentLoc *operator->() const { return &Arg; }
2941 };
2942
2943 TemplateArgumentLocInventIterator() { }
2944
2945 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2946 InputIterator Iter)
2947 : Self(Self), Iter(Iter) { }
2948
2949 TemplateArgumentLocInventIterator &operator++() {
2950 ++Iter;
2951 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002952 }
2953
Douglas Gregorfe921a72010-12-20 23:36:19 +00002954 TemplateArgumentLocInventIterator operator++(int) {
2955 TemplateArgumentLocInventIterator Old(*this);
2956 ++(*this);
2957 return Old;
2958 }
2959
2960 reference operator*() const {
2961 TemplateArgumentLoc Result;
2962 Self.InventTemplateArgumentLoc(*Iter, Result);
2963 return Result;
2964 }
2965
2966 pointer operator->() const { return pointer(**this); }
2967
2968 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2969 const TemplateArgumentLocInventIterator &Y) {
2970 return X.Iter == Y.Iter;
2971 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002972
Douglas Gregorfe921a72010-12-20 23:36:19 +00002973 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2974 const TemplateArgumentLocInventIterator &Y) {
2975 return X.Iter != Y.Iter;
2976 }
2977};
2978
Douglas Gregor42cafa82010-12-20 17:42:22 +00002979template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002980template<typename InputIterator>
2981bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2982 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002983 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002984 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002985 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002986 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002987
2988 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2989 // Unpack argument packs, which we translate them into separate
2990 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002991 // FIXME: We could do much better if we could guarantee that the
2992 // TemplateArgumentLocInfo for the pack expansion would be usable for
2993 // all of the template arguments in the argument pack.
2994 typedef TemplateArgumentLocInventIterator<Derived,
2995 TemplateArgument::pack_iterator>
2996 PackLocIterator;
2997 if (TransformTemplateArguments(PackLocIterator(*this,
2998 In.getArgument().pack_begin()),
2999 PackLocIterator(*this,
3000 In.getArgument().pack_end()),
3001 Outputs))
3002 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003003
3004 continue;
3005 }
3006
3007 if (In.getArgument().isPackExpansion()) {
3008 // We have a pack expansion, for which we will be substituting into
3009 // the pattern.
3010 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003011 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003012 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003013 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3014 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003015
3016 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3017 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3018 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3019
3020 // Determine whether the set of unexpanded parameter packs can and should
3021 // be expanded.
3022 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003023 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003024 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003025 if (getDerived().TryExpandParameterPacks(Ellipsis,
3026 Pattern.getSourceRange(),
3027 Unexpanded.data(),
3028 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003029 Expand,
3030 RetainExpansion,
3031 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003032 return true;
3033
3034 if (!Expand) {
3035 // The transform has determined that we should perform a simple
3036 // transformation on the pack expansion, producing another pack
3037 // expansion.
3038 TemplateArgumentLoc OutPattern;
3039 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3040 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3041 return true;
3042
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003043 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3044 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003045 if (Out.getArgument().isNull())
3046 return true;
3047
3048 Outputs.addArgument(Out);
3049 continue;
3050 }
3051
3052 // The transform has determined that we should perform an elementwise
3053 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003054 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003055 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3056
3057 if (getDerived().TransformTemplateArgument(Pattern, Out))
3058 return true;
3059
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003060 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003061 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3062 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003063 if (Out.getArgument().isNull())
3064 return true;
3065 }
3066
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003067 Outputs.addArgument(Out);
3068 }
3069
Douglas Gregor48d24112011-01-10 20:53:55 +00003070 // If we're supposed to retain a pack expansion, do so by temporarily
3071 // forgetting the partially-substituted parameter pack.
3072 if (RetainExpansion) {
3073 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3074
3075 if (getDerived().TransformTemplateArgument(Pattern, Out))
3076 return true;
3077
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003078 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3079 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003080 if (Out.getArgument().isNull())
3081 return true;
3082
3083 Outputs.addArgument(Out);
3084 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003085
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003086 continue;
3087 }
3088
3089 // The simple case:
3090 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003091 return true;
3092
3093 Outputs.addArgument(Out);
3094 }
3095
3096 return false;
3097
3098}
3099
Douglas Gregord6ff3322009-08-04 16:50:30 +00003100//===----------------------------------------------------------------------===//
3101// Type transformation
3102//===----------------------------------------------------------------------===//
3103
3104template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003105QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003106 if (getDerived().AlreadyTransformed(T))
3107 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003108
John McCall550e0c22009-10-21 00:40:46 +00003109 // Temporary workaround. All of these transformations should
3110 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003111 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3112 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003113
John McCall31f82722010-11-12 08:19:04 +00003114 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003115
John McCall550e0c22009-10-21 00:40:46 +00003116 if (!NewDI)
3117 return QualType();
3118
3119 return NewDI->getType();
3120}
3121
3122template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003123TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003124 if (getDerived().AlreadyTransformed(DI->getType()))
3125 return DI;
3126
3127 TypeLocBuilder TLB;
3128
3129 TypeLoc TL = DI->getTypeLoc();
3130 TLB.reserve(TL.getFullDataSize());
3131
John McCall31f82722010-11-12 08:19:04 +00003132 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003133 if (Result.isNull())
3134 return 0;
3135
John McCallbcd03502009-12-07 02:54:59 +00003136 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003137}
3138
3139template<typename Derived>
3140QualType
John McCall31f82722010-11-12 08:19:04 +00003141TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003142 switch (T.getTypeLocClass()) {
3143#define ABSTRACT_TYPELOC(CLASS, PARENT)
3144#define TYPELOC(CLASS, PARENT) \
3145 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003146 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003147#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003148 }
Mike Stump11289f42009-09-09 15:08:12 +00003149
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003150 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003151 return QualType();
3152}
3153
3154/// FIXME: By default, this routine adds type qualifiers only to types
3155/// that can have qualifiers, and silently suppresses those qualifiers
3156/// that are not permitted (e.g., qualifiers on reference or function
3157/// types). This is the right thing for template instantiation, but
3158/// probably not for other clients.
3159template<typename Derived>
3160QualType
3161TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003162 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003163 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003164
John McCall31f82722010-11-12 08:19:04 +00003165 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003166 if (Result.isNull())
3167 return QualType();
3168
3169 // Silently suppress qualifiers if the result type can't be qualified.
3170 // FIXME: this is the right thing for template instantiation, but
3171 // probably not for other clients.
3172 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003173 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003174
John McCall31168b02011-06-15 23:02:42 +00003175 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003176 // resulting type.
3177 if (Quals.hasObjCLifetime()) {
3178 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3179 Quals.removeObjCLifetime();
3180 else if (Result.getObjCLifetime() &&
3181 Result.getObjCLifetime() != Quals.getObjCLifetime()) {
3182 // Objective-C ARC:
3183 // A lifetime qualifier applied to a substituted template parameter
3184 // overrides the lifetime qualifier from the template argument.
3185 if (const SubstTemplateTypeParmType *SubstTypeParam
3186 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3187 QualType Replacement = SubstTypeParam->getReplacementType();
3188 Qualifiers Qs = Replacement.getQualifiers();
3189 Qs.removeObjCLifetime();
3190 Replacement
3191 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3192 Qs);
3193 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3194 SubstTypeParam->getReplacedParameter(),
3195 Replacement);
3196 TLB.TypeWasModifiedSafely(Result);
3197 } else {
3198 // Otherwise, drop the new qualifier.
3199 // FIXME: I don't recall the justification for this!
3200 Quals.removeObjCLifetime();
3201 }
3202 }
3203 }
John McCallcb0f89a2010-06-05 06:41:15 +00003204 if (!Quals.empty()) {
3205 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3206 TLB.push<QualifiedTypeLoc>(Result);
3207 // No location information to preserve.
3208 }
John McCall550e0c22009-10-21 00:40:46 +00003209
3210 return Result;
3211}
3212
Douglas Gregor14454802011-02-25 02:25:35 +00003213template<typename Derived>
3214TypeLoc
3215TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3216 QualType ObjectType,
3217 NamedDecl *UnqualLookup,
3218 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003219 QualType T = TL.getType();
3220 if (getDerived().AlreadyTransformed(T))
3221 return TL;
3222
3223 TypeLocBuilder TLB;
3224 QualType Result;
3225
3226 if (isa<TemplateSpecializationType>(T)) {
3227 TemplateSpecializationTypeLoc SpecTL
3228 = cast<TemplateSpecializationTypeLoc>(TL);
3229
3230 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003231 getDerived().TransformTemplateName(SS,
3232 SpecTL.getTypePtr()->getTemplateName(),
3233 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003234 ObjectType, UnqualLookup);
3235 if (Template.isNull())
3236 return TypeLoc();
3237
3238 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3239 Template);
3240 } else if (isa<DependentTemplateSpecializationType>(T)) {
3241 DependentTemplateSpecializationTypeLoc SpecTL
3242 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3243
Douglas Gregor5a064722011-02-28 17:23:35 +00003244 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003245 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003246 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003247 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003248 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003249 if (Template.isNull())
3250 return TypeLoc();
3251
Douglas Gregor14454802011-02-25 02:25:35 +00003252 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003253 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003254 Template,
3255 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003256 } else {
3257 // Nothing special needs to be done for these.
3258 Result = getDerived().TransformType(TLB, TL);
3259 }
3260
3261 if (Result.isNull())
3262 return TypeLoc();
3263
3264 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3265}
3266
Douglas Gregor579c15f2011-03-02 18:32:08 +00003267template<typename Derived>
3268TypeSourceInfo *
3269TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3270 QualType ObjectType,
3271 NamedDecl *UnqualLookup,
3272 CXXScopeSpec &SS) {
3273 // FIXME: Painfully copy-paste from the above!
3274
3275 QualType T = TSInfo->getType();
3276 if (getDerived().AlreadyTransformed(T))
3277 return TSInfo;
3278
3279 TypeLocBuilder TLB;
3280 QualType Result;
3281
3282 TypeLoc TL = TSInfo->getTypeLoc();
3283 if (isa<TemplateSpecializationType>(T)) {
3284 TemplateSpecializationTypeLoc SpecTL
3285 = cast<TemplateSpecializationTypeLoc>(TL);
3286
3287 TemplateName Template
3288 = getDerived().TransformTemplateName(SS,
3289 SpecTL.getTypePtr()->getTemplateName(),
3290 SpecTL.getTemplateNameLoc(),
3291 ObjectType, UnqualLookup);
3292 if (Template.isNull())
3293 return 0;
3294
3295 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3296 Template);
3297 } else if (isa<DependentTemplateSpecializationType>(T)) {
3298 DependentTemplateSpecializationTypeLoc SpecTL
3299 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3300
3301 TemplateName Template
3302 = getDerived().RebuildTemplateName(SS,
3303 *SpecTL.getTypePtr()->getIdentifier(),
3304 SpecTL.getNameLoc(),
3305 ObjectType, UnqualLookup);
3306 if (Template.isNull())
3307 return 0;
3308
3309 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3310 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003311 Template,
3312 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003313 } else {
3314 // Nothing special needs to be done for these.
3315 Result = getDerived().TransformType(TLB, TL);
3316 }
3317
3318 if (Result.isNull())
3319 return 0;
3320
3321 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3322}
3323
John McCall550e0c22009-10-21 00:40:46 +00003324template <class TyLoc> static inline
3325QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3326 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3327 NewT.setNameLoc(T.getNameLoc());
3328 return T.getType();
3329}
3330
John McCall550e0c22009-10-21 00:40:46 +00003331template<typename Derived>
3332QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003333 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003334 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3335 NewT.setBuiltinLoc(T.getBuiltinLoc());
3336 if (T.needsExtraLocalData())
3337 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3338 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003339}
Mike Stump11289f42009-09-09 15:08:12 +00003340
Douglas Gregord6ff3322009-08-04 16:50:30 +00003341template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003342QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003343 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003344 // FIXME: recurse?
3345 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003346}
Mike Stump11289f42009-09-09 15:08:12 +00003347
Douglas Gregord6ff3322009-08-04 16:50:30 +00003348template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003349QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003350 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003351 QualType PointeeType
3352 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003353 if (PointeeType.isNull())
3354 return QualType();
3355
3356 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003357 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003358 // A dependent pointer type 'T *' has is being transformed such
3359 // that an Objective-C class type is being replaced for 'T'. The
3360 // resulting pointer type is an ObjCObjectPointerType, not a
3361 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003362 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003363
John McCall8b07ec22010-05-15 11:32:37 +00003364 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3365 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003366 return Result;
3367 }
John McCall31f82722010-11-12 08:19:04 +00003368
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003369 if (getDerived().AlwaysRebuild() ||
3370 PointeeType != TL.getPointeeLoc().getType()) {
3371 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3372 if (Result.isNull())
3373 return QualType();
3374 }
John McCall31168b02011-06-15 23:02:42 +00003375
3376 // Objective-C ARC can add lifetime qualifiers to the type that we're
3377 // pointing to.
3378 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3379
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003380 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3381 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003382 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003383}
Mike Stump11289f42009-09-09 15:08:12 +00003384
3385template<typename Derived>
3386QualType
John McCall550e0c22009-10-21 00:40:46 +00003387TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003388 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003389 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003390 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3391 if (PointeeType.isNull())
3392 return QualType();
3393
3394 QualType Result = TL.getType();
3395 if (getDerived().AlwaysRebuild() ||
3396 PointeeType != TL.getPointeeLoc().getType()) {
3397 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003398 TL.getSigilLoc());
3399 if (Result.isNull())
3400 return QualType();
3401 }
3402
Douglas Gregor049211a2010-04-22 16:50:51 +00003403 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003404 NewT.setSigilLoc(TL.getSigilLoc());
3405 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003406}
3407
John McCall70dd5f62009-10-30 00:06:24 +00003408/// Transforms a reference type. Note that somewhat paradoxically we
3409/// don't care whether the type itself is an l-value type or an r-value
3410/// type; we only care if the type was *written* as an l-value type
3411/// or an r-value type.
3412template<typename Derived>
3413QualType
3414TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003415 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003416 const ReferenceType *T = TL.getTypePtr();
3417
3418 // Note that this works with the pointee-as-written.
3419 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3420 if (PointeeType.isNull())
3421 return QualType();
3422
3423 QualType Result = TL.getType();
3424 if (getDerived().AlwaysRebuild() ||
3425 PointeeType != T->getPointeeTypeAsWritten()) {
3426 Result = getDerived().RebuildReferenceType(PointeeType,
3427 T->isSpelledAsLValue(),
3428 TL.getSigilLoc());
3429 if (Result.isNull())
3430 return QualType();
3431 }
3432
John McCall31168b02011-06-15 23:02:42 +00003433 // Objective-C ARC can add lifetime qualifiers to the type that we're
3434 // referring to.
3435 TLB.TypeWasModifiedSafely(
3436 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3437
John McCall70dd5f62009-10-30 00:06:24 +00003438 // r-value references can be rebuilt as l-value references.
3439 ReferenceTypeLoc NewTL;
3440 if (isa<LValueReferenceType>(Result))
3441 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3442 else
3443 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3444 NewTL.setSigilLoc(TL.getSigilLoc());
3445
3446 return Result;
3447}
3448
Mike Stump11289f42009-09-09 15:08:12 +00003449template<typename Derived>
3450QualType
John McCall550e0c22009-10-21 00:40:46 +00003451TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003452 LValueReferenceTypeLoc TL) {
3453 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003454}
3455
Mike Stump11289f42009-09-09 15:08:12 +00003456template<typename Derived>
3457QualType
John McCall550e0c22009-10-21 00:40:46 +00003458TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003459 RValueReferenceTypeLoc TL) {
3460 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003461}
Mike Stump11289f42009-09-09 15:08:12 +00003462
Douglas Gregord6ff3322009-08-04 16:50:30 +00003463template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003464QualType
John McCall550e0c22009-10-21 00:40:46 +00003465TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003466 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003467 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003468 if (PointeeType.isNull())
3469 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003470
Abramo Bagnara509357842011-03-05 14:42:21 +00003471 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3472 TypeSourceInfo* NewClsTInfo = 0;
3473 if (OldClsTInfo) {
3474 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3475 if (!NewClsTInfo)
3476 return QualType();
3477 }
3478
3479 const MemberPointerType *T = TL.getTypePtr();
3480 QualType OldClsType = QualType(T->getClass(), 0);
3481 QualType NewClsType;
3482 if (NewClsTInfo)
3483 NewClsType = NewClsTInfo->getType();
3484 else {
3485 NewClsType = getDerived().TransformType(OldClsType);
3486 if (NewClsType.isNull())
3487 return QualType();
3488 }
Mike Stump11289f42009-09-09 15:08:12 +00003489
John McCall550e0c22009-10-21 00:40:46 +00003490 QualType Result = TL.getType();
3491 if (getDerived().AlwaysRebuild() ||
3492 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003493 NewClsType != OldClsType) {
3494 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003495 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003496 if (Result.isNull())
3497 return QualType();
3498 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003499
John McCall550e0c22009-10-21 00:40:46 +00003500 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3501 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003502 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003503
3504 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003505}
3506
Mike Stump11289f42009-09-09 15:08:12 +00003507template<typename Derived>
3508QualType
John McCall550e0c22009-10-21 00:40:46 +00003509TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003510 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003511 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003512 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003513 if (ElementType.isNull())
3514 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003515
John McCall550e0c22009-10-21 00:40:46 +00003516 QualType Result = TL.getType();
3517 if (getDerived().AlwaysRebuild() ||
3518 ElementType != T->getElementType()) {
3519 Result = getDerived().RebuildConstantArrayType(ElementType,
3520 T->getSizeModifier(),
3521 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003522 T->getIndexTypeCVRQualifiers(),
3523 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003524 if (Result.isNull())
3525 return QualType();
3526 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003527
John McCall550e0c22009-10-21 00:40:46 +00003528 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3529 NewTL.setLBracketLoc(TL.getLBracketLoc());
3530 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003531
John McCall550e0c22009-10-21 00:40:46 +00003532 Expr *Size = TL.getSizeExpr();
3533 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003534 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003535 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3536 }
3537 NewTL.setSizeExpr(Size);
3538
3539 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003540}
Mike Stump11289f42009-09-09 15:08:12 +00003541
Douglas Gregord6ff3322009-08-04 16:50:30 +00003542template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003543QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003544 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003545 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003546 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003547 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003548 if (ElementType.isNull())
3549 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003550
John McCall550e0c22009-10-21 00:40:46 +00003551 QualType Result = TL.getType();
3552 if (getDerived().AlwaysRebuild() ||
3553 ElementType != T->getElementType()) {
3554 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003555 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003556 T->getIndexTypeCVRQualifiers(),
3557 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003558 if (Result.isNull())
3559 return QualType();
3560 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003561
John McCall550e0c22009-10-21 00:40:46 +00003562 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3563 NewTL.setLBracketLoc(TL.getLBracketLoc());
3564 NewTL.setRBracketLoc(TL.getRBracketLoc());
3565 NewTL.setSizeExpr(0);
3566
3567 return Result;
3568}
3569
3570template<typename Derived>
3571QualType
3572TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003573 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003574 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003575 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3576 if (ElementType.isNull())
3577 return QualType();
3578
3579 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003580 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003581
John McCalldadc5752010-08-24 06:29:42 +00003582 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003583 = getDerived().TransformExpr(T->getSizeExpr());
3584 if (SizeResult.isInvalid())
3585 return QualType();
3586
John McCallb268a282010-08-23 23:25:46 +00003587 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003588
3589 QualType Result = TL.getType();
3590 if (getDerived().AlwaysRebuild() ||
3591 ElementType != T->getElementType() ||
3592 Size != T->getSizeExpr()) {
3593 Result = getDerived().RebuildVariableArrayType(ElementType,
3594 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003595 Size,
John McCall550e0c22009-10-21 00:40:46 +00003596 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003597 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003598 if (Result.isNull())
3599 return QualType();
3600 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003601
John McCall550e0c22009-10-21 00:40:46 +00003602 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3603 NewTL.setLBracketLoc(TL.getLBracketLoc());
3604 NewTL.setRBracketLoc(TL.getRBracketLoc());
3605 NewTL.setSizeExpr(Size);
3606
3607 return Result;
3608}
3609
3610template<typename Derived>
3611QualType
3612TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003613 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003614 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003615 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3616 if (ElementType.isNull())
3617 return QualType();
3618
3619 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003620 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003621
John McCall33ddac02011-01-19 10:06:00 +00003622 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3623 Expr *origSize = TL.getSizeExpr();
3624 if (!origSize) origSize = T->getSizeExpr();
3625
3626 ExprResult sizeResult
3627 = getDerived().TransformExpr(origSize);
3628 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003629 return QualType();
3630
John McCall33ddac02011-01-19 10:06:00 +00003631 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003632
3633 QualType Result = TL.getType();
3634 if (getDerived().AlwaysRebuild() ||
3635 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003636 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003637 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3638 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003639 size,
John McCall550e0c22009-10-21 00:40:46 +00003640 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003641 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003642 if (Result.isNull())
3643 return QualType();
3644 }
John McCall550e0c22009-10-21 00:40:46 +00003645
3646 // We might have any sort of array type now, but fortunately they
3647 // all have the same location layout.
3648 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3649 NewTL.setLBracketLoc(TL.getLBracketLoc());
3650 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003651 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003652
3653 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003654}
Mike Stump11289f42009-09-09 15:08:12 +00003655
3656template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003657QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003658 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003659 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003660 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003661
3662 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003663 QualType ElementType = getDerived().TransformType(T->getElementType());
3664 if (ElementType.isNull())
3665 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003666
Douglas Gregore922c772009-08-04 22:27:00 +00003667 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003668 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003669
John McCalldadc5752010-08-24 06:29:42 +00003670 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003671 if (Size.isInvalid())
3672 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003673
John McCall550e0c22009-10-21 00:40:46 +00003674 QualType Result = TL.getType();
3675 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003676 ElementType != T->getElementType() ||
3677 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003678 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003679 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003680 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003681 if (Result.isNull())
3682 return QualType();
3683 }
John McCall550e0c22009-10-21 00:40:46 +00003684
3685 // Result might be dependent or not.
3686 if (isa<DependentSizedExtVectorType>(Result)) {
3687 DependentSizedExtVectorTypeLoc NewTL
3688 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3689 NewTL.setNameLoc(TL.getNameLoc());
3690 } else {
3691 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3692 NewTL.setNameLoc(TL.getNameLoc());
3693 }
3694
3695 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003696}
Mike Stump11289f42009-09-09 15:08:12 +00003697
3698template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003699QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003700 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003701 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003702 QualType ElementType = getDerived().TransformType(T->getElementType());
3703 if (ElementType.isNull())
3704 return QualType();
3705
John McCall550e0c22009-10-21 00:40:46 +00003706 QualType Result = TL.getType();
3707 if (getDerived().AlwaysRebuild() ||
3708 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003709 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003710 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003711 if (Result.isNull())
3712 return QualType();
3713 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003714
John McCall550e0c22009-10-21 00:40:46 +00003715 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3716 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003717
John McCall550e0c22009-10-21 00:40:46 +00003718 return Result;
3719}
3720
3721template<typename Derived>
3722QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003723 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003724 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003725 QualType ElementType = getDerived().TransformType(T->getElementType());
3726 if (ElementType.isNull())
3727 return QualType();
3728
3729 QualType Result = TL.getType();
3730 if (getDerived().AlwaysRebuild() ||
3731 ElementType != T->getElementType()) {
3732 Result = getDerived().RebuildExtVectorType(ElementType,
3733 T->getNumElements(),
3734 /*FIXME*/ SourceLocation());
3735 if (Result.isNull())
3736 return QualType();
3737 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003738
John McCall550e0c22009-10-21 00:40:46 +00003739 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3740 NewTL.setNameLoc(TL.getNameLoc());
3741
3742 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003743}
Mike Stump11289f42009-09-09 15:08:12 +00003744
3745template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003746ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003747TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003748 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003749 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003750 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003751 TypeSourceInfo *NewDI = 0;
3752
3753 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3754 // If we're substituting into a pack expansion type and we know the
3755 TypeLoc OldTL = OldDI->getTypeLoc();
3756 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3757
3758 TypeLocBuilder TLB;
3759 TypeLoc NewTL = OldDI->getTypeLoc();
3760 TLB.reserve(NewTL.getFullDataSize());
3761
3762 QualType Result = getDerived().TransformType(TLB,
3763 OldExpansionTL.getPatternLoc());
3764 if (Result.isNull())
3765 return 0;
3766
3767 Result = RebuildPackExpansionType(Result,
3768 OldExpansionTL.getPatternLoc().getSourceRange(),
3769 OldExpansionTL.getEllipsisLoc(),
3770 NumExpansions);
3771 if (Result.isNull())
3772 return 0;
3773
3774 PackExpansionTypeLoc NewExpansionTL
3775 = TLB.push<PackExpansionTypeLoc>(Result);
3776 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3777 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3778 } else
3779 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003780 if (!NewDI)
3781 return 0;
3782
John McCall8fb0d9d2011-05-01 22:35:37 +00003783 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003784 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003785
3786 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3787 OldParm->getDeclContext(),
3788 OldParm->getInnerLocStart(),
3789 OldParm->getLocation(),
3790 OldParm->getIdentifier(),
3791 NewDI->getType(),
3792 NewDI,
3793 OldParm->getStorageClass(),
3794 OldParm->getStorageClassAsWritten(),
3795 /* DefArg */ NULL);
3796 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3797 OldParm->getFunctionScopeIndex() + indexAdjustment);
3798 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003799}
3800
3801template<typename Derived>
3802bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003803 TransformFunctionTypeParams(SourceLocation Loc,
3804 ParmVarDecl **Params, unsigned NumParams,
3805 const QualType *ParamTypes,
3806 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3807 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003808 int indexAdjustment = 0;
3809
Douglas Gregordd472162011-01-07 00:20:55 +00003810 for (unsigned i = 0; i != NumParams; ++i) {
3811 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003812 assert(OldParm->getFunctionScopeIndex() == i);
3813
Douglas Gregor715e4612011-01-14 22:40:04 +00003814 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003815 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003816 if (OldParm->isParameterPack()) {
3817 // We have a function parameter pack that may need to be expanded.
3818 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003819
Douglas Gregor5499af42011-01-05 23:12:31 +00003820 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003821 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3822 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3823 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3824 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003825 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3826
Douglas Gregor5499af42011-01-05 23:12:31 +00003827 // Determine whether we should expand the parameter packs.
3828 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003829 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003830 llvm::Optional<unsigned> OrigNumExpansions
3831 = ExpansionTL.getTypePtr()->getNumExpansions();
3832 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003833 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3834 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003835 Unexpanded.data(),
3836 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003837 ShouldExpand,
3838 RetainExpansion,
3839 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003840 return true;
3841 }
3842
3843 if (ShouldExpand) {
3844 // Expand the function parameter pack into multiple, separate
3845 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003846 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003847 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003848 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3849 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003850 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003851 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003852 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003853 if (!NewParm)
3854 return true;
3855
Douglas Gregordd472162011-01-07 00:20:55 +00003856 OutParamTypes.push_back(NewParm->getType());
3857 if (PVars)
3858 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003859 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003860
3861 // If we're supposed to retain a pack expansion, do so by temporarily
3862 // forgetting the partially-substituted parameter pack.
3863 if (RetainExpansion) {
3864 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3865 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003866 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003867 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003868 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003869 if (!NewParm)
3870 return true;
3871
3872 OutParamTypes.push_back(NewParm->getType());
3873 if (PVars)
3874 PVars->push_back(NewParm);
3875 }
3876
John McCall8fb0d9d2011-05-01 22:35:37 +00003877 // The next parameter should have the same adjustment as the
3878 // last thing we pushed, but we post-incremented indexAdjustment
3879 // on every push. Also, if we push nothing, the adjustment should
3880 // go down by one.
3881 indexAdjustment--;
3882
Douglas Gregor5499af42011-01-05 23:12:31 +00003883 // We're done with the pack expansion.
3884 continue;
3885 }
3886
3887 // We'll substitute the parameter now without expanding the pack
3888 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003889 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3890 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003891 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003892 NumExpansions);
3893 } else {
3894 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003895 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003896 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003897 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003898
John McCall58f10c32010-03-11 09:03:00 +00003899 if (!NewParm)
3900 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003901
Douglas Gregordd472162011-01-07 00:20:55 +00003902 OutParamTypes.push_back(NewParm->getType());
3903 if (PVars)
3904 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003905 continue;
3906 }
John McCall58f10c32010-03-11 09:03:00 +00003907
3908 // Deal with the possibility that we don't have a parameter
3909 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003910 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003911 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003912 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003913 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003914 if (const PackExpansionType *Expansion
3915 = dyn_cast<PackExpansionType>(OldType)) {
3916 // We have a function parameter pack that may need to be expanded.
3917 QualType Pattern = Expansion->getPattern();
3918 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3919 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3920
3921 // Determine whether we should expand the parameter packs.
3922 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003923 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003924 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003925 Unexpanded.data(),
3926 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003927 ShouldExpand,
3928 RetainExpansion,
3929 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003930 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003931 }
3932
3933 if (ShouldExpand) {
3934 // Expand the function parameter pack into multiple, separate
3935 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003936 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003937 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3938 QualType NewType = getDerived().TransformType(Pattern);
3939 if (NewType.isNull())
3940 return true;
John McCall58f10c32010-03-11 09:03:00 +00003941
Douglas Gregordd472162011-01-07 00:20:55 +00003942 OutParamTypes.push_back(NewType);
3943 if (PVars)
3944 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003945 }
3946
3947 // We're done with the pack expansion.
3948 continue;
3949 }
3950
Douglas Gregor48d24112011-01-10 20:53:55 +00003951 // If we're supposed to retain a pack expansion, do so by temporarily
3952 // forgetting the partially-substituted parameter pack.
3953 if (RetainExpansion) {
3954 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3955 QualType NewType = getDerived().TransformType(Pattern);
3956 if (NewType.isNull())
3957 return true;
3958
3959 OutParamTypes.push_back(NewType);
3960 if (PVars)
3961 PVars->push_back(0);
3962 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003963
Douglas Gregor5499af42011-01-05 23:12:31 +00003964 // We'll substitute the parameter now without expanding the pack
3965 // expansion.
3966 OldType = Expansion->getPattern();
3967 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003968 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3969 NewType = getDerived().TransformType(OldType);
3970 } else {
3971 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003972 }
3973
Douglas Gregor5499af42011-01-05 23:12:31 +00003974 if (NewType.isNull())
3975 return true;
3976
3977 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003978 NewType = getSema().Context.getPackExpansionType(NewType,
3979 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003980
Douglas Gregordd472162011-01-07 00:20:55 +00003981 OutParamTypes.push_back(NewType);
3982 if (PVars)
3983 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003984 }
3985
John McCall8fb0d9d2011-05-01 22:35:37 +00003986#ifndef NDEBUG
3987 if (PVars) {
3988 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3989 if (ParmVarDecl *parm = (*PVars)[i])
3990 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00003991 }
John McCall8fb0d9d2011-05-01 22:35:37 +00003992#endif
3993
3994 return false;
3995}
John McCall58f10c32010-03-11 09:03:00 +00003996
3997template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003998QualType
John McCall550e0c22009-10-21 00:40:46 +00003999TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004000 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004001 // Transform the parameters and return type.
4002 //
4003 // We instantiate in source order, with the return type first followed by
4004 // the parameters, because users tend to expect this (even if they shouldn't
4005 // rely on it!).
4006 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00004007 // When the function has a trailing return type, we instantiate the
4008 // parameters before the return type, since the return type can then refer
4009 // to the parameters themselves (via decltype, sizeof, etc.).
4010 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00004011 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00004012 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004013 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004014
Douglas Gregor7fb25412010-10-01 18:44:50 +00004015 QualType ResultType;
4016
4017 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004018 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4019 TL.getParmArray(),
4020 TL.getNumArgs(),
4021 TL.getTypePtr()->arg_type_begin(),
4022 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004023 return QualType();
4024
4025 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4026 if (ResultType.isNull())
4027 return QualType();
4028 }
4029 else {
4030 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4031 if (ResultType.isNull())
4032 return QualType();
4033
Douglas Gregordd472162011-01-07 00:20:55 +00004034 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4035 TL.getParmArray(),
4036 TL.getNumArgs(),
4037 TL.getTypePtr()->arg_type_begin(),
4038 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004039 return QualType();
4040 }
4041
John McCall550e0c22009-10-21 00:40:46 +00004042 QualType Result = TL.getType();
4043 if (getDerived().AlwaysRebuild() ||
4044 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004045 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004046 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4047 Result = getDerived().RebuildFunctionProtoType(ResultType,
4048 ParamTypes.data(),
4049 ParamTypes.size(),
4050 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004051 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004052 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004053 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004054 if (Result.isNull())
4055 return QualType();
4056 }
Mike Stump11289f42009-09-09 15:08:12 +00004057
John McCall550e0c22009-10-21 00:40:46 +00004058 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004059 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4060 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004061 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004062 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4063 NewTL.setArg(i, ParamDecls[i]);
4064
4065 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004066}
Mike Stump11289f42009-09-09 15:08:12 +00004067
Douglas Gregord6ff3322009-08-04 16:50:30 +00004068template<typename Derived>
4069QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004070 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004071 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004072 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004073 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4074 if (ResultType.isNull())
4075 return QualType();
4076
4077 QualType Result = TL.getType();
4078 if (getDerived().AlwaysRebuild() ||
4079 ResultType != T->getResultType())
4080 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4081
4082 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004083 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4084 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004085 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004086
4087 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004088}
Mike Stump11289f42009-09-09 15:08:12 +00004089
John McCallb96ec562009-12-04 22:46:56 +00004090template<typename Derived> QualType
4091TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004092 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004093 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004094 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004095 if (!D)
4096 return QualType();
4097
4098 QualType Result = TL.getType();
4099 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4100 Result = getDerived().RebuildUnresolvedUsingType(D);
4101 if (Result.isNull())
4102 return QualType();
4103 }
4104
4105 // We might get an arbitrary type spec type back. We should at
4106 // least always get a type spec type, though.
4107 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4108 NewTL.setNameLoc(TL.getNameLoc());
4109
4110 return Result;
4111}
4112
Douglas Gregord6ff3322009-08-04 16:50:30 +00004113template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004114QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004115 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004116 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004117 TypedefNameDecl *Typedef
4118 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4119 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004120 if (!Typedef)
4121 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004122
John McCall550e0c22009-10-21 00:40:46 +00004123 QualType Result = TL.getType();
4124 if (getDerived().AlwaysRebuild() ||
4125 Typedef != T->getDecl()) {
4126 Result = getDerived().RebuildTypedefType(Typedef);
4127 if (Result.isNull())
4128 return QualType();
4129 }
Mike Stump11289f42009-09-09 15:08:12 +00004130
John McCall550e0c22009-10-21 00:40:46 +00004131 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4132 NewTL.setNameLoc(TL.getNameLoc());
4133
4134 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004135}
Mike Stump11289f42009-09-09 15:08:12 +00004136
Douglas Gregord6ff3322009-08-04 16:50:30 +00004137template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004138QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004139 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004140 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004141 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004142
John McCalldadc5752010-08-24 06:29:42 +00004143 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004144 if (E.isInvalid())
4145 return QualType();
4146
John McCall550e0c22009-10-21 00:40:46 +00004147 QualType Result = TL.getType();
4148 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004149 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004150 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004151 if (Result.isNull())
4152 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004153 }
John McCall550e0c22009-10-21 00:40:46 +00004154 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004155
John McCall550e0c22009-10-21 00:40:46 +00004156 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004157 NewTL.setTypeofLoc(TL.getTypeofLoc());
4158 NewTL.setLParenLoc(TL.getLParenLoc());
4159 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004160
4161 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004162}
Mike Stump11289f42009-09-09 15:08:12 +00004163
4164template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004165QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004166 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004167 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4168 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4169 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004170 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004171
John McCall550e0c22009-10-21 00:40:46 +00004172 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004173 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4174 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004175 if (Result.isNull())
4176 return QualType();
4177 }
Mike Stump11289f42009-09-09 15:08:12 +00004178
John McCall550e0c22009-10-21 00:40:46 +00004179 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004180 NewTL.setTypeofLoc(TL.getTypeofLoc());
4181 NewTL.setLParenLoc(TL.getLParenLoc());
4182 NewTL.setRParenLoc(TL.getRParenLoc());
4183 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004184
4185 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004186}
Mike Stump11289f42009-09-09 15:08:12 +00004187
4188template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004189QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004190 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004191 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004192
Douglas Gregore922c772009-08-04 22:27:00 +00004193 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004194 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004195
John McCalldadc5752010-08-24 06:29:42 +00004196 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004197 if (E.isInvalid())
4198 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004199
John McCall550e0c22009-10-21 00:40:46 +00004200 QualType Result = TL.getType();
4201 if (getDerived().AlwaysRebuild() ||
4202 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004203 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004204 if (Result.isNull())
4205 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004206 }
John McCall550e0c22009-10-21 00:40:46 +00004207 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004208
John McCall550e0c22009-10-21 00:40:46 +00004209 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4210 NewTL.setNameLoc(TL.getNameLoc());
4211
4212 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004213}
4214
4215template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004216QualType TreeTransform<Derived>::TransformUnaryTransformType(
4217 TypeLocBuilder &TLB,
4218 UnaryTransformTypeLoc TL) {
4219 QualType Result = TL.getType();
4220 if (Result->isDependentType()) {
4221 const UnaryTransformType *T = TL.getTypePtr();
4222 QualType NewBase =
4223 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4224 Result = getDerived().RebuildUnaryTransformType(NewBase,
4225 T->getUTTKind(),
4226 TL.getKWLoc());
4227 if (Result.isNull())
4228 return QualType();
4229 }
4230
4231 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4232 NewTL.setKWLoc(TL.getKWLoc());
4233 NewTL.setParensRange(TL.getParensRange());
4234 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4235 return Result;
4236}
4237
4238template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004239QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4240 AutoTypeLoc TL) {
4241 const AutoType *T = TL.getTypePtr();
4242 QualType OldDeduced = T->getDeducedType();
4243 QualType NewDeduced;
4244 if (!OldDeduced.isNull()) {
4245 NewDeduced = getDerived().TransformType(OldDeduced);
4246 if (NewDeduced.isNull())
4247 return QualType();
4248 }
4249
4250 QualType Result = TL.getType();
4251 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4252 Result = getDerived().RebuildAutoType(NewDeduced);
4253 if (Result.isNull())
4254 return QualType();
4255 }
4256
4257 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4258 NewTL.setNameLoc(TL.getNameLoc());
4259
4260 return Result;
4261}
4262
4263template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004264QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004265 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004266 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004267 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004268 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4269 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004270 if (!Record)
4271 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004272
John McCall550e0c22009-10-21 00:40:46 +00004273 QualType Result = TL.getType();
4274 if (getDerived().AlwaysRebuild() ||
4275 Record != T->getDecl()) {
4276 Result = getDerived().RebuildRecordType(Record);
4277 if (Result.isNull())
4278 return QualType();
4279 }
Mike Stump11289f42009-09-09 15:08:12 +00004280
John McCall550e0c22009-10-21 00:40:46 +00004281 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4282 NewTL.setNameLoc(TL.getNameLoc());
4283
4284 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004285}
Mike Stump11289f42009-09-09 15:08:12 +00004286
4287template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004288QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004289 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004290 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004291 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004292 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4293 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004294 if (!Enum)
4295 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004296
John McCall550e0c22009-10-21 00:40:46 +00004297 QualType Result = TL.getType();
4298 if (getDerived().AlwaysRebuild() ||
4299 Enum != T->getDecl()) {
4300 Result = getDerived().RebuildEnumType(Enum);
4301 if (Result.isNull())
4302 return QualType();
4303 }
Mike Stump11289f42009-09-09 15:08:12 +00004304
John McCall550e0c22009-10-21 00:40:46 +00004305 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4306 NewTL.setNameLoc(TL.getNameLoc());
4307
4308 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004309}
John McCallfcc33b02009-09-05 00:15:47 +00004310
John McCalle78aac42010-03-10 03:28:59 +00004311template<typename Derived>
4312QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4313 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004314 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004315 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4316 TL.getTypePtr()->getDecl());
4317 if (!D) return QualType();
4318
4319 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4320 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4321 return T;
4322}
4323
Douglas Gregord6ff3322009-08-04 16:50:30 +00004324template<typename Derived>
4325QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004326 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004327 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004328 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004329}
4330
Mike Stump11289f42009-09-09 15:08:12 +00004331template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004332QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004333 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004334 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004335 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4336
4337 // Substitute into the replacement type, which itself might involve something
4338 // that needs to be transformed. This only tends to occur with default
4339 // template arguments of template template parameters.
4340 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4341 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4342 if (Replacement.isNull())
4343 return QualType();
4344
4345 // Always canonicalize the replacement type.
4346 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4347 QualType Result
4348 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4349 Replacement);
4350
4351 // Propagate type-source information.
4352 SubstTemplateTypeParmTypeLoc NewTL
4353 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4354 NewTL.setNameLoc(TL.getNameLoc());
4355 return Result;
4356
John McCallcebee162009-10-18 09:09:24 +00004357}
4358
4359template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004360QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4361 TypeLocBuilder &TLB,
4362 SubstTemplateTypeParmPackTypeLoc TL) {
4363 return TransformTypeSpecType(TLB, TL);
4364}
4365
4366template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004367QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004368 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004369 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004370 const TemplateSpecializationType *T = TL.getTypePtr();
4371
Douglas Gregordf846d12011-03-02 18:46:51 +00004372 // The nested-name-specifier never matters in a TemplateSpecializationType,
4373 // because we can't have a dependent nested-name-specifier anyway.
4374 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004375 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004376 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4377 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004378 if (Template.isNull())
4379 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004380
John McCall31f82722010-11-12 08:19:04 +00004381 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4382}
4383
Douglas Gregorfe921a72010-12-20 23:36:19 +00004384namespace {
4385 /// \brief Simple iterator that traverses the template arguments in a
4386 /// container that provides a \c getArgLoc() member function.
4387 ///
4388 /// This iterator is intended to be used with the iterator form of
4389 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4390 template<typename ArgLocContainer>
4391 class TemplateArgumentLocContainerIterator {
4392 ArgLocContainer *Container;
4393 unsigned Index;
4394
4395 public:
4396 typedef TemplateArgumentLoc value_type;
4397 typedef TemplateArgumentLoc reference;
4398 typedef int difference_type;
4399 typedef std::input_iterator_tag iterator_category;
4400
4401 class pointer {
4402 TemplateArgumentLoc Arg;
4403
4404 public:
4405 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4406
4407 const TemplateArgumentLoc *operator->() const {
4408 return &Arg;
4409 }
4410 };
4411
4412
4413 TemplateArgumentLocContainerIterator() {}
4414
4415 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4416 unsigned Index)
4417 : Container(&Container), Index(Index) { }
4418
4419 TemplateArgumentLocContainerIterator &operator++() {
4420 ++Index;
4421 return *this;
4422 }
4423
4424 TemplateArgumentLocContainerIterator operator++(int) {
4425 TemplateArgumentLocContainerIterator Old(*this);
4426 ++(*this);
4427 return Old;
4428 }
4429
4430 TemplateArgumentLoc operator*() const {
4431 return Container->getArgLoc(Index);
4432 }
4433
4434 pointer operator->() const {
4435 return pointer(Container->getArgLoc(Index));
4436 }
4437
4438 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004439 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004440 return X.Container == Y.Container && X.Index == Y.Index;
4441 }
4442
4443 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004444 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004445 return !(X == Y);
4446 }
4447 };
4448}
4449
4450
John McCall31f82722010-11-12 08:19:04 +00004451template <typename Derived>
4452QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4453 TypeLocBuilder &TLB,
4454 TemplateSpecializationTypeLoc TL,
4455 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004456 TemplateArgumentListInfo NewTemplateArgs;
4457 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4458 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004459 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4460 ArgIterator;
4461 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4462 ArgIterator(TL, TL.getNumArgs()),
4463 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004464 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004465
John McCall0ad16662009-10-29 08:12:44 +00004466 // FIXME: maybe don't rebuild if all the template arguments are the same.
4467
4468 QualType Result =
4469 getDerived().RebuildTemplateSpecializationType(Template,
4470 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004471 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004472
4473 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004474 // Specializations of template template parameters are represented as
4475 // TemplateSpecializationTypes, and substitution of type alias templates
4476 // within a dependent context can transform them into
4477 // DependentTemplateSpecializationTypes.
4478 if (isa<DependentTemplateSpecializationType>(Result)) {
4479 DependentTemplateSpecializationTypeLoc NewTL
4480 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4481 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4482 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4483 NewTL.setNameLoc(TL.getTemplateNameLoc());
4484 NewTL.setLAngleLoc(TL.getLAngleLoc());
4485 NewTL.setRAngleLoc(TL.getRAngleLoc());
4486 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4487 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4488 return Result;
4489 }
4490
John McCall0ad16662009-10-29 08:12:44 +00004491 TemplateSpecializationTypeLoc NewTL
4492 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4493 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4494 NewTL.setLAngleLoc(TL.getLAngleLoc());
4495 NewTL.setRAngleLoc(TL.getRAngleLoc());
4496 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4497 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004498 }
Mike Stump11289f42009-09-09 15:08:12 +00004499
John McCall0ad16662009-10-29 08:12:44 +00004500 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004501}
Mike Stump11289f42009-09-09 15:08:12 +00004502
Douglas Gregor5a064722011-02-28 17:23:35 +00004503template <typename Derived>
4504QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4505 TypeLocBuilder &TLB,
4506 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004507 TemplateName Template,
4508 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004509 TemplateArgumentListInfo NewTemplateArgs;
4510 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4511 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4512 typedef TemplateArgumentLocContainerIterator<
4513 DependentTemplateSpecializationTypeLoc> ArgIterator;
4514 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4515 ArgIterator(TL, TL.getNumArgs()),
4516 NewTemplateArgs))
4517 return QualType();
4518
4519 // FIXME: maybe don't rebuild if all the template arguments are the same.
4520
4521 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4522 QualType Result
4523 = getSema().Context.getDependentTemplateSpecializationType(
4524 TL.getTypePtr()->getKeyword(),
4525 DTN->getQualifier(),
4526 DTN->getIdentifier(),
4527 NewTemplateArgs);
4528
4529 DependentTemplateSpecializationTypeLoc NewTL
4530 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4531 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004532
Douglas Gregora7a795b2011-03-01 20:11:18 +00004533 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004534 NewTL.setNameLoc(TL.getNameLoc());
4535 NewTL.setLAngleLoc(TL.getLAngleLoc());
4536 NewTL.setRAngleLoc(TL.getRAngleLoc());
4537 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4538 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4539 return Result;
4540 }
4541
4542 QualType Result
4543 = getDerived().RebuildTemplateSpecializationType(Template,
4544 TL.getNameLoc(),
4545 NewTemplateArgs);
4546
4547 if (!Result.isNull()) {
4548 /// FIXME: Wrap this in an elaborated-type-specifier?
4549 TemplateSpecializationTypeLoc NewTL
4550 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4551 NewTL.setTemplateNameLoc(TL.getNameLoc());
4552 NewTL.setLAngleLoc(TL.getLAngleLoc());
4553 NewTL.setRAngleLoc(TL.getRAngleLoc());
4554 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4555 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4556 }
4557
4558 return Result;
4559}
4560
Mike Stump11289f42009-09-09 15:08:12 +00004561template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004562QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004563TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004564 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004565 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004566
Douglas Gregor844cb502011-03-01 18:12:44 +00004567 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004568 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004569 if (TL.getQualifierLoc()) {
4570 QualifierLoc
4571 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4572 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004573 return QualType();
4574 }
Mike Stump11289f42009-09-09 15:08:12 +00004575
John McCall31f82722010-11-12 08:19:04 +00004576 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4577 if (NamedT.isNull())
4578 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004579
Richard Smith3f1b5d02011-05-05 21:57:07 +00004580 // C++0x [dcl.type.elab]p2:
4581 // If the identifier resolves to a typedef-name or the simple-template-id
4582 // resolves to an alias template specialization, the
4583 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004584 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4585 if (const TemplateSpecializationType *TST =
4586 NamedT->getAs<TemplateSpecializationType>()) {
4587 TemplateName Template = TST->getTemplateName();
4588 if (TypeAliasTemplateDecl *TAT =
4589 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4590 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4591 diag::err_tag_reference_non_tag) << 4;
4592 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4593 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004594 }
4595 }
4596
John McCall550e0c22009-10-21 00:40:46 +00004597 QualType Result = TL.getType();
4598 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004599 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004600 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004601 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004602 T->getKeyword(),
4603 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004604 if (Result.isNull())
4605 return QualType();
4606 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004607
Abramo Bagnara6150c882010-05-11 21:36:43 +00004608 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004609 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004610 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004611 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004612}
Mike Stump11289f42009-09-09 15:08:12 +00004613
4614template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004615QualType TreeTransform<Derived>::TransformAttributedType(
4616 TypeLocBuilder &TLB,
4617 AttributedTypeLoc TL) {
4618 const AttributedType *oldType = TL.getTypePtr();
4619 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4620 if (modifiedType.isNull())
4621 return QualType();
4622
4623 QualType result = TL.getType();
4624
4625 // FIXME: dependent operand expressions?
4626 if (getDerived().AlwaysRebuild() ||
4627 modifiedType != oldType->getModifiedType()) {
4628 // TODO: this is really lame; we should really be rebuilding the
4629 // equivalent type from first principles.
4630 QualType equivalentType
4631 = getDerived().TransformType(oldType->getEquivalentType());
4632 if (equivalentType.isNull())
4633 return QualType();
4634 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4635 modifiedType,
4636 equivalentType);
4637 }
4638
4639 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4640 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4641 if (TL.hasAttrOperand())
4642 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4643 if (TL.hasAttrExprOperand())
4644 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4645 else if (TL.hasAttrEnumOperand())
4646 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4647
4648 return result;
4649}
4650
4651template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004652QualType
4653TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4654 ParenTypeLoc TL) {
4655 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4656 if (Inner.isNull())
4657 return QualType();
4658
4659 QualType Result = TL.getType();
4660 if (getDerived().AlwaysRebuild() ||
4661 Inner != TL.getInnerLoc().getType()) {
4662 Result = getDerived().RebuildParenType(Inner);
4663 if (Result.isNull())
4664 return QualType();
4665 }
4666
4667 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4668 NewTL.setLParenLoc(TL.getLParenLoc());
4669 NewTL.setRParenLoc(TL.getRParenLoc());
4670 return Result;
4671}
4672
4673template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004674QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004675 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004676 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004677
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004678 NestedNameSpecifierLoc QualifierLoc
4679 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4680 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004681 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004682
John McCallc392f372010-06-11 00:33:02 +00004683 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004684 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004685 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004686 QualifierLoc,
4687 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004688 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004689 if (Result.isNull())
4690 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004691
Abramo Bagnarad7548482010-05-19 21:37:53 +00004692 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4693 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004694 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4695
Abramo Bagnarad7548482010-05-19 21:37:53 +00004696 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4697 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004698 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004699 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004700 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4701 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004702 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004703 NewTL.setNameLoc(TL.getNameLoc());
4704 }
John McCall550e0c22009-10-21 00:40:46 +00004705 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004706}
Mike Stump11289f42009-09-09 15:08:12 +00004707
Douglas Gregord6ff3322009-08-04 16:50:30 +00004708template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004709QualType TreeTransform<Derived>::
4710 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004711 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004712 NestedNameSpecifierLoc QualifierLoc;
4713 if (TL.getQualifierLoc()) {
4714 QualifierLoc
4715 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4716 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004717 return QualType();
4718 }
4719
John McCall31f82722010-11-12 08:19:04 +00004720 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004721 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004722}
4723
4724template<typename Derived>
4725QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004726TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4727 DependentTemplateSpecializationTypeLoc TL,
4728 NestedNameSpecifierLoc QualifierLoc) {
4729 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4730
4731 TemplateArgumentListInfo NewTemplateArgs;
4732 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4733 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4734
4735 typedef TemplateArgumentLocContainerIterator<
4736 DependentTemplateSpecializationTypeLoc> ArgIterator;
4737 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4738 ArgIterator(TL, TL.getNumArgs()),
4739 NewTemplateArgs))
4740 return QualType();
4741
4742 QualType Result
4743 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4744 QualifierLoc,
4745 T->getIdentifier(),
4746 TL.getNameLoc(),
4747 NewTemplateArgs);
4748 if (Result.isNull())
4749 return QualType();
4750
4751 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4752 QualType NamedT = ElabT->getNamedType();
4753
4754 // Copy information relevant to the template specialization.
4755 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004756 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004757 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004758 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4759 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004760 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004761 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004762
4763 // Copy information relevant to the elaborated type.
4764 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4765 NewTL.setKeywordLoc(TL.getKeywordLoc());
4766 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004767 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4768 DependentTemplateSpecializationTypeLoc SpecTL
4769 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004770 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004771 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004772 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004773 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4774 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004775 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004776 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004777 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004778 TemplateSpecializationTypeLoc SpecTL
4779 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004780 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004781 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4782 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004783 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004784 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004785 }
4786 return Result;
4787}
4788
4789template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004790QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4791 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004792 QualType Pattern
4793 = getDerived().TransformType(TLB, TL.getPatternLoc());
4794 if (Pattern.isNull())
4795 return QualType();
4796
4797 QualType Result = TL.getType();
4798 if (getDerived().AlwaysRebuild() ||
4799 Pattern != TL.getPatternLoc().getType()) {
4800 Result = getDerived().RebuildPackExpansionType(Pattern,
4801 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004802 TL.getEllipsisLoc(),
4803 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004804 if (Result.isNull())
4805 return QualType();
4806 }
4807
4808 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4809 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4810 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004811}
4812
4813template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004814QualType
4815TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004816 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004817 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004818 TLB.pushFullCopy(TL);
4819 return TL.getType();
4820}
4821
4822template<typename Derived>
4823QualType
4824TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004825 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004826 // ObjCObjectType is never dependent.
4827 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004828 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004829}
Mike Stump11289f42009-09-09 15:08:12 +00004830
4831template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004832QualType
4833TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004834 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004835 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004836 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004837 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004838}
4839
Douglas Gregord6ff3322009-08-04 16:50:30 +00004840//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004841// Statement transformation
4842//===----------------------------------------------------------------------===//
4843template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004844StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004845TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004846 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004847}
4848
4849template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004850StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004851TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4852 return getDerived().TransformCompoundStmt(S, false);
4853}
4854
4855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004856StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004857TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004858 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004859 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004860 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004861 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004862 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4863 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004864 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004865 if (Result.isInvalid()) {
4866 // Immediately fail if this was a DeclStmt, since it's very
4867 // likely that this will cause problems for future statements.
4868 if (isa<DeclStmt>(*B))
4869 return StmtError();
4870
4871 // Otherwise, just keep processing substatements and fail later.
4872 SubStmtInvalid = true;
4873 continue;
4874 }
Mike Stump11289f42009-09-09 15:08:12 +00004875
Douglas Gregorebe10102009-08-20 07:17:43 +00004876 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4877 Statements.push_back(Result.takeAs<Stmt>());
4878 }
Mike Stump11289f42009-09-09 15:08:12 +00004879
John McCall1ababa62010-08-27 19:56:05 +00004880 if (SubStmtInvalid)
4881 return StmtError();
4882
Douglas Gregorebe10102009-08-20 07:17:43 +00004883 if (!getDerived().AlwaysRebuild() &&
4884 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004885 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004886
4887 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4888 move_arg(Statements),
4889 S->getRBracLoc(),
4890 IsStmtExpr);
4891}
Mike Stump11289f42009-09-09 15:08:12 +00004892
Douglas Gregorebe10102009-08-20 07:17:43 +00004893template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004894StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004895TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004896 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004897 {
4898 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004899 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004900
Eli Friedman06577382009-11-19 03:14:00 +00004901 // Transform the left-hand case value.
4902 LHS = getDerived().TransformExpr(S->getLHS());
4903 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004904 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004905
Eli Friedman06577382009-11-19 03:14:00 +00004906 // Transform the right-hand case value (for the GNU case-range extension).
4907 RHS = getDerived().TransformExpr(S->getRHS());
4908 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004909 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004910 }
Mike Stump11289f42009-09-09 15:08:12 +00004911
Douglas Gregorebe10102009-08-20 07:17:43 +00004912 // Build the case statement.
4913 // Case statements are always rebuilt so that they will attached to their
4914 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004915 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004916 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004917 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004918 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004919 S->getColonLoc());
4920 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004921 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004922
Douglas Gregorebe10102009-08-20 07:17:43 +00004923 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004924 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004925 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004926 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004927
Douglas Gregorebe10102009-08-20 07:17:43 +00004928 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004929 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004930}
4931
4932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004933StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004934TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004935 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004936 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004937 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004938 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004939
Douglas Gregorebe10102009-08-20 07:17:43 +00004940 // Default statements are always rebuilt
4941 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004942 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004943}
Mike Stump11289f42009-09-09 15:08:12 +00004944
Douglas Gregorebe10102009-08-20 07:17:43 +00004945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004946StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004947TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004948 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004949 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004950 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004951
Chris Lattnercab02a62011-02-17 20:34:02 +00004952 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4953 S->getDecl());
4954 if (!LD)
4955 return StmtError();
4956
4957
Douglas Gregorebe10102009-08-20 07:17:43 +00004958 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004959 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004960 cast<LabelDecl>(LD), SourceLocation(),
4961 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004962}
Mike Stump11289f42009-09-09 15:08:12 +00004963
Douglas Gregorebe10102009-08-20 07:17:43 +00004964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004965StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004966TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004967 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004968 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004969 VarDecl *ConditionVar = 0;
4970 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004971 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004972 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004973 getDerived().TransformDefinition(
4974 S->getConditionVariable()->getLocation(),
4975 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004976 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004977 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004978 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004979 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004980
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004981 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004982 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004983
4984 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004985 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004986 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4987 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004988 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004989 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004990
John McCallb268a282010-08-23 23:25:46 +00004991 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004992 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004993 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004994
John McCallb268a282010-08-23 23:25:46 +00004995 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4996 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004997 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004998
Douglas Gregorebe10102009-08-20 07:17:43 +00004999 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005000 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005001 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005002 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005003
Douglas Gregorebe10102009-08-20 07:17:43 +00005004 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005005 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005006 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005007 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005008
Douglas Gregorebe10102009-08-20 07:17:43 +00005009 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005010 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005011 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005012 Then.get() == S->getThen() &&
5013 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005014 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005015
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005016 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005017 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005018 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005019}
5020
5021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005022StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005023TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005024 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005025 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005026 VarDecl *ConditionVar = 0;
5027 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005028 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005029 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005030 getDerived().TransformDefinition(
5031 S->getConditionVariable()->getLocation(),
5032 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005033 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005034 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005035 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005036 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005037
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005038 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005039 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005040 }
Mike Stump11289f42009-09-09 15:08:12 +00005041
Douglas Gregorebe10102009-08-20 07:17:43 +00005042 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005043 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005044 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005045 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005046 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005047 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005048
Douglas Gregorebe10102009-08-20 07:17:43 +00005049 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005050 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005051 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005052 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005053
Douglas Gregorebe10102009-08-20 07:17:43 +00005054 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005055 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5056 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005057}
Mike Stump11289f42009-09-09 15:08:12 +00005058
Douglas Gregorebe10102009-08-20 07:17:43 +00005059template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005060StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005061TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005062 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005063 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005064 VarDecl *ConditionVar = 0;
5065 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005066 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005067 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005068 getDerived().TransformDefinition(
5069 S->getConditionVariable()->getLocation(),
5070 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005071 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005072 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005073 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005074 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005075
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005076 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005077 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005078
5079 if (S->getCond()) {
5080 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005081 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5082 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005083 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005084 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005085 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005086 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005087 }
Mike Stump11289f42009-09-09 15:08:12 +00005088
John McCallb268a282010-08-23 23:25:46 +00005089 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5090 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005091 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005092
Douglas Gregorebe10102009-08-20 07:17:43 +00005093 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005094 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005095 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005096 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005097
Douglas Gregorebe10102009-08-20 07:17:43 +00005098 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005099 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005100 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005101 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005102 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005103
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005104 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005105 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005106}
Mike Stump11289f42009-09-09 15:08:12 +00005107
Douglas Gregorebe10102009-08-20 07:17:43 +00005108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005109StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005110TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005111 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005112 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005113 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005114 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005115
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005116 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005117 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005118 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005119 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005120
Douglas Gregorebe10102009-08-20 07:17:43 +00005121 if (!getDerived().AlwaysRebuild() &&
5122 Cond.get() == S->getCond() &&
5123 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005124 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005125
John McCallb268a282010-08-23 23:25:46 +00005126 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5127 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005128 S->getRParenLoc());
5129}
Mike Stump11289f42009-09-09 15:08:12 +00005130
Douglas Gregorebe10102009-08-20 07:17:43 +00005131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005132StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005133TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005134 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005135 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005136 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005137 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005138
Douglas Gregorebe10102009-08-20 07:17:43 +00005139 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005140 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005141 VarDecl *ConditionVar = 0;
5142 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005143 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005144 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005145 getDerived().TransformDefinition(
5146 S->getConditionVariable()->getLocation(),
5147 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005148 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005149 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005150 } else {
5151 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005152
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005153 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005154 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005155
5156 if (S->getCond()) {
5157 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005158 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5159 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005160 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005161 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005162
John McCallb268a282010-08-23 23:25:46 +00005163 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005164 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005165 }
Mike Stump11289f42009-09-09 15:08:12 +00005166
John McCallb268a282010-08-23 23:25:46 +00005167 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5168 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005169 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005170
Douglas Gregorebe10102009-08-20 07:17:43 +00005171 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005172 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005173 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005174 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005175
John McCallb268a282010-08-23 23:25:46 +00005176 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5177 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005178 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005179
Douglas Gregorebe10102009-08-20 07:17:43 +00005180 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005181 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005182 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005183 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005184
Douglas Gregorebe10102009-08-20 07:17:43 +00005185 if (!getDerived().AlwaysRebuild() &&
5186 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005187 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005188 Inc.get() == S->getInc() &&
5189 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005190 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005191
Douglas Gregorebe10102009-08-20 07:17:43 +00005192 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005193 Init.get(), FullCond, ConditionVar,
5194 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005195}
5196
5197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005198StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005199TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005200 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5201 S->getLabel());
5202 if (!LD)
5203 return StmtError();
5204
Douglas Gregorebe10102009-08-20 07:17:43 +00005205 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005206 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005207 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005208}
5209
5210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005211StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005212TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005213 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005214 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005215 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005216
Douglas Gregorebe10102009-08-20 07:17:43 +00005217 if (!getDerived().AlwaysRebuild() &&
5218 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005219 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005220
5221 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005222 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005223}
5224
5225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005226StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005227TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005228 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005229}
Mike Stump11289f42009-09-09 15:08:12 +00005230
Douglas Gregorebe10102009-08-20 07:17:43 +00005231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005232StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005233TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005234 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005235}
Mike Stump11289f42009-09-09 15:08:12 +00005236
Douglas Gregorebe10102009-08-20 07:17:43 +00005237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005238StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005239TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005240 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005241 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005242 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005243
Mike Stump11289f42009-09-09 15:08:12 +00005244 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005245 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005246 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005247}
Mike Stump11289f42009-09-09 15:08:12 +00005248
Douglas Gregorebe10102009-08-20 07:17:43 +00005249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005250StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005251TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005252 bool DeclChanged = false;
5253 llvm::SmallVector<Decl *, 4> Decls;
5254 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5255 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005256 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5257 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005258 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005259 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregorebe10102009-08-20 07:17:43 +00005261 if (Transformed != *D)
5262 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005263
Douglas Gregorebe10102009-08-20 07:17:43 +00005264 Decls.push_back(Transformed);
5265 }
Mike Stump11289f42009-09-09 15:08:12 +00005266
Douglas Gregorebe10102009-08-20 07:17:43 +00005267 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005268 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005269
5270 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005271 S->getStartLoc(), S->getEndLoc());
5272}
Mike Stump11289f42009-09-09 15:08:12 +00005273
Douglas Gregorebe10102009-08-20 07:17:43 +00005274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005275StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005276TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005277
John McCall37ad5512010-08-23 06:44:23 +00005278 ASTOwningVector<Expr*> Constraints(getSema());
5279 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005280 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005281
John McCalldadc5752010-08-24 06:29:42 +00005282 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005283 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005284
5285 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005286
Anders Carlssonaaeef072010-01-24 05:50:09 +00005287 // Go through the outputs.
5288 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005289 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005290
Anders Carlssonaaeef072010-01-24 05:50:09 +00005291 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005292 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005293
Anders Carlssonaaeef072010-01-24 05:50:09 +00005294 // Transform the output expr.
5295 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005296 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005297 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005298 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005299
Anders Carlssonaaeef072010-01-24 05:50:09 +00005300 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005301
John McCallb268a282010-08-23 23:25:46 +00005302 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005303 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005304
Anders Carlssonaaeef072010-01-24 05:50:09 +00005305 // Go through the inputs.
5306 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005307 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005308
Anders Carlssonaaeef072010-01-24 05:50:09 +00005309 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005310 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005311
Anders Carlssonaaeef072010-01-24 05:50:09 +00005312 // Transform the input expr.
5313 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005314 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005315 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005316 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005317
Anders Carlssonaaeef072010-01-24 05:50:09 +00005318 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005319
John McCallb268a282010-08-23 23:25:46 +00005320 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005321 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005322
Anders Carlssonaaeef072010-01-24 05:50:09 +00005323 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005324 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005325
5326 // Go through the clobbers.
5327 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005328 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005329
5330 // No need to transform the asm string literal.
5331 AsmString = SemaRef.Owned(S->getAsmString());
5332
5333 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5334 S->isSimple(),
5335 S->isVolatile(),
5336 S->getNumOutputs(),
5337 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005338 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005339 move_arg(Constraints),
5340 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005341 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005342 move_arg(Clobbers),
5343 S->getRParenLoc(),
5344 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005345}
5346
5347
5348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005349StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005350TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005351 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005352 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005353 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005354 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005355
Douglas Gregor96c79492010-04-23 22:50:49 +00005356 // Transform the @catch statements (if present).
5357 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005358 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005359 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005360 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005361 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005362 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005363 if (Catch.get() != S->getCatchStmt(I))
5364 AnyCatchChanged = true;
5365 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005366 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005367
Douglas Gregor306de2f2010-04-22 23:59:56 +00005368 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005369 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005370 if (S->getFinallyStmt()) {
5371 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5372 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005373 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005374 }
5375
5376 // If nothing changed, just retain this statement.
5377 if (!getDerived().AlwaysRebuild() &&
5378 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005379 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005380 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005381 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005382
Douglas Gregor306de2f2010-04-22 23:59:56 +00005383 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005384 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5385 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005386}
Mike Stump11289f42009-09-09 15:08:12 +00005387
Douglas Gregorebe10102009-08-20 07:17:43 +00005388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005389StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005390TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005391 // Transform the @catch parameter, if there is one.
5392 VarDecl *Var = 0;
5393 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5394 TypeSourceInfo *TSInfo = 0;
5395 if (FromVar->getTypeSourceInfo()) {
5396 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5397 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005398 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005399 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005400
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005401 QualType T;
5402 if (TSInfo)
5403 T = TSInfo->getType();
5404 else {
5405 T = getDerived().TransformType(FromVar->getType());
5406 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005407 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005408 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005409
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005410 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5411 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005412 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005413 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005414
John McCalldadc5752010-08-24 06:29:42 +00005415 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005416 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005417 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005418
5419 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005420 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005421 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005422}
Mike Stump11289f42009-09-09 15:08:12 +00005423
Douglas Gregorebe10102009-08-20 07:17:43 +00005424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005425StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005426TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005427 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005428 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005429 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005430 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005431
Douglas Gregor306de2f2010-04-22 23:59:56 +00005432 // If nothing changed, just retain this statement.
5433 if (!getDerived().AlwaysRebuild() &&
5434 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005435 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005436
5437 // Build a new statement.
5438 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005439 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005440}
Mike Stump11289f42009-09-09 15:08:12 +00005441
Douglas Gregorebe10102009-08-20 07:17:43 +00005442template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005443StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005444TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005445 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005446 if (S->getThrowExpr()) {
5447 Operand = getDerived().TransformExpr(S->getThrowExpr());
5448 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005449 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005450 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005451
Douglas Gregor2900c162010-04-22 21:44:01 +00005452 if (!getDerived().AlwaysRebuild() &&
5453 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005454 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005455
John McCallb268a282010-08-23 23:25:46 +00005456 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005457}
Mike Stump11289f42009-09-09 15:08:12 +00005458
Douglas Gregorebe10102009-08-20 07:17:43 +00005459template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005460StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005461TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005462 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005463 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005464 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005465 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005466 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005467
Douglas Gregor6148de72010-04-22 22:01:21 +00005468 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005469 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005470 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005471 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005472
Douglas Gregor6148de72010-04-22 22:01:21 +00005473 // If nothing change, just retain the current statement.
5474 if (!getDerived().AlwaysRebuild() &&
5475 Object.get() == S->getSynchExpr() &&
5476 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005477 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005478
5479 // Build a new statement.
5480 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005481 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005482}
5483
5484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005485StmtResult
John McCall31168b02011-06-15 23:02:42 +00005486TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5487 ObjCAutoreleasePoolStmt *S) {
5488 // Transform the body.
5489 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5490 if (Body.isInvalid())
5491 return StmtError();
5492
5493 // If nothing changed, just retain this statement.
5494 if (!getDerived().AlwaysRebuild() &&
5495 Body.get() == S->getSubStmt())
5496 return SemaRef.Owned(S);
5497
5498 // Build a new statement.
5499 return getDerived().RebuildObjCAutoreleasePoolStmt(
5500 S->getAtLoc(), Body.get());
5501}
5502
5503template<typename Derived>
5504StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005505TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005506 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005507 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005508 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005509 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005510 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005511
Douglas Gregorf68a5082010-04-22 23:10:45 +00005512 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005513 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005514 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005515 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005516
Douglas Gregorf68a5082010-04-22 23:10:45 +00005517 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005518 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005519 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005520 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005521
Douglas Gregorf68a5082010-04-22 23:10:45 +00005522 // If nothing changed, just retain this statement.
5523 if (!getDerived().AlwaysRebuild() &&
5524 Element.get() == S->getElement() &&
5525 Collection.get() == S->getCollection() &&
5526 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005527 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005528
Douglas Gregorf68a5082010-04-22 23:10:45 +00005529 // Build a new statement.
5530 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5531 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005532 Element.get(),
5533 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005534 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005535 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005536}
5537
5538
5539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005540StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005541TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5542 // Transform the exception declaration, if any.
5543 VarDecl *Var = 0;
5544 if (S->getExceptionDecl()) {
5545 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005546 TypeSourceInfo *T = getDerived().TransformType(
5547 ExceptionDecl->getTypeSourceInfo());
5548 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005549 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005550
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005551 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005552 ExceptionDecl->getInnerLocStart(),
5553 ExceptionDecl->getLocation(),
5554 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005555 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005556 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005557 }
Mike Stump11289f42009-09-09 15:08:12 +00005558
Douglas Gregorebe10102009-08-20 07:17:43 +00005559 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005560 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005561 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005562 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005563
Douglas Gregorebe10102009-08-20 07:17:43 +00005564 if (!getDerived().AlwaysRebuild() &&
5565 !Var &&
5566 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005567 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005568
5569 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5570 Var,
John McCallb268a282010-08-23 23:25:46 +00005571 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005572}
Mike Stump11289f42009-09-09 15:08:12 +00005573
Douglas Gregorebe10102009-08-20 07:17:43 +00005574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005575StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005576TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5577 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005578 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005579 = getDerived().TransformCompoundStmt(S->getTryBlock());
5580 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005581 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005582
Douglas Gregorebe10102009-08-20 07:17:43 +00005583 // Transform the handlers.
5584 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005585 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005586 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005587 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005588 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5589 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005590 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005591
Douglas Gregorebe10102009-08-20 07:17:43 +00005592 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5593 Handlers.push_back(Handler.takeAs<Stmt>());
5594 }
Mike Stump11289f42009-09-09 15:08:12 +00005595
Douglas Gregorebe10102009-08-20 07:17:43 +00005596 if (!getDerived().AlwaysRebuild() &&
5597 TryBlock.get() == S->getTryBlock() &&
5598 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005599 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005600
John McCallb268a282010-08-23 23:25:46 +00005601 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005602 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005603}
Mike Stump11289f42009-09-09 15:08:12 +00005604
Richard Smith02e85f32011-04-14 22:09:26 +00005605template<typename Derived>
5606StmtResult
5607TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5608 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5609 if (Range.isInvalid())
5610 return StmtError();
5611
5612 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5613 if (BeginEnd.isInvalid())
5614 return StmtError();
5615
5616 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5617 if (Cond.isInvalid())
5618 return StmtError();
5619
5620 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5621 if (Inc.isInvalid())
5622 return StmtError();
5623
5624 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5625 if (LoopVar.isInvalid())
5626 return StmtError();
5627
5628 StmtResult NewStmt = S;
5629 if (getDerived().AlwaysRebuild() ||
5630 Range.get() != S->getRangeStmt() ||
5631 BeginEnd.get() != S->getBeginEndStmt() ||
5632 Cond.get() != S->getCond() ||
5633 Inc.get() != S->getInc() ||
5634 LoopVar.get() != S->getLoopVarStmt())
5635 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5636 S->getColonLoc(), Range.get(),
5637 BeginEnd.get(), Cond.get(),
5638 Inc.get(), LoopVar.get(),
5639 S->getRParenLoc());
5640
5641 StmtResult Body = getDerived().TransformStmt(S->getBody());
5642 if (Body.isInvalid())
5643 return StmtError();
5644
5645 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5646 // it now so we have a new statement to attach the body to.
5647 if (Body.get() != S->getBody() && NewStmt.get() == S)
5648 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5649 S->getColonLoc(), Range.get(),
5650 BeginEnd.get(), Cond.get(),
5651 Inc.get(), LoopVar.get(),
5652 S->getRParenLoc());
5653
5654 if (NewStmt.get() == S)
5655 return SemaRef.Owned(S);
5656
5657 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5658}
5659
John Wiegley1c0675e2011-04-28 01:08:34 +00005660template<typename Derived>
5661StmtResult
5662TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5663 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5664 if(TryBlock.isInvalid()) return StmtError();
5665
5666 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5667 if(!getDerived().AlwaysRebuild() &&
5668 TryBlock.get() == S->getTryBlock() &&
5669 Handler.get() == S->getHandler())
5670 return SemaRef.Owned(S);
5671
5672 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5673 S->getTryLoc(),
5674 TryBlock.take(),
5675 Handler.take());
5676}
5677
5678template<typename Derived>
5679StmtResult
5680TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5681 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5682 if(Block.isInvalid()) return StmtError();
5683
5684 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5685 Block.take());
5686}
5687
5688template<typename Derived>
5689StmtResult
5690TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5691 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5692 if(FilterExpr.isInvalid()) return StmtError();
5693
5694 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5695 if(Block.isInvalid()) return StmtError();
5696
5697 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5698 FilterExpr.take(),
5699 Block.take());
5700}
5701
5702template<typename Derived>
5703StmtResult
5704TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5705 if(isa<SEHFinallyStmt>(Handler))
5706 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5707 else
5708 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5709}
5710
Douglas Gregorebe10102009-08-20 07:17:43 +00005711//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005712// Expression transformation
5713//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005715ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005716TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005717 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005718}
Mike Stump11289f42009-09-09 15:08:12 +00005719
5720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005721ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005722TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005723 NestedNameSpecifierLoc QualifierLoc;
5724 if (E->getQualifierLoc()) {
5725 QualifierLoc
5726 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5727 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005728 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005729 }
John McCallce546572009-12-08 09:08:17 +00005730
5731 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005732 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5733 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005734 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005735 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005736
John McCall815039a2010-08-17 21:27:17 +00005737 DeclarationNameInfo NameInfo = E->getNameInfo();
5738 if (NameInfo.getName()) {
5739 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5740 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005741 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005742 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005743
5744 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005745 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005746 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005747 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005748 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005749
5750 // Mark it referenced in the new context regardless.
5751 // FIXME: this is a bit instantiation-specific.
5752 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5753
John McCallc3007a22010-10-26 07:05:15 +00005754 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005755 }
John McCallce546572009-12-08 09:08:17 +00005756
5757 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005758 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005759 TemplateArgs = &TransArgs;
5760 TransArgs.setLAngleLoc(E->getLAngleLoc());
5761 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005762 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5763 E->getNumTemplateArgs(),
5764 TransArgs))
5765 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005766 }
5767
Douglas Gregorea972d32011-02-28 21:54:11 +00005768 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5769 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005770}
Mike Stump11289f42009-09-09 15:08:12 +00005771
Douglas Gregora16548e2009-08-11 05:31:07 +00005772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005773ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005774TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005775 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005776}
Mike Stump11289f42009-09-09 15:08:12 +00005777
Douglas Gregora16548e2009-08-11 05:31:07 +00005778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005779ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005780TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005781 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005782}
Mike Stump11289f42009-09-09 15:08:12 +00005783
Douglas Gregora16548e2009-08-11 05:31:07 +00005784template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005785ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005786TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005787 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005788}
Mike Stump11289f42009-09-09 15:08:12 +00005789
Douglas Gregora16548e2009-08-11 05:31:07 +00005790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005791ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005792TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005793 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005794}
Mike Stump11289f42009-09-09 15:08:12 +00005795
Douglas Gregora16548e2009-08-11 05:31:07 +00005796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005797ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005798TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005799 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005800}
5801
5802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005803ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005804TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5805 ExprResult ControllingExpr =
5806 getDerived().TransformExpr(E->getControllingExpr());
5807 if (ControllingExpr.isInvalid())
5808 return ExprError();
5809
5810 llvm::SmallVector<Expr *, 4> AssocExprs;
5811 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5812 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5813 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5814 if (TS) {
5815 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5816 if (!AssocType)
5817 return ExprError();
5818 AssocTypes.push_back(AssocType);
5819 } else {
5820 AssocTypes.push_back(0);
5821 }
5822
5823 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5824 if (AssocExpr.isInvalid())
5825 return ExprError();
5826 AssocExprs.push_back(AssocExpr.release());
5827 }
5828
5829 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5830 E->getDefaultLoc(),
5831 E->getRParenLoc(),
5832 ControllingExpr.release(),
5833 AssocTypes.data(),
5834 AssocExprs.data(),
5835 E->getNumAssocs());
5836}
5837
5838template<typename Derived>
5839ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005840TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005841 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005842 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005843 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005844
Douglas Gregora16548e2009-08-11 05:31:07 +00005845 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005846 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005847
John McCallb268a282010-08-23 23:25:46 +00005848 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005849 E->getRParen());
5850}
5851
Mike Stump11289f42009-09-09 15:08:12 +00005852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005854TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005855 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005856 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005857 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005858
Douglas Gregora16548e2009-08-11 05:31:07 +00005859 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005860 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005861
Douglas Gregora16548e2009-08-11 05:31:07 +00005862 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5863 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005864 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005865}
Mike Stump11289f42009-09-09 15:08:12 +00005866
Douglas Gregora16548e2009-08-11 05:31:07 +00005867template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005868ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005869TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5870 // Transform the type.
5871 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5872 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005873 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005874
Douglas Gregor882211c2010-04-28 22:16:22 +00005875 // Transform all of the components into components similar to what the
5876 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005877 // FIXME: It would be slightly more efficient in the non-dependent case to
5878 // just map FieldDecls, rather than requiring the rebuilder to look for
5879 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005880 // template code that we don't care.
5881 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005882 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005883 typedef OffsetOfExpr::OffsetOfNode Node;
5884 llvm::SmallVector<Component, 4> Components;
5885 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5886 const Node &ON = E->getComponent(I);
5887 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005888 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005889 Comp.LocStart = ON.getSourceRange().getBegin();
5890 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005891 switch (ON.getKind()) {
5892 case Node::Array: {
5893 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005894 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005895 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005896 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005897
Douglas Gregor882211c2010-04-28 22:16:22 +00005898 ExprChanged = ExprChanged || Index.get() != FromIndex;
5899 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005900 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005901 break;
5902 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005903
Douglas Gregor882211c2010-04-28 22:16:22 +00005904 case Node::Field:
5905 case Node::Identifier:
5906 Comp.isBrackets = false;
5907 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005908 if (!Comp.U.IdentInfo)
5909 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005910
Douglas Gregor882211c2010-04-28 22:16:22 +00005911 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005912
Douglas Gregord1702062010-04-29 00:18:15 +00005913 case Node::Base:
5914 // Will be recomputed during the rebuild.
5915 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005916 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005917
Douglas Gregor882211c2010-04-28 22:16:22 +00005918 Components.push_back(Comp);
5919 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005920
Douglas Gregor882211c2010-04-28 22:16:22 +00005921 // If nothing changed, retain the existing expression.
5922 if (!getDerived().AlwaysRebuild() &&
5923 Type == E->getTypeSourceInfo() &&
5924 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005925 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005926
Douglas Gregor882211c2010-04-28 22:16:22 +00005927 // Build a new offsetof expression.
5928 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5929 Components.data(), Components.size(),
5930 E->getRParenLoc());
5931}
5932
5933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005934ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005935TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5936 assert(getDerived().AlreadyTransformed(E->getType()) &&
5937 "opaque value expression requires transformation");
5938 return SemaRef.Owned(E);
5939}
5940
5941template<typename Derived>
5942ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005943TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5944 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005945 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005946 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005947
John McCallbcd03502009-12-07 02:54:59 +00005948 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005949 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005950 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005951
John McCall4c98fd82009-11-04 07:28:41 +00005952 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005953 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005954
Peter Collingbournee190dee2011-03-11 19:24:49 +00005955 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5956 E->getKind(),
5957 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005958 }
Mike Stump11289f42009-09-09 15:08:12 +00005959
John McCalldadc5752010-08-24 06:29:42 +00005960 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005961 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005962 // C++0x [expr.sizeof]p1:
5963 // The operand is either an expression, which is an unevaluated operand
5964 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005965 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005966
Douglas Gregora16548e2009-08-11 05:31:07 +00005967 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5968 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005969 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005970
Douglas Gregora16548e2009-08-11 05:31:07 +00005971 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005972 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005973 }
Mike Stump11289f42009-09-09 15:08:12 +00005974
Peter Collingbournee190dee2011-03-11 19:24:49 +00005975 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5976 E->getOperatorLoc(),
5977 E->getKind(),
5978 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005979}
Mike Stump11289f42009-09-09 15:08:12 +00005980
Douglas Gregora16548e2009-08-11 05:31:07 +00005981template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005982ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005983TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005984 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005985 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005986 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005987
John McCalldadc5752010-08-24 06:29:42 +00005988 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005989 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005990 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005991
5992
Douglas Gregora16548e2009-08-11 05:31:07 +00005993 if (!getDerived().AlwaysRebuild() &&
5994 LHS.get() == E->getLHS() &&
5995 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005996 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005997
John McCallb268a282010-08-23 23:25:46 +00005998 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005999 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006000 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006001 E->getRBracketLoc());
6002}
Mike Stump11289f42009-09-09 15:08:12 +00006003
6004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006005ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006006TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006007 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006008 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006009 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006010 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006011
6012 // Transform arguments.
6013 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006014 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006015 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6016 &ArgChanged))
6017 return ExprError();
6018
Douglas Gregora16548e2009-08-11 05:31:07 +00006019 if (!getDerived().AlwaysRebuild() &&
6020 Callee.get() == E->getCallee() &&
6021 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006022 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006023
Douglas Gregora16548e2009-08-11 05:31:07 +00006024 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006025 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006026 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006027 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006028 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006029 E->getRParenLoc());
6030}
Mike Stump11289f42009-09-09 15:08:12 +00006031
6032template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006033ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006034TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006035 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006036 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006037 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006038
Douglas Gregorea972d32011-02-28 21:54:11 +00006039 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006040 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006041 QualifierLoc
6042 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6043
6044 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006045 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006046 }
Mike Stump11289f42009-09-09 15:08:12 +00006047
Eli Friedman2cfcef62009-12-04 06:40:45 +00006048 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006049 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6050 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006051 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006052 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006053
John McCall16df1e52010-03-30 21:47:33 +00006054 NamedDecl *FoundDecl = E->getFoundDecl();
6055 if (FoundDecl == E->getMemberDecl()) {
6056 FoundDecl = Member;
6057 } else {
6058 FoundDecl = cast_or_null<NamedDecl>(
6059 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6060 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006061 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006062 }
6063
Douglas Gregora16548e2009-08-11 05:31:07 +00006064 if (!getDerived().AlwaysRebuild() &&
6065 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006066 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006067 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006068 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006069 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006070
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006071 // Mark it referenced in the new context regardless.
6072 // FIXME: this is a bit instantiation-specific.
6073 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00006074 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006075 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006076
John McCall6b51f282009-11-23 01:53:49 +00006077 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006078 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006079 TransArgs.setLAngleLoc(E->getLAngleLoc());
6080 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006081 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6082 E->getNumTemplateArgs(),
6083 TransArgs))
6084 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006085 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006086
Douglas Gregora16548e2009-08-11 05:31:07 +00006087 // FIXME: Bogus source location for the operator
6088 SourceLocation FakeOperatorLoc
6089 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6090
John McCall38836f02010-01-15 08:34:02 +00006091 // FIXME: to do this check properly, we will need to preserve the
6092 // first-qualifier-in-scope here, just in case we had a dependent
6093 // base (and therefore couldn't do the check) and a
6094 // nested-name-qualifier (and therefore could do the lookup).
6095 NamedDecl *FirstQualifierInScope = 0;
6096
John McCallb268a282010-08-23 23:25:46 +00006097 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006098 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006099 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006100 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006101 Member,
John McCall16df1e52010-03-30 21:47:33 +00006102 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006103 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006104 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006105 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006106}
Mike Stump11289f42009-09-09 15:08:12 +00006107
Douglas Gregora16548e2009-08-11 05:31:07 +00006108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006109ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006110TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006111 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006112 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006114
John McCalldadc5752010-08-24 06:29:42 +00006115 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006116 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006117 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006118
Douglas Gregora16548e2009-08-11 05:31:07 +00006119 if (!getDerived().AlwaysRebuild() &&
6120 LHS.get() == E->getLHS() &&
6121 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006122 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006123
Douglas Gregora16548e2009-08-11 05:31:07 +00006124 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006125 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006126}
6127
Mike Stump11289f42009-09-09 15:08:12 +00006128template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006129ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006130TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006131 CompoundAssignOperator *E) {
6132 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006133}
Mike Stump11289f42009-09-09 15:08:12 +00006134
Douglas Gregora16548e2009-08-11 05:31:07 +00006135template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006136ExprResult TreeTransform<Derived>::
6137TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6138 // Just rebuild the common and RHS expressions and see whether we
6139 // get any changes.
6140
6141 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6142 if (commonExpr.isInvalid())
6143 return ExprError();
6144
6145 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6146 if (rhs.isInvalid())
6147 return ExprError();
6148
6149 if (!getDerived().AlwaysRebuild() &&
6150 commonExpr.get() == e->getCommon() &&
6151 rhs.get() == e->getFalseExpr())
6152 return SemaRef.Owned(e);
6153
6154 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6155 e->getQuestionLoc(),
6156 0,
6157 e->getColonLoc(),
6158 rhs.get());
6159}
6160
6161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006162ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006163TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006164 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006165 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006166 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006167
John McCalldadc5752010-08-24 06:29:42 +00006168 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006169 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006170 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006171
John McCalldadc5752010-08-24 06:29:42 +00006172 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006173 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006174 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006175
Douglas Gregora16548e2009-08-11 05:31:07 +00006176 if (!getDerived().AlwaysRebuild() &&
6177 Cond.get() == E->getCond() &&
6178 LHS.get() == E->getLHS() &&
6179 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006180 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006181
John McCallb268a282010-08-23 23:25:46 +00006182 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006183 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006184 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006185 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006186 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006187}
Mike Stump11289f42009-09-09 15:08:12 +00006188
6189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006190ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006191TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006192 // Implicit casts are eliminated during transformation, since they
6193 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006194 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006195}
Mike Stump11289f42009-09-09 15:08:12 +00006196
Douglas Gregora16548e2009-08-11 05:31:07 +00006197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006198ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006199TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006200 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6201 if (!Type)
6202 return ExprError();
6203
John McCalldadc5752010-08-24 06:29:42 +00006204 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006205 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006206 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006207 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006208
Douglas Gregora16548e2009-08-11 05:31:07 +00006209 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006210 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006211 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006212 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006213
John McCall97513962010-01-15 18:39:57 +00006214 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006215 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006216 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006217 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006218}
Mike Stump11289f42009-09-09 15:08:12 +00006219
Douglas Gregora16548e2009-08-11 05:31:07 +00006220template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006221ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006222TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006223 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6224 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6225 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006227
John McCalldadc5752010-08-24 06:29:42 +00006228 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006229 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006230 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006231
Douglas Gregora16548e2009-08-11 05:31:07 +00006232 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006233 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006234 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006235 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006236
John McCall5d7aa7f2010-01-19 22:33:45 +00006237 // Note: the expression type doesn't necessarily match the
6238 // type-as-written, but that's okay, because it should always be
6239 // derivable from the initializer.
6240
John McCalle15bbff2010-01-18 19:35:47 +00006241 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006242 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006243 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006244}
Mike Stump11289f42009-09-09 15:08:12 +00006245
Douglas Gregora16548e2009-08-11 05:31:07 +00006246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006247ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006248TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006249 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006250 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006251 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006252
Douglas Gregora16548e2009-08-11 05:31:07 +00006253 if (!getDerived().AlwaysRebuild() &&
6254 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006255 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006256
Douglas Gregora16548e2009-08-11 05:31:07 +00006257 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006258 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006259 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006260 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006261 E->getAccessorLoc(),
6262 E->getAccessor());
6263}
Mike Stump11289f42009-09-09 15:08:12 +00006264
Douglas Gregora16548e2009-08-11 05:31:07 +00006265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006266ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006267TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006268 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006269
John McCall37ad5512010-08-23 06:44:23 +00006270 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006271 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6272 Inits, &InitChanged))
6273 return ExprError();
6274
Douglas Gregora16548e2009-08-11 05:31:07 +00006275 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006276 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006277
Douglas Gregora16548e2009-08-11 05:31:07 +00006278 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006279 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006280}
Mike Stump11289f42009-09-09 15:08:12 +00006281
Douglas Gregora16548e2009-08-11 05:31:07 +00006282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006283ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006284TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006285 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006286
Douglas Gregorebe10102009-08-20 07:17:43 +00006287 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006288 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006289 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006290 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006291
Douglas Gregorebe10102009-08-20 07:17:43 +00006292 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006293 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006294 bool ExprChanged = false;
6295 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6296 DEnd = E->designators_end();
6297 D != DEnd; ++D) {
6298 if (D->isFieldDesignator()) {
6299 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6300 D->getDotLoc(),
6301 D->getFieldLoc()));
6302 continue;
6303 }
Mike Stump11289f42009-09-09 15:08:12 +00006304
Douglas Gregora16548e2009-08-11 05:31:07 +00006305 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006306 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006307 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006308 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006309
6310 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006311 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006312
Douglas Gregora16548e2009-08-11 05:31:07 +00006313 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6314 ArrayExprs.push_back(Index.release());
6315 continue;
6316 }
Mike Stump11289f42009-09-09 15:08:12 +00006317
Douglas Gregora16548e2009-08-11 05:31:07 +00006318 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006319 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006320 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6321 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006322 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006323
John McCalldadc5752010-08-24 06:29:42 +00006324 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006325 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006326 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006327
6328 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006329 End.get(),
6330 D->getLBracketLoc(),
6331 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006332
Douglas Gregora16548e2009-08-11 05:31:07 +00006333 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6334 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006335
Douglas Gregora16548e2009-08-11 05:31:07 +00006336 ArrayExprs.push_back(Start.release());
6337 ArrayExprs.push_back(End.release());
6338 }
Mike Stump11289f42009-09-09 15:08:12 +00006339
Douglas Gregora16548e2009-08-11 05:31:07 +00006340 if (!getDerived().AlwaysRebuild() &&
6341 Init.get() == E->getInit() &&
6342 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006343 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006344
Douglas Gregora16548e2009-08-11 05:31:07 +00006345 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6346 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006347 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006348}
Mike Stump11289f42009-09-09 15:08:12 +00006349
Douglas Gregora16548e2009-08-11 05:31:07 +00006350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006351ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006352TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006353 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006354 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006355
Douglas Gregor3da3c062009-10-28 00:29:27 +00006356 // FIXME: Will we ever have proper type location here? Will we actually
6357 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006358 QualType T = getDerived().TransformType(E->getType());
6359 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006360 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006361
Douglas Gregora16548e2009-08-11 05:31:07 +00006362 if (!getDerived().AlwaysRebuild() &&
6363 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006364 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006365
Douglas Gregora16548e2009-08-11 05:31:07 +00006366 return getDerived().RebuildImplicitValueInitExpr(T);
6367}
Mike Stump11289f42009-09-09 15:08:12 +00006368
Douglas Gregora16548e2009-08-11 05:31:07 +00006369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006370ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006371TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006372 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6373 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006374 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006375
John McCalldadc5752010-08-24 06:29:42 +00006376 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006377 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006378 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006379
Douglas Gregora16548e2009-08-11 05:31:07 +00006380 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006381 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006382 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006383 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006384
John McCallb268a282010-08-23 23:25:46 +00006385 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006386 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006387}
6388
6389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006390ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006391TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006392 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006393 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006394 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6395 &ArgumentChanged))
6396 return ExprError();
6397
Douglas Gregora16548e2009-08-11 05:31:07 +00006398 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6399 move_arg(Inits),
6400 E->getRParenLoc());
6401}
Mike Stump11289f42009-09-09 15:08:12 +00006402
Douglas Gregora16548e2009-08-11 05:31:07 +00006403/// \brief Transform an address-of-label expression.
6404///
6405/// By default, the transformation of an address-of-label expression always
6406/// rebuilds the expression, so that the label identifier can be resolved to
6407/// the corresponding label statement by semantic analysis.
6408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006409ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006410TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006411 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6412 E->getLabel());
6413 if (!LD)
6414 return ExprError();
6415
Douglas Gregora16548e2009-08-11 05:31:07 +00006416 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006417 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006418}
Mike Stump11289f42009-09-09 15:08:12 +00006419
6420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006422TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006423 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006424 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6425 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006427
Douglas Gregora16548e2009-08-11 05:31:07 +00006428 if (!getDerived().AlwaysRebuild() &&
6429 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006430 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006431
6432 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006433 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006434 E->getRParenLoc());
6435}
Mike Stump11289f42009-09-09 15:08:12 +00006436
Douglas Gregora16548e2009-08-11 05:31:07 +00006437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006438ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006439TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006440 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006441 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006442 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006443
John McCalldadc5752010-08-24 06:29:42 +00006444 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006445 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006446 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006447
John McCalldadc5752010-08-24 06:29:42 +00006448 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006449 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006450 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006451
Douglas Gregora16548e2009-08-11 05:31:07 +00006452 if (!getDerived().AlwaysRebuild() &&
6453 Cond.get() == E->getCond() &&
6454 LHS.get() == E->getLHS() &&
6455 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006456 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006457
Douglas Gregora16548e2009-08-11 05:31:07 +00006458 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006459 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006460 E->getRParenLoc());
6461}
Mike Stump11289f42009-09-09 15:08:12 +00006462
Douglas Gregora16548e2009-08-11 05:31:07 +00006463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006464ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006465TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006466 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006467}
6468
6469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006471TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006472 switch (E->getOperator()) {
6473 case OO_New:
6474 case OO_Delete:
6475 case OO_Array_New:
6476 case OO_Array_Delete:
6477 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006478 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006479
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006480 case OO_Call: {
6481 // This is a call to an object's operator().
6482 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6483
6484 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006485 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006486 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006487 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006488
6489 // FIXME: Poor location information
6490 SourceLocation FakeLParenLoc
6491 = SemaRef.PP.getLocForEndOfToken(
6492 static_cast<Expr *>(Object.get())->getLocEnd());
6493
6494 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006495 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006496 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6497 Args))
6498 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006499
John McCallb268a282010-08-23 23:25:46 +00006500 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006501 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006502 E->getLocEnd());
6503 }
6504
6505#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6506 case OO_##Name:
6507#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6508#include "clang/Basic/OperatorKinds.def"
6509 case OO_Subscript:
6510 // Handled below.
6511 break;
6512
6513 case OO_Conditional:
6514 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006515 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006516
6517 case OO_None:
6518 case NUM_OVERLOADED_OPERATORS:
6519 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006520 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006521 }
6522
John McCalldadc5752010-08-24 06:29:42 +00006523 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006524 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006525 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006526
John McCalldadc5752010-08-24 06:29:42 +00006527 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006528 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006529 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006530
John McCalldadc5752010-08-24 06:29:42 +00006531 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006532 if (E->getNumArgs() == 2) {
6533 Second = getDerived().TransformExpr(E->getArg(1));
6534 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006535 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006536 }
Mike Stump11289f42009-09-09 15:08:12 +00006537
Douglas Gregora16548e2009-08-11 05:31:07 +00006538 if (!getDerived().AlwaysRebuild() &&
6539 Callee.get() == E->getCallee() &&
6540 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006541 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006542 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006543
Douglas Gregora16548e2009-08-11 05:31:07 +00006544 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6545 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006546 Callee.get(),
6547 First.get(),
6548 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006549}
Mike Stump11289f42009-09-09 15:08:12 +00006550
Douglas Gregora16548e2009-08-11 05:31:07 +00006551template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006552ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006553TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6554 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006555}
Mike Stump11289f42009-09-09 15:08:12 +00006556
Douglas Gregora16548e2009-08-11 05:31:07 +00006557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006558ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006559TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6560 // Transform the callee.
6561 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6562 if (Callee.isInvalid())
6563 return ExprError();
6564
6565 // Transform exec config.
6566 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6567 if (EC.isInvalid())
6568 return ExprError();
6569
6570 // Transform arguments.
6571 bool ArgChanged = false;
6572 ASTOwningVector<Expr*> Args(SemaRef);
6573 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6574 &ArgChanged))
6575 return ExprError();
6576
6577 if (!getDerived().AlwaysRebuild() &&
6578 Callee.get() == E->getCallee() &&
6579 !ArgChanged)
6580 return SemaRef.Owned(E);
6581
6582 // FIXME: Wrong source location information for the '('.
6583 SourceLocation FakeLParenLoc
6584 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6585 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6586 move_arg(Args),
6587 E->getRParenLoc(), EC.get());
6588}
6589
6590template<typename Derived>
6591ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006592TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006593 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6594 if (!Type)
6595 return ExprError();
6596
John McCalldadc5752010-08-24 06:29:42 +00006597 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006598 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006599 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006601
Douglas Gregora16548e2009-08-11 05:31:07 +00006602 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006603 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006604 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006605 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006606
Douglas Gregora16548e2009-08-11 05:31:07 +00006607 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006608 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006609 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6610 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6611 SourceLocation FakeRParenLoc
6612 = SemaRef.PP.getLocForEndOfToken(
6613 E->getSubExpr()->getSourceRange().getEnd());
6614 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006615 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006616 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006617 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006618 FakeRAngleLoc,
6619 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006620 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006621 FakeRParenLoc);
6622}
Mike Stump11289f42009-09-09 15:08:12 +00006623
Douglas Gregora16548e2009-08-11 05:31:07 +00006624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006625ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006626TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6627 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006628}
Mike Stump11289f42009-09-09 15:08:12 +00006629
6630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006631ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006632TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6633 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006634}
6635
Douglas Gregora16548e2009-08-11 05:31:07 +00006636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006637ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006638TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006639 CXXReinterpretCastExpr *E) {
6640 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006641}
Mike Stump11289f42009-09-09 15:08:12 +00006642
Douglas Gregora16548e2009-08-11 05:31:07 +00006643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006644ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006645TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6646 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006647}
Mike Stump11289f42009-09-09 15:08:12 +00006648
Douglas Gregora16548e2009-08-11 05:31:07 +00006649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006650ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006651TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006652 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006653 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6654 if (!Type)
6655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006656
John McCalldadc5752010-08-24 06:29:42 +00006657 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006658 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006659 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006660 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006661
Douglas Gregora16548e2009-08-11 05:31:07 +00006662 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006663 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006664 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006665 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006666
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006667 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006668 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006669 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006670 E->getRParenLoc());
6671}
Mike Stump11289f42009-09-09 15:08:12 +00006672
Douglas Gregora16548e2009-08-11 05:31:07 +00006673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006674ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006675TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006677 TypeSourceInfo *TInfo
6678 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6679 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006680 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006681
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006683 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006684 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006685
Douglas Gregor9da64192010-04-26 22:37:10 +00006686 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6687 E->getLocStart(),
6688 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006689 E->getLocEnd());
6690 }
Mike Stump11289f42009-09-09 15:08:12 +00006691
Douglas Gregora16548e2009-08-11 05:31:07 +00006692 // We don't know whether the expression is potentially evaluated until
6693 // after we perform semantic analysis, so the expression is potentially
6694 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006695 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006696 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006697
John McCalldadc5752010-08-24 06:29:42 +00006698 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006699 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006700 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006701
Douglas Gregora16548e2009-08-11 05:31:07 +00006702 if (!getDerived().AlwaysRebuild() &&
6703 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006704 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006705
Douglas Gregor9da64192010-04-26 22:37:10 +00006706 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6707 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006708 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006709 E->getLocEnd());
6710}
6711
6712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006713ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006714TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6715 if (E->isTypeOperand()) {
6716 TypeSourceInfo *TInfo
6717 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6718 if (!TInfo)
6719 return ExprError();
6720
6721 if (!getDerived().AlwaysRebuild() &&
6722 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006723 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006724
Douglas Gregor69735112011-03-06 17:40:41 +00006725 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006726 E->getLocStart(),
6727 TInfo,
6728 E->getLocEnd());
6729 }
6730
6731 // We don't know whether the expression is potentially evaluated until
6732 // after we perform semantic analysis, so the expression is potentially
6733 // potentially evaluated.
6734 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6735
6736 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6737 if (SubExpr.isInvalid())
6738 return ExprError();
6739
6740 if (!getDerived().AlwaysRebuild() &&
6741 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006742 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006743
6744 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6745 E->getLocStart(),
6746 SubExpr.get(),
6747 E->getLocEnd());
6748}
6749
6750template<typename Derived>
6751ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006752TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006753 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006754}
Mike Stump11289f42009-09-09 15:08:12 +00006755
Douglas Gregora16548e2009-08-11 05:31:07 +00006756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006757ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006758TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006759 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006760 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006761}
Mike Stump11289f42009-09-09 15:08:12 +00006762
Douglas Gregora16548e2009-08-11 05:31:07 +00006763template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006764ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006765TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006766 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith938f40b2011-06-11 17:19:42 +00006767 QualType T;
6768 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6769 T = MD->getThisType(getSema().Context);
6770 else
6771 T = getSema().Context.getPointerType(
6772 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump11289f42009-09-09 15:08:12 +00006773
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006774 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006775 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006776
Douglas Gregorb15af892010-01-07 23:12:05 +00006777 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006778}
Mike Stump11289f42009-09-09 15:08:12 +00006779
Douglas Gregora16548e2009-08-11 05:31:07 +00006780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006781ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006782TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006783 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006784 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006786
Douglas Gregora16548e2009-08-11 05:31:07 +00006787 if (!getDerived().AlwaysRebuild() &&
6788 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006789 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006790
John McCallb268a282010-08-23 23:25:46 +00006791 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006792}
Mike Stump11289f42009-09-09 15:08:12 +00006793
Douglas Gregora16548e2009-08-11 05:31:07 +00006794template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006795ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006796TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006797 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006798 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6799 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006800 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006801 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006802
Chandler Carruth794da4c2010-02-08 06:42:49 +00006803 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006804 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006805 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006806
Douglas Gregor033f6752009-12-23 23:03:06 +00006807 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006808}
Mike Stump11289f42009-09-09 15:08:12 +00006809
Douglas Gregora16548e2009-08-11 05:31:07 +00006810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006811ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006812TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6813 CXXScalarValueInitExpr *E) {
6814 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6815 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006816 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006817
Douglas Gregora16548e2009-08-11 05:31:07 +00006818 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006819 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006820 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006821
Douglas Gregor2b88c112010-09-08 00:15:04 +00006822 return getDerived().RebuildCXXScalarValueInitExpr(T,
6823 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006824 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006825}
Mike Stump11289f42009-09-09 15:08:12 +00006826
Douglas Gregora16548e2009-08-11 05:31:07 +00006827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006828ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006829TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006830 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006831 TypeSourceInfo *AllocTypeInfo
6832 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6833 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006834 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006835
Douglas Gregora16548e2009-08-11 05:31:07 +00006836 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006837 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006838 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006839 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006840
Douglas Gregora16548e2009-08-11 05:31:07 +00006841 // Transform the placement arguments (if any).
6842 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006843 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006844 if (getDerived().TransformExprs(E->getPlacementArgs(),
6845 E->getNumPlacementArgs(), true,
6846 PlacementArgs, &ArgumentChanged))
6847 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006848
Douglas Gregorebe10102009-08-20 07:17:43 +00006849 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006850 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006851 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6852 ConstructorArgs, &ArgumentChanged))
6853 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006854
Douglas Gregord2d9da02010-02-26 00:38:10 +00006855 // Transform constructor, new operator, and delete operator.
6856 CXXConstructorDecl *Constructor = 0;
6857 if (E->getConstructor()) {
6858 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006859 getDerived().TransformDecl(E->getLocStart(),
6860 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006861 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006862 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006863 }
6864
6865 FunctionDecl *OperatorNew = 0;
6866 if (E->getOperatorNew()) {
6867 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006868 getDerived().TransformDecl(E->getLocStart(),
6869 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006870 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006871 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006872 }
6873
6874 FunctionDecl *OperatorDelete = 0;
6875 if (E->getOperatorDelete()) {
6876 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006877 getDerived().TransformDecl(E->getLocStart(),
6878 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006879 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006880 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006881 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006882
Douglas Gregora16548e2009-08-11 05:31:07 +00006883 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006884 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006885 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006886 Constructor == E->getConstructor() &&
6887 OperatorNew == E->getOperatorNew() &&
6888 OperatorDelete == E->getOperatorDelete() &&
6889 !ArgumentChanged) {
6890 // Mark any declarations we need as referenced.
6891 // FIXME: instantiation-specific.
6892 if (Constructor)
6893 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6894 if (OperatorNew)
6895 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6896 if (OperatorDelete)
6897 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006898 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006899 }
Mike Stump11289f42009-09-09 15:08:12 +00006900
Douglas Gregor0744ef62010-09-07 21:49:58 +00006901 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006902 if (!ArraySize.get()) {
6903 // If no array size was specified, but the new expression was
6904 // instantiated with an array type (e.g., "new T" where T is
6905 // instantiated with "int[4]"), extract the outer bound from the
6906 // array type as our array size. We do this with constant and
6907 // dependently-sized array types.
6908 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6909 if (!ArrayT) {
6910 // Do nothing
6911 } else if (const ConstantArrayType *ConsArrayT
6912 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006913 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006914 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6915 ConsArrayT->getSize(),
6916 SemaRef.Context.getSizeType(),
6917 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006918 AllocType = ConsArrayT->getElementType();
6919 } else if (const DependentSizedArrayType *DepArrayT
6920 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6921 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006922 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006923 AllocType = DepArrayT->getElementType();
6924 }
6925 }
6926 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006927
Douglas Gregora16548e2009-08-11 05:31:07 +00006928 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6929 E->isGlobalNew(),
6930 /*FIXME:*/E->getLocStart(),
6931 move_arg(PlacementArgs),
6932 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006933 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006934 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006935 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006936 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006937 /*FIXME:*/E->getLocStart(),
6938 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006939 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006940}
Mike Stump11289f42009-09-09 15:08:12 +00006941
Douglas Gregora16548e2009-08-11 05:31:07 +00006942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006944TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006945 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006946 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006947 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006948
Douglas Gregord2d9da02010-02-26 00:38:10 +00006949 // Transform the delete operator, if known.
6950 FunctionDecl *OperatorDelete = 0;
6951 if (E->getOperatorDelete()) {
6952 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006953 getDerived().TransformDecl(E->getLocStart(),
6954 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006955 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006956 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006957 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006958
Douglas Gregora16548e2009-08-11 05:31:07 +00006959 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006960 Operand.get() == E->getArgument() &&
6961 OperatorDelete == E->getOperatorDelete()) {
6962 // Mark any declarations we need as referenced.
6963 // FIXME: instantiation-specific.
6964 if (OperatorDelete)
6965 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006966
6967 if (!E->getArgument()->isTypeDependent()) {
6968 QualType Destroyed = SemaRef.Context.getBaseElementType(
6969 E->getDestroyedType());
6970 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6971 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6972 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6973 SemaRef.LookupDestructor(Record));
6974 }
6975 }
6976
John McCallc3007a22010-10-26 07:05:15 +00006977 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006978 }
Mike Stump11289f42009-09-09 15:08:12 +00006979
Douglas Gregora16548e2009-08-11 05:31:07 +00006980 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6981 E->isGlobalDelete(),
6982 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006983 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006984}
Mike Stump11289f42009-09-09 15:08:12 +00006985
Douglas Gregora16548e2009-08-11 05:31:07 +00006986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006987ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006988TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006989 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006990 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006991 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006992 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006993
John McCallba7bf592010-08-24 05:47:05 +00006994 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006995 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006996 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006997 E->getOperatorLoc(),
6998 E->isArrow()? tok::arrow : tok::period,
6999 ObjectTypePtr,
7000 MayBePseudoDestructor);
7001 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007002 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007003
John McCallba7bf592010-08-24 05:47:05 +00007004 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007005 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7006 if (QualifierLoc) {
7007 QualifierLoc
7008 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7009 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007010 return ExprError();
7011 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007012 CXXScopeSpec SS;
7013 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007014
Douglas Gregor678f90d2010-02-25 01:56:36 +00007015 PseudoDestructorTypeStorage Destroyed;
7016 if (E->getDestroyedTypeInfo()) {
7017 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007018 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007019 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007020 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007021 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007022 Destroyed = DestroyedTypeInfo;
7023 } else if (ObjectType->isDependentType()) {
7024 // We aren't likely to be able to resolve the identifier down to a type
7025 // now anyway, so just retain the identifier.
7026 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7027 E->getDestroyedTypeLoc());
7028 } else {
7029 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007030 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007031 *E->getDestroyedTypeIdentifier(),
7032 E->getDestroyedTypeLoc(),
7033 /*Scope=*/0,
7034 SS, ObjectTypePtr,
7035 false);
7036 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007037 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007038
Douglas Gregor678f90d2010-02-25 01:56:36 +00007039 Destroyed
7040 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7041 E->getDestroyedTypeLoc());
7042 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007043
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007044 TypeSourceInfo *ScopeTypeInfo = 0;
7045 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00007046 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007047 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007048 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007049 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007050
John McCallb268a282010-08-23 23:25:46 +00007051 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007052 E->getOperatorLoc(),
7053 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007054 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007055 ScopeTypeInfo,
7056 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007057 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007058 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007059}
Mike Stump11289f42009-09-09 15:08:12 +00007060
Douglas Gregorad8a3362009-09-04 17:36:40 +00007061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007062ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007063TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007064 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007065 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7066 Sema::LookupOrdinaryName);
7067
7068 // Transform all the decls.
7069 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7070 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007071 NamedDecl *InstD = static_cast<NamedDecl*>(
7072 getDerived().TransformDecl(Old->getNameLoc(),
7073 *I));
John McCall84d87672009-12-10 09:41:52 +00007074 if (!InstD) {
7075 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7076 // This can happen because of dependent hiding.
7077 if (isa<UsingShadowDecl>(*I))
7078 continue;
7079 else
John McCallfaf5fb42010-08-26 23:41:50 +00007080 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007081 }
John McCalle66edc12009-11-24 19:00:30 +00007082
7083 // Expand using declarations.
7084 if (isa<UsingDecl>(InstD)) {
7085 UsingDecl *UD = cast<UsingDecl>(InstD);
7086 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7087 E = UD->shadow_end(); I != E; ++I)
7088 R.addDecl(*I);
7089 continue;
7090 }
7091
7092 R.addDecl(InstD);
7093 }
7094
7095 // Resolve a kind, but don't do any further analysis. If it's
7096 // ambiguous, the callee needs to deal with it.
7097 R.resolveKind();
7098
7099 // Rebuild the nested-name qualifier, if present.
7100 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007101 if (Old->getQualifierLoc()) {
7102 NestedNameSpecifierLoc QualifierLoc
7103 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7104 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007105 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007106
Douglas Gregor0da1d432011-02-28 20:01:57 +00007107 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007108 }
7109
Douglas Gregor9262f472010-04-27 18:19:34 +00007110 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007111 CXXRecordDecl *NamingClass
7112 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7113 Old->getNameLoc(),
7114 Old->getNamingClass()));
7115 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007116 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007117
Douglas Gregorda7be082010-04-27 16:10:10 +00007118 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007119 }
7120
7121 // If we have no template arguments, it's a normal declaration name.
7122 if (!Old->hasExplicitTemplateArgs())
7123 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7124
7125 // If we have template arguments, rebuild them, then rebuild the
7126 // templateid expression.
7127 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007128 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7129 Old->getNumTemplateArgs(),
7130 TransArgs))
7131 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007132
7133 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7134 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007135}
Mike Stump11289f42009-09-09 15:08:12 +00007136
Douglas Gregora16548e2009-08-11 05:31:07 +00007137template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007138ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007139TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007140 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7141 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007142 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007143
Douglas Gregora16548e2009-08-11 05:31:07 +00007144 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007145 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007146 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007147
Mike Stump11289f42009-09-09 15:08:12 +00007148 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007149 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007150 T,
7151 E->getLocEnd());
7152}
Mike Stump11289f42009-09-09 15:08:12 +00007153
Douglas Gregora16548e2009-08-11 05:31:07 +00007154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007155ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007156TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7157 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7158 if (!LhsT)
7159 return ExprError();
7160
7161 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7162 if (!RhsT)
7163 return ExprError();
7164
7165 if (!getDerived().AlwaysRebuild() &&
7166 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7167 return SemaRef.Owned(E);
7168
7169 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7170 E->getLocStart(),
7171 LhsT, RhsT,
7172 E->getLocEnd());
7173}
7174
7175template<typename Derived>
7176ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007177TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7178 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7179 if (!T)
7180 return ExprError();
7181
7182 if (!getDerived().AlwaysRebuild() &&
7183 T == E->getQueriedTypeSourceInfo())
7184 return SemaRef.Owned(E);
7185
7186 ExprResult SubExpr;
7187 {
7188 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7189 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7190 if (SubExpr.isInvalid())
7191 return ExprError();
7192
7193 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7194 return SemaRef.Owned(E);
7195 }
7196
7197 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7198 E->getLocStart(),
7199 T,
7200 SubExpr.get(),
7201 E->getLocEnd());
7202}
7203
7204template<typename Derived>
7205ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007206TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7207 ExprResult SubExpr;
7208 {
7209 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7210 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7211 if (SubExpr.isInvalid())
7212 return ExprError();
7213
7214 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7215 return SemaRef.Owned(E);
7216 }
7217
7218 return getDerived().RebuildExpressionTrait(
7219 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7220}
7221
7222template<typename Derived>
7223ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007224TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007225 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007226 NestedNameSpecifierLoc QualifierLoc
7227 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7228 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007229 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007230
John McCall31f82722010-11-12 08:19:04 +00007231 // TODO: If this is a conversion-function-id, verify that the
7232 // destination type name (if present) resolves the same way after
7233 // instantiation as it did in the local scope.
7234
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007235 DeclarationNameInfo NameInfo
7236 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7237 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007239
John McCalle66edc12009-11-24 19:00:30 +00007240 if (!E->hasExplicitTemplateArgs()) {
7241 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007242 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007243 // Note: it is sufficient to compare the Name component of NameInfo:
7244 // if name has not changed, DNLoc has not changed either.
7245 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007246 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007247
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007248 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007249 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007250 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007251 }
John McCall6b51f282009-11-23 01:53:49 +00007252
7253 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007254 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7255 E->getNumTemplateArgs(),
7256 TransArgs))
7257 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007258
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007259 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007260 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007261 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007262}
7263
7264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007265ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007266TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007267 // CXXConstructExprs are always implicit, so when we have a
7268 // 1-argument construction we just transform that argument.
7269 if (E->getNumArgs() == 1 ||
7270 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7271 return getDerived().TransformExpr(E->getArg(0));
7272
Douglas Gregora16548e2009-08-11 05:31:07 +00007273 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7274
7275 QualType T = getDerived().TransformType(E->getType());
7276 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007277 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007278
7279 CXXConstructorDecl *Constructor
7280 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007281 getDerived().TransformDecl(E->getLocStart(),
7282 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007283 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007285
Douglas Gregora16548e2009-08-11 05:31:07 +00007286 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007287 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007288 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7289 &ArgumentChanged))
7290 return ExprError();
7291
Douglas Gregora16548e2009-08-11 05:31:07 +00007292 if (!getDerived().AlwaysRebuild() &&
7293 T == E->getType() &&
7294 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007295 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007296 // Mark the constructor as referenced.
7297 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007298 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007299 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007300 }
Mike Stump11289f42009-09-09 15:08:12 +00007301
Douglas Gregordb121ba2009-12-14 16:27:04 +00007302 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7303 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007304 move_arg(Args),
7305 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007306 E->getConstructionKind(),
7307 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007308}
Mike Stump11289f42009-09-09 15:08:12 +00007309
Douglas Gregora16548e2009-08-11 05:31:07 +00007310/// \brief Transform a C++ temporary-binding expression.
7311///
Douglas Gregor363b1512009-12-24 18:51:59 +00007312/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7313/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007316TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007317 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007318}
Mike Stump11289f42009-09-09 15:08:12 +00007319
John McCall5d413782010-12-06 08:20:24 +00007320/// \brief Transform a C++ expression that contains cleanups that should
7321/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007322///
John McCall5d413782010-12-06 08:20:24 +00007323/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007324/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007325template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007326ExprResult
John McCall5d413782010-12-06 08:20:24 +00007327TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007328 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007329}
Mike Stump11289f42009-09-09 15:08:12 +00007330
Douglas Gregora16548e2009-08-11 05:31:07 +00007331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007332ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007333TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007334 CXXTemporaryObjectExpr *E) {
7335 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7336 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007337 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007338
Douglas Gregora16548e2009-08-11 05:31:07 +00007339 CXXConstructorDecl *Constructor
7340 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007341 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007342 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007343 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007345
Douglas Gregora16548e2009-08-11 05:31:07 +00007346 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007347 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007348 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007349 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7350 &ArgumentChanged))
7351 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007352
Douglas Gregora16548e2009-08-11 05:31:07 +00007353 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007354 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007355 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007356 !ArgumentChanged) {
7357 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007358 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007359 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007360 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007361
7362 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7363 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007364 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007365 E->getLocEnd());
7366}
Mike Stump11289f42009-09-09 15:08:12 +00007367
Douglas Gregora16548e2009-08-11 05:31:07 +00007368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007369ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007370TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007371 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007372 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7373 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007374 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007375
Douglas Gregora16548e2009-08-11 05:31:07 +00007376 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007377 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007378 Args.reserve(E->arg_size());
7379 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7380 &ArgumentChanged))
7381 return ExprError();
7382
Douglas Gregora16548e2009-08-11 05:31:07 +00007383 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007384 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007385 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007386 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007387
Douglas Gregora16548e2009-08-11 05:31:07 +00007388 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007389 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007390 E->getLParenLoc(),
7391 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007392 E->getRParenLoc());
7393}
Mike Stump11289f42009-09-09 15:08:12 +00007394
Douglas Gregora16548e2009-08-11 05:31:07 +00007395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007396ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007397TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007398 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007399 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007400 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007401 Expr *OldBase;
7402 QualType BaseType;
7403 QualType ObjectType;
7404 if (!E->isImplicitAccess()) {
7405 OldBase = E->getBase();
7406 Base = getDerived().TransformExpr(OldBase);
7407 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007408 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007409
John McCall2d74de92009-12-01 22:10:20 +00007410 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007411 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007412 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007413 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007414 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007415 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007416 ObjectTy,
7417 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007418 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007419 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007420
John McCallba7bf592010-08-24 05:47:05 +00007421 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007422 BaseType = ((Expr*) Base.get())->getType();
7423 } else {
7424 OldBase = 0;
7425 BaseType = getDerived().TransformType(E->getBaseType());
7426 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7427 }
Mike Stump11289f42009-09-09 15:08:12 +00007428
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007429 // Transform the first part of the nested-name-specifier that qualifies
7430 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007431 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007432 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007433 E->getFirstQualifierFoundInScope(),
7434 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007435
Douglas Gregore16af532011-02-28 18:50:33 +00007436 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007437 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007438 QualifierLoc
7439 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7440 ObjectType,
7441 FirstQualifierInScope);
7442 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007443 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007444 }
Mike Stump11289f42009-09-09 15:08:12 +00007445
John McCall31f82722010-11-12 08:19:04 +00007446 // TODO: If this is a conversion-function-id, verify that the
7447 // destination type name (if present) resolves the same way after
7448 // instantiation as it did in the local scope.
7449
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007450 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007451 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007452 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007454
John McCall2d74de92009-12-01 22:10:20 +00007455 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007456 // This is a reference to a member without an explicitly-specified
7457 // template argument list. Optimize for this common case.
7458 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007459 Base.get() == OldBase &&
7460 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007461 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007462 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007463 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007464 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007465
John McCallb268a282010-08-23 23:25:46 +00007466 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007467 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007468 E->isArrow(),
7469 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007470 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007471 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007472 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007473 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007474 }
7475
John McCall6b51f282009-11-23 01:53:49 +00007476 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007477 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7478 E->getNumTemplateArgs(),
7479 TransArgs))
7480 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007481
John McCallb268a282010-08-23 23:25:46 +00007482 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007483 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007484 E->isArrow(),
7485 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007486 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007487 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007488 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007489 &TransArgs);
7490}
7491
7492template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007493ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007494TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007495 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007496 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007497 QualType BaseType;
7498 if (!Old->isImplicitAccess()) {
7499 Base = getDerived().TransformExpr(Old->getBase());
7500 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007501 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007502 BaseType = ((Expr*) Base.get())->getType();
7503 } else {
7504 BaseType = getDerived().TransformType(Old->getBaseType());
7505 }
John McCall10eae182009-11-30 22:42:35 +00007506
Douglas Gregor0da1d432011-02-28 20:01:57 +00007507 NestedNameSpecifierLoc QualifierLoc;
7508 if (Old->getQualifierLoc()) {
7509 QualifierLoc
7510 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7511 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007512 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007513 }
7514
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007515 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007516 Sema::LookupOrdinaryName);
7517
7518 // Transform all the decls.
7519 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7520 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007521 NamedDecl *InstD = static_cast<NamedDecl*>(
7522 getDerived().TransformDecl(Old->getMemberLoc(),
7523 *I));
John McCall84d87672009-12-10 09:41:52 +00007524 if (!InstD) {
7525 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7526 // This can happen because of dependent hiding.
7527 if (isa<UsingShadowDecl>(*I))
7528 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007529 else {
7530 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007531 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007532 }
John McCall84d87672009-12-10 09:41:52 +00007533 }
John McCall10eae182009-11-30 22:42:35 +00007534
7535 // Expand using declarations.
7536 if (isa<UsingDecl>(InstD)) {
7537 UsingDecl *UD = cast<UsingDecl>(InstD);
7538 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7539 E = UD->shadow_end(); I != E; ++I)
7540 R.addDecl(*I);
7541 continue;
7542 }
7543
7544 R.addDecl(InstD);
7545 }
7546
7547 R.resolveKind();
7548
Douglas Gregor9262f472010-04-27 18:19:34 +00007549 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007550 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007551 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007552 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007553 Old->getMemberLoc(),
7554 Old->getNamingClass()));
7555 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007556 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007557
Douglas Gregorda7be082010-04-27 16:10:10 +00007558 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007559 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007560
John McCall10eae182009-11-30 22:42:35 +00007561 TemplateArgumentListInfo TransArgs;
7562 if (Old->hasExplicitTemplateArgs()) {
7563 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7564 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007565 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7566 Old->getNumTemplateArgs(),
7567 TransArgs))
7568 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007569 }
John McCall38836f02010-01-15 08:34:02 +00007570
7571 // FIXME: to do this check properly, we will need to preserve the
7572 // first-qualifier-in-scope here, just in case we had a dependent
7573 // base (and therefore couldn't do the check) and a
7574 // nested-name-qualifier (and therefore could do the lookup).
7575 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007576
John McCallb268a282010-08-23 23:25:46 +00007577 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007578 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007579 Old->getOperatorLoc(),
7580 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007581 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007582 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007583 R,
7584 (Old->hasExplicitTemplateArgs()
7585 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007586}
7587
7588template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007589ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007590TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00007591 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007592 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7593 if (SubExpr.isInvalid())
7594 return ExprError();
7595
7596 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007597 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007598
7599 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7600}
7601
7602template<typename Derived>
7603ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007604TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007605 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7606 if (Pattern.isInvalid())
7607 return ExprError();
7608
7609 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7610 return SemaRef.Owned(E);
7611
Douglas Gregorb8840002011-01-14 21:20:45 +00007612 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7613 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007614}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007615
7616template<typename Derived>
7617ExprResult
7618TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7619 // If E is not value-dependent, then nothing will change when we transform it.
7620 // Note: This is an instantiation-centric view.
7621 if (!E->isValueDependent())
7622 return SemaRef.Owned(E);
7623
7624 // Note: None of the implementations of TryExpandParameterPacks can ever
7625 // produce a diagnostic when given only a single unexpanded parameter pack,
7626 // so
7627 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7628 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007629 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007630 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007631 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7632 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007633 ShouldExpand, RetainExpansion,
7634 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007635 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007636
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007637 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007638 return SemaRef.Owned(E);
7639
7640 // We now know the length of the parameter pack, so build a new expression
7641 // that stores that length.
7642 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7643 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007644 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007645}
7646
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007647template<typename Derived>
7648ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007649TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7650 SubstNonTypeTemplateParmPackExpr *E) {
7651 // Default behavior is to do nothing with this transformation.
7652 return SemaRef.Owned(E);
7653}
7654
7655template<typename Derived>
7656ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007657TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007658 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007659}
7660
Mike Stump11289f42009-09-09 15:08:12 +00007661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007662ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007663TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007664 TypeSourceInfo *EncodedTypeInfo
7665 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7666 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007667 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007668
Douglas Gregora16548e2009-08-11 05:31:07 +00007669 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007670 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007671 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007672
7673 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007674 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007675 E->getRParenLoc());
7676}
Mike Stump11289f42009-09-09 15:08:12 +00007677
Douglas Gregora16548e2009-08-11 05:31:07 +00007678template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00007679ExprResult TreeTransform<Derived>::
7680TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7681 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7682 if (result.isInvalid()) return ExprError();
7683 Expr *subExpr = result.take();
7684
7685 if (!getDerived().AlwaysRebuild() &&
7686 subExpr == E->getSubExpr())
7687 return SemaRef.Owned(E);
7688
7689 return SemaRef.Owned(new(SemaRef.Context)
7690 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7691}
7692
7693template<typename Derived>
7694ExprResult TreeTransform<Derived>::
7695TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7696 TypeSourceInfo *TSInfo
7697 = getDerived().TransformType(E->getTypeInfoAsWritten());
7698 if (!TSInfo)
7699 return ExprError();
7700
7701 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7702 if (Result.isInvalid())
7703 return ExprError();
7704
7705 if (!getDerived().AlwaysRebuild() &&
7706 TSInfo == E->getTypeInfoAsWritten() &&
7707 Result.get() == E->getSubExpr())
7708 return SemaRef.Owned(E);
7709
7710 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7711 E->getBridgeKeywordLoc(), TSInfo,
7712 Result.get());
7713}
7714
7715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007716ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007717TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007718 // Transform arguments.
7719 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007720 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007721 Args.reserve(E->getNumArgs());
7722 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7723 &ArgChanged))
7724 return ExprError();
7725
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007726 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7727 // Class message: transform the receiver type.
7728 TypeSourceInfo *ReceiverTypeInfo
7729 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7730 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007731 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007732
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007733 // If nothing changed, just retain the existing message send.
7734 if (!getDerived().AlwaysRebuild() &&
7735 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007736 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007737
7738 // Build a new class message send.
7739 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7740 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007741 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007742 E->getMethodDecl(),
7743 E->getLeftLoc(),
7744 move_arg(Args),
7745 E->getRightLoc());
7746 }
7747
7748 // Instance message: transform the receiver
7749 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7750 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007751 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007752 = getDerived().TransformExpr(E->getInstanceReceiver());
7753 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007754 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007755
7756 // If nothing changed, just retain the existing message send.
7757 if (!getDerived().AlwaysRebuild() &&
7758 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007759 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007760
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007761 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007762 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007763 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007764 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007765 E->getMethodDecl(),
7766 E->getLeftLoc(),
7767 move_arg(Args),
7768 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007769}
7770
Mike Stump11289f42009-09-09 15:08:12 +00007771template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007772ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007773TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007774 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007775}
7776
Mike Stump11289f42009-09-09 15:08:12 +00007777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007778ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007779TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007780 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007781}
7782
Mike Stump11289f42009-09-09 15:08:12 +00007783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007784ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007785TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007786 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007787 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007788 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007789 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007790
7791 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007792
Douglas Gregord51d90d2010-04-26 20:11:03 +00007793 // If nothing changed, just retain the existing expression.
7794 if (!getDerived().AlwaysRebuild() &&
7795 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007796 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007797
John McCallb268a282010-08-23 23:25:46 +00007798 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007799 E->getLocation(),
7800 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007801}
7802
Mike Stump11289f42009-09-09 15:08:12 +00007803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007805TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007806 // 'super' and types never change. Property never changes. Just
7807 // retain the existing expression.
7808 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007809 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007810
Douglas Gregor9faee212010-04-26 20:47:02 +00007811 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007812 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007813 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007814 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007815
Douglas Gregor9faee212010-04-26 20:47:02 +00007816 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007817
Douglas Gregor9faee212010-04-26 20:47:02 +00007818 // If nothing changed, just retain the existing expression.
7819 if (!getDerived().AlwaysRebuild() &&
7820 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007821 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007822
John McCallb7bd14f2010-12-02 01:19:52 +00007823 if (E->isExplicitProperty())
7824 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7825 E->getExplicitProperty(),
7826 E->getLocation());
7827
7828 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7829 E->getType(),
7830 E->getImplicitPropertyGetter(),
7831 E->getImplicitPropertySetter(),
7832 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007833}
7834
Mike Stump11289f42009-09-09 15:08:12 +00007835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007836ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007837TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007838 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007839 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007840 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007841 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007842
Douglas Gregord51d90d2010-04-26 20:11:03 +00007843 // If nothing changed, just retain the existing expression.
7844 if (!getDerived().AlwaysRebuild() &&
7845 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007846 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007847
John McCallb268a282010-08-23 23:25:46 +00007848 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007849 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007850}
7851
Mike Stump11289f42009-09-09 15:08:12 +00007852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007854TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007855 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007856 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007857 SubExprs.reserve(E->getNumSubExprs());
7858 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7859 SubExprs, &ArgumentChanged))
7860 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007861
Douglas Gregora16548e2009-08-11 05:31:07 +00007862 if (!getDerived().AlwaysRebuild() &&
7863 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007864 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007865
Douglas Gregora16548e2009-08-11 05:31:07 +00007866 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7867 move_arg(SubExprs),
7868 E->getRParenLoc());
7869}
7870
Mike Stump11289f42009-09-09 15:08:12 +00007871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007872ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007873TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007874 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007875
John McCall490112f2011-02-04 18:33:18 +00007876 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7877 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7878
7879 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00007880 // We built a new blockScopeInfo in call to ActOnBlockStart
7881 // in above, CapturesCXXThis need be set here from the block
7882 // expression.
7883 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7884
John McCall490112f2011-02-04 18:33:18 +00007885 llvm::SmallVector<ParmVarDecl*, 4> params;
7886 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007887
7888 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007889 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7890 oldBlock->param_begin(),
7891 oldBlock->param_size(),
7892 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007893 return true;
John McCall490112f2011-02-04 18:33:18 +00007894
7895 const FunctionType *exprFunctionType = E->getFunctionType();
7896 QualType exprResultType = exprFunctionType->getResultType();
7897 if (!exprResultType.isNull()) {
7898 if (!exprResultType->isDependentType())
7899 blockScope->ReturnType = exprResultType;
7900 else if (exprResultType != getSema().Context.DependentTy)
7901 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007902 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007903
7904 // If the return type has not been determined yet, leave it as a dependent
7905 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007906 if (blockScope->ReturnType.isNull())
7907 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007908
7909 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007910 if (blockScope->ReturnType->isObjCObjectType()) {
7911 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007912 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007913 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007914 return ExprError();
7915 }
John McCall3882ace2011-01-05 12:14:39 +00007916
John McCall490112f2011-02-04 18:33:18 +00007917 QualType functionType = getDerived().RebuildFunctionProtoType(
7918 blockScope->ReturnType,
7919 paramTypes.data(),
7920 paramTypes.size(),
7921 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007922 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007923 exprFunctionType->getExtInfo());
7924 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007925
7926 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007927 if (!params.empty())
7928 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007929
7930 // If the return type wasn't explicitly set, it will have been marked as a
7931 // dependent type (DependentTy); clear out the return type setting so
7932 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007933 if (blockScope->ReturnType == getSema().Context.DependentTy)
7934 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007935
John McCall3882ace2011-01-05 12:14:39 +00007936 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007937 StmtResult body = getDerived().TransformStmt(E->getBody());
7938 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007939 return ExprError();
7940
John McCall490112f2011-02-04 18:33:18 +00007941#ifndef NDEBUG
7942 // In builds with assertions, make sure that we captured everything we
7943 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007944 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
7945 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7946 e = oldBlock->capture_end(); i != e; ++i) {
7947 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007948
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007949 // Ignore parameter packs.
7950 if (isa<ParmVarDecl>(oldCapture) &&
7951 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7952 continue;
John McCall490112f2011-02-04 18:33:18 +00007953
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007954 VarDecl *newCapture =
7955 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7956 oldCapture));
7957 assert(blockScope->CaptureMap.count(newCapture));
7958 }
John McCall490112f2011-02-04 18:33:18 +00007959 }
7960#endif
7961
7962 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7963 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007964}
7965
Mike Stump11289f42009-09-09 15:08:12 +00007966template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007967ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007968TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007969 ValueDecl *ND
7970 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7971 E->getDecl()));
7972 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007973 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007974
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007975 if (!getDerived().AlwaysRebuild() &&
7976 ND == E->getDecl()) {
7977 // Mark it referenced in the new context regardless.
7978 // FIXME: this is a bit instantiation-specific.
7979 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7980
John McCallc3007a22010-10-26 07:05:15 +00007981 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007982 }
7983
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007984 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007985 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007986 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007987}
Mike Stump11289f42009-09-09 15:08:12 +00007988
Tanya Lattner55808c12011-06-04 00:47:47 +00007989template<typename Derived>
7990ExprResult
7991TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
7992 assert(false && "Cannot transform asType expressions yet");
7993 return SemaRef.Owned(E);
7994}
7995
Douglas Gregora16548e2009-08-11 05:31:07 +00007996//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007997// Type reconstruction
7998//===----------------------------------------------------------------------===//
7999
Mike Stump11289f42009-09-09 15:08:12 +00008000template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008001QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8002 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008003 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008004 getDerived().getBaseEntity());
8005}
8006
Mike Stump11289f42009-09-09 15:08:12 +00008007template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008008QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8009 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008010 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008011 getDerived().getBaseEntity());
8012}
8013
Mike Stump11289f42009-09-09 15:08:12 +00008014template<typename Derived>
8015QualType
John McCall70dd5f62009-10-30 00:06:24 +00008016TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8017 bool WrittenAsLValue,
8018 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008019 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00008020 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008021}
8022
8023template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008024QualType
John McCall70dd5f62009-10-30 00:06:24 +00008025TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8026 QualType ClassType,
8027 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008028 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00008029 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008030}
8031
8032template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008033QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00008034TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8035 ArrayType::ArraySizeModifier SizeMod,
8036 const llvm::APInt *Size,
8037 Expr *SizeExpr,
8038 unsigned IndexTypeQuals,
8039 SourceRange BracketsRange) {
8040 if (SizeExpr || !Size)
8041 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8042 IndexTypeQuals, BracketsRange,
8043 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00008044
8045 QualType Types[] = {
8046 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8047 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8048 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00008049 };
8050 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8051 QualType SizeType;
8052 for (unsigned I = 0; I != NumTypes; ++I)
8053 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8054 SizeType = Types[I];
8055 break;
8056 }
Mike Stump11289f42009-09-09 15:08:12 +00008057
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008058 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8059 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00008060 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008061 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00008062 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008063}
Mike Stump11289f42009-09-09 15:08:12 +00008064
Douglas Gregord6ff3322009-08-04 16:50:30 +00008065template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008066QualType
8067TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008068 ArrayType::ArraySizeModifier SizeMod,
8069 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00008070 unsigned IndexTypeQuals,
8071 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008072 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008073 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008074}
8075
8076template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008077QualType
Mike Stump11289f42009-09-09 15:08:12 +00008078TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008079 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00008080 unsigned IndexTypeQuals,
8081 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008082 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008083 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008084}
Mike Stump11289f42009-09-09 15:08:12 +00008085
Douglas Gregord6ff3322009-08-04 16:50:30 +00008086template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008087QualType
8088TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008089 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008090 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008091 unsigned IndexTypeQuals,
8092 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008093 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008094 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008095 IndexTypeQuals, BracketsRange);
8096}
8097
8098template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008099QualType
8100TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008101 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008102 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008103 unsigned IndexTypeQuals,
8104 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008105 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008106 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008107 IndexTypeQuals, BracketsRange);
8108}
8109
8110template<typename Derived>
8111QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00008112 unsigned NumElements,
8113 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00008114 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00008115 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008116}
Mike Stump11289f42009-09-09 15:08:12 +00008117
Douglas Gregord6ff3322009-08-04 16:50:30 +00008118template<typename Derived>
8119QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8120 unsigned NumElements,
8121 SourceLocation AttributeLoc) {
8122 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8123 NumElements, true);
8124 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008125 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8126 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00008127 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008128}
Mike Stump11289f42009-09-09 15:08:12 +00008129
Douglas Gregord6ff3322009-08-04 16:50:30 +00008130template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008131QualType
8132TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00008133 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008134 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00008135 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008136}
Mike Stump11289f42009-09-09 15:08:12 +00008137
Douglas Gregord6ff3322009-08-04 16:50:30 +00008138template<typename Derived>
8139QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00008140 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008141 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00008142 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00008143 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008144 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00008145 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00008146 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008147 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008148 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008149 getDerived().getBaseEntity(),
8150 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008151}
Mike Stump11289f42009-09-09 15:08:12 +00008152
Douglas Gregord6ff3322009-08-04 16:50:30 +00008153template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008154QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8155 return SemaRef.Context.getFunctionNoProtoType(T);
8156}
8157
8158template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008159QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8160 assert(D && "no decl found");
8161 if (D->isInvalidDecl()) return QualType();
8162
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008163 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008164 TypeDecl *Ty;
8165 if (isa<UsingDecl>(D)) {
8166 UsingDecl *Using = cast<UsingDecl>(D);
8167 assert(Using->isTypeName() &&
8168 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8169
8170 // A valid resolved using typename decl points to exactly one type decl.
8171 assert(++Using->shadow_begin() == Using->shadow_end());
8172 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008173
John McCallb96ec562009-12-04 22:46:56 +00008174 } else {
8175 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8176 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8177 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8178 }
8179
8180 return SemaRef.Context.getTypeDeclType(Ty);
8181}
8182
8183template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008184QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8185 SourceLocation Loc) {
8186 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008187}
8188
8189template<typename Derived>
8190QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8191 return SemaRef.Context.getTypeOfType(Underlying);
8192}
8193
8194template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008195QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8196 SourceLocation Loc) {
8197 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008198}
8199
8200template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00008201QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8202 UnaryTransformType::UTTKind UKind,
8203 SourceLocation Loc) {
8204 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8205}
8206
8207template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00008208QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008209 TemplateName Template,
8210 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008211 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008212 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008213}
Mike Stump11289f42009-09-09 15:08:12 +00008214
Douglas Gregor1135c352009-08-06 05:28:30 +00008215template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008216TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008217TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008218 bool TemplateKW,
8219 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008220 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008221 Template);
8222}
8223
8224template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008225TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008226TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8227 const IdentifierInfo &Name,
8228 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008229 QualType ObjectType,
8230 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008231 UnqualifiedId TemplateName;
8232 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008233 Sema::TemplateTy Template;
8234 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008235 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008236 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008237 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008238 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008239 /*EnteringContext=*/false,
8240 Template);
John McCall31f82722010-11-12 08:19:04 +00008241 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008242}
Mike Stump11289f42009-09-09 15:08:12 +00008243
Douglas Gregora16548e2009-08-11 05:31:07 +00008244template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008245TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008246TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008247 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008248 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008249 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008250 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008251 // FIXME: Bogus location information.
8252 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8253 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008254 Sema::TemplateTy Template;
8255 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008256 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008257 SS,
8258 Name,
John McCallba7bf592010-08-24 05:47:05 +00008259 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008260 /*EnteringContext=*/false,
8261 Template);
8262 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008263}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008264
Douglas Gregor71395fa2009-11-04 00:56:37 +00008265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008266ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008267TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8268 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008269 Expr *OrigCallee,
8270 Expr *First,
8271 Expr *Second) {
8272 Expr *Callee = OrigCallee->IgnoreParenCasts();
8273 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008274
Douglas Gregora16548e2009-08-11 05:31:07 +00008275 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008276 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008277 if (!First->getType()->isOverloadableType() &&
8278 !Second->getType()->isOverloadableType())
8279 return getSema().CreateBuiltinArraySubscriptExpr(First,
8280 Callee->getLocStart(),
8281 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008282 } else if (Op == OO_Arrow) {
8283 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008284 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8285 } else if (Second == 0 || isPostIncDec) {
8286 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008287 // The argument is not of overloadable type, so try to create a
8288 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008289 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008290 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008291
John McCallb268a282010-08-23 23:25:46 +00008292 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008293 }
8294 } else {
John McCallb268a282010-08-23 23:25:46 +00008295 if (!First->getType()->isOverloadableType() &&
8296 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008297 // Neither of the arguments is an overloadable type, so try to
8298 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008299 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008300 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008301 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008302 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008303 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008304
Douglas Gregora16548e2009-08-11 05:31:07 +00008305 return move(Result);
8306 }
8307 }
Mike Stump11289f42009-09-09 15:08:12 +00008308
8309 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008310 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008311 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008312
John McCallb268a282010-08-23 23:25:46 +00008313 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008314 assert(ULE->requiresADL());
8315
8316 // FIXME: Do we have to check
8317 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008318 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008319 } else {
John McCallb268a282010-08-23 23:25:46 +00008320 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008321 }
Mike Stump11289f42009-09-09 15:08:12 +00008322
Douglas Gregora16548e2009-08-11 05:31:07 +00008323 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008324 Expr *Args[2] = { First, Second };
8325 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008326
Douglas Gregora16548e2009-08-11 05:31:07 +00008327 // Create the overloaded operator invocation for unary operators.
8328 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008329 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008330 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008331 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008332 }
Mike Stump11289f42009-09-09 15:08:12 +00008333
Sebastian Redladba46e2009-10-29 20:17:01 +00008334 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00008335 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00008336 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008337 First,
8338 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00008339
Douglas Gregora16548e2009-08-11 05:31:07 +00008340 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008341 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008342 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008343 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8344 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008345 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008346
Mike Stump11289f42009-09-09 15:08:12 +00008347 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008348}
Mike Stump11289f42009-09-09 15:08:12 +00008349
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008351ExprResult
John McCallb268a282010-08-23 23:25:46 +00008352TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008353 SourceLocation OperatorLoc,
8354 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008355 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008356 TypeSourceInfo *ScopeType,
8357 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008358 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008359 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008360 QualType BaseType = Base->getType();
8361 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008362 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008363 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008364 !BaseType->getAs<PointerType>()->getPointeeType()
8365 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008366 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008367 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008368 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008369 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008370 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008371 /*FIXME?*/true);
8372 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008373
Douglas Gregor678f90d2010-02-25 01:56:36 +00008374 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008375 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8376 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8377 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8378 NameInfo.setNamedTypeInfo(DestroyedType);
8379
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008380 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008381
John McCallb268a282010-08-23 23:25:46 +00008382 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008383 OperatorLoc, isArrow,
8384 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008385 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008386 /*TemplateArgs*/ 0);
8387}
8388
Douglas Gregord6ff3322009-08-04 16:50:30 +00008389} // end namespace clang
8390
8391#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H