blob: e007f062356a0b223f03286523a4525d830507f9 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000034#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000035#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000036#include <algorithm>
37
38namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000039using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000040
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// \brief A semantic tree transformation that allows one to transform one
42/// abstract syntax tree into another.
43///
Mike Stump11289f42009-09-09 15:08:12 +000044/// A new tree transformation is defined by creating a new subclass \c X of
45/// \c TreeTransform<X> and then overriding certain operations to provide
46/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000047/// instantiation is implemented as a tree transformation where the
48/// transformation of TemplateTypeParmType nodes involves substituting the
49/// template arguments for their corresponding template parameters; a similar
50/// transformation is performed for non-type template parameters and
51/// template template parameters.
52///
53/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000054/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000055/// override any of the transformation or rebuild operators by providing an
56/// operation with the same signature as the default implementation. The
57/// overridding function should not be virtual.
58///
59/// Semantic tree transformations are split into two stages, either of which
60/// can be replaced by a subclass. The "transform" step transforms an AST node
61/// or the parts of an AST node using the various transformation functions,
62/// then passes the pieces on to the "rebuild" step, which constructs a new AST
63/// node of the appropriate kind from the pieces. The default transformation
64/// routines recursively transform the operands to composite AST nodes (e.g.,
65/// the pointee type of a PointerType node) and, if any of those operand nodes
66/// were changed by the transformation, invokes the rebuild operation to create
67/// a new AST node.
68///
Mike Stump11289f42009-09-09 15:08:12 +000069/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000070/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000071/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// TransformTemplateName(), or TransformTemplateArgument() with entirely
73/// new implementations.
74///
75/// For more fine-grained transformations, subclasses can replace any of the
76/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000077/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000078/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000079/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// parameters. Additionally, subclasses can override the \c RebuildXXX
81/// functions to control how AST nodes are rebuilt when their operands change.
82/// By default, \c TreeTransform will invoke semantic analysis to rebuild
83/// AST nodes. However, certain other tree transformations (e.g, cloning) may
84/// be able to use more efficient rebuild steps.
85///
86/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000087/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000088/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
89/// operands have not changed (\c AlwaysRebuild()), and customize the
90/// default locations and entity names used for type-checking
91/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000092template<typename Derived>
93class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000094 /// \brief Private RAII object that helps us forget and then re-remember
95 /// the template argument corresponding to a partially-substituted parameter
96 /// pack.
97 class ForgetPartiallySubstitutedPackRAII {
98 Derived &Self;
99 TemplateArgument Old;
100
101 public:
102 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
103 Old = Self.ForgetPartiallySubstitutedPack();
104 }
105
106 ~ForgetPartiallySubstitutedPackRAII() {
107 Self.RememberPartiallySubstitutedPack(Old);
108 }
109 };
110
Douglas Gregord6ff3322009-08-04 16:50:30 +0000111protected:
112 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000113
Mike Stump11289f42009-09-09 15:08:12 +0000114public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000116 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000117
Douglas Gregord6ff3322009-08-04 16:50:30 +0000118 /// \brief Retrieves a reference to the derived class.
119 Derived &getDerived() { return static_cast<Derived&>(*this); }
120
121 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000122 const Derived &getDerived() const {
123 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 }
125
John McCalldadc5752010-08-24 06:29:42 +0000126 static inline ExprResult Owned(Expr *E) { return E; }
127 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000128
Douglas Gregord6ff3322009-08-04 16:50:30 +0000129 /// \brief Retrieves a reference to the semantic analysis object used for
130 /// this tree transform.
131 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000132
Douglas Gregord6ff3322009-08-04 16:50:30 +0000133 /// \brief Whether the transformation should always rebuild AST nodes, even
134 /// if none of the children have changed.
135 ///
136 /// Subclasses may override this function to specify when the transformation
137 /// should rebuild all AST nodes.
138 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Returns the location of the entity being transformed, if that
141 /// information was not available elsewhere in the AST.
142 ///
Mike Stump11289f42009-09-09 15:08:12 +0000143 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000144 /// provide an alternative implementation that provides better location
145 /// information.
146 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000147
Douglas Gregord6ff3322009-08-04 16:50:30 +0000148 /// \brief Returns the name of the entity being transformed, if that
149 /// information was not available elsewhere in the AST.
150 ///
151 /// By default, returns an empty name. Subclasses can provide an alternative
152 /// implementation with a more precise name.
153 DeclarationName getBaseEntity() { return DeclarationName(); }
154
Douglas Gregora16548e2009-08-11 05:31:07 +0000155 /// \brief Sets the "base" location and entity when that
156 /// information is known based on another transformation.
157 ///
158 /// By default, the source location and entity are ignored. Subclasses can
159 /// override this function to provide a customized implementation.
160 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000161
Douglas Gregora16548e2009-08-11 05:31:07 +0000162 /// \brief RAII object that temporarily sets the base location and entity
163 /// used for reporting diagnostics in types.
164 class TemporaryBase {
165 TreeTransform &Self;
166 SourceLocation OldLocation;
167 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000168
Douglas Gregora16548e2009-08-11 05:31:07 +0000169 public:
170 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000171 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 OldLocation = Self.getDerived().getBaseLocation();
173 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000174
175 if (Location.isValid())
176 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000177 }
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 ~TemporaryBase() {
180 Self.getDerived().setBase(OldLocation, OldEntity);
181 }
182 };
Mike Stump11289f42009-09-09 15:08:12 +0000183
184 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// transformed.
186 ///
187 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000188 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000189 /// not change. For example, template instantiation need not traverse
190 /// non-dependent types.
191 bool AlreadyTransformed(QualType T) {
192 return T.isNull();
193 }
194
Douglas Gregord196a582009-12-14 19:27:10 +0000195 /// \brief Determine whether the given call argument should be dropped, e.g.,
196 /// because it is a default argument.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine to
199 /// determine which kinds of call arguments get dropped. By default,
200 /// CXXDefaultArgument nodes are dropped (prior to transformation).
201 bool DropCallArgument(Expr *E) {
202 return E->isDefaultArgument();
203 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000204
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000205 /// \brief Determine whether we should expand a pack expansion with the
206 /// given set of parameter packs into separate arguments by repeatedly
207 /// transforming the pattern.
208 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000209 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000210 /// Subclasses can override this routine to provide different behavior.
211 ///
212 /// \param EllipsisLoc The location of the ellipsis that identifies the
213 /// pack expansion.
214 ///
215 /// \param PatternRange The source range that covers the entire pattern of
216 /// the pack expansion.
217 ///
218 /// \param Unexpanded The set of unexpanded parameter packs within the
219 /// pattern.
220 ///
221 /// \param NumUnexpanded The number of unexpanded parameter packs in
222 /// \p Unexpanded.
223 ///
224 /// \param ShouldExpand Will be set to \c true if the transformer should
225 /// expand the corresponding pack expansions into separate arguments. When
226 /// set, \c NumExpansions must also be set.
227 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000228 /// \param RetainExpansion Whether the caller should add an unexpanded
229 /// pack expansion after all of the expanded arguments. This is used
230 /// when extending explicitly-specified template argument packs per
231 /// C++0x [temp.arg.explicit]p9.
232 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000233 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000234 /// the expanded form of the corresponding pack expansion. This is both an
235 /// input and an output parameter, which can be set by the caller if the
236 /// number of expansions is known a priori (e.g., due to a prior substitution)
237 /// and will be set by the callee when the number of expansions is known.
238 /// The callee must set this value when \c ShouldExpand is \c true; it may
239 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 ///
241 /// \returns true if an error occurred (e.g., because the parameter packs
242 /// are to be instantiated with arguments of different lengths), false
243 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
244 /// must be set.
245 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
246 SourceRange PatternRange,
247 const UnexpandedParameterPack *Unexpanded,
248 unsigned NumUnexpanded,
249 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 /// \brief "Forget" about the partially-substituted pack template argument,
257 /// when performing an instantiation that must preserve the parameter pack
258 /// use.
259 ///
260 /// This routine is meant to be overridden by the template instantiator.
261 TemplateArgument ForgetPartiallySubstitutedPack() {
262 return TemplateArgument();
263 }
264
265 /// \brief "Remember" the partially-substituted pack template argument
266 /// after performing an instantiation that must preserve the parameter pack
267 /// use.
268 ///
269 /// This routine is meant to be overridden by the template instantiator.
270 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271
Douglas Gregorf3010112011-01-07 16:43:16 +0000272 /// \brief Note to the derived class when a function parameter pack is
273 /// being expanded.
274 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
275
Douglas Gregord6ff3322009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCall550e0c22009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000280 /// function. This is expensive, but we don't mind, because
281 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000286
John McCall550e0c22009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
John McCall550e0c22009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by delegating to the
291 /// appropriate TransformXXXType to build a new type. Subclasses
292 /// may override this function (to take over all type
293 /// transformations) or some set of the TransformXXXType functions
294 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000296
297 /// \brief Transform the given type-with-location into a new
298 /// type, collecting location information in the given builder
299 /// as necessary.
300 ///
John McCall31f82722010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000302
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000304 ///
Mike Stump11289f42009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000306 /// appropriate TransformXXXStmt function to transform a specific kind of
307 /// statement or the TransformExpr() function to transform an expression.
308 /// Subclasses may override this function to transform statements using some
309 /// other mechanism.
310 ///
311 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000313
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000316 /// By default, this routine transforms an expression by delegating to the
317 /// appropriate TransformXXXExpr function to build a new expression.
318 /// Subclasses may override this function to transform expressions using some
319 /// other mechanism.
320 ///
321 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000323
Douglas Gregora3efea12011-01-03 19:04:46 +0000324 /// \brief Transform the given list of expressions.
325 ///
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
331 ///
332 /// \param Inputs The set of expressions to be transformed.
333 ///
334 /// \param NumInputs The number of expressions in \c Inputs.
335 ///
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
338 /// be.
339 ///
340 /// \param Outputs The transformed input expressions will be added to this
341 /// vector.
342 ///
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
345 ///
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
348 llvm::SmallVectorImpl<Expr *> &Outputs,
349 bool *ArgChanged = 0);
350
Douglas Gregord6ff3322009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000354 /// By default, acts as the identity function on declarations. Subclasses
355 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump11289f42009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000364 }
Mike Stump11289f42009-09-09 15:08:12 +0000365
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000366 /// \brief Transform the given declaration, which was the first part of a
367 /// nested-name-specifier in a member access expression.
368 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000370 /// identifier in a nested-name-specifier of a member access expression, e.g.,
371 /// the \c T in \c x->T::member
372 ///
373 /// By default, invokes TransformDecl() to transform the declaration.
374 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000377 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000378
Douglas Gregor14454802011-02-25 02:25:35 +0000379 /// \brief Transform the given nested-name-specifier with source-location
380 /// information.
381 ///
382 /// By default, transforms all of the types and declarations within the
383 /// nested-name-specifier. Subclasses may override this function to provide
384 /// alternate behavior.
385 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386 NestedNameSpecifierLoc NNS,
387 QualType ObjectType = QualType(),
388 NamedDecl *FirstQualifierInScope = 0);
389
Douglas Gregorf816bd72009-09-03 22:13:48 +0000390 /// \brief Transform the given declaration name.
391 ///
392 /// By default, transforms the types of conversion function, constructor,
393 /// and destructor names and then (if needed) rebuilds the declaration name.
394 /// Identifiers and selectors are returned unmodified. Sublcasses may
395 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000398
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000400 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000401 /// \param SS The nested-name-specifier that qualifies the template
402 /// name. This nested-name-specifier must already have been transformed.
403 ///
404 /// \param Name The template name to transform.
405 ///
406 /// \param NameLoc The source location of the template name.
407 ///
408 /// \param ObjectType If we're translating a template name within a member
409 /// access expression, this is the type of the object whose member template
410 /// is being referenced.
411 ///
412 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413 /// also refers to a name within the current (lexical) scope, this is the
414 /// declaration it refers to.
415 ///
416 /// By default, transforms the template name by transforming the declarations
417 /// and nested-name-specifiers that occur within the template name.
418 /// Subclasses may override this function to provide alternate behavior.
419 TemplateName TransformTemplateName(CXXScopeSpec &SS,
420 TemplateName Name,
421 SourceLocation NameLoc,
422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
424
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump11289f42009-09-09 15:08:12 +0000427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000431 ///
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
435
Douglas Gregor62e06f22010-12-20 17:31:10 +0000436 /// \brief Transform the given set of template arguments.
437 ///
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
441 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
445 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000446 /// \param Inputs The set of template arguments to be transformed.
447 ///
448 /// \param NumInputs The number of template arguments in \p Inputs.
449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000459
460 /// \brief Transform the given set of template arguments.
461 ///
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
465 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000466 /// \param First An iterator to the first template argument.
467 ///
468 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000469 ///
470 /// \param Outputs The set of transformed template arguments output by this
471 /// routine.
472 ///
473 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000478
John McCall0ad16662009-10-29 08:12:44 +0000479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
482
John McCallbcd03502009-12-07 02:54:59 +0000483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump11289f42009-09-09 15:08:12 +0000488
John McCall550e0c22009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493
John Wiegley1c0675e2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall31f82722010-11-12 08:19:04 +0000497 QualType
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
501
502 QualType
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall58f10c32010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000523 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000524 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000534
John McCall31f82722010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000536
John McCalldadc5752010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000539
Douglas Gregorebe10102009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000546
Douglas Gregord6ff3322009-08-04 16:50:30 +0000547 /// \brief Build a new pointer type given its pointee type.
548 ///
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump11289f42009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558
John McCall70dd5f62009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 ///
John McCall70dd5f62009-10-30 00:06:24 +0000561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000564 ///
John McCall70dd5f62009-10-30 00:06:24 +0000565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
568 bool LValue,
569 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000570
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
573 ///
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000578
Douglas Gregord6ff3322009-08-04 16:50:30 +0000579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
581 /// qualifiers.
582 ///
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
589 Expr *SizeExpr,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000592
Douglas Gregord6ff3322009-08-04 16:50:30 +0000593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000603
Douglas Gregord6ff3322009-08-04 16:50:30 +0000604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000613
Mike Stump11289f42009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump11289f42009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626 /// size modifier, size expression, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
635
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000643
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000653 /// given the element type and number of elements.
654 ///
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new function type.
662 ///
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000671
John McCall550e0c22009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCallb96ec562009-12-04 22:46:56 +0000675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
678
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681 return SemaRef.Context.getTypeDeclType(Typedef);
682 }
683
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
687 }
688
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
692 }
John McCallfcc33b02009-09-05 00:15:47 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000699
Mike Stump11289f42009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Mike Stump11289f42009-09-09 15:08:12 +0000705 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 ///
707 /// By default, performs semantic analysis when building the decltype type.
708 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000709 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000710
Richard Smith30482bc2011-02-20 03:19:35 +0000711 /// \brief Build a new C++0x auto type.
712 ///
713 /// By default, builds a new AutoType with the given deduced type.
714 QualType RebuildAutoType(QualType Deduced) {
715 return SemaRef.Context.getAutoType(Deduced);
716 }
717
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 /// \brief Build a new template specialization type.
719 ///
720 /// By default, performs semantic analysis when building the template
721 /// specialization type. Subclasses may override this routine to provide
722 /// different behavior.
723 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000724 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000725 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000726
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000727 /// \brief Build a new parenthesized type.
728 ///
729 /// By default, builds a new ParenType type from the inner type.
730 /// Subclasses may override this routine to provide different behavior.
731 QualType RebuildParenType(QualType InnerType) {
732 return SemaRef.Context.getParenType(InnerType);
733 }
734
Douglas Gregord6ff3322009-08-04 16:50:30 +0000735 /// \brief Build a new qualified name type.
736 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000737 /// By default, builds a new ElaboratedType type from the keyword,
738 /// the nested-name-specifier and the named type.
739 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000740 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
741 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000742 NestedNameSpecifierLoc QualifierLoc,
743 QualType Named) {
744 return SemaRef.Context.getElaboratedType(Keyword,
745 QualifierLoc.getNestedNameSpecifier(),
746 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000747 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748
749 /// \brief Build a new typename type that refers to a template-id.
750 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000751 /// By default, builds a new DependentNameType type from the
752 /// nested-name-specifier and the given type. Subclasses may override
753 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000754 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000755 ElaboratedTypeKeyword Keyword,
756 NestedNameSpecifierLoc QualifierLoc,
757 const IdentifierInfo *Name,
758 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000759 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000760 // Rebuild the template name.
761 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000762 CXXScopeSpec SS;
763 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000764 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000765 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000766
767 if (InstName.isNull())
768 return QualType();
769
770 // If it's still dependent, make a dependent specialization.
771 if (InstName.getAsDependentTemplateName())
772 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
773 QualifierLoc.getNestedNameSpecifier(),
774 Name,
775 Args);
776
777 // Otherwise, make an elaborated type wrapping a non-dependent
778 // specialization.
779 QualType T =
780 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
781 if (T.isNull()) return QualType();
782
783 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
784 return T;
785
786 return SemaRef.Context.getElaboratedType(Keyword,
787 QualifierLoc.getNestedNameSpecifier(),
788 T);
789 }
790
Douglas Gregord6ff3322009-08-04 16:50:30 +0000791 /// \brief Build a new typename type that refers to an identifier.
792 ///
793 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000794 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000795 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000796 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000797 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000798 NestedNameSpecifierLoc QualifierLoc,
799 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000800 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000801 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000802 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000803
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000804 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000805 // If the name is still dependent, just build a new dependent name type.
806 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000807 return SemaRef.Context.getDependentNameType(Keyword,
808 QualifierLoc.getNestedNameSpecifier(),
809 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000810 }
811
Abramo Bagnara6150c882010-05-11 21:36:43 +0000812 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000813 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000814 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000815
816 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
817
Abramo Bagnarad7548482010-05-19 21:37:53 +0000818 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000819 // into a non-dependent elaborated-type-specifier. Find the tag we're
820 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000821 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000822 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
823 if (!DC)
824 return QualType();
825
John McCallbf8c5192010-05-27 06:40:31 +0000826 if (SemaRef.RequireCompleteDeclContext(SS, DC))
827 return QualType();
828
Douglas Gregore677daf2010-03-31 22:19:08 +0000829 TagDecl *Tag = 0;
830 SemaRef.LookupQualifiedName(Result, DC);
831 switch (Result.getResultKind()) {
832 case LookupResult::NotFound:
833 case LookupResult::NotFoundInCurrentInstantiation:
834 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000835
Douglas Gregore677daf2010-03-31 22:19:08 +0000836 case LookupResult::Found:
837 Tag = Result.getAsSingle<TagDecl>();
838 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000839
Douglas Gregore677daf2010-03-31 22:19:08 +0000840 case LookupResult::FoundOverloaded:
841 case LookupResult::FoundUnresolvedValue:
842 llvm_unreachable("Tag lookup cannot find non-tags");
843 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000844
Douglas Gregore677daf2010-03-31 22:19:08 +0000845 case LookupResult::Ambiguous:
846 // Let the LookupResult structure handle ambiguities.
847 return QualType();
848 }
849
850 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000851 // Check where the name exists but isn't a tag type and use that to emit
852 // better diagnostics.
853 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
854 SemaRef.LookupQualifiedName(Result, DC);
855 switch (Result.getResultKind()) {
856 case LookupResult::Found:
857 case LookupResult::FoundOverloaded:
858 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000859 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000860 unsigned Kind = 0;
861 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000862 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
863 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000864 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
865 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
866 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000867 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000868 default:
869 // FIXME: Would be nice to highlight just the source range.
870 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
871 << Kind << Id << DC;
872 break;
873 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000874 return QualType();
875 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000876
Abramo Bagnarad7548482010-05-19 21:37:53 +0000877 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
878 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000879 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
880 return QualType();
881 }
882
883 // Build the elaborated-type-specifier type.
884 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000885 return SemaRef.Context.getElaboratedType(Keyword,
886 QualifierLoc.getNestedNameSpecifier(),
887 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000888 }
Mike Stump11289f42009-09-09 15:08:12 +0000889
Douglas Gregor822d0302011-01-12 17:07:58 +0000890 /// \brief Build a new pack expansion type.
891 ///
892 /// By default, builds a new PackExpansionType type from the given pattern.
893 /// Subclasses may override this routine to provide different behavior.
894 QualType RebuildPackExpansionType(QualType Pattern,
895 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000896 SourceLocation EllipsisLoc,
897 llvm::Optional<unsigned> NumExpansions) {
898 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
899 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000900 }
901
Douglas Gregor71dc5092009-08-06 06:41:21 +0000902 /// \brief Build a new template name given a nested name specifier, a flag
903 /// indicating whether the "template" keyword was provided, and the template
904 /// that the template name refers to.
905 ///
906 /// By default, builds the new template name directly. Subclasses may override
907 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000908 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000909 bool TemplateKW,
910 TemplateDecl *Template);
911
Douglas Gregor71dc5092009-08-06 06:41:21 +0000912 /// \brief Build a new template name given a nested name specifier and the
913 /// name that is referred to as a template.
914 ///
915 /// By default, performs semantic analysis to determine whether the name can
916 /// be resolved to a specific template, then builds the appropriate kind of
917 /// template name. Subclasses may override this routine to provide different
918 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000919 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
920 const IdentifierInfo &Name,
921 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000922 QualType ObjectType,
923 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000924
Douglas Gregor71395fa2009-11-04 00:56:37 +0000925 /// \brief Build a new template name given a nested name specifier and the
926 /// overloaded operator name that is referred to as a template.
927 ///
928 /// By default, performs semantic analysis to determine whether the name can
929 /// be resolved to a specific template, then builds the appropriate kind of
930 /// template name. Subclasses may override this routine to provide different
931 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000932 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000933 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000934 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000935 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000936
937 /// \brief Build a new template name given a template template parameter pack
938 /// and the
939 ///
940 /// By default, performs semantic analysis to determine whether the name can
941 /// be resolved to a specific template, then builds the appropriate kind of
942 /// template name. Subclasses may override this routine to provide different
943 /// behavior.
944 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
945 const TemplateArgument &ArgPack) {
946 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
947 }
948
Douglas Gregorebe10102009-08-20 07:17:43 +0000949 /// \brief Build a new compound statement.
950 ///
951 /// By default, performs semantic analysis to build the new statement.
952 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000953 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000954 MultiStmtArg Statements,
955 SourceLocation RBraceLoc,
956 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000957 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000958 IsStmtExpr);
959 }
960
961 /// \brief Build a new case statement.
962 ///
963 /// By default, performs semantic analysis to build the new statement.
964 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000965 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000966 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000967 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000968 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000969 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000970 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000971 ColonLoc);
972 }
Mike Stump11289f42009-09-09 15:08:12 +0000973
Douglas Gregorebe10102009-08-20 07:17:43 +0000974 /// \brief Attach the body to a new case statement.
975 ///
976 /// By default, performs semantic analysis to build the new statement.
977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000978 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000979 getSema().ActOnCaseStmtBody(S, Body);
980 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000981 }
Mike Stump11289f42009-09-09 15:08:12 +0000982
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 /// \brief Build a new default statement.
984 ///
985 /// By default, performs semantic analysis to build the new statement.
986 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000987 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000988 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000989 Stmt *SubStmt) {
990 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000991 /*CurScope=*/0);
992 }
Mike Stump11289f42009-09-09 15:08:12 +0000993
Douglas Gregorebe10102009-08-20 07:17:43 +0000994 /// \brief Build a new label statement.
995 ///
996 /// By default, performs semantic analysis to build the new statement.
997 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +0000998 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
999 SourceLocation ColonLoc, Stmt *SubStmt) {
1000 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001001 }
Mike Stump11289f42009-09-09 15:08:12 +00001002
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 /// \brief Build a new "if" statement.
1004 ///
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001007 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001008 VarDecl *CondVar, Stmt *Then,
1009 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001010 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001011 }
Mike Stump11289f42009-09-09 15:08:12 +00001012
Douglas Gregorebe10102009-08-20 07:17:43 +00001013 /// \brief Start building a new switch statement.
1014 ///
1015 /// By default, performs semantic analysis to build the new statement.
1016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001017 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001018 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001019 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001020 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001021 }
Mike Stump11289f42009-09-09 15:08:12 +00001022
Douglas Gregorebe10102009-08-20 07:17:43 +00001023 /// \brief Attach the body to the switch statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001027 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001028 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001029 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001030 }
1031
1032 /// \brief Build a new while statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001036 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1037 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001038 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001039 }
Mike Stump11289f42009-09-09 15:08:12 +00001040
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 /// \brief Build a new do-while statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001046 SourceLocation WhileLoc, SourceLocation LParenLoc,
1047 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001048 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1049 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 }
1051
1052 /// \brief Build a new for statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001056 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1057 Stmt *Init, Sema::FullExprArg Cond,
1058 VarDecl *CondVar, Sema::FullExprArg Inc,
1059 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001060 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001061 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 }
Mike Stump11289f42009-09-09 15:08:12 +00001063
Douglas Gregorebe10102009-08-20 07:17:43 +00001064 /// \brief Build a new goto statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001068 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1069 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001070 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001071 }
1072
1073 /// \brief Build a new indirect goto statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001077 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001078 SourceLocation StarLoc,
1079 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001080 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 }
Mike Stump11289f42009-09-09 15:08:12 +00001082
Douglas Gregorebe10102009-08-20 07:17:43 +00001083 /// \brief Build a new return statement.
1084 ///
1085 /// By default, performs semantic analysis to build the new statement.
1086 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001087 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001088 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001089 }
Mike Stump11289f42009-09-09 15:08:12 +00001090
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 /// \brief Build a new declaration statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001095 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001096 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001097 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001098 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1099 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 }
Mike Stump11289f42009-09-09 15:08:12 +00001101
Anders Carlssonaaeef072010-01-24 05:50:09 +00001102 /// \brief Build a new inline asm statement.
1103 ///
1104 /// By default, performs semantic analysis to build the new statement.
1105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001106 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001107 bool IsSimple,
1108 bool IsVolatile,
1109 unsigned NumOutputs,
1110 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001111 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001112 MultiExprArg Constraints,
1113 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001114 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001115 MultiExprArg Clobbers,
1116 SourceLocation RParenLoc,
1117 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001118 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001119 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001120 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001121 RParenLoc, MSAsm);
1122 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001123
1124 /// \brief Build a new Objective-C @try statement.
1125 ///
1126 /// By default, performs semantic analysis to build the new statement.
1127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001128 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001129 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001130 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001131 Stmt *Finally) {
1132 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1133 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001134 }
1135
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001136 /// \brief Rebuild an Objective-C exception declaration.
1137 ///
1138 /// By default, performs semantic analysis to build the new declaration.
1139 /// Subclasses may override this routine to provide different behavior.
1140 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1141 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001142 return getSema().BuildObjCExceptionDecl(TInfo, T,
1143 ExceptionDecl->getInnerLocStart(),
1144 ExceptionDecl->getLocation(),
1145 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001146 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001147
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001148 /// \brief Build a new Objective-C @catch statement.
1149 ///
1150 /// By default, performs semantic analysis to build the new statement.
1151 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001152 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001153 SourceLocation RParenLoc,
1154 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001155 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001156 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001157 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001158 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001159
Douglas Gregor306de2f2010-04-22 23:59:56 +00001160 /// \brief Build a new Objective-C @finally statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001165 Stmt *Body) {
1166 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001167 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001168
Douglas Gregor6148de72010-04-22 22:01:21 +00001169 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001170 ///
1171 /// By default, performs semantic analysis to build the new statement.
1172 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001173 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001174 Expr *Operand) {
1175 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001176 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001177
Douglas Gregor6148de72010-04-22 22:01:21 +00001178 /// \brief Build a new Objective-C @synchronized statement.
1179 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001180 /// By default, performs semantic analysis to build the new statement.
1181 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001182 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001183 Expr *Object,
1184 Stmt *Body) {
1185 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1186 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001187 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001188
1189 /// \brief Build a new Objective-C fast enumeration statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001193 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001194 SourceLocation LParenLoc,
1195 Stmt *Element,
1196 Expr *Collection,
1197 SourceLocation RParenLoc,
1198 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001199 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001200 Element,
1201 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001202 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001203 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001204 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001205
Douglas Gregorebe10102009-08-20 07:17:43 +00001206 /// \brief Build a new C++ exception declaration.
1207 ///
1208 /// By default, performs semantic analysis to build the new decaration.
1209 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001210 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001211 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001212 SourceLocation StartLoc,
1213 SourceLocation IdLoc,
1214 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001215 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1216 StartLoc, IdLoc, Id);
1217 if (Var)
1218 getSema().CurContext->addDecl(Var);
1219 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 }
1221
1222 /// \brief Build a new C++ catch statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001226 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001227 VarDecl *ExceptionDecl,
1228 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001229 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1230 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001231 }
Mike Stump11289f42009-09-09 15:08:12 +00001232
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 /// \brief Build a new C++ try statement.
1234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001237 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001238 Stmt *TryBlock,
1239 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001240 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001241 }
Mike Stump11289f42009-09-09 15:08:12 +00001242
Richard Smith02e85f32011-04-14 22:09:26 +00001243 /// \brief Build a new C++0x range-based for statement.
1244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
1247 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1248 SourceLocation ColonLoc,
1249 Stmt *Range, Stmt *BeginEnd,
1250 Expr *Cond, Expr *Inc,
1251 Stmt *LoopVar,
1252 SourceLocation RParenLoc) {
1253 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1254 Cond, Inc, LoopVar, RParenLoc);
1255 }
1256
1257 /// \brief Attach body to a C++0x range-based for statement.
1258 ///
1259 /// By default, performs semantic analysis to finish the new statement.
1260 /// Subclasses may override this routine to provide different behavior.
1261 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1262 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1263 }
1264
John Wiegley1c0675e2011-04-28 01:08:34 +00001265 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1266 SourceLocation TryLoc,
1267 Stmt *TryBlock,
1268 Stmt *Handler) {
1269 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1270 }
1271
1272 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1273 Expr *FilterExpr,
1274 Stmt *Block) {
1275 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1276 }
1277
1278 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1279 Stmt *Block) {
1280 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1281 }
1282
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 /// \brief Build a new expression that references a declaration.
1284 ///
1285 /// By default, performs semantic analysis to build the new expression.
1286 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001287 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001288 LookupResult &R,
1289 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001290 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1291 }
1292
1293
1294 /// \brief Build a new expression that references a declaration.
1295 ///
1296 /// By default, performs semantic analysis to build the new expression.
1297 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001298 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001299 ValueDecl *VD,
1300 const DeclarationNameInfo &NameInfo,
1301 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001302 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001303 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001304
1305 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001306
1307 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 }
Mike Stump11289f42009-09-09 15:08:12 +00001309
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001311 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001314 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001316 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 }
1318
Douglas Gregorad8a3362009-09-04 17:36:40 +00001319 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001323 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001324 SourceLocation OperatorLoc,
1325 bool isArrow,
1326 CXXScopeSpec &SS,
1327 TypeSourceInfo *ScopeType,
1328 SourceLocation CCLoc,
1329 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001330 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001333 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001336 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001337 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001338 Expr *SubExpr) {
1339 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Douglas Gregor882211c2010-04-28 22:16:22 +00001342 /// \brief Build a new builtin offsetof expression.
1343 ///
1344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001346 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001347 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001348 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001349 unsigned NumComponents,
1350 SourceLocation RParenLoc) {
1351 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1352 NumComponents, RParenLoc);
1353 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001354
Peter Collingbournee190dee2011-03-11 19:24:49 +00001355 /// \brief Build a new sizeof, alignof or vec_step expression with a
1356 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001357 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 /// By default, performs semantic analysis to build the new expression.
1359 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001360 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1361 SourceLocation OpLoc,
1362 UnaryExprOrTypeTrait ExprKind,
1363 SourceRange R) {
1364 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 }
1366
Peter Collingbournee190dee2011-03-11 19:24:49 +00001367 /// \brief Build a new sizeof, alignof or vec step expression with an
1368 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001369 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001370 /// By default, performs semantic analysis to build the new expression.
1371 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001372 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1373 UnaryExprOrTypeTrait ExprKind,
1374 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001375 ExprResult Result
Peter Collingbournee190dee2011-03-11 19:24:49 +00001376 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001378 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001379
Douglas Gregora16548e2009-08-11 05:31:07 +00001380 return move(Result);
1381 }
Mike Stump11289f42009-09-09 15:08:12 +00001382
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001384 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 /// By default, performs semantic analysis to build the new expression.
1386 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001387 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001388 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001389 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001391 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1392 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 RBracketLoc);
1394 }
1395
1396 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001397 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 /// By default, performs semantic analysis to build the new expression.
1399 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001400 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001402 SourceLocation RParenLoc,
1403 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001404 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001405 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 }
1407
1408 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001409 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 /// By default, performs semantic analysis to build the new expression.
1411 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001412 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001413 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001414 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001415 const DeclarationNameInfo &MemberNameInfo,
1416 ValueDecl *Member,
1417 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001418 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001419 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001420 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001421 // We have a reference to an unnamed field. This is always the
1422 // base of an anonymous struct/union member access, i.e. the
1423 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001424 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001425 assert(Member->getType()->isRecordType() &&
1426 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001427
John Wiegley01296292011-04-08 18:41:53 +00001428 ExprResult BaseResult =
1429 getSema().PerformObjectMemberConversion(Base,
1430 QualifierLoc.getNestedNameSpecifier(),
1431 FoundDecl, Member);
1432 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001433 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001434 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001435 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001436 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001437 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001438 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001439 cast<FieldDecl>(Member)->getType(),
1440 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001441 return getSema().Owned(ME);
1442 }
Mike Stump11289f42009-09-09 15:08:12 +00001443
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001444 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001445 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001446
John Wiegley01296292011-04-08 18:41:53 +00001447 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1448 if (BaseResult.isInvalid())
1449 return ExprError();
1450 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001451 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001452
John McCall16df1e52010-03-30 21:47:33 +00001453 // FIXME: this involves duplicating earlier analysis in a lot of
1454 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001455 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001456 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001457 R.resolveKind();
1458
John McCallb268a282010-08-23 23:25:46 +00001459 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001460 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001461 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 }
Mike Stump11289f42009-09-09 15:08:12 +00001463
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001465 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 /// By default, performs semantic analysis to build the new expression.
1467 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001468 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001469 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001470 Expr *LHS, Expr *RHS) {
1471 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 }
1473
1474 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001475 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001478 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001479 SourceLocation QuestionLoc,
1480 Expr *LHS,
1481 SourceLocation ColonLoc,
1482 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001483 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1484 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 }
1486
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001488 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 /// By default, performs semantic analysis to build the new expression.
1490 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001491 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001492 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001494 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001495 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001496 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 }
Mike Stump11289f42009-09-09 15:08:12 +00001498
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001500 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 /// By default, performs semantic analysis to build the new expression.
1502 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001503 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001504 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001506 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001507 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001508 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 }
Mike Stump11289f42009-09-09 15:08:12 +00001510
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001512 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001515 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 SourceLocation OpLoc,
1517 SourceLocation AccessorLoc,
1518 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001519
John McCall10eae182009-11-30 22:42:35 +00001520 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001521 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001522 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001523 OpLoc, /*IsArrow*/ false,
1524 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001525 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001526 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 }
Mike Stump11289f42009-09-09 15:08:12 +00001528
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001530 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 /// By default, performs semantic analysis to build the new expression.
1532 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001533 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001535 SourceLocation RBraceLoc,
1536 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001537 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001538 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1539 if (Result.isInvalid() || ResultTy->isDependentType())
1540 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001541
Douglas Gregord3d93062009-11-09 17:16:50 +00001542 // Patch in the result type we were given, which may have been computed
1543 // when the initial InitListExpr was built.
1544 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1545 ILE->setType(ResultTy);
1546 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 }
Mike Stump11289f42009-09-09 15:08:12 +00001548
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001550 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001553 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 MultiExprArg ArrayExprs,
1555 SourceLocation EqualOrColonLoc,
1556 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001557 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001558 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001560 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001562 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001563
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 ArrayExprs.release();
1565 return move(Result);
1566 }
Mike Stump11289f42009-09-09 15:08:12 +00001567
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001569 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 /// By default, builds the implicit value initialization without performing
1571 /// any semantic analysis. Subclasses may override this routine to provide
1572 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001573 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1575 }
Mike Stump11289f42009-09-09 15:08:12 +00001576
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001578 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001581 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001582 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001583 SourceLocation RParenLoc) {
1584 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001585 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001586 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 }
1588
1589 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001590 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 /// By default, performs semantic analysis to build the new expression.
1592 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001593 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 MultiExprArg SubExprs,
1595 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001596 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001597 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001598 }
Mike Stump11289f42009-09-09 15:08:12 +00001599
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001601 ///
1602 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 /// rather than attempting to map the label statement itself.
1604 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001605 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001606 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001607 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 }
Mike Stump11289f42009-09-09 15:08:12 +00001609
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001611 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 /// By default, performs semantic analysis to build the new expression.
1613 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001614 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001615 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001617 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 }
Mike Stump11289f42009-09-09 15:08:12 +00001619
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 /// \brief Build a new __builtin_choose_expr expression.
1621 ///
1622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001624 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001625 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 SourceLocation RParenLoc) {
1627 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001628 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 RParenLoc);
1630 }
Mike Stump11289f42009-09-09 15:08:12 +00001631
Peter Collingbourne91147592011-04-15 00:35:48 +00001632 /// \brief Build a new generic selection expression.
1633 ///
1634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
1636 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1637 SourceLocation DefaultLoc,
1638 SourceLocation RParenLoc,
1639 Expr *ControllingExpr,
1640 TypeSourceInfo **Types,
1641 Expr **Exprs,
1642 unsigned NumAssocs) {
1643 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1644 ControllingExpr, Types, Exprs,
1645 NumAssocs);
1646 }
1647
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 /// \brief Build a new overloaded operator call expression.
1649 ///
1650 /// By default, performs semantic analysis to build the new expression.
1651 /// The semantic analysis provides the behavior of template instantiation,
1652 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001653 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 /// argument-dependent lookup, etc. Subclasses may override this routine to
1655 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001656 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001658 Expr *Callee,
1659 Expr *First,
1660 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001661
1662 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 /// reinterpret_cast.
1664 ///
1665 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001666 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001668 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 Stmt::StmtClass Class,
1670 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001671 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 SourceLocation RAngleLoc,
1673 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001674 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 SourceLocation RParenLoc) {
1676 switch (Class) {
1677 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001678 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001679 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001680 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001681
1682 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001683 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001684 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001685 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001686
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001688 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001689 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001690 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001692
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001694 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001695 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001696 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001697
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 default:
1699 assert(false && "Invalid C++ named cast");
1700 break;
1701 }
Mike Stump11289f42009-09-09 15:08:12 +00001702
John McCallfaf5fb42010-08-26 23:41:50 +00001703 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 }
Mike Stump11289f42009-09-09 15:08:12 +00001705
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 /// \brief Build a new C++ static_cast expression.
1707 ///
1708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001710 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001712 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 SourceLocation RAngleLoc,
1714 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001715 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001716 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001717 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001718 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001719 SourceRange(LAngleLoc, RAngleLoc),
1720 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 }
1722
1723 /// \brief Build a new C++ dynamic_cast expression.
1724 ///
1725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001727 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001729 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 SourceLocation RAngleLoc,
1731 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001732 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001733 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001734 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001735 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001736 SourceRange(LAngleLoc, RAngleLoc),
1737 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 }
1739
1740 /// \brief Build a new C++ reinterpret_cast expression.
1741 ///
1742 /// By default, performs semantic analysis to build the new expression.
1743 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001744 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001746 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001747 SourceLocation RAngleLoc,
1748 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001749 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001750 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001751 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001752 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001753 SourceRange(LAngleLoc, RAngleLoc),
1754 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 }
1756
1757 /// \brief Build a new C++ const_cast expression.
1758 ///
1759 /// By default, performs semantic analysis to build the new expression.
1760 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001761 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001763 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 SourceLocation RAngleLoc,
1765 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001766 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001768 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001769 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001770 SourceRange(LAngleLoc, RAngleLoc),
1771 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 }
Mike Stump11289f42009-09-09 15:08:12 +00001773
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 /// \brief Build a new C++ functional-style cast expression.
1775 ///
1776 /// By default, performs semantic analysis to build the new expression.
1777 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001778 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1779 SourceLocation LParenLoc,
1780 Expr *Sub,
1781 SourceLocation RParenLoc) {
1782 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001783 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001784 RParenLoc);
1785 }
Mike Stump11289f42009-09-09 15:08:12 +00001786
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 /// \brief Build a new C++ typeid(type) expression.
1788 ///
1789 /// By default, performs semantic analysis to build the new expression.
1790 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001791 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001792 SourceLocation TypeidLoc,
1793 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001795 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001796 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 }
Mike Stump11289f42009-09-09 15:08:12 +00001798
Francois Pichet9f4f2072010-09-08 12:20:18 +00001799
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 /// \brief Build a new C++ typeid(expr) expression.
1801 ///
1802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001805 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001806 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001808 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001809 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001810 }
1811
Francois Pichet9f4f2072010-09-08 12:20:18 +00001812 /// \brief Build a new C++ __uuidof(type) expression.
1813 ///
1814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
1816 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1817 SourceLocation TypeidLoc,
1818 TypeSourceInfo *Operand,
1819 SourceLocation RParenLoc) {
1820 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1821 RParenLoc);
1822 }
1823
1824 /// \brief Build a new C++ __uuidof(expr) expression.
1825 ///
1826 /// By default, performs semantic analysis to build the new expression.
1827 /// Subclasses may override this routine to provide different behavior.
1828 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1829 SourceLocation TypeidLoc,
1830 Expr *Operand,
1831 SourceLocation RParenLoc) {
1832 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1833 RParenLoc);
1834 }
1835
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 /// \brief Build a new C++ "this" expression.
1837 ///
1838 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001839 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001841 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001842 QualType ThisType,
1843 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001845 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1846 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001847 }
1848
1849 /// \brief Build a new C++ throw expression.
1850 ///
1851 /// By default, performs semantic analysis to build the new expression.
1852 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001853 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001854 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001855 }
1856
1857 /// \brief Build a new C++ default-argument expression.
1858 ///
1859 /// By default, builds a new default-argument expression, which does not
1860 /// require any semantic analysis. Subclasses may override this routine to
1861 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001862 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001863 ParmVarDecl *Param) {
1864 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1865 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001866 }
1867
1868 /// \brief Build a new C++ zero-initialization expression.
1869 ///
1870 /// By default, performs semantic analysis to build the new expression.
1871 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001872 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1873 SourceLocation LParenLoc,
1874 SourceLocation RParenLoc) {
1875 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001876 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001877 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 }
Mike Stump11289f42009-09-09 15:08:12 +00001879
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 /// \brief Build a new C++ "new" expression.
1881 ///
1882 /// By default, performs semantic analysis to build the new expression.
1883 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001884 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001885 bool UseGlobal,
1886 SourceLocation PlacementLParen,
1887 MultiExprArg PlacementArgs,
1888 SourceLocation PlacementRParen,
1889 SourceRange TypeIdParens,
1890 QualType AllocatedType,
1891 TypeSourceInfo *AllocatedTypeInfo,
1892 Expr *ArraySize,
1893 SourceLocation ConstructorLParen,
1894 MultiExprArg ConstructorArgs,
1895 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001896 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 PlacementLParen,
1898 move(PlacementArgs),
1899 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001900 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001901 AllocatedType,
1902 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001903 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 ConstructorLParen,
1905 move(ConstructorArgs),
1906 ConstructorRParen);
1907 }
Mike Stump11289f42009-09-09 15:08:12 +00001908
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 /// \brief Build a new C++ "delete" expression.
1910 ///
1911 /// By default, performs semantic analysis to build the new expression.
1912 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001913 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 bool IsGlobalDelete,
1915 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001916 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001918 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 }
Mike Stump11289f42009-09-09 15:08:12 +00001920
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 /// \brief Build a new unary type trait expression.
1922 ///
1923 /// By default, performs semantic analysis to build the new expression.
1924 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001925 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001926 SourceLocation StartLoc,
1927 TypeSourceInfo *T,
1928 SourceLocation RParenLoc) {
1929 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 }
1931
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001932 /// \brief Build a new binary type trait expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
1936 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1937 SourceLocation StartLoc,
1938 TypeSourceInfo *LhsT,
1939 TypeSourceInfo *RhsT,
1940 SourceLocation RParenLoc) {
1941 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1942 }
1943
John Wiegley6242b6a2011-04-28 00:16:57 +00001944 /// \brief Build a new array type trait expression.
1945 ///
1946 /// By default, performs semantic analysis to build the new expression.
1947 /// Subclasses may override this routine to provide different behavior.
1948 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1949 SourceLocation StartLoc,
1950 TypeSourceInfo *TSInfo,
1951 Expr *DimExpr,
1952 SourceLocation RParenLoc) {
1953 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1954 }
1955
John Wiegleyf9f65842011-04-25 06:54:41 +00001956 /// \brief Build a new expression trait expression.
1957 ///
1958 /// By default, performs semantic analysis to build the new expression.
1959 /// Subclasses may override this routine to provide different behavior.
1960 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1961 SourceLocation StartLoc,
1962 Expr *Queried,
1963 SourceLocation RParenLoc) {
1964 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1965 }
1966
Mike Stump11289f42009-09-09 15:08:12 +00001967 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 /// expression.
1969 ///
1970 /// By default, performs semantic analysis to build the new expression.
1971 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001972 ExprResult RebuildDependentScopeDeclRefExpr(
1973 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001974 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001975 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001977 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001978
1979 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001980 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001981 *TemplateArgs);
1982
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001983 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 }
1985
1986 /// \brief Build a new template-id expression.
1987 ///
1988 /// By default, performs semantic analysis to build the new expression.
1989 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001990 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001991 LookupResult &R,
1992 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001993 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001994 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 }
1996
1997 /// \brief Build a new object-construction expression.
1998 ///
1999 /// By default, performs semantic analysis to build the new expression.
2000 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002001 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002002 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 CXXConstructorDecl *Constructor,
2004 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002005 MultiExprArg Args,
2006 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002007 CXXConstructExpr::ConstructionKind ConstructKind,
2008 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002009 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002010 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002011 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002012 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002013
Douglas Gregordb121ba2009-12-14 16:27:04 +00002014 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002015 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00002016 RequiresZeroInit, ConstructKind,
2017 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 }
2019
2020 /// \brief Build a new object-construction expression.
2021 ///
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002024 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2025 SourceLocation LParenLoc,
2026 MultiExprArg Args,
2027 SourceLocation RParenLoc) {
2028 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 LParenLoc,
2030 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002031 RParenLoc);
2032 }
2033
2034 /// \brief Build a new object-construction expression.
2035 ///
2036 /// By default, performs semantic analysis to build the new expression.
2037 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002038 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2039 SourceLocation LParenLoc,
2040 MultiExprArg Args,
2041 SourceLocation RParenLoc) {
2042 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 LParenLoc,
2044 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 RParenLoc);
2046 }
Mike Stump11289f42009-09-09 15:08:12 +00002047
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 /// \brief Build a new member reference expression.
2049 ///
2050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002052 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002053 QualType BaseType,
2054 bool IsArrow,
2055 SourceLocation OperatorLoc,
2056 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002057 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002058 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002059 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002060 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002061 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002062
John McCallb268a282010-08-23 23:25:46 +00002063 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002064 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002065 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002066 MemberNameInfo,
2067 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002068 }
2069
John McCall10eae182009-11-30 22:42:35 +00002070 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002071 ///
2072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002074 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002075 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002076 SourceLocation OperatorLoc,
2077 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002078 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002079 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002080 LookupResult &R,
2081 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002082 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002083 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002084
John McCallb268a282010-08-23 23:25:46 +00002085 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002086 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002087 SS, FirstQualifierInScope,
2088 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002089 }
Mike Stump11289f42009-09-09 15:08:12 +00002090
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002091 /// \brief Build a new noexcept expression.
2092 ///
2093 /// By default, performs semantic analysis to build the new expression.
2094 /// Subclasses may override this routine to provide different behavior.
2095 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2096 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2097 }
2098
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002099 /// \brief Build a new expression to compute the length of a parameter pack.
2100 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2101 SourceLocation PackLoc,
2102 SourceLocation RParenLoc,
2103 unsigned Length) {
2104 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2105 OperatorLoc, Pack, PackLoc,
2106 RParenLoc, Length);
2107 }
2108
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 /// \brief Build a new Objective-C @encode expression.
2110 ///
2111 /// By default, performs semantic analysis to build the new expression.
2112 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002113 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002114 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002115 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002116 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002118 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002119
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002120 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002121 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002122 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002123 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002124 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002125 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002126 MultiExprArg Args,
2127 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002128 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2129 ReceiverTypeInfo->getType(),
2130 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002131 Sel, Method, LBracLoc, SelectorLoc,
2132 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002133 }
2134
2135 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002136 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002137 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002138 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002139 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002140 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002141 MultiExprArg Args,
2142 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002143 return SemaRef.BuildInstanceMessage(Receiver,
2144 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002145 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002146 Sel, Method, LBracLoc, SelectorLoc,
2147 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002148 }
2149
Douglas Gregord51d90d2010-04-26 20:11:03 +00002150 /// \brief Build a new Objective-C ivar reference expression.
2151 ///
2152 /// By default, performs semantic analysis to build the new expression.
2153 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002154 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002155 SourceLocation IvarLoc,
2156 bool IsArrow, bool IsFreeIvar) {
2157 // FIXME: We lose track of the IsFreeIvar bit.
2158 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002159 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002160 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2161 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002162 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002163 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002164 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002165 false);
John Wiegley01296292011-04-08 18:41:53 +00002166 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002167 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002168
Douglas Gregord51d90d2010-04-26 20:11:03 +00002169 if (Result.get())
2170 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002171
John Wiegley01296292011-04-08 18:41:53 +00002172 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002173 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002174 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002175 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002176 /*TemplateArgs=*/0);
2177 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002178
2179 /// \brief Build a new Objective-C property reference expression.
2180 ///
2181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002184 ObjCPropertyDecl *Property,
2185 SourceLocation PropertyLoc) {
2186 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002187 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002188 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2189 Sema::LookupMemberName);
2190 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002191 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002192 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002193 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002194 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002195 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002196
Douglas Gregor9faee212010-04-26 20:47:02 +00002197 if (Result.get())
2198 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002199
John Wiegley01296292011-04-08 18:41:53 +00002200 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002201 /*FIXME:*/PropertyLoc, IsArrow,
2202 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002203 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002204 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002205 /*TemplateArgs=*/0);
2206 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002207
John McCallb7bd14f2010-12-02 01:19:52 +00002208 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002209 ///
2210 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002211 /// Subclasses may override this routine to provide different behavior.
2212 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2213 ObjCMethodDecl *Getter,
2214 ObjCMethodDecl *Setter,
2215 SourceLocation PropertyLoc) {
2216 // Since these expressions can only be value-dependent, we do not
2217 // need to perform semantic analysis again.
2218 return Owned(
2219 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2220 VK_LValue, OK_ObjCProperty,
2221 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002222 }
2223
Douglas Gregord51d90d2010-04-26 20:11:03 +00002224 /// \brief Build a new Objective-C "isa" expression.
2225 ///
2226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002228 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002229 bool IsArrow) {
2230 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002231 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002232 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2233 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002234 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002235 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002236 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002237 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002238 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002239
Douglas Gregord51d90d2010-04-26 20:11:03 +00002240 if (Result.get())
2241 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002242
John Wiegley01296292011-04-08 18:41:53 +00002243 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002244 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002245 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002246 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002247 /*TemplateArgs=*/0);
2248 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002249
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 /// \brief Build a new shuffle vector expression.
2251 ///
2252 /// By default, performs semantic analysis to build the new expression.
2253 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002254 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002255 MultiExprArg SubExprs,
2256 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002258 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2260 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2261 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2262 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002263
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 // Build a reference to the __builtin_shufflevector builtin
2265 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002266 ExprResult Callee
2267 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2268 VK_LValue, BuiltinLoc));
2269 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2270 if (Callee.isInvalid())
2271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002272
2273 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 unsigned NumSubExprs = SubExprs.size();
2275 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002276 ExprResult TheCall = SemaRef.Owned(
2277 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002279 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002280 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002281 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002282
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002284 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 }
John McCall31f82722010-11-12 08:19:04 +00002286
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002287 /// \brief Build a new template argument pack expansion.
2288 ///
2289 /// By default, performs semantic analysis to build a new pack expansion
2290 /// for a template argument. Subclasses may override this routine to provide
2291 /// different behavior.
2292 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002293 SourceLocation EllipsisLoc,
2294 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002295 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002296 case TemplateArgument::Expression: {
2297 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002298 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2299 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002300 if (Result.isInvalid())
2301 return TemplateArgumentLoc();
2302
2303 return TemplateArgumentLoc(Result.get(), Result.get());
2304 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002305
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002306 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002307 return TemplateArgumentLoc(TemplateArgument(
2308 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002309 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002310 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002311 Pattern.getTemplateNameLoc(),
2312 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002313
2314 case TemplateArgument::Null:
2315 case TemplateArgument::Integral:
2316 case TemplateArgument::Declaration:
2317 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002318 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002319 llvm_unreachable("Pack expansion pattern has no parameter packs");
2320
2321 case TemplateArgument::Type:
2322 if (TypeSourceInfo *Expansion
2323 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002324 EllipsisLoc,
2325 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002326 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2327 Expansion);
2328 break;
2329 }
2330
2331 return TemplateArgumentLoc();
2332 }
2333
Douglas Gregor968f23a2011-01-03 19:31:53 +00002334 /// \brief Build a new expression pack expansion.
2335 ///
2336 /// By default, performs semantic analysis to build a new pack expansion
2337 /// for an expression. Subclasses may override this routine to provide
2338 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002339 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2340 llvm::Optional<unsigned> NumExpansions) {
2341 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002342 }
2343
John McCall31f82722010-11-12 08:19:04 +00002344private:
Douglas Gregor14454802011-02-25 02:25:35 +00002345 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2346 QualType ObjectType,
2347 NamedDecl *FirstQualifierInScope,
2348 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002349
2350 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2351 QualType ObjectType,
2352 NamedDecl *FirstQualifierInScope,
2353 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002354};
Douglas Gregora16548e2009-08-11 05:31:07 +00002355
Douglas Gregorebe10102009-08-20 07:17:43 +00002356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002357StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002358 if (!S)
2359 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002360
Douglas Gregorebe10102009-08-20 07:17:43 +00002361 switch (S->getStmtClass()) {
2362 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002363
Douglas Gregorebe10102009-08-20 07:17:43 +00002364 // Transform individual statement nodes
2365#define STMT(Node, Parent) \
2366 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002367#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002368#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002369#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002370
Douglas Gregorebe10102009-08-20 07:17:43 +00002371 // Transform expressions by calling TransformExpr.
2372#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002373#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002374#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002375#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002376 {
John McCalldadc5752010-08-24 06:29:42 +00002377 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002378 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002379 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002380
John McCallb268a282010-08-23 23:25:46 +00002381 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002382 }
Mike Stump11289f42009-09-09 15:08:12 +00002383 }
2384
John McCallc3007a22010-10-26 07:05:15 +00002385 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002386}
Mike Stump11289f42009-09-09 15:08:12 +00002387
2388
Douglas Gregore922c772009-08-04 22:27:00 +00002389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002390ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002391 if (!E)
2392 return SemaRef.Owned(E);
2393
2394 switch (E->getStmtClass()) {
2395 case Stmt::NoStmtClass: break;
2396#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002397#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002398#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002399 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002400#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002401 }
2402
John McCallc3007a22010-10-26 07:05:15 +00002403 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002404}
2405
2406template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002407bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2408 unsigned NumInputs,
2409 bool IsCall,
2410 llvm::SmallVectorImpl<Expr *> &Outputs,
2411 bool *ArgChanged) {
2412 for (unsigned I = 0; I != NumInputs; ++I) {
2413 // If requested, drop call arguments that need to be dropped.
2414 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2415 if (ArgChanged)
2416 *ArgChanged = true;
2417
2418 break;
2419 }
2420
Douglas Gregor968f23a2011-01-03 19:31:53 +00002421 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2422 Expr *Pattern = Expansion->getPattern();
2423
2424 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2425 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2426 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2427
2428 // Determine whether the set of unexpanded parameter packs can and should
2429 // be expanded.
2430 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002431 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002432 llvm::Optional<unsigned> OrigNumExpansions
2433 = Expansion->getNumExpansions();
2434 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002435 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2436 Pattern->getSourceRange(),
2437 Unexpanded.data(),
2438 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002439 Expand, RetainExpansion,
2440 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002441 return true;
2442
2443 if (!Expand) {
2444 // The transform has determined that we should perform a simple
2445 // transformation on the pack expansion, producing another pack
2446 // expansion.
2447 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2448 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2449 if (OutPattern.isInvalid())
2450 return true;
2451
2452 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002453 Expansion->getEllipsisLoc(),
2454 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002455 if (Out.isInvalid())
2456 return true;
2457
2458 if (ArgChanged)
2459 *ArgChanged = true;
2460 Outputs.push_back(Out.get());
2461 continue;
2462 }
2463
2464 // The transform has determined that we should perform an elementwise
2465 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002466 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002467 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2468 ExprResult Out = getDerived().TransformExpr(Pattern);
2469 if (Out.isInvalid())
2470 return true;
2471
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002472 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002473 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2474 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002475 if (Out.isInvalid())
2476 return true;
2477 }
2478
Douglas Gregor968f23a2011-01-03 19:31:53 +00002479 if (ArgChanged)
2480 *ArgChanged = true;
2481 Outputs.push_back(Out.get());
2482 }
2483
2484 continue;
2485 }
2486
Douglas Gregora3efea12011-01-03 19:04:46 +00002487 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2488 if (Result.isInvalid())
2489 return true;
2490
2491 if (Result.get() != Inputs[I] && ArgChanged)
2492 *ArgChanged = true;
2493
2494 Outputs.push_back(Result.get());
2495 }
2496
2497 return false;
2498}
2499
2500template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002501NestedNameSpecifierLoc
2502TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2503 NestedNameSpecifierLoc NNS,
2504 QualType ObjectType,
2505 NamedDecl *FirstQualifierInScope) {
2506 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2507 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2508 Qualifier = Qualifier.getPrefix())
2509 Qualifiers.push_back(Qualifier);
2510
2511 CXXScopeSpec SS;
2512 while (!Qualifiers.empty()) {
2513 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2514 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2515
2516 switch (QNNS->getKind()) {
2517 case NestedNameSpecifier::Identifier:
2518 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2519 *QNNS->getAsIdentifier(),
2520 Q.getLocalBeginLoc(),
2521 Q.getLocalEndLoc(),
2522 ObjectType, false, SS,
2523 FirstQualifierInScope, false))
2524 return NestedNameSpecifierLoc();
2525
2526 break;
2527
2528 case NestedNameSpecifier::Namespace: {
2529 NamespaceDecl *NS
2530 = cast_or_null<NamespaceDecl>(
2531 getDerived().TransformDecl(
2532 Q.getLocalBeginLoc(),
2533 QNNS->getAsNamespace()));
2534 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2535 break;
2536 }
2537
2538 case NestedNameSpecifier::NamespaceAlias: {
2539 NamespaceAliasDecl *Alias
2540 = cast_or_null<NamespaceAliasDecl>(
2541 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2542 QNNS->getAsNamespaceAlias()));
2543 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2544 Q.getLocalEndLoc());
2545 break;
2546 }
2547
2548 case NestedNameSpecifier::Global:
2549 // There is no meaningful transformation that one could perform on the
2550 // global scope.
2551 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2552 break;
2553
2554 case NestedNameSpecifier::TypeSpecWithTemplate:
2555 case NestedNameSpecifier::TypeSpec: {
2556 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2557 FirstQualifierInScope, SS);
2558
2559 if (!TL)
2560 return NestedNameSpecifierLoc();
2561
2562 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2563 (SemaRef.getLangOptions().CPlusPlus0x &&
2564 TL.getType()->isEnumeralType())) {
2565 assert(!TL.getType().hasLocalQualifiers() &&
2566 "Can't get cv-qualifiers here");
2567 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2568 Q.getLocalEndLoc());
2569 break;
2570 }
Richard Trieude756fb2011-05-07 01:36:37 +00002571 // If the nested-name-specifier is an invalid type def, don't emit an
2572 // error because a previous error should have already been emitted.
2573 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2574 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2575 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2576 << TL.getType() << SS.getRange();
2577 }
Douglas Gregor14454802011-02-25 02:25:35 +00002578 return NestedNameSpecifierLoc();
2579 }
Douglas Gregore16af532011-02-28 18:50:33 +00002580 }
Douglas Gregor14454802011-02-25 02:25:35 +00002581
Douglas Gregore16af532011-02-28 18:50:33 +00002582 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002583 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002584 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002585 }
2586
2587 // Don't rebuild the nested-name-specifier if we don't have to.
2588 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2589 !getDerived().AlwaysRebuild())
2590 return NNS;
2591
2592 // If we can re-use the source-location data from the original
2593 // nested-name-specifier, do so.
2594 if (SS.location_size() == NNS.getDataLength() &&
2595 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2596 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2597
2598 // Allocate new nested-name-specifier location information.
2599 return SS.getWithLocInContext(SemaRef.Context);
2600}
2601
2602template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002603DeclarationNameInfo
2604TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002605::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002606 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002607 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002608 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002609
2610 switch (Name.getNameKind()) {
2611 case DeclarationName::Identifier:
2612 case DeclarationName::ObjCZeroArgSelector:
2613 case DeclarationName::ObjCOneArgSelector:
2614 case DeclarationName::ObjCMultiArgSelector:
2615 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002616 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002617 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002618 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002619
Douglas Gregorf816bd72009-09-03 22:13:48 +00002620 case DeclarationName::CXXConstructorName:
2621 case DeclarationName::CXXDestructorName:
2622 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002623 TypeSourceInfo *NewTInfo;
2624 CanQualType NewCanTy;
2625 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002626 NewTInfo = getDerived().TransformType(OldTInfo);
2627 if (!NewTInfo)
2628 return DeclarationNameInfo();
2629 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002630 }
2631 else {
2632 NewTInfo = 0;
2633 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002634 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002635 if (NewT.isNull())
2636 return DeclarationNameInfo();
2637 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2638 }
Mike Stump11289f42009-09-09 15:08:12 +00002639
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002640 DeclarationName NewName
2641 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2642 NewCanTy);
2643 DeclarationNameInfo NewNameInfo(NameInfo);
2644 NewNameInfo.setName(NewName);
2645 NewNameInfo.setNamedTypeInfo(NewTInfo);
2646 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002647 }
Mike Stump11289f42009-09-09 15:08:12 +00002648 }
2649
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002650 assert(0 && "Unknown name kind.");
2651 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002652}
2653
2654template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002655TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002656TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2657 TemplateName Name,
2658 SourceLocation NameLoc,
2659 QualType ObjectType,
2660 NamedDecl *FirstQualifierInScope) {
2661 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2662 TemplateDecl *Template = QTN->getTemplateDecl();
2663 assert(Template && "qualified template name must refer to a template");
2664
2665 TemplateDecl *TransTemplate
2666 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2667 Template));
2668 if (!TransTemplate)
2669 return TemplateName();
2670
2671 if (!getDerived().AlwaysRebuild() &&
2672 SS.getScopeRep() == QTN->getQualifier() &&
2673 TransTemplate == Template)
2674 return Name;
2675
2676 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2677 TransTemplate);
2678 }
2679
2680 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2681 if (SS.getScopeRep()) {
2682 // These apply to the scope specifier, not the template.
2683 ObjectType = QualType();
2684 FirstQualifierInScope = 0;
2685 }
2686
2687 if (!getDerived().AlwaysRebuild() &&
2688 SS.getScopeRep() == DTN->getQualifier() &&
2689 ObjectType.isNull())
2690 return Name;
2691
2692 if (DTN->isIdentifier()) {
2693 return getDerived().RebuildTemplateName(SS,
2694 *DTN->getIdentifier(),
2695 NameLoc,
2696 ObjectType,
2697 FirstQualifierInScope);
2698 }
2699
2700 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2701 ObjectType);
2702 }
2703
2704 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2705 TemplateDecl *TransTemplate
2706 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2707 Template));
2708 if (!TransTemplate)
2709 return TemplateName();
2710
2711 if (!getDerived().AlwaysRebuild() &&
2712 TransTemplate == Template)
2713 return Name;
2714
2715 return TemplateName(TransTemplate);
2716 }
2717
2718 if (SubstTemplateTemplateParmPackStorage *SubstPack
2719 = Name.getAsSubstTemplateTemplateParmPack()) {
2720 TemplateTemplateParmDecl *TransParam
2721 = cast_or_null<TemplateTemplateParmDecl>(
2722 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2723 if (!TransParam)
2724 return TemplateName();
2725
2726 if (!getDerived().AlwaysRebuild() &&
2727 TransParam == SubstPack->getParameterPack())
2728 return Name;
2729
2730 return getDerived().RebuildTemplateName(TransParam,
2731 SubstPack->getArgumentPack());
2732 }
2733
2734 // These should be getting filtered out before they reach the AST.
2735 llvm_unreachable("overloaded function decl survived to here");
2736 return TemplateName();
2737}
2738
2739template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002740void TreeTransform<Derived>::InventTemplateArgumentLoc(
2741 const TemplateArgument &Arg,
2742 TemplateArgumentLoc &Output) {
2743 SourceLocation Loc = getDerived().getBaseLocation();
2744 switch (Arg.getKind()) {
2745 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002746 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002747 break;
2748
2749 case TemplateArgument::Type:
2750 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002751 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002752
John McCall0ad16662009-10-29 08:12:44 +00002753 break;
2754
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002755 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002756 case TemplateArgument::TemplateExpansion: {
2757 NestedNameSpecifierLocBuilder Builder;
2758 TemplateName Template = Arg.getAsTemplate();
2759 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2760 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2761 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2762 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2763
2764 if (Arg.getKind() == TemplateArgument::Template)
2765 Output = TemplateArgumentLoc(Arg,
2766 Builder.getWithLocInContext(SemaRef.Context),
2767 Loc);
2768 else
2769 Output = TemplateArgumentLoc(Arg,
2770 Builder.getWithLocInContext(SemaRef.Context),
2771 Loc, Loc);
2772
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002773 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002774 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002775
John McCall0ad16662009-10-29 08:12:44 +00002776 case TemplateArgument::Expression:
2777 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2778 break;
2779
2780 case TemplateArgument::Declaration:
2781 case TemplateArgument::Integral:
2782 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002783 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002784 break;
2785 }
2786}
2787
2788template<typename Derived>
2789bool TreeTransform<Derived>::TransformTemplateArgument(
2790 const TemplateArgumentLoc &Input,
2791 TemplateArgumentLoc &Output) {
2792 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002793 switch (Arg.getKind()) {
2794 case TemplateArgument::Null:
2795 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002796 Output = Input;
2797 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002798
Douglas Gregore922c772009-08-04 22:27:00 +00002799 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002800 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002801 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002802 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002803
2804 DI = getDerived().TransformType(DI);
2805 if (!DI) return true;
2806
2807 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2808 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002809 }
Mike Stump11289f42009-09-09 15:08:12 +00002810
Douglas Gregore922c772009-08-04 22:27:00 +00002811 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002812 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002813 DeclarationName Name;
2814 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2815 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002816 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002817 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002818 if (!D) return true;
2819
John McCall0d07eb32009-10-29 18:45:58 +00002820 Expr *SourceExpr = Input.getSourceDeclExpression();
2821 if (SourceExpr) {
2822 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002823 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002824 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002825 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002826 }
2827
2828 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002829 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002830 }
Mike Stump11289f42009-09-09 15:08:12 +00002831
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002832 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002833 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2834 if (QualifierLoc) {
2835 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2836 if (!QualifierLoc)
2837 return true;
2838 }
2839
Douglas Gregordf846d12011-03-02 18:46:51 +00002840 CXXScopeSpec SS;
2841 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002842 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002843 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2844 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002845 if (Template.isNull())
2846 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002847
Douglas Gregor9d802122011-03-02 17:09:35 +00002848 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002849 Input.getTemplateNameLoc());
2850 return false;
2851 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002852
2853 case TemplateArgument::TemplateExpansion:
2854 llvm_unreachable("Caller should expand pack expansions");
2855
Douglas Gregore922c772009-08-04 22:27:00 +00002856 case TemplateArgument::Expression: {
2857 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002858 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002859 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002860
John McCall0ad16662009-10-29 08:12:44 +00002861 Expr *InputExpr = Input.getSourceExpression();
2862 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2863
Chris Lattnercdb591a2011-04-25 20:37:58 +00002864 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002865 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002866 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002867 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002868 }
Mike Stump11289f42009-09-09 15:08:12 +00002869
Douglas Gregore922c772009-08-04 22:27:00 +00002870 case TemplateArgument::Pack: {
2871 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2872 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002873 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002874 AEnd = Arg.pack_end();
2875 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002876
John McCall0ad16662009-10-29 08:12:44 +00002877 // FIXME: preserve source information here when we start
2878 // caring about parameter packs.
2879
John McCall0d07eb32009-10-29 18:45:58 +00002880 TemplateArgumentLoc InputArg;
2881 TemplateArgumentLoc OutputArg;
2882 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2883 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002884 return true;
2885
John McCall0d07eb32009-10-29 18:45:58 +00002886 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002887 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002888
2889 TemplateArgument *TransformedArgsPtr
2890 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2891 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2892 TransformedArgsPtr);
2893 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2894 TransformedArgs.size()),
2895 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002896 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002897 }
2898 }
Mike Stump11289f42009-09-09 15:08:12 +00002899
Douglas Gregore922c772009-08-04 22:27:00 +00002900 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002901 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002902}
2903
Douglas Gregorfe921a72010-12-20 23:36:19 +00002904/// \brief Iterator adaptor that invents template argument location information
2905/// for each of the template arguments in its underlying iterator.
2906template<typename Derived, typename InputIterator>
2907class TemplateArgumentLocInventIterator {
2908 TreeTransform<Derived> &Self;
2909 InputIterator Iter;
2910
2911public:
2912 typedef TemplateArgumentLoc value_type;
2913 typedef TemplateArgumentLoc reference;
2914 typedef typename std::iterator_traits<InputIterator>::difference_type
2915 difference_type;
2916 typedef std::input_iterator_tag iterator_category;
2917
2918 class pointer {
2919 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002920
Douglas Gregorfe921a72010-12-20 23:36:19 +00002921 public:
2922 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2923
2924 const TemplateArgumentLoc *operator->() const { return &Arg; }
2925 };
2926
2927 TemplateArgumentLocInventIterator() { }
2928
2929 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2930 InputIterator Iter)
2931 : Self(Self), Iter(Iter) { }
2932
2933 TemplateArgumentLocInventIterator &operator++() {
2934 ++Iter;
2935 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002936 }
2937
Douglas Gregorfe921a72010-12-20 23:36:19 +00002938 TemplateArgumentLocInventIterator operator++(int) {
2939 TemplateArgumentLocInventIterator Old(*this);
2940 ++(*this);
2941 return Old;
2942 }
2943
2944 reference operator*() const {
2945 TemplateArgumentLoc Result;
2946 Self.InventTemplateArgumentLoc(*Iter, Result);
2947 return Result;
2948 }
2949
2950 pointer operator->() const { return pointer(**this); }
2951
2952 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2953 const TemplateArgumentLocInventIterator &Y) {
2954 return X.Iter == Y.Iter;
2955 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002956
Douglas Gregorfe921a72010-12-20 23:36:19 +00002957 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2958 const TemplateArgumentLocInventIterator &Y) {
2959 return X.Iter != Y.Iter;
2960 }
2961};
2962
Douglas Gregor42cafa82010-12-20 17:42:22 +00002963template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002964template<typename InputIterator>
2965bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2966 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002967 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002968 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002969 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002970 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002971
2972 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2973 // Unpack argument packs, which we translate them into separate
2974 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002975 // FIXME: We could do much better if we could guarantee that the
2976 // TemplateArgumentLocInfo for the pack expansion would be usable for
2977 // all of the template arguments in the argument pack.
2978 typedef TemplateArgumentLocInventIterator<Derived,
2979 TemplateArgument::pack_iterator>
2980 PackLocIterator;
2981 if (TransformTemplateArguments(PackLocIterator(*this,
2982 In.getArgument().pack_begin()),
2983 PackLocIterator(*this,
2984 In.getArgument().pack_end()),
2985 Outputs))
2986 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002987
2988 continue;
2989 }
2990
2991 if (In.getArgument().isPackExpansion()) {
2992 // We have a pack expansion, for which we will be substituting into
2993 // the pattern.
2994 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002995 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002996 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002997 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2998 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002999
3000 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3001 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3002 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3003
3004 // Determine whether the set of unexpanded parameter packs can and should
3005 // be expanded.
3006 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003007 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003008 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003009 if (getDerived().TryExpandParameterPacks(Ellipsis,
3010 Pattern.getSourceRange(),
3011 Unexpanded.data(),
3012 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003013 Expand,
3014 RetainExpansion,
3015 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003016 return true;
3017
3018 if (!Expand) {
3019 // The transform has determined that we should perform a simple
3020 // transformation on the pack expansion, producing another pack
3021 // expansion.
3022 TemplateArgumentLoc OutPattern;
3023 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3024 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3025 return true;
3026
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003027 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3028 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003029 if (Out.getArgument().isNull())
3030 return true;
3031
3032 Outputs.addArgument(Out);
3033 continue;
3034 }
3035
3036 // The transform has determined that we should perform an elementwise
3037 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003038 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003039 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3040
3041 if (getDerived().TransformTemplateArgument(Pattern, Out))
3042 return true;
3043
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003044 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003045 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3046 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003047 if (Out.getArgument().isNull())
3048 return true;
3049 }
3050
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003051 Outputs.addArgument(Out);
3052 }
3053
Douglas Gregor48d24112011-01-10 20:53:55 +00003054 // If we're supposed to retain a pack expansion, do so by temporarily
3055 // forgetting the partially-substituted parameter pack.
3056 if (RetainExpansion) {
3057 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3058
3059 if (getDerived().TransformTemplateArgument(Pattern, Out))
3060 return true;
3061
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003062 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3063 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003064 if (Out.getArgument().isNull())
3065 return true;
3066
3067 Outputs.addArgument(Out);
3068 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003069
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003070 continue;
3071 }
3072
3073 // The simple case:
3074 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003075 return true;
3076
3077 Outputs.addArgument(Out);
3078 }
3079
3080 return false;
3081
3082}
3083
Douglas Gregord6ff3322009-08-04 16:50:30 +00003084//===----------------------------------------------------------------------===//
3085// Type transformation
3086//===----------------------------------------------------------------------===//
3087
3088template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003089QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003090 if (getDerived().AlreadyTransformed(T))
3091 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003092
John McCall550e0c22009-10-21 00:40:46 +00003093 // Temporary workaround. All of these transformations should
3094 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003095 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3096 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003097
John McCall31f82722010-11-12 08:19:04 +00003098 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003099
John McCall550e0c22009-10-21 00:40:46 +00003100 if (!NewDI)
3101 return QualType();
3102
3103 return NewDI->getType();
3104}
3105
3106template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003107TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003108 if (getDerived().AlreadyTransformed(DI->getType()))
3109 return DI;
3110
3111 TypeLocBuilder TLB;
3112
3113 TypeLoc TL = DI->getTypeLoc();
3114 TLB.reserve(TL.getFullDataSize());
3115
John McCall31f82722010-11-12 08:19:04 +00003116 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003117 if (Result.isNull())
3118 return 0;
3119
John McCallbcd03502009-12-07 02:54:59 +00003120 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003121}
3122
3123template<typename Derived>
3124QualType
John McCall31f82722010-11-12 08:19:04 +00003125TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003126 switch (T.getTypeLocClass()) {
3127#define ABSTRACT_TYPELOC(CLASS, PARENT)
3128#define TYPELOC(CLASS, PARENT) \
3129 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003130 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003131#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003132 }
Mike Stump11289f42009-09-09 15:08:12 +00003133
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003134 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003135 return QualType();
3136}
3137
3138/// FIXME: By default, this routine adds type qualifiers only to types
3139/// that can have qualifiers, and silently suppresses those qualifiers
3140/// that are not permitted (e.g., qualifiers on reference or function
3141/// types). This is the right thing for template instantiation, but
3142/// probably not for other clients.
3143template<typename Derived>
3144QualType
3145TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003146 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003147 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003148
John McCall31f82722010-11-12 08:19:04 +00003149 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003150 if (Result.isNull())
3151 return QualType();
3152
3153 // Silently suppress qualifiers if the result type can't be qualified.
3154 // FIXME: this is the right thing for template instantiation, but
3155 // probably not for other clients.
3156 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003157 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003158
John McCallcb0f89a2010-06-05 06:41:15 +00003159 if (!Quals.empty()) {
3160 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3161 TLB.push<QualifiedTypeLoc>(Result);
3162 // No location information to preserve.
3163 }
John McCall550e0c22009-10-21 00:40:46 +00003164
3165 return Result;
3166}
3167
Douglas Gregor14454802011-02-25 02:25:35 +00003168template<typename Derived>
3169TypeLoc
3170TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3171 QualType ObjectType,
3172 NamedDecl *UnqualLookup,
3173 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003174 QualType T = TL.getType();
3175 if (getDerived().AlreadyTransformed(T))
3176 return TL;
3177
3178 TypeLocBuilder TLB;
3179 QualType Result;
3180
3181 if (isa<TemplateSpecializationType>(T)) {
3182 TemplateSpecializationTypeLoc SpecTL
3183 = cast<TemplateSpecializationTypeLoc>(TL);
3184
3185 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003186 getDerived().TransformTemplateName(SS,
3187 SpecTL.getTypePtr()->getTemplateName(),
3188 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003189 ObjectType, UnqualLookup);
3190 if (Template.isNull())
3191 return TypeLoc();
3192
3193 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3194 Template);
3195 } else if (isa<DependentTemplateSpecializationType>(T)) {
3196 DependentTemplateSpecializationTypeLoc SpecTL
3197 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3198
Douglas Gregor5a064722011-02-28 17:23:35 +00003199 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003200 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003201 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003202 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003203 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003204 if (Template.isNull())
3205 return TypeLoc();
3206
Douglas Gregor14454802011-02-25 02:25:35 +00003207 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003208 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003209 Template,
3210 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003211 } else {
3212 // Nothing special needs to be done for these.
3213 Result = getDerived().TransformType(TLB, TL);
3214 }
3215
3216 if (Result.isNull())
3217 return TypeLoc();
3218
3219 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3220}
3221
Douglas Gregor579c15f2011-03-02 18:32:08 +00003222template<typename Derived>
3223TypeSourceInfo *
3224TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3225 QualType ObjectType,
3226 NamedDecl *UnqualLookup,
3227 CXXScopeSpec &SS) {
3228 // FIXME: Painfully copy-paste from the above!
3229
3230 QualType T = TSInfo->getType();
3231 if (getDerived().AlreadyTransformed(T))
3232 return TSInfo;
3233
3234 TypeLocBuilder TLB;
3235 QualType Result;
3236
3237 TypeLoc TL = TSInfo->getTypeLoc();
3238 if (isa<TemplateSpecializationType>(T)) {
3239 TemplateSpecializationTypeLoc SpecTL
3240 = cast<TemplateSpecializationTypeLoc>(TL);
3241
3242 TemplateName Template
3243 = getDerived().TransformTemplateName(SS,
3244 SpecTL.getTypePtr()->getTemplateName(),
3245 SpecTL.getTemplateNameLoc(),
3246 ObjectType, UnqualLookup);
3247 if (Template.isNull())
3248 return 0;
3249
3250 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3251 Template);
3252 } else if (isa<DependentTemplateSpecializationType>(T)) {
3253 DependentTemplateSpecializationTypeLoc SpecTL
3254 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3255
3256 TemplateName Template
3257 = getDerived().RebuildTemplateName(SS,
3258 *SpecTL.getTypePtr()->getIdentifier(),
3259 SpecTL.getNameLoc(),
3260 ObjectType, UnqualLookup);
3261 if (Template.isNull())
3262 return 0;
3263
3264 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3265 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003266 Template,
3267 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003268 } else {
3269 // Nothing special needs to be done for these.
3270 Result = getDerived().TransformType(TLB, TL);
3271 }
3272
3273 if (Result.isNull())
3274 return 0;
3275
3276 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3277}
3278
John McCall550e0c22009-10-21 00:40:46 +00003279template <class TyLoc> static inline
3280QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3281 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3282 NewT.setNameLoc(T.getNameLoc());
3283 return T.getType();
3284}
3285
John McCall550e0c22009-10-21 00:40:46 +00003286template<typename Derived>
3287QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003288 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003289 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3290 NewT.setBuiltinLoc(T.getBuiltinLoc());
3291 if (T.needsExtraLocalData())
3292 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3293 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003294}
Mike Stump11289f42009-09-09 15:08:12 +00003295
Douglas Gregord6ff3322009-08-04 16:50:30 +00003296template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003297QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003298 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003299 // FIXME: recurse?
3300 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003301}
Mike Stump11289f42009-09-09 15:08:12 +00003302
Douglas Gregord6ff3322009-08-04 16:50:30 +00003303template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003304QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003305 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003306 QualType PointeeType
3307 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003308 if (PointeeType.isNull())
3309 return QualType();
3310
3311 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003312 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003313 // A dependent pointer type 'T *' has is being transformed such
3314 // that an Objective-C class type is being replaced for 'T'. The
3315 // resulting pointer type is an ObjCObjectPointerType, not a
3316 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003317 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003318
John McCall8b07ec22010-05-15 11:32:37 +00003319 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3320 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003321 return Result;
3322 }
John McCall31f82722010-11-12 08:19:04 +00003323
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003324 if (getDerived().AlwaysRebuild() ||
3325 PointeeType != TL.getPointeeLoc().getType()) {
3326 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3327 if (Result.isNull())
3328 return QualType();
3329 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003330
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003331 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3332 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003333 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003334}
Mike Stump11289f42009-09-09 15:08:12 +00003335
3336template<typename Derived>
3337QualType
John McCall550e0c22009-10-21 00:40:46 +00003338TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003339 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003340 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003341 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3342 if (PointeeType.isNull())
3343 return QualType();
3344
3345 QualType Result = TL.getType();
3346 if (getDerived().AlwaysRebuild() ||
3347 PointeeType != TL.getPointeeLoc().getType()) {
3348 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003349 TL.getSigilLoc());
3350 if (Result.isNull())
3351 return QualType();
3352 }
3353
Douglas Gregor049211a2010-04-22 16:50:51 +00003354 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003355 NewT.setSigilLoc(TL.getSigilLoc());
3356 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003357}
3358
John McCall70dd5f62009-10-30 00:06:24 +00003359/// Transforms a reference type. Note that somewhat paradoxically we
3360/// don't care whether the type itself is an l-value type or an r-value
3361/// type; we only care if the type was *written* as an l-value type
3362/// or an r-value type.
3363template<typename Derived>
3364QualType
3365TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003366 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003367 const ReferenceType *T = TL.getTypePtr();
3368
3369 // Note that this works with the pointee-as-written.
3370 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3371 if (PointeeType.isNull())
3372 return QualType();
3373
3374 QualType Result = TL.getType();
3375 if (getDerived().AlwaysRebuild() ||
3376 PointeeType != T->getPointeeTypeAsWritten()) {
3377 Result = getDerived().RebuildReferenceType(PointeeType,
3378 T->isSpelledAsLValue(),
3379 TL.getSigilLoc());
3380 if (Result.isNull())
3381 return QualType();
3382 }
3383
3384 // r-value references can be rebuilt as l-value references.
3385 ReferenceTypeLoc NewTL;
3386 if (isa<LValueReferenceType>(Result))
3387 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3388 else
3389 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3390 NewTL.setSigilLoc(TL.getSigilLoc());
3391
3392 return Result;
3393}
3394
Mike Stump11289f42009-09-09 15:08:12 +00003395template<typename Derived>
3396QualType
John McCall550e0c22009-10-21 00:40:46 +00003397TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003398 LValueReferenceTypeLoc TL) {
3399 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003400}
3401
Mike Stump11289f42009-09-09 15:08:12 +00003402template<typename Derived>
3403QualType
John McCall550e0c22009-10-21 00:40:46 +00003404TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003405 RValueReferenceTypeLoc TL) {
3406 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003407}
Mike Stump11289f42009-09-09 15:08:12 +00003408
Douglas Gregord6ff3322009-08-04 16:50:30 +00003409template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003410QualType
John McCall550e0c22009-10-21 00:40:46 +00003411TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003412 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003413 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003414 if (PointeeType.isNull())
3415 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003416
Abramo Bagnara509357842011-03-05 14:42:21 +00003417 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3418 TypeSourceInfo* NewClsTInfo = 0;
3419 if (OldClsTInfo) {
3420 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3421 if (!NewClsTInfo)
3422 return QualType();
3423 }
3424
3425 const MemberPointerType *T = TL.getTypePtr();
3426 QualType OldClsType = QualType(T->getClass(), 0);
3427 QualType NewClsType;
3428 if (NewClsTInfo)
3429 NewClsType = NewClsTInfo->getType();
3430 else {
3431 NewClsType = getDerived().TransformType(OldClsType);
3432 if (NewClsType.isNull())
3433 return QualType();
3434 }
Mike Stump11289f42009-09-09 15:08:12 +00003435
John McCall550e0c22009-10-21 00:40:46 +00003436 QualType Result = TL.getType();
3437 if (getDerived().AlwaysRebuild() ||
3438 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003439 NewClsType != OldClsType) {
3440 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003441 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003442 if (Result.isNull())
3443 return QualType();
3444 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003445
John McCall550e0c22009-10-21 00:40:46 +00003446 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3447 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003448 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003449
3450 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003451}
3452
Mike Stump11289f42009-09-09 15:08:12 +00003453template<typename Derived>
3454QualType
John McCall550e0c22009-10-21 00:40:46 +00003455TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003456 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003457 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003458 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003459 if (ElementType.isNull())
3460 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003461
John McCall550e0c22009-10-21 00:40:46 +00003462 QualType Result = TL.getType();
3463 if (getDerived().AlwaysRebuild() ||
3464 ElementType != T->getElementType()) {
3465 Result = getDerived().RebuildConstantArrayType(ElementType,
3466 T->getSizeModifier(),
3467 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003468 T->getIndexTypeCVRQualifiers(),
3469 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003470 if (Result.isNull())
3471 return QualType();
3472 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003473
John McCall550e0c22009-10-21 00:40:46 +00003474 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3475 NewTL.setLBracketLoc(TL.getLBracketLoc());
3476 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003477
John McCall550e0c22009-10-21 00:40:46 +00003478 Expr *Size = TL.getSizeExpr();
3479 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003480 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003481 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3482 }
3483 NewTL.setSizeExpr(Size);
3484
3485 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003486}
Mike Stump11289f42009-09-09 15:08:12 +00003487
Douglas Gregord6ff3322009-08-04 16:50:30 +00003488template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003489QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003490 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003491 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003492 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003493 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003494 if (ElementType.isNull())
3495 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003496
John McCall550e0c22009-10-21 00:40:46 +00003497 QualType Result = TL.getType();
3498 if (getDerived().AlwaysRebuild() ||
3499 ElementType != T->getElementType()) {
3500 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003501 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003502 T->getIndexTypeCVRQualifiers(),
3503 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003504 if (Result.isNull())
3505 return QualType();
3506 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003507
John McCall550e0c22009-10-21 00:40:46 +00003508 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3509 NewTL.setLBracketLoc(TL.getLBracketLoc());
3510 NewTL.setRBracketLoc(TL.getRBracketLoc());
3511 NewTL.setSizeExpr(0);
3512
3513 return Result;
3514}
3515
3516template<typename Derived>
3517QualType
3518TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003519 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003520 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003521 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3522 if (ElementType.isNull())
3523 return QualType();
3524
3525 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003526 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003527
John McCalldadc5752010-08-24 06:29:42 +00003528 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003529 = getDerived().TransformExpr(T->getSizeExpr());
3530 if (SizeResult.isInvalid())
3531 return QualType();
3532
John McCallb268a282010-08-23 23:25:46 +00003533 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003534
3535 QualType Result = TL.getType();
3536 if (getDerived().AlwaysRebuild() ||
3537 ElementType != T->getElementType() ||
3538 Size != T->getSizeExpr()) {
3539 Result = getDerived().RebuildVariableArrayType(ElementType,
3540 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003541 Size,
John McCall550e0c22009-10-21 00:40:46 +00003542 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003543 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003544 if (Result.isNull())
3545 return QualType();
3546 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003547
John McCall550e0c22009-10-21 00:40:46 +00003548 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3549 NewTL.setLBracketLoc(TL.getLBracketLoc());
3550 NewTL.setRBracketLoc(TL.getRBracketLoc());
3551 NewTL.setSizeExpr(Size);
3552
3553 return Result;
3554}
3555
3556template<typename Derived>
3557QualType
3558TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003559 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003560 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003561 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3562 if (ElementType.isNull())
3563 return QualType();
3564
3565 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003566 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003567
John McCall33ddac02011-01-19 10:06:00 +00003568 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3569 Expr *origSize = TL.getSizeExpr();
3570 if (!origSize) origSize = T->getSizeExpr();
3571
3572 ExprResult sizeResult
3573 = getDerived().TransformExpr(origSize);
3574 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003575 return QualType();
3576
John McCall33ddac02011-01-19 10:06:00 +00003577 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003578
3579 QualType Result = TL.getType();
3580 if (getDerived().AlwaysRebuild() ||
3581 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003582 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003583 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3584 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003585 size,
John McCall550e0c22009-10-21 00:40:46 +00003586 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003587 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003588 if (Result.isNull())
3589 return QualType();
3590 }
John McCall550e0c22009-10-21 00:40:46 +00003591
3592 // We might have any sort of array type now, but fortunately they
3593 // all have the same location layout.
3594 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3595 NewTL.setLBracketLoc(TL.getLBracketLoc());
3596 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003597 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003598
3599 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003600}
Mike Stump11289f42009-09-09 15:08:12 +00003601
3602template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003603QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003604 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003605 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003606 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003607
3608 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003609 QualType ElementType = getDerived().TransformType(T->getElementType());
3610 if (ElementType.isNull())
3611 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003612
Douglas Gregore922c772009-08-04 22:27:00 +00003613 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003614 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003615
John McCalldadc5752010-08-24 06:29:42 +00003616 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003617 if (Size.isInvalid())
3618 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003619
John McCall550e0c22009-10-21 00:40:46 +00003620 QualType Result = TL.getType();
3621 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003622 ElementType != T->getElementType() ||
3623 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003624 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003625 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003626 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003627 if (Result.isNull())
3628 return QualType();
3629 }
John McCall550e0c22009-10-21 00:40:46 +00003630
3631 // Result might be dependent or not.
3632 if (isa<DependentSizedExtVectorType>(Result)) {
3633 DependentSizedExtVectorTypeLoc NewTL
3634 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3635 NewTL.setNameLoc(TL.getNameLoc());
3636 } else {
3637 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3638 NewTL.setNameLoc(TL.getNameLoc());
3639 }
3640
3641 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003642}
Mike Stump11289f42009-09-09 15:08:12 +00003643
3644template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003645QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003646 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003647 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003648 QualType ElementType = getDerived().TransformType(T->getElementType());
3649 if (ElementType.isNull())
3650 return QualType();
3651
John McCall550e0c22009-10-21 00:40:46 +00003652 QualType Result = TL.getType();
3653 if (getDerived().AlwaysRebuild() ||
3654 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003655 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003656 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003657 if (Result.isNull())
3658 return QualType();
3659 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003660
John McCall550e0c22009-10-21 00:40:46 +00003661 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3662 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003663
John McCall550e0c22009-10-21 00:40:46 +00003664 return Result;
3665}
3666
3667template<typename Derived>
3668QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003669 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003670 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003671 QualType ElementType = getDerived().TransformType(T->getElementType());
3672 if (ElementType.isNull())
3673 return QualType();
3674
3675 QualType Result = TL.getType();
3676 if (getDerived().AlwaysRebuild() ||
3677 ElementType != T->getElementType()) {
3678 Result = getDerived().RebuildExtVectorType(ElementType,
3679 T->getNumElements(),
3680 /*FIXME*/ SourceLocation());
3681 if (Result.isNull())
3682 return QualType();
3683 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003684
John McCall550e0c22009-10-21 00:40:46 +00003685 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3686 NewTL.setNameLoc(TL.getNameLoc());
3687
3688 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003689}
Mike Stump11289f42009-09-09 15:08:12 +00003690
3691template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003692ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003693TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003694 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003695 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003696 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003697 TypeSourceInfo *NewDI = 0;
3698
3699 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3700 // If we're substituting into a pack expansion type and we know the
3701 TypeLoc OldTL = OldDI->getTypeLoc();
3702 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3703
3704 TypeLocBuilder TLB;
3705 TypeLoc NewTL = OldDI->getTypeLoc();
3706 TLB.reserve(NewTL.getFullDataSize());
3707
3708 QualType Result = getDerived().TransformType(TLB,
3709 OldExpansionTL.getPatternLoc());
3710 if (Result.isNull())
3711 return 0;
3712
3713 Result = RebuildPackExpansionType(Result,
3714 OldExpansionTL.getPatternLoc().getSourceRange(),
3715 OldExpansionTL.getEllipsisLoc(),
3716 NumExpansions);
3717 if (Result.isNull())
3718 return 0;
3719
3720 PackExpansionTypeLoc NewExpansionTL
3721 = TLB.push<PackExpansionTypeLoc>(Result);
3722 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3723 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3724 } else
3725 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003726 if (!NewDI)
3727 return 0;
3728
John McCall8fb0d9d2011-05-01 22:35:37 +00003729 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003730 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003731
3732 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3733 OldParm->getDeclContext(),
3734 OldParm->getInnerLocStart(),
3735 OldParm->getLocation(),
3736 OldParm->getIdentifier(),
3737 NewDI->getType(),
3738 NewDI,
3739 OldParm->getStorageClass(),
3740 OldParm->getStorageClassAsWritten(),
3741 /* DefArg */ NULL);
3742 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3743 OldParm->getFunctionScopeIndex() + indexAdjustment);
3744 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003745}
3746
3747template<typename Derived>
3748bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003749 TransformFunctionTypeParams(SourceLocation Loc,
3750 ParmVarDecl **Params, unsigned NumParams,
3751 const QualType *ParamTypes,
3752 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3753 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003754 int indexAdjustment = 0;
3755
Douglas Gregordd472162011-01-07 00:20:55 +00003756 for (unsigned i = 0; i != NumParams; ++i) {
3757 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003758 assert(OldParm->getFunctionScopeIndex() == i);
3759
Douglas Gregor715e4612011-01-14 22:40:04 +00003760 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003761 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003762 if (OldParm->isParameterPack()) {
3763 // We have a function parameter pack that may need to be expanded.
3764 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003765
Douglas Gregor5499af42011-01-05 23:12:31 +00003766 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003767 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3768 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3769 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3770 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003771 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3772
Douglas Gregor5499af42011-01-05 23:12:31 +00003773 // Determine whether we should expand the parameter packs.
3774 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003775 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003776 llvm::Optional<unsigned> OrigNumExpansions
3777 = ExpansionTL.getTypePtr()->getNumExpansions();
3778 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003779 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3780 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003781 Unexpanded.data(),
3782 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003783 ShouldExpand,
3784 RetainExpansion,
3785 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003786 return true;
3787 }
3788
3789 if (ShouldExpand) {
3790 // Expand the function parameter pack into multiple, separate
3791 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003792 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003793 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003794 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3795 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003796 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003797 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003798 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003799 if (!NewParm)
3800 return true;
3801
Douglas Gregordd472162011-01-07 00:20:55 +00003802 OutParamTypes.push_back(NewParm->getType());
3803 if (PVars)
3804 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003805 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003806
3807 // If we're supposed to retain a pack expansion, do so by temporarily
3808 // forgetting the partially-substituted parameter pack.
3809 if (RetainExpansion) {
3810 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3811 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003812 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003813 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003814 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003815 if (!NewParm)
3816 return true;
3817
3818 OutParamTypes.push_back(NewParm->getType());
3819 if (PVars)
3820 PVars->push_back(NewParm);
3821 }
3822
John McCall8fb0d9d2011-05-01 22:35:37 +00003823 // The next parameter should have the same adjustment as the
3824 // last thing we pushed, but we post-incremented indexAdjustment
3825 // on every push. Also, if we push nothing, the adjustment should
3826 // go down by one.
3827 indexAdjustment--;
3828
Douglas Gregor5499af42011-01-05 23:12:31 +00003829 // We're done with the pack expansion.
3830 continue;
3831 }
3832
3833 // We'll substitute the parameter now without expanding the pack
3834 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003835 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3836 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003837 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003838 NumExpansions);
3839 } else {
3840 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003841 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003842 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003843 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003844
John McCall58f10c32010-03-11 09:03:00 +00003845 if (!NewParm)
3846 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003847
Douglas Gregordd472162011-01-07 00:20:55 +00003848 OutParamTypes.push_back(NewParm->getType());
3849 if (PVars)
3850 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003851 continue;
3852 }
John McCall58f10c32010-03-11 09:03:00 +00003853
3854 // Deal with the possibility that we don't have a parameter
3855 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003856 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003857 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003858 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003859 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003860 if (const PackExpansionType *Expansion
3861 = dyn_cast<PackExpansionType>(OldType)) {
3862 // We have a function parameter pack that may need to be expanded.
3863 QualType Pattern = Expansion->getPattern();
3864 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3865 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3866
3867 // Determine whether we should expand the parameter packs.
3868 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003869 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003870 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003871 Unexpanded.data(),
3872 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003873 ShouldExpand,
3874 RetainExpansion,
3875 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003876 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003877 }
3878
3879 if (ShouldExpand) {
3880 // Expand the function parameter pack into multiple, separate
3881 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003882 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003883 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3884 QualType NewType = getDerived().TransformType(Pattern);
3885 if (NewType.isNull())
3886 return true;
John McCall58f10c32010-03-11 09:03:00 +00003887
Douglas Gregordd472162011-01-07 00:20:55 +00003888 OutParamTypes.push_back(NewType);
3889 if (PVars)
3890 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003891 }
3892
3893 // We're done with the pack expansion.
3894 continue;
3895 }
3896
Douglas Gregor48d24112011-01-10 20:53:55 +00003897 // If we're supposed to retain a pack expansion, do so by temporarily
3898 // forgetting the partially-substituted parameter pack.
3899 if (RetainExpansion) {
3900 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3901 QualType NewType = getDerived().TransformType(Pattern);
3902 if (NewType.isNull())
3903 return true;
3904
3905 OutParamTypes.push_back(NewType);
3906 if (PVars)
3907 PVars->push_back(0);
3908 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003909
Douglas Gregor5499af42011-01-05 23:12:31 +00003910 // We'll substitute the parameter now without expanding the pack
3911 // expansion.
3912 OldType = Expansion->getPattern();
3913 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003914 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3915 NewType = getDerived().TransformType(OldType);
3916 } else {
3917 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003918 }
3919
Douglas Gregor5499af42011-01-05 23:12:31 +00003920 if (NewType.isNull())
3921 return true;
3922
3923 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003924 NewType = getSema().Context.getPackExpansionType(NewType,
3925 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003926
Douglas Gregordd472162011-01-07 00:20:55 +00003927 OutParamTypes.push_back(NewType);
3928 if (PVars)
3929 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003930 }
3931
John McCall8fb0d9d2011-05-01 22:35:37 +00003932#ifndef NDEBUG
3933 if (PVars) {
3934 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3935 if (ParmVarDecl *parm = (*PVars)[i])
3936 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00003937 }
John McCall8fb0d9d2011-05-01 22:35:37 +00003938#endif
3939
3940 return false;
3941}
John McCall58f10c32010-03-11 09:03:00 +00003942
3943template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003944QualType
John McCall550e0c22009-10-21 00:40:46 +00003945TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003946 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003947 // Transform the parameters and return type.
3948 //
3949 // We instantiate in source order, with the return type first followed by
3950 // the parameters, because users tend to expect this (even if they shouldn't
3951 // rely on it!).
3952 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003953 // When the function has a trailing return type, we instantiate the
3954 // parameters before the return type, since the return type can then refer
3955 // to the parameters themselves (via decltype, sizeof, etc.).
3956 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003957 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003958 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003959 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003960
Douglas Gregor7fb25412010-10-01 18:44:50 +00003961 QualType ResultType;
3962
3963 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003964 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3965 TL.getParmArray(),
3966 TL.getNumArgs(),
3967 TL.getTypePtr()->arg_type_begin(),
3968 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003969 return QualType();
3970
3971 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3972 if (ResultType.isNull())
3973 return QualType();
3974 }
3975 else {
3976 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3977 if (ResultType.isNull())
3978 return QualType();
3979
Douglas Gregordd472162011-01-07 00:20:55 +00003980 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3981 TL.getParmArray(),
3982 TL.getNumArgs(),
3983 TL.getTypePtr()->arg_type_begin(),
3984 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003985 return QualType();
3986 }
3987
John McCall550e0c22009-10-21 00:40:46 +00003988 QualType Result = TL.getType();
3989 if (getDerived().AlwaysRebuild() ||
3990 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003991 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003992 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3993 Result = getDerived().RebuildFunctionProtoType(ResultType,
3994 ParamTypes.data(),
3995 ParamTypes.size(),
3996 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003997 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003998 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003999 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004000 if (Result.isNull())
4001 return QualType();
4002 }
Mike Stump11289f42009-09-09 15:08:12 +00004003
John McCall550e0c22009-10-21 00:40:46 +00004004 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004005 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4006 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004007 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004008 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4009 NewTL.setArg(i, ParamDecls[i]);
4010
4011 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004012}
Mike Stump11289f42009-09-09 15:08:12 +00004013
Douglas Gregord6ff3322009-08-04 16:50:30 +00004014template<typename Derived>
4015QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004016 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004017 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004018 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004019 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4020 if (ResultType.isNull())
4021 return QualType();
4022
4023 QualType Result = TL.getType();
4024 if (getDerived().AlwaysRebuild() ||
4025 ResultType != T->getResultType())
4026 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4027
4028 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004029 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4030 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004031 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004032
4033 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004034}
Mike Stump11289f42009-09-09 15:08:12 +00004035
John McCallb96ec562009-12-04 22:46:56 +00004036template<typename Derived> QualType
4037TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004038 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004039 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004040 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004041 if (!D)
4042 return QualType();
4043
4044 QualType Result = TL.getType();
4045 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4046 Result = getDerived().RebuildUnresolvedUsingType(D);
4047 if (Result.isNull())
4048 return QualType();
4049 }
4050
4051 // We might get an arbitrary type spec type back. We should at
4052 // least always get a type spec type, though.
4053 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4054 NewTL.setNameLoc(TL.getNameLoc());
4055
4056 return Result;
4057}
4058
Douglas Gregord6ff3322009-08-04 16:50:30 +00004059template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004060QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004061 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004062 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004063 TypedefNameDecl *Typedef
4064 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4065 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004066 if (!Typedef)
4067 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004068
John McCall550e0c22009-10-21 00:40:46 +00004069 QualType Result = TL.getType();
4070 if (getDerived().AlwaysRebuild() ||
4071 Typedef != T->getDecl()) {
4072 Result = getDerived().RebuildTypedefType(Typedef);
4073 if (Result.isNull())
4074 return QualType();
4075 }
Mike Stump11289f42009-09-09 15:08:12 +00004076
John McCall550e0c22009-10-21 00:40:46 +00004077 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4078 NewTL.setNameLoc(TL.getNameLoc());
4079
4080 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004081}
Mike Stump11289f42009-09-09 15:08:12 +00004082
Douglas Gregord6ff3322009-08-04 16:50:30 +00004083template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004084QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004085 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004086 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004087 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004088
John McCalldadc5752010-08-24 06:29:42 +00004089 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004090 if (E.isInvalid())
4091 return QualType();
4092
John McCall550e0c22009-10-21 00:40:46 +00004093 QualType Result = TL.getType();
4094 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004095 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004096 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004097 if (Result.isNull())
4098 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004099 }
John McCall550e0c22009-10-21 00:40:46 +00004100 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004101
John McCall550e0c22009-10-21 00:40:46 +00004102 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004103 NewTL.setTypeofLoc(TL.getTypeofLoc());
4104 NewTL.setLParenLoc(TL.getLParenLoc());
4105 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004106
4107 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004108}
Mike Stump11289f42009-09-09 15:08:12 +00004109
4110template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004111QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004112 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004113 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4114 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4115 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004116 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004117
John McCall550e0c22009-10-21 00:40:46 +00004118 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004119 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4120 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004121 if (Result.isNull())
4122 return QualType();
4123 }
Mike Stump11289f42009-09-09 15:08:12 +00004124
John McCall550e0c22009-10-21 00:40:46 +00004125 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004126 NewTL.setTypeofLoc(TL.getTypeofLoc());
4127 NewTL.setLParenLoc(TL.getLParenLoc());
4128 NewTL.setRParenLoc(TL.getRParenLoc());
4129 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004130
4131 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004132}
Mike Stump11289f42009-09-09 15:08:12 +00004133
4134template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004135QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004136 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004137 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004138
Douglas Gregore922c772009-08-04 22:27:00 +00004139 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004140 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004141
John McCalldadc5752010-08-24 06:29:42 +00004142 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004143 if (E.isInvalid())
4144 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004145
John McCall550e0c22009-10-21 00:40:46 +00004146 QualType Result = TL.getType();
4147 if (getDerived().AlwaysRebuild() ||
4148 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004149 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004150 if (Result.isNull())
4151 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004152 }
John McCall550e0c22009-10-21 00:40:46 +00004153 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004154
John McCall550e0c22009-10-21 00:40:46 +00004155 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4156 NewTL.setNameLoc(TL.getNameLoc());
4157
4158 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004159}
4160
4161template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004162QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4163 AutoTypeLoc TL) {
4164 const AutoType *T = TL.getTypePtr();
4165 QualType OldDeduced = T->getDeducedType();
4166 QualType NewDeduced;
4167 if (!OldDeduced.isNull()) {
4168 NewDeduced = getDerived().TransformType(OldDeduced);
4169 if (NewDeduced.isNull())
4170 return QualType();
4171 }
4172
4173 QualType Result = TL.getType();
4174 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4175 Result = getDerived().RebuildAutoType(NewDeduced);
4176 if (Result.isNull())
4177 return QualType();
4178 }
4179
4180 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4181 NewTL.setNameLoc(TL.getNameLoc());
4182
4183 return Result;
4184}
4185
4186template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004187QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004188 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004189 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004190 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004191 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4192 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004193 if (!Record)
4194 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004195
John McCall550e0c22009-10-21 00:40:46 +00004196 QualType Result = TL.getType();
4197 if (getDerived().AlwaysRebuild() ||
4198 Record != T->getDecl()) {
4199 Result = getDerived().RebuildRecordType(Record);
4200 if (Result.isNull())
4201 return QualType();
4202 }
Mike Stump11289f42009-09-09 15:08:12 +00004203
John McCall550e0c22009-10-21 00:40:46 +00004204 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4205 NewTL.setNameLoc(TL.getNameLoc());
4206
4207 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004208}
Mike Stump11289f42009-09-09 15:08:12 +00004209
4210template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004211QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004212 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004213 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004214 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004215 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4216 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004217 if (!Enum)
4218 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004219
John McCall550e0c22009-10-21 00:40:46 +00004220 QualType Result = TL.getType();
4221 if (getDerived().AlwaysRebuild() ||
4222 Enum != T->getDecl()) {
4223 Result = getDerived().RebuildEnumType(Enum);
4224 if (Result.isNull())
4225 return QualType();
4226 }
Mike Stump11289f42009-09-09 15:08:12 +00004227
John McCall550e0c22009-10-21 00:40:46 +00004228 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4229 NewTL.setNameLoc(TL.getNameLoc());
4230
4231 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004232}
John McCallfcc33b02009-09-05 00:15:47 +00004233
John McCalle78aac42010-03-10 03:28:59 +00004234template<typename Derived>
4235QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4236 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004237 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004238 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4239 TL.getTypePtr()->getDecl());
4240 if (!D) return QualType();
4241
4242 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4243 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4244 return T;
4245}
4246
Douglas Gregord6ff3322009-08-04 16:50:30 +00004247template<typename Derived>
4248QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004249 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004250 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004251 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004252}
4253
Mike Stump11289f42009-09-09 15:08:12 +00004254template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004255QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004256 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004257 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004258 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4259
4260 // Substitute into the replacement type, which itself might involve something
4261 // that needs to be transformed. This only tends to occur with default
4262 // template arguments of template template parameters.
4263 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4264 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4265 if (Replacement.isNull())
4266 return QualType();
4267
4268 // Always canonicalize the replacement type.
4269 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4270 QualType Result
4271 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4272 Replacement);
4273
4274 // Propagate type-source information.
4275 SubstTemplateTypeParmTypeLoc NewTL
4276 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4277 NewTL.setNameLoc(TL.getNameLoc());
4278 return Result;
4279
John McCallcebee162009-10-18 09:09:24 +00004280}
4281
4282template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004283QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4284 TypeLocBuilder &TLB,
4285 SubstTemplateTypeParmPackTypeLoc TL) {
4286 return TransformTypeSpecType(TLB, TL);
4287}
4288
4289template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004290QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004291 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004292 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004293 const TemplateSpecializationType *T = TL.getTypePtr();
4294
Douglas Gregordf846d12011-03-02 18:46:51 +00004295 // The nested-name-specifier never matters in a TemplateSpecializationType,
4296 // because we can't have a dependent nested-name-specifier anyway.
4297 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004298 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004299 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4300 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004301 if (Template.isNull())
4302 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004303
John McCall31f82722010-11-12 08:19:04 +00004304 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4305}
4306
Douglas Gregorfe921a72010-12-20 23:36:19 +00004307namespace {
4308 /// \brief Simple iterator that traverses the template arguments in a
4309 /// container that provides a \c getArgLoc() member function.
4310 ///
4311 /// This iterator is intended to be used with the iterator form of
4312 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4313 template<typename ArgLocContainer>
4314 class TemplateArgumentLocContainerIterator {
4315 ArgLocContainer *Container;
4316 unsigned Index;
4317
4318 public:
4319 typedef TemplateArgumentLoc value_type;
4320 typedef TemplateArgumentLoc reference;
4321 typedef int difference_type;
4322 typedef std::input_iterator_tag iterator_category;
4323
4324 class pointer {
4325 TemplateArgumentLoc Arg;
4326
4327 public:
4328 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4329
4330 const TemplateArgumentLoc *operator->() const {
4331 return &Arg;
4332 }
4333 };
4334
4335
4336 TemplateArgumentLocContainerIterator() {}
4337
4338 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4339 unsigned Index)
4340 : Container(&Container), Index(Index) { }
4341
4342 TemplateArgumentLocContainerIterator &operator++() {
4343 ++Index;
4344 return *this;
4345 }
4346
4347 TemplateArgumentLocContainerIterator operator++(int) {
4348 TemplateArgumentLocContainerIterator Old(*this);
4349 ++(*this);
4350 return Old;
4351 }
4352
4353 TemplateArgumentLoc operator*() const {
4354 return Container->getArgLoc(Index);
4355 }
4356
4357 pointer operator->() const {
4358 return pointer(Container->getArgLoc(Index));
4359 }
4360
4361 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004362 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004363 return X.Container == Y.Container && X.Index == Y.Index;
4364 }
4365
4366 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004367 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004368 return !(X == Y);
4369 }
4370 };
4371}
4372
4373
John McCall31f82722010-11-12 08:19:04 +00004374template <typename Derived>
4375QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4376 TypeLocBuilder &TLB,
4377 TemplateSpecializationTypeLoc TL,
4378 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004379 TemplateArgumentListInfo NewTemplateArgs;
4380 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4381 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004382 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4383 ArgIterator;
4384 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4385 ArgIterator(TL, TL.getNumArgs()),
4386 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004387 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004388
John McCall0ad16662009-10-29 08:12:44 +00004389 // FIXME: maybe don't rebuild if all the template arguments are the same.
4390
4391 QualType Result =
4392 getDerived().RebuildTemplateSpecializationType(Template,
4393 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004394 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004395
4396 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004397 // Specializations of template template parameters are represented as
4398 // TemplateSpecializationTypes, and substitution of type alias templates
4399 // within a dependent context can transform them into
4400 // DependentTemplateSpecializationTypes.
4401 if (isa<DependentTemplateSpecializationType>(Result)) {
4402 DependentTemplateSpecializationTypeLoc NewTL
4403 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4404 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4405 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4406 NewTL.setNameLoc(TL.getTemplateNameLoc());
4407 NewTL.setLAngleLoc(TL.getLAngleLoc());
4408 NewTL.setRAngleLoc(TL.getRAngleLoc());
4409 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4410 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4411 return Result;
4412 }
4413
John McCall0ad16662009-10-29 08:12:44 +00004414 TemplateSpecializationTypeLoc NewTL
4415 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4416 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4417 NewTL.setLAngleLoc(TL.getLAngleLoc());
4418 NewTL.setRAngleLoc(TL.getRAngleLoc());
4419 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4420 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004421 }
Mike Stump11289f42009-09-09 15:08:12 +00004422
John McCall0ad16662009-10-29 08:12:44 +00004423 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004424}
Mike Stump11289f42009-09-09 15:08:12 +00004425
Douglas Gregor5a064722011-02-28 17:23:35 +00004426template <typename Derived>
4427QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4428 TypeLocBuilder &TLB,
4429 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004430 TemplateName Template,
4431 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004432 TemplateArgumentListInfo NewTemplateArgs;
4433 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4434 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4435 typedef TemplateArgumentLocContainerIterator<
4436 DependentTemplateSpecializationTypeLoc> ArgIterator;
4437 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4438 ArgIterator(TL, TL.getNumArgs()),
4439 NewTemplateArgs))
4440 return QualType();
4441
4442 // FIXME: maybe don't rebuild if all the template arguments are the same.
4443
4444 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4445 QualType Result
4446 = getSema().Context.getDependentTemplateSpecializationType(
4447 TL.getTypePtr()->getKeyword(),
4448 DTN->getQualifier(),
4449 DTN->getIdentifier(),
4450 NewTemplateArgs);
4451
4452 DependentTemplateSpecializationTypeLoc NewTL
4453 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4454 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004455
Douglas Gregora7a795b2011-03-01 20:11:18 +00004456 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004457 NewTL.setNameLoc(TL.getNameLoc());
4458 NewTL.setLAngleLoc(TL.getLAngleLoc());
4459 NewTL.setRAngleLoc(TL.getRAngleLoc());
4460 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4461 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4462 return Result;
4463 }
4464
4465 QualType Result
4466 = getDerived().RebuildTemplateSpecializationType(Template,
4467 TL.getNameLoc(),
4468 NewTemplateArgs);
4469
4470 if (!Result.isNull()) {
4471 /// FIXME: Wrap this in an elaborated-type-specifier?
4472 TemplateSpecializationTypeLoc NewTL
4473 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4474 NewTL.setTemplateNameLoc(TL.getNameLoc());
4475 NewTL.setLAngleLoc(TL.getLAngleLoc());
4476 NewTL.setRAngleLoc(TL.getRAngleLoc());
4477 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4478 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4479 }
4480
4481 return Result;
4482}
4483
Mike Stump11289f42009-09-09 15:08:12 +00004484template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004485QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004486TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004487 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004488 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004489
Douglas Gregor844cb502011-03-01 18:12:44 +00004490 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004491 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004492 if (TL.getQualifierLoc()) {
4493 QualifierLoc
4494 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4495 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004496 return QualType();
4497 }
Mike Stump11289f42009-09-09 15:08:12 +00004498
John McCall31f82722010-11-12 08:19:04 +00004499 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4500 if (NamedT.isNull())
4501 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004502
Richard Smith3f1b5d02011-05-05 21:57:07 +00004503 // C++0x [dcl.type.elab]p2:
4504 // If the identifier resolves to a typedef-name or the simple-template-id
4505 // resolves to an alias template specialization, the
4506 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004507 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4508 if (const TemplateSpecializationType *TST =
4509 NamedT->getAs<TemplateSpecializationType>()) {
4510 TemplateName Template = TST->getTemplateName();
4511 if (TypeAliasTemplateDecl *TAT =
4512 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4513 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4514 diag::err_tag_reference_non_tag) << 4;
4515 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4516 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004517 }
4518 }
4519
John McCall550e0c22009-10-21 00:40:46 +00004520 QualType Result = TL.getType();
4521 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004522 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004523 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004524 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004525 T->getKeyword(),
4526 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004527 if (Result.isNull())
4528 return QualType();
4529 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004530
Abramo Bagnara6150c882010-05-11 21:36:43 +00004531 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004532 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004533 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004534 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004535}
Mike Stump11289f42009-09-09 15:08:12 +00004536
4537template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004538QualType TreeTransform<Derived>::TransformAttributedType(
4539 TypeLocBuilder &TLB,
4540 AttributedTypeLoc TL) {
4541 const AttributedType *oldType = TL.getTypePtr();
4542 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4543 if (modifiedType.isNull())
4544 return QualType();
4545
4546 QualType result = TL.getType();
4547
4548 // FIXME: dependent operand expressions?
4549 if (getDerived().AlwaysRebuild() ||
4550 modifiedType != oldType->getModifiedType()) {
4551 // TODO: this is really lame; we should really be rebuilding the
4552 // equivalent type from first principles.
4553 QualType equivalentType
4554 = getDerived().TransformType(oldType->getEquivalentType());
4555 if (equivalentType.isNull())
4556 return QualType();
4557 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4558 modifiedType,
4559 equivalentType);
4560 }
4561
4562 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4563 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4564 if (TL.hasAttrOperand())
4565 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4566 if (TL.hasAttrExprOperand())
4567 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4568 else if (TL.hasAttrEnumOperand())
4569 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4570
4571 return result;
4572}
4573
4574template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004575QualType
4576TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4577 ParenTypeLoc TL) {
4578 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4579 if (Inner.isNull())
4580 return QualType();
4581
4582 QualType Result = TL.getType();
4583 if (getDerived().AlwaysRebuild() ||
4584 Inner != TL.getInnerLoc().getType()) {
4585 Result = getDerived().RebuildParenType(Inner);
4586 if (Result.isNull())
4587 return QualType();
4588 }
4589
4590 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4591 NewTL.setLParenLoc(TL.getLParenLoc());
4592 NewTL.setRParenLoc(TL.getRParenLoc());
4593 return Result;
4594}
4595
4596template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004597QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004598 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004599 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004600
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004601 NestedNameSpecifierLoc QualifierLoc
4602 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4603 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004604 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004605
John McCallc392f372010-06-11 00:33:02 +00004606 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004607 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004608 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004609 QualifierLoc,
4610 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004611 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004612 if (Result.isNull())
4613 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004614
Abramo Bagnarad7548482010-05-19 21:37:53 +00004615 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4616 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004617 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4618
Abramo Bagnarad7548482010-05-19 21:37:53 +00004619 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4620 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004621 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004622 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004623 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4624 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004625 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004626 NewTL.setNameLoc(TL.getNameLoc());
4627 }
John McCall550e0c22009-10-21 00:40:46 +00004628 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004629}
Mike Stump11289f42009-09-09 15:08:12 +00004630
Douglas Gregord6ff3322009-08-04 16:50:30 +00004631template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004632QualType TreeTransform<Derived>::
4633 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004634 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004635 NestedNameSpecifierLoc QualifierLoc;
4636 if (TL.getQualifierLoc()) {
4637 QualifierLoc
4638 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4639 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004640 return QualType();
4641 }
4642
John McCall31f82722010-11-12 08:19:04 +00004643 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004644 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004645}
4646
4647template<typename Derived>
4648QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004649TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4650 DependentTemplateSpecializationTypeLoc TL,
4651 NestedNameSpecifierLoc QualifierLoc) {
4652 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4653
4654 TemplateArgumentListInfo NewTemplateArgs;
4655 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4656 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4657
4658 typedef TemplateArgumentLocContainerIterator<
4659 DependentTemplateSpecializationTypeLoc> ArgIterator;
4660 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4661 ArgIterator(TL, TL.getNumArgs()),
4662 NewTemplateArgs))
4663 return QualType();
4664
4665 QualType Result
4666 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4667 QualifierLoc,
4668 T->getIdentifier(),
4669 TL.getNameLoc(),
4670 NewTemplateArgs);
4671 if (Result.isNull())
4672 return QualType();
4673
4674 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4675 QualType NamedT = ElabT->getNamedType();
4676
4677 // Copy information relevant to the template specialization.
4678 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004679 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004680 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004681 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4682 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004683 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004684 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004685
4686 // Copy information relevant to the elaborated type.
4687 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4688 NewTL.setKeywordLoc(TL.getKeywordLoc());
4689 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004690 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4691 DependentTemplateSpecializationTypeLoc SpecTL
4692 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004693 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004694 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004695 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004696 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4697 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004698 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004699 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004700 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004701 TemplateSpecializationTypeLoc SpecTL
4702 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004703 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004704 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4705 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004706 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004707 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004708 }
4709 return Result;
4710}
4711
4712template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004713QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4714 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004715 QualType Pattern
4716 = getDerived().TransformType(TLB, TL.getPatternLoc());
4717 if (Pattern.isNull())
4718 return QualType();
4719
4720 QualType Result = TL.getType();
4721 if (getDerived().AlwaysRebuild() ||
4722 Pattern != TL.getPatternLoc().getType()) {
4723 Result = getDerived().RebuildPackExpansionType(Pattern,
4724 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004725 TL.getEllipsisLoc(),
4726 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004727 if (Result.isNull())
4728 return QualType();
4729 }
4730
4731 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4732 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4733 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004734}
4735
4736template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004737QualType
4738TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004739 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004740 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004741 TLB.pushFullCopy(TL);
4742 return TL.getType();
4743}
4744
4745template<typename Derived>
4746QualType
4747TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004748 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004749 // ObjCObjectType is never dependent.
4750 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004751 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004752}
Mike Stump11289f42009-09-09 15:08:12 +00004753
4754template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004755QualType
4756TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004757 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004758 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004759 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004760 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004761}
4762
Douglas Gregord6ff3322009-08-04 16:50:30 +00004763//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004764// Statement transformation
4765//===----------------------------------------------------------------------===//
4766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004767StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004768TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004769 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004770}
4771
4772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004773StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004774TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4775 return getDerived().TransformCompoundStmt(S, false);
4776}
4777
4778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004779StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004780TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004781 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004782 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004783 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004784 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004785 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4786 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004787 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004788 if (Result.isInvalid()) {
4789 // Immediately fail if this was a DeclStmt, since it's very
4790 // likely that this will cause problems for future statements.
4791 if (isa<DeclStmt>(*B))
4792 return StmtError();
4793
4794 // Otherwise, just keep processing substatements and fail later.
4795 SubStmtInvalid = true;
4796 continue;
4797 }
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregorebe10102009-08-20 07:17:43 +00004799 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4800 Statements.push_back(Result.takeAs<Stmt>());
4801 }
Mike Stump11289f42009-09-09 15:08:12 +00004802
John McCall1ababa62010-08-27 19:56:05 +00004803 if (SubStmtInvalid)
4804 return StmtError();
4805
Douglas Gregorebe10102009-08-20 07:17:43 +00004806 if (!getDerived().AlwaysRebuild() &&
4807 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004808 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004809
4810 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4811 move_arg(Statements),
4812 S->getRBracLoc(),
4813 IsStmtExpr);
4814}
Mike Stump11289f42009-09-09 15:08:12 +00004815
Douglas Gregorebe10102009-08-20 07:17:43 +00004816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004817StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004818TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004819 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004820 {
4821 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004822 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004823
Eli Friedman06577382009-11-19 03:14:00 +00004824 // Transform the left-hand case value.
4825 LHS = getDerived().TransformExpr(S->getLHS());
4826 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004827 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004828
Eli Friedman06577382009-11-19 03:14:00 +00004829 // Transform the right-hand case value (for the GNU case-range extension).
4830 RHS = getDerived().TransformExpr(S->getRHS());
4831 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004832 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004833 }
Mike Stump11289f42009-09-09 15:08:12 +00004834
Douglas Gregorebe10102009-08-20 07:17:43 +00004835 // Build the case statement.
4836 // Case statements are always rebuilt so that they will attached to their
4837 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004838 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004839 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004840 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004841 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004842 S->getColonLoc());
4843 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004844 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004845
Douglas Gregorebe10102009-08-20 07:17:43 +00004846 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004847 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004848 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004849 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004850
Douglas Gregorebe10102009-08-20 07:17:43 +00004851 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004852 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004853}
4854
4855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004856StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004857TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004858 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004859 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004860 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004861 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004862
Douglas Gregorebe10102009-08-20 07:17:43 +00004863 // Default statements are always rebuilt
4864 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004865 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004866}
Mike Stump11289f42009-09-09 15:08:12 +00004867
Douglas Gregorebe10102009-08-20 07:17:43 +00004868template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004869StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004870TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004871 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004872 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004873 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004874
Chris Lattnercab02a62011-02-17 20:34:02 +00004875 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4876 S->getDecl());
4877 if (!LD)
4878 return StmtError();
4879
4880
Douglas Gregorebe10102009-08-20 07:17:43 +00004881 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004882 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004883 cast<LabelDecl>(LD), SourceLocation(),
4884 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004885}
Mike Stump11289f42009-09-09 15:08:12 +00004886
Douglas Gregorebe10102009-08-20 07:17:43 +00004887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004888StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004889TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004890 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004891 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004892 VarDecl *ConditionVar = 0;
4893 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004894 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004895 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004896 getDerived().TransformDefinition(
4897 S->getConditionVariable()->getLocation(),
4898 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004899 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004900 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004901 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004902 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004903
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004904 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004905 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004906
4907 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004908 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004909 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4910 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004911 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004912 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004913
John McCallb268a282010-08-23 23:25:46 +00004914 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004915 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004916 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004917
John McCallb268a282010-08-23 23:25:46 +00004918 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4919 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004920 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004921
Douglas Gregorebe10102009-08-20 07:17:43 +00004922 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004923 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004924 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004925 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004926
Douglas Gregorebe10102009-08-20 07:17:43 +00004927 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004928 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004929 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004930 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004931
Douglas Gregorebe10102009-08-20 07:17:43 +00004932 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004933 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004934 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004935 Then.get() == S->getThen() &&
4936 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004937 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004938
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004939 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004940 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004941 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004942}
4943
4944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004945StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004946TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004947 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004948 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004949 VarDecl *ConditionVar = 0;
4950 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004951 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004952 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004953 getDerived().TransformDefinition(
4954 S->getConditionVariable()->getLocation(),
4955 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004956 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004957 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004958 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004959 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004960
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004961 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004962 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004963 }
Mike Stump11289f42009-09-09 15:08:12 +00004964
Douglas Gregorebe10102009-08-20 07:17:43 +00004965 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004966 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004967 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004968 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004969 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004970 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004971
Douglas Gregorebe10102009-08-20 07:17:43 +00004972 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004973 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004974 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004975 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004976
Douglas Gregorebe10102009-08-20 07:17:43 +00004977 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004978 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4979 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004980}
Mike Stump11289f42009-09-09 15:08:12 +00004981
Douglas Gregorebe10102009-08-20 07:17:43 +00004982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004983StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004984TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004985 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004986 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004987 VarDecl *ConditionVar = 0;
4988 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004989 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004990 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004991 getDerived().TransformDefinition(
4992 S->getConditionVariable()->getLocation(),
4993 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004994 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004995 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004996 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004997 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004998
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004999 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005000 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005001
5002 if (S->getCond()) {
5003 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005004 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5005 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005006 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005007 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005008 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005009 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005010 }
Mike Stump11289f42009-09-09 15:08:12 +00005011
John McCallb268a282010-08-23 23:25:46 +00005012 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5013 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005014 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005015
Douglas Gregorebe10102009-08-20 07:17:43 +00005016 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005017 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005018 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005019 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005020
Douglas Gregorebe10102009-08-20 07:17:43 +00005021 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005022 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005023 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005024 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005025 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005026
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005027 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005028 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005029}
Mike Stump11289f42009-09-09 15:08:12 +00005030
Douglas Gregorebe10102009-08-20 07:17:43 +00005031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005032StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005033TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005034 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005035 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005036 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005037 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005038
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005039 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005040 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005041 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005042 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005043
Douglas Gregorebe10102009-08-20 07:17:43 +00005044 if (!getDerived().AlwaysRebuild() &&
5045 Cond.get() == S->getCond() &&
5046 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005047 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005048
John McCallb268a282010-08-23 23:25:46 +00005049 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5050 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005051 S->getRParenLoc());
5052}
Mike Stump11289f42009-09-09 15:08:12 +00005053
Douglas Gregorebe10102009-08-20 07:17:43 +00005054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005055StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005056TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005057 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005058 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005059 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005060 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregorebe10102009-08-20 07:17:43 +00005062 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005063 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005064 VarDecl *ConditionVar = 0;
5065 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005066 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005067 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005068 getDerived().TransformDefinition(
5069 S->getConditionVariable()->getLocation(),
5070 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005071 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005072 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005073 } else {
5074 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->getForLoc(),
5082 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005083 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005084 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005085
John McCallb268a282010-08-23 23:25:46 +00005086 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005087 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005088 }
Mike Stump11289f42009-09-09 15:08:12 +00005089
John McCallb268a282010-08-23 23:25:46 +00005090 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5091 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005092 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005093
Douglas Gregorebe10102009-08-20 07:17:43 +00005094 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005095 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005096 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005097 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005098
John McCallb268a282010-08-23 23:25:46 +00005099 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5100 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005101 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005102
Douglas Gregorebe10102009-08-20 07:17:43 +00005103 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005104 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005105 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005106 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005107
Douglas Gregorebe10102009-08-20 07:17:43 +00005108 if (!getDerived().AlwaysRebuild() &&
5109 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005110 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005111 Inc.get() == S->getInc() &&
5112 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005113 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005114
Douglas Gregorebe10102009-08-20 07:17:43 +00005115 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005116 Init.get(), FullCond, ConditionVar,
5117 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005118}
5119
5120template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005121StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005122TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005123 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5124 S->getLabel());
5125 if (!LD)
5126 return StmtError();
5127
Douglas Gregorebe10102009-08-20 07:17:43 +00005128 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005129 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005130 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005131}
5132
5133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005134StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005135TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005136 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005137 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005138 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005139
Douglas Gregorebe10102009-08-20 07:17:43 +00005140 if (!getDerived().AlwaysRebuild() &&
5141 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005142 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005143
5144 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005145 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005146}
5147
5148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005149StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005150TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005151 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005152}
Mike Stump11289f42009-09-09 15:08:12 +00005153
Douglas Gregorebe10102009-08-20 07:17:43 +00005154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005155StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005156TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005157 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005158}
Mike Stump11289f42009-09-09 15:08:12 +00005159
Douglas Gregorebe10102009-08-20 07:17:43 +00005160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005161StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005162TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005163 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005164 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005165 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005166
Mike Stump11289f42009-09-09 15:08:12 +00005167 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005168 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005169 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005170}
Mike Stump11289f42009-09-09 15:08:12 +00005171
Douglas Gregorebe10102009-08-20 07:17:43 +00005172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005173StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005174TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005175 bool DeclChanged = false;
5176 llvm::SmallVector<Decl *, 4> Decls;
5177 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5178 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005179 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5180 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005181 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005182 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005183
Douglas Gregorebe10102009-08-20 07:17:43 +00005184 if (Transformed != *D)
5185 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005186
Douglas Gregorebe10102009-08-20 07:17:43 +00005187 Decls.push_back(Transformed);
5188 }
Mike Stump11289f42009-09-09 15:08:12 +00005189
Douglas Gregorebe10102009-08-20 07:17:43 +00005190 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005191 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005192
5193 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005194 S->getStartLoc(), S->getEndLoc());
5195}
Mike Stump11289f42009-09-09 15:08:12 +00005196
Douglas Gregorebe10102009-08-20 07:17:43 +00005197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005198StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005199TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005200
John McCall37ad5512010-08-23 06:44:23 +00005201 ASTOwningVector<Expr*> Constraints(getSema());
5202 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005203 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005204
John McCalldadc5752010-08-24 06:29:42 +00005205 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005206 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005207
5208 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005209
Anders Carlssonaaeef072010-01-24 05:50:09 +00005210 // Go through the outputs.
5211 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005212 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005213
Anders Carlssonaaeef072010-01-24 05:50:09 +00005214 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005215 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005216
Anders Carlssonaaeef072010-01-24 05:50:09 +00005217 // Transform the output expr.
5218 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005219 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005220 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005221 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005222
Anders Carlssonaaeef072010-01-24 05:50:09 +00005223 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005224
John McCallb268a282010-08-23 23:25:46 +00005225 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005226 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005227
Anders Carlssonaaeef072010-01-24 05:50:09 +00005228 // Go through the inputs.
5229 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005230 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005231
Anders Carlssonaaeef072010-01-24 05:50:09 +00005232 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005233 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005234
Anders Carlssonaaeef072010-01-24 05:50:09 +00005235 // Transform the input expr.
5236 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005237 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005238 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005239 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005240
Anders Carlssonaaeef072010-01-24 05:50:09 +00005241 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005242
John McCallb268a282010-08-23 23:25:46 +00005243 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005244 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005245
Anders Carlssonaaeef072010-01-24 05:50:09 +00005246 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005247 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005248
5249 // Go through the clobbers.
5250 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005251 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005252
5253 // No need to transform the asm string literal.
5254 AsmString = SemaRef.Owned(S->getAsmString());
5255
5256 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5257 S->isSimple(),
5258 S->isVolatile(),
5259 S->getNumOutputs(),
5260 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005261 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005262 move_arg(Constraints),
5263 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005264 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005265 move_arg(Clobbers),
5266 S->getRParenLoc(),
5267 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005268}
5269
5270
5271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005272StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005273TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005274 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005275 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005276 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005277 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005278
Douglas Gregor96c79492010-04-23 22:50:49 +00005279 // Transform the @catch statements (if present).
5280 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005281 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005282 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005283 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005284 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005285 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005286 if (Catch.get() != S->getCatchStmt(I))
5287 AnyCatchChanged = true;
5288 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005289 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005290
Douglas Gregor306de2f2010-04-22 23:59:56 +00005291 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005292 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005293 if (S->getFinallyStmt()) {
5294 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5295 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005296 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005297 }
5298
5299 // If nothing changed, just retain this statement.
5300 if (!getDerived().AlwaysRebuild() &&
5301 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005302 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005303 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005304 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005305
Douglas Gregor306de2f2010-04-22 23:59:56 +00005306 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005307 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5308 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005309}
Mike Stump11289f42009-09-09 15:08:12 +00005310
Douglas Gregorebe10102009-08-20 07:17:43 +00005311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005312StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005313TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005314 // Transform the @catch parameter, if there is one.
5315 VarDecl *Var = 0;
5316 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5317 TypeSourceInfo *TSInfo = 0;
5318 if (FromVar->getTypeSourceInfo()) {
5319 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5320 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005321 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005322 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005323
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005324 QualType T;
5325 if (TSInfo)
5326 T = TSInfo->getType();
5327 else {
5328 T = getDerived().TransformType(FromVar->getType());
5329 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005330 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005331 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005332
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005333 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5334 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005335 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005336 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005337
John McCalldadc5752010-08-24 06:29:42 +00005338 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005339 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005340 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005341
5342 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005343 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005344 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005345}
Mike Stump11289f42009-09-09 15:08:12 +00005346
Douglas Gregorebe10102009-08-20 07:17:43 +00005347template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005348StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005349TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005350 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005351 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005352 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005353 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005354
Douglas Gregor306de2f2010-04-22 23:59:56 +00005355 // If nothing changed, just retain this statement.
5356 if (!getDerived().AlwaysRebuild() &&
5357 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005358 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005359
5360 // Build a new statement.
5361 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005362 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005363}
Mike Stump11289f42009-09-09 15:08:12 +00005364
Douglas Gregorebe10102009-08-20 07:17:43 +00005365template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005366StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005367TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005368 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005369 if (S->getThrowExpr()) {
5370 Operand = getDerived().TransformExpr(S->getThrowExpr());
5371 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005372 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005373 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005374
Douglas Gregor2900c162010-04-22 21:44:01 +00005375 if (!getDerived().AlwaysRebuild() &&
5376 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005377 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005378
John McCallb268a282010-08-23 23:25:46 +00005379 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005380}
Mike Stump11289f42009-09-09 15:08:12 +00005381
Douglas Gregorebe10102009-08-20 07:17:43 +00005382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005383StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005384TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005385 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005386 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005387 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005388 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005389 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005390
Douglas Gregor6148de72010-04-22 22:01:21 +00005391 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005392 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005393 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005394 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005395
Douglas Gregor6148de72010-04-22 22:01:21 +00005396 // If nothing change, just retain the current statement.
5397 if (!getDerived().AlwaysRebuild() &&
5398 Object.get() == S->getSynchExpr() &&
5399 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005400 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005401
5402 // Build a new statement.
5403 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005404 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005405}
5406
5407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005408StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005409TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005410 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005411 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005412 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005413 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005414 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005415
Douglas Gregorf68a5082010-04-22 23:10:45 +00005416 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005417 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005418 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005419 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005420
Douglas Gregorf68a5082010-04-22 23:10:45 +00005421 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005422 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005423 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005424 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005425
Douglas Gregorf68a5082010-04-22 23:10:45 +00005426 // If nothing changed, just retain this statement.
5427 if (!getDerived().AlwaysRebuild() &&
5428 Element.get() == S->getElement() &&
5429 Collection.get() == S->getCollection() &&
5430 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005431 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005432
Douglas Gregorf68a5082010-04-22 23:10:45 +00005433 // Build a new statement.
5434 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5435 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005436 Element.get(),
5437 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005438 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005439 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005440}
5441
5442
5443template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005444StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005445TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5446 // Transform the exception declaration, if any.
5447 VarDecl *Var = 0;
5448 if (S->getExceptionDecl()) {
5449 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005450 TypeSourceInfo *T = getDerived().TransformType(
5451 ExceptionDecl->getTypeSourceInfo());
5452 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005453 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005454
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005455 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005456 ExceptionDecl->getInnerLocStart(),
5457 ExceptionDecl->getLocation(),
5458 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005459 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005460 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005461 }
Mike Stump11289f42009-09-09 15:08:12 +00005462
Douglas Gregorebe10102009-08-20 07:17:43 +00005463 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005464 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005465 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005466 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005467
Douglas Gregorebe10102009-08-20 07:17:43 +00005468 if (!getDerived().AlwaysRebuild() &&
5469 !Var &&
5470 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005471 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005472
5473 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5474 Var,
John McCallb268a282010-08-23 23:25:46 +00005475 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005476}
Mike Stump11289f42009-09-09 15:08:12 +00005477
Douglas Gregorebe10102009-08-20 07:17:43 +00005478template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005479StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005480TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5481 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005482 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005483 = getDerived().TransformCompoundStmt(S->getTryBlock());
5484 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005485 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005486
Douglas Gregorebe10102009-08-20 07:17:43 +00005487 // Transform the handlers.
5488 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005489 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005490 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005491 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005492 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5493 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005494 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005495
Douglas Gregorebe10102009-08-20 07:17:43 +00005496 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5497 Handlers.push_back(Handler.takeAs<Stmt>());
5498 }
Mike Stump11289f42009-09-09 15:08:12 +00005499
Douglas Gregorebe10102009-08-20 07:17:43 +00005500 if (!getDerived().AlwaysRebuild() &&
5501 TryBlock.get() == S->getTryBlock() &&
5502 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005503 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005504
John McCallb268a282010-08-23 23:25:46 +00005505 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005506 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005507}
Mike Stump11289f42009-09-09 15:08:12 +00005508
Richard Smith02e85f32011-04-14 22:09:26 +00005509template<typename Derived>
5510StmtResult
5511TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5512 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5513 if (Range.isInvalid())
5514 return StmtError();
5515
5516 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5517 if (BeginEnd.isInvalid())
5518 return StmtError();
5519
5520 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5521 if (Cond.isInvalid())
5522 return StmtError();
5523
5524 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5525 if (Inc.isInvalid())
5526 return StmtError();
5527
5528 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5529 if (LoopVar.isInvalid())
5530 return StmtError();
5531
5532 StmtResult NewStmt = S;
5533 if (getDerived().AlwaysRebuild() ||
5534 Range.get() != S->getRangeStmt() ||
5535 BeginEnd.get() != S->getBeginEndStmt() ||
5536 Cond.get() != S->getCond() ||
5537 Inc.get() != S->getInc() ||
5538 LoopVar.get() != S->getLoopVarStmt())
5539 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5540 S->getColonLoc(), Range.get(),
5541 BeginEnd.get(), Cond.get(),
5542 Inc.get(), LoopVar.get(),
5543 S->getRParenLoc());
5544
5545 StmtResult Body = getDerived().TransformStmt(S->getBody());
5546 if (Body.isInvalid())
5547 return StmtError();
5548
5549 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5550 // it now so we have a new statement to attach the body to.
5551 if (Body.get() != S->getBody() && NewStmt.get() == S)
5552 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5553 S->getColonLoc(), Range.get(),
5554 BeginEnd.get(), Cond.get(),
5555 Inc.get(), LoopVar.get(),
5556 S->getRParenLoc());
5557
5558 if (NewStmt.get() == S)
5559 return SemaRef.Owned(S);
5560
5561 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5562}
5563
John Wiegley1c0675e2011-04-28 01:08:34 +00005564template<typename Derived>
5565StmtResult
5566TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5567 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5568 if(TryBlock.isInvalid()) return StmtError();
5569
5570 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5571 if(!getDerived().AlwaysRebuild() &&
5572 TryBlock.get() == S->getTryBlock() &&
5573 Handler.get() == S->getHandler())
5574 return SemaRef.Owned(S);
5575
5576 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5577 S->getTryLoc(),
5578 TryBlock.take(),
5579 Handler.take());
5580}
5581
5582template<typename Derived>
5583StmtResult
5584TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5585 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5586 if(Block.isInvalid()) return StmtError();
5587
5588 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5589 Block.take());
5590}
5591
5592template<typename Derived>
5593StmtResult
5594TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5595 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5596 if(FilterExpr.isInvalid()) return StmtError();
5597
5598 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5599 if(Block.isInvalid()) return StmtError();
5600
5601 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5602 FilterExpr.take(),
5603 Block.take());
5604}
5605
5606template<typename Derived>
5607StmtResult
5608TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5609 if(isa<SEHFinallyStmt>(Handler))
5610 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5611 else
5612 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5613}
5614
Douglas Gregorebe10102009-08-20 07:17:43 +00005615//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005616// Expression transformation
5617//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005619ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005620TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005621 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005622}
Mike Stump11289f42009-09-09 15:08:12 +00005623
5624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005625ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005626TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005627 NestedNameSpecifierLoc QualifierLoc;
5628 if (E->getQualifierLoc()) {
5629 QualifierLoc
5630 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5631 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005632 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005633 }
John McCallce546572009-12-08 09:08:17 +00005634
5635 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005636 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5637 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005638 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005639 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005640
John McCall815039a2010-08-17 21:27:17 +00005641 DeclarationNameInfo NameInfo = E->getNameInfo();
5642 if (NameInfo.getName()) {
5643 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5644 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005645 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005646 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005647
5648 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005649 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005650 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005651 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005652 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005653
5654 // Mark it referenced in the new context regardless.
5655 // FIXME: this is a bit instantiation-specific.
5656 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5657
John McCallc3007a22010-10-26 07:05:15 +00005658 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005659 }
John McCallce546572009-12-08 09:08:17 +00005660
5661 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005662 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005663 TemplateArgs = &TransArgs;
5664 TransArgs.setLAngleLoc(E->getLAngleLoc());
5665 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005666 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5667 E->getNumTemplateArgs(),
5668 TransArgs))
5669 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005670 }
5671
Douglas Gregorea972d32011-02-28 21:54:11 +00005672 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5673 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005674}
Mike Stump11289f42009-09-09 15:08:12 +00005675
Douglas Gregora16548e2009-08-11 05:31:07 +00005676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005677ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005678TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005679 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005680}
Mike Stump11289f42009-09-09 15:08:12 +00005681
Douglas Gregora16548e2009-08-11 05:31:07 +00005682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005683ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005684TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005685 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005686}
Mike Stump11289f42009-09-09 15:08:12 +00005687
Douglas Gregora16548e2009-08-11 05:31:07 +00005688template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005689ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005690TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005691 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005692}
Mike Stump11289f42009-09-09 15:08:12 +00005693
Douglas Gregora16548e2009-08-11 05:31:07 +00005694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005695ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005696TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005697 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005698}
Mike Stump11289f42009-09-09 15:08:12 +00005699
Douglas Gregora16548e2009-08-11 05:31:07 +00005700template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005701ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005702TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005703 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005704}
5705
5706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005707ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005708TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5709 ExprResult ControllingExpr =
5710 getDerived().TransformExpr(E->getControllingExpr());
5711 if (ControllingExpr.isInvalid())
5712 return ExprError();
5713
5714 llvm::SmallVector<Expr *, 4> AssocExprs;
5715 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5716 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5717 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5718 if (TS) {
5719 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5720 if (!AssocType)
5721 return ExprError();
5722 AssocTypes.push_back(AssocType);
5723 } else {
5724 AssocTypes.push_back(0);
5725 }
5726
5727 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5728 if (AssocExpr.isInvalid())
5729 return ExprError();
5730 AssocExprs.push_back(AssocExpr.release());
5731 }
5732
5733 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5734 E->getDefaultLoc(),
5735 E->getRParenLoc(),
5736 ControllingExpr.release(),
5737 AssocTypes.data(),
5738 AssocExprs.data(),
5739 E->getNumAssocs());
5740}
5741
5742template<typename Derived>
5743ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005744TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005745 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005746 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005748
Douglas Gregora16548e2009-08-11 05:31:07 +00005749 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005750 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005751
John McCallb268a282010-08-23 23:25:46 +00005752 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005753 E->getRParen());
5754}
5755
Mike Stump11289f42009-09-09 15:08:12 +00005756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005757ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005758TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005759 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005760 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005761 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005762
Douglas Gregora16548e2009-08-11 05:31:07 +00005763 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005764 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005765
Douglas Gregora16548e2009-08-11 05:31:07 +00005766 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5767 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005768 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005769}
Mike Stump11289f42009-09-09 15:08:12 +00005770
Douglas Gregora16548e2009-08-11 05:31:07 +00005771template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005772ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005773TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5774 // Transform the type.
5775 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5776 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005777 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005778
Douglas Gregor882211c2010-04-28 22:16:22 +00005779 // Transform all of the components into components similar to what the
5780 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005781 // FIXME: It would be slightly more efficient in the non-dependent case to
5782 // just map FieldDecls, rather than requiring the rebuilder to look for
5783 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005784 // template code that we don't care.
5785 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005786 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005787 typedef OffsetOfExpr::OffsetOfNode Node;
5788 llvm::SmallVector<Component, 4> Components;
5789 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5790 const Node &ON = E->getComponent(I);
5791 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005792 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005793 Comp.LocStart = ON.getSourceRange().getBegin();
5794 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005795 switch (ON.getKind()) {
5796 case Node::Array: {
5797 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005798 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005799 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005800 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005801
Douglas Gregor882211c2010-04-28 22:16:22 +00005802 ExprChanged = ExprChanged || Index.get() != FromIndex;
5803 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005804 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005805 break;
5806 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005807
Douglas Gregor882211c2010-04-28 22:16:22 +00005808 case Node::Field:
5809 case Node::Identifier:
5810 Comp.isBrackets = false;
5811 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005812 if (!Comp.U.IdentInfo)
5813 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005814
Douglas Gregor882211c2010-04-28 22:16:22 +00005815 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005816
Douglas Gregord1702062010-04-29 00:18:15 +00005817 case Node::Base:
5818 // Will be recomputed during the rebuild.
5819 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005820 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005821
Douglas Gregor882211c2010-04-28 22:16:22 +00005822 Components.push_back(Comp);
5823 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005824
Douglas Gregor882211c2010-04-28 22:16:22 +00005825 // If nothing changed, retain the existing expression.
5826 if (!getDerived().AlwaysRebuild() &&
5827 Type == E->getTypeSourceInfo() &&
5828 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005829 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005830
Douglas Gregor882211c2010-04-28 22:16:22 +00005831 // Build a new offsetof expression.
5832 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5833 Components.data(), Components.size(),
5834 E->getRParenLoc());
5835}
5836
5837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005838ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005839TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5840 assert(getDerived().AlreadyTransformed(E->getType()) &&
5841 "opaque value expression requires transformation");
5842 return SemaRef.Owned(E);
5843}
5844
5845template<typename Derived>
5846ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005847TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5848 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005849 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005850 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005851
John McCallbcd03502009-12-07 02:54:59 +00005852 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005853 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005854 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005855
John McCall4c98fd82009-11-04 07:28:41 +00005856 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005857 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005858
Peter Collingbournee190dee2011-03-11 19:24:49 +00005859 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5860 E->getKind(),
5861 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005862 }
Mike Stump11289f42009-09-09 15:08:12 +00005863
John McCalldadc5752010-08-24 06:29:42 +00005864 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005865 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005866 // C++0x [expr.sizeof]p1:
5867 // The operand is either an expression, which is an unevaluated operand
5868 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005869 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005870
Douglas Gregora16548e2009-08-11 05:31:07 +00005871 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5872 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005873 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005874
Douglas Gregora16548e2009-08-11 05:31:07 +00005875 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005876 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005877 }
Mike Stump11289f42009-09-09 15:08:12 +00005878
Peter Collingbournee190dee2011-03-11 19:24:49 +00005879 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5880 E->getOperatorLoc(),
5881 E->getKind(),
5882 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005883}
Mike Stump11289f42009-09-09 15:08:12 +00005884
Douglas Gregora16548e2009-08-11 05:31:07 +00005885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005886ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005887TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005888 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005890 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005891
John McCalldadc5752010-08-24 06:29:42 +00005892 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005895
5896
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 if (!getDerived().AlwaysRebuild() &&
5898 LHS.get() == E->getLHS() &&
5899 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005900 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005901
John McCallb268a282010-08-23 23:25:46 +00005902 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005903 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005904 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005905 E->getRBracketLoc());
5906}
Mike Stump11289f42009-09-09 15:08:12 +00005907
5908template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005909ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005910TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005911 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005912 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005913 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005914 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005915
5916 // Transform arguments.
5917 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005918 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005919 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5920 &ArgChanged))
5921 return ExprError();
5922
Douglas Gregora16548e2009-08-11 05:31:07 +00005923 if (!getDerived().AlwaysRebuild() &&
5924 Callee.get() == E->getCallee() &&
5925 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005926 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005927
Douglas Gregora16548e2009-08-11 05:31:07 +00005928 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005929 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005930 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005931 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005932 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005933 E->getRParenLoc());
5934}
Mike Stump11289f42009-09-09 15:08:12 +00005935
5936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005937ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005938TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005939 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005940 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005941 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005942
Douglas Gregorea972d32011-02-28 21:54:11 +00005943 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005944 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005945 QualifierLoc
5946 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5947
5948 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005949 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005950 }
Mike Stump11289f42009-09-09 15:08:12 +00005951
Eli Friedman2cfcef62009-12-04 06:40:45 +00005952 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005953 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5954 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005955 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005956 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005957
John McCall16df1e52010-03-30 21:47:33 +00005958 NamedDecl *FoundDecl = E->getFoundDecl();
5959 if (FoundDecl == E->getMemberDecl()) {
5960 FoundDecl = Member;
5961 } else {
5962 FoundDecl = cast_or_null<NamedDecl>(
5963 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5964 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005965 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005966 }
5967
Douglas Gregora16548e2009-08-11 05:31:07 +00005968 if (!getDerived().AlwaysRebuild() &&
5969 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005970 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005971 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005972 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005973 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005974
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005975 // Mark it referenced in the new context regardless.
5976 // FIXME: this is a bit instantiation-specific.
5977 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005978 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005979 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005980
John McCall6b51f282009-11-23 01:53:49 +00005981 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005982 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005983 TransArgs.setLAngleLoc(E->getLAngleLoc());
5984 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005985 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5986 E->getNumTemplateArgs(),
5987 TransArgs))
5988 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005989 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005990
Douglas Gregora16548e2009-08-11 05:31:07 +00005991 // FIXME: Bogus source location for the operator
5992 SourceLocation FakeOperatorLoc
5993 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5994
John McCall38836f02010-01-15 08:34:02 +00005995 // FIXME: to do this check properly, we will need to preserve the
5996 // first-qualifier-in-scope here, just in case we had a dependent
5997 // base (and therefore couldn't do the check) and a
5998 // nested-name-qualifier (and therefore could do the lookup).
5999 NamedDecl *FirstQualifierInScope = 0;
6000
John McCallb268a282010-08-23 23:25:46 +00006001 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006002 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006003 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006004 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006005 Member,
John McCall16df1e52010-03-30 21:47:33 +00006006 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006007 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006008 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006009 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006010}
Mike Stump11289f42009-09-09 15:08:12 +00006011
Douglas Gregora16548e2009-08-11 05:31:07 +00006012template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006013ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006014TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006015 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006016 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006017 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006018
John McCalldadc5752010-08-24 06:29:42 +00006019 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006020 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006021 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006022
Douglas Gregora16548e2009-08-11 05:31:07 +00006023 if (!getDerived().AlwaysRebuild() &&
6024 LHS.get() == E->getLHS() &&
6025 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006026 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006027
Douglas Gregora16548e2009-08-11 05:31:07 +00006028 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006029 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006030}
6031
Mike Stump11289f42009-09-09 15:08:12 +00006032template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006033ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006034TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006035 CompoundAssignOperator *E) {
6036 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006037}
Mike Stump11289f42009-09-09 15:08:12 +00006038
Douglas Gregora16548e2009-08-11 05:31:07 +00006039template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006040ExprResult TreeTransform<Derived>::
6041TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6042 // Just rebuild the common and RHS expressions and see whether we
6043 // get any changes.
6044
6045 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6046 if (commonExpr.isInvalid())
6047 return ExprError();
6048
6049 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6050 if (rhs.isInvalid())
6051 return ExprError();
6052
6053 if (!getDerived().AlwaysRebuild() &&
6054 commonExpr.get() == e->getCommon() &&
6055 rhs.get() == e->getFalseExpr())
6056 return SemaRef.Owned(e);
6057
6058 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6059 e->getQuestionLoc(),
6060 0,
6061 e->getColonLoc(),
6062 rhs.get());
6063}
6064
6065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006066ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006067TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006068 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006069 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006070 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006071
John McCalldadc5752010-08-24 06:29:42 +00006072 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006073 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006074 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006075
John McCalldadc5752010-08-24 06:29:42 +00006076 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006077 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006078 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006079
Douglas Gregora16548e2009-08-11 05:31:07 +00006080 if (!getDerived().AlwaysRebuild() &&
6081 Cond.get() == E->getCond() &&
6082 LHS.get() == E->getLHS() &&
6083 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006084 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006085
John McCallb268a282010-08-23 23:25:46 +00006086 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006087 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006088 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006089 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006090 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006091}
Mike Stump11289f42009-09-09 15:08:12 +00006092
6093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006094ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006095TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006096 // Implicit casts are eliminated during transformation, since they
6097 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006098 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006099}
Mike Stump11289f42009-09-09 15:08:12 +00006100
Douglas Gregora16548e2009-08-11 05:31:07 +00006101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006102ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006103TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006104 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6105 if (!Type)
6106 return ExprError();
6107
John McCalldadc5752010-08-24 06:29:42 +00006108 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006109 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006110 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006111 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006112
Douglas Gregora16548e2009-08-11 05:31:07 +00006113 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006114 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006115 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006116 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006117
John McCall97513962010-01-15 18:39:57 +00006118 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006119 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006120 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006121 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006122}
Mike Stump11289f42009-09-09 15:08:12 +00006123
Douglas Gregora16548e2009-08-11 05:31:07 +00006124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006126TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006127 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6128 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6129 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006131
John McCalldadc5752010-08-24 06:29:42 +00006132 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006133 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006134 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006135
Douglas Gregora16548e2009-08-11 05:31:07 +00006136 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006137 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006138 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006139 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006140
John McCall5d7aa7f2010-01-19 22:33:45 +00006141 // Note: the expression type doesn't necessarily match the
6142 // type-as-written, but that's okay, because it should always be
6143 // derivable from the initializer.
6144
John McCalle15bbff2010-01-18 19:35:47 +00006145 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006146 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006147 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006148}
Mike Stump11289f42009-09-09 15:08:12 +00006149
Douglas Gregora16548e2009-08-11 05:31:07 +00006150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006151ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006152TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006153 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006154 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006155 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006156
Douglas Gregora16548e2009-08-11 05:31:07 +00006157 if (!getDerived().AlwaysRebuild() &&
6158 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006159 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006160
Douglas Gregora16548e2009-08-11 05:31:07 +00006161 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006162 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006163 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006164 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006165 E->getAccessorLoc(),
6166 E->getAccessor());
6167}
Mike Stump11289f42009-09-09 15:08:12 +00006168
Douglas Gregora16548e2009-08-11 05:31:07 +00006169template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006170ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006171TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006172 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006173
John McCall37ad5512010-08-23 06:44:23 +00006174 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006175 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6176 Inits, &InitChanged))
6177 return ExprError();
6178
Douglas Gregora16548e2009-08-11 05:31:07 +00006179 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006180 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006181
Douglas Gregora16548e2009-08-11 05:31:07 +00006182 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006183 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006184}
Mike Stump11289f42009-09-09 15:08:12 +00006185
Douglas Gregora16548e2009-08-11 05:31:07 +00006186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006187ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006188TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006189 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006190
Douglas Gregorebe10102009-08-20 07:17:43 +00006191 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006192 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006193 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006194 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006195
Douglas Gregorebe10102009-08-20 07:17:43 +00006196 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006197 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006198 bool ExprChanged = false;
6199 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6200 DEnd = E->designators_end();
6201 D != DEnd; ++D) {
6202 if (D->isFieldDesignator()) {
6203 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6204 D->getDotLoc(),
6205 D->getFieldLoc()));
6206 continue;
6207 }
Mike Stump11289f42009-09-09 15:08:12 +00006208
Douglas Gregora16548e2009-08-11 05:31:07 +00006209 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006210 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006211 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006213
6214 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006215 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006216
Douglas Gregora16548e2009-08-11 05:31:07 +00006217 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6218 ArrayExprs.push_back(Index.release());
6219 continue;
6220 }
Mike Stump11289f42009-09-09 15:08:12 +00006221
Douglas Gregora16548e2009-08-11 05:31:07 +00006222 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006223 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006224 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6225 if (Start.isInvalid())
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 End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006229 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006230 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006231
6232 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006233 End.get(),
6234 D->getLBracketLoc(),
6235 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006236
Douglas Gregora16548e2009-08-11 05:31:07 +00006237 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6238 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006239
Douglas Gregora16548e2009-08-11 05:31:07 +00006240 ArrayExprs.push_back(Start.release());
6241 ArrayExprs.push_back(End.release());
6242 }
Mike Stump11289f42009-09-09 15:08:12 +00006243
Douglas Gregora16548e2009-08-11 05:31:07 +00006244 if (!getDerived().AlwaysRebuild() &&
6245 Init.get() == E->getInit() &&
6246 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006247 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006248
Douglas Gregora16548e2009-08-11 05:31:07 +00006249 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6250 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006251 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006252}
Mike Stump11289f42009-09-09 15:08:12 +00006253
Douglas Gregora16548e2009-08-11 05:31:07 +00006254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006255ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006256TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006257 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006258 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006259
Douglas Gregor3da3c062009-10-28 00:29:27 +00006260 // FIXME: Will we ever have proper type location here? Will we actually
6261 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006262 QualType T = getDerived().TransformType(E->getType());
6263 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006264 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006265
Douglas Gregora16548e2009-08-11 05:31:07 +00006266 if (!getDerived().AlwaysRebuild() &&
6267 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006268 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006269
Douglas Gregora16548e2009-08-11 05:31:07 +00006270 return getDerived().RebuildImplicitValueInitExpr(T);
6271}
Mike Stump11289f42009-09-09 15:08:12 +00006272
Douglas Gregora16548e2009-08-11 05:31:07 +00006273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006274ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006275TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006276 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6277 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006278 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006279
John McCalldadc5752010-08-24 06:29:42 +00006280 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006281 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006282 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006283
Douglas Gregora16548e2009-08-11 05:31:07 +00006284 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006285 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006286 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006287 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006288
John McCallb268a282010-08-23 23:25:46 +00006289 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006290 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006291}
6292
6293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006294ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006295TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006296 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006297 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006298 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6299 &ArgumentChanged))
6300 return ExprError();
6301
Douglas Gregora16548e2009-08-11 05:31:07 +00006302 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6303 move_arg(Inits),
6304 E->getRParenLoc());
6305}
Mike Stump11289f42009-09-09 15:08:12 +00006306
Douglas Gregora16548e2009-08-11 05:31:07 +00006307/// \brief Transform an address-of-label expression.
6308///
6309/// By default, the transformation of an address-of-label expression always
6310/// rebuilds the expression, so that the label identifier can be resolved to
6311/// the corresponding label statement by semantic analysis.
6312template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006313ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006314TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006315 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6316 E->getLabel());
6317 if (!LD)
6318 return ExprError();
6319
Douglas Gregora16548e2009-08-11 05:31:07 +00006320 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006321 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006322}
Mike Stump11289f42009-09-09 15:08:12 +00006323
6324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006325ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006326TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006327 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006328 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6329 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006330 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006331
Douglas Gregora16548e2009-08-11 05:31:07 +00006332 if (!getDerived().AlwaysRebuild() &&
6333 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006334 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006335
6336 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006337 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006338 E->getRParenLoc());
6339}
Mike Stump11289f42009-09-09 15:08:12 +00006340
Douglas Gregora16548e2009-08-11 05:31:07 +00006341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006342ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006343TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006344 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006345 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006347
John McCalldadc5752010-08-24 06:29:42 +00006348 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006349 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006350 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006351
John McCalldadc5752010-08-24 06:29:42 +00006352 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006353 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006354 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006355
Douglas Gregora16548e2009-08-11 05:31:07 +00006356 if (!getDerived().AlwaysRebuild() &&
6357 Cond.get() == E->getCond() &&
6358 LHS.get() == E->getLHS() &&
6359 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006360 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006361
Douglas Gregora16548e2009-08-11 05:31:07 +00006362 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006363 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006364 E->getRParenLoc());
6365}
Mike Stump11289f42009-09-09 15:08:12 +00006366
Douglas Gregora16548e2009-08-11 05:31:07 +00006367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006369TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006370 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006371}
6372
6373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006374ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006375TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006376 switch (E->getOperator()) {
6377 case OO_New:
6378 case OO_Delete:
6379 case OO_Array_New:
6380 case OO_Array_Delete:
6381 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006382 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006383
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006384 case OO_Call: {
6385 // This is a call to an object's operator().
6386 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6387
6388 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006389 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006390 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006391 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006392
6393 // FIXME: Poor location information
6394 SourceLocation FakeLParenLoc
6395 = SemaRef.PP.getLocForEndOfToken(
6396 static_cast<Expr *>(Object.get())->getLocEnd());
6397
6398 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006399 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006400 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6401 Args))
6402 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006403
John McCallb268a282010-08-23 23:25:46 +00006404 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006405 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006406 E->getLocEnd());
6407 }
6408
6409#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6410 case OO_##Name:
6411#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6412#include "clang/Basic/OperatorKinds.def"
6413 case OO_Subscript:
6414 // Handled below.
6415 break;
6416
6417 case OO_Conditional:
6418 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006419 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006420
6421 case OO_None:
6422 case NUM_OVERLOADED_OPERATORS:
6423 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006424 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006425 }
6426
John McCalldadc5752010-08-24 06:29:42 +00006427 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006428 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006429 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006430
John McCalldadc5752010-08-24 06:29:42 +00006431 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006432 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006433 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006434
John McCalldadc5752010-08-24 06:29:42 +00006435 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006436 if (E->getNumArgs() == 2) {
6437 Second = getDerived().TransformExpr(E->getArg(1));
6438 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006439 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006440 }
Mike Stump11289f42009-09-09 15:08:12 +00006441
Douglas Gregora16548e2009-08-11 05:31:07 +00006442 if (!getDerived().AlwaysRebuild() &&
6443 Callee.get() == E->getCallee() &&
6444 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006445 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006446 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006447
Douglas Gregora16548e2009-08-11 05:31:07 +00006448 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6449 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006450 Callee.get(),
6451 First.get(),
6452 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006453}
Mike Stump11289f42009-09-09 15:08:12 +00006454
Douglas Gregora16548e2009-08-11 05:31:07 +00006455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006456ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006457TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6458 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006459}
Mike Stump11289f42009-09-09 15:08:12 +00006460
Douglas Gregora16548e2009-08-11 05:31:07 +00006461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006462ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006463TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6464 // Transform the callee.
6465 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6466 if (Callee.isInvalid())
6467 return ExprError();
6468
6469 // Transform exec config.
6470 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6471 if (EC.isInvalid())
6472 return ExprError();
6473
6474 // Transform arguments.
6475 bool ArgChanged = false;
6476 ASTOwningVector<Expr*> Args(SemaRef);
6477 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6478 &ArgChanged))
6479 return ExprError();
6480
6481 if (!getDerived().AlwaysRebuild() &&
6482 Callee.get() == E->getCallee() &&
6483 !ArgChanged)
6484 return SemaRef.Owned(E);
6485
6486 // FIXME: Wrong source location information for the '('.
6487 SourceLocation FakeLParenLoc
6488 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6489 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6490 move_arg(Args),
6491 E->getRParenLoc(), EC.get());
6492}
6493
6494template<typename Derived>
6495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006496TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006497 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6498 if (!Type)
6499 return ExprError();
6500
John McCalldadc5752010-08-24 06:29:42 +00006501 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006502 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006503 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006504 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006505
Douglas Gregora16548e2009-08-11 05:31:07 +00006506 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006507 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006508 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006509 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006510
Douglas Gregora16548e2009-08-11 05:31:07 +00006511 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006512 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006513 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6514 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6515 SourceLocation FakeRParenLoc
6516 = SemaRef.PP.getLocForEndOfToken(
6517 E->getSubExpr()->getSourceRange().getEnd());
6518 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006519 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006520 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006521 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006522 FakeRAngleLoc,
6523 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006524 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006525 FakeRParenLoc);
6526}
Mike Stump11289f42009-09-09 15:08:12 +00006527
Douglas Gregora16548e2009-08-11 05:31:07 +00006528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006529ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006530TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6531 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006532}
Mike Stump11289f42009-09-09 15:08:12 +00006533
6534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006535ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006536TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6537 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006538}
6539
Douglas Gregora16548e2009-08-11 05:31:07 +00006540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006541ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006542TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006543 CXXReinterpretCastExpr *E) {
6544 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006545}
Mike Stump11289f42009-09-09 15:08:12 +00006546
Douglas Gregora16548e2009-08-11 05:31:07 +00006547template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006548ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006549TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6550 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006551}
Mike Stump11289f42009-09-09 15:08:12 +00006552
Douglas Gregora16548e2009-08-11 05:31:07 +00006553template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006554ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006555TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006556 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006557 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6558 if (!Type)
6559 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006560
John McCalldadc5752010-08-24 06:29:42 +00006561 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006562 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006563 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006565
Douglas Gregora16548e2009-08-11 05:31:07 +00006566 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006567 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006568 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006569 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006570
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006571 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006572 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006573 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006574 E->getRParenLoc());
6575}
Mike Stump11289f42009-09-09 15:08:12 +00006576
Douglas Gregora16548e2009-08-11 05:31:07 +00006577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006578ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006579TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006580 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006581 TypeSourceInfo *TInfo
6582 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6583 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006584 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006585
Douglas Gregora16548e2009-08-11 05:31:07 +00006586 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006587 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006588 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006589
Douglas Gregor9da64192010-04-26 22:37:10 +00006590 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6591 E->getLocStart(),
6592 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006593 E->getLocEnd());
6594 }
Mike Stump11289f42009-09-09 15:08:12 +00006595
Douglas Gregora16548e2009-08-11 05:31:07 +00006596 // We don't know whether the expression is potentially evaluated until
6597 // after we perform semantic analysis, so the expression is potentially
6598 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006599 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006600 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006601
John McCalldadc5752010-08-24 06:29:42 +00006602 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006603 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006604 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006605
Douglas Gregora16548e2009-08-11 05:31:07 +00006606 if (!getDerived().AlwaysRebuild() &&
6607 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006608 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006609
Douglas Gregor9da64192010-04-26 22:37:10 +00006610 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6611 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006612 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006613 E->getLocEnd());
6614}
6615
6616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006617ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006618TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6619 if (E->isTypeOperand()) {
6620 TypeSourceInfo *TInfo
6621 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6622 if (!TInfo)
6623 return ExprError();
6624
6625 if (!getDerived().AlwaysRebuild() &&
6626 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006627 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006628
Douglas Gregor69735112011-03-06 17:40:41 +00006629 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006630 E->getLocStart(),
6631 TInfo,
6632 E->getLocEnd());
6633 }
6634
6635 // We don't know whether the expression is potentially evaluated until
6636 // after we perform semantic analysis, so the expression is potentially
6637 // potentially evaluated.
6638 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6639
6640 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6641 if (SubExpr.isInvalid())
6642 return ExprError();
6643
6644 if (!getDerived().AlwaysRebuild() &&
6645 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006646 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006647
6648 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6649 E->getLocStart(),
6650 SubExpr.get(),
6651 E->getLocEnd());
6652}
6653
6654template<typename Derived>
6655ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006656TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006657 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006658}
Mike Stump11289f42009-09-09 15:08:12 +00006659
Douglas Gregora16548e2009-08-11 05:31:07 +00006660template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006661ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006662TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006663 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006664 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006665}
Mike Stump11289f42009-09-09 15:08:12 +00006666
Douglas Gregora16548e2009-08-11 05:31:07 +00006667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006668ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006669TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006670 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6671 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6672 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006673
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006674 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006675 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006676
Douglas Gregorb15af892010-01-07 23:12:05 +00006677 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006678}
Mike Stump11289f42009-09-09 15:08:12 +00006679
Douglas Gregora16548e2009-08-11 05:31:07 +00006680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006681ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006682TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006683 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006685 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006686
Douglas Gregora16548e2009-08-11 05:31:07 +00006687 if (!getDerived().AlwaysRebuild() &&
6688 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006689 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006690
John McCallb268a282010-08-23 23:25:46 +00006691 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006692}
Mike Stump11289f42009-09-09 15:08:12 +00006693
Douglas Gregora16548e2009-08-11 05:31:07 +00006694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006695ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006696TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006697 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006698 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6699 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006700 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006701 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006702
Chandler Carruth794da4c2010-02-08 06:42:49 +00006703 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006704 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006705 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006706
Douglas Gregor033f6752009-12-23 23:03:06 +00006707 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006708}
Mike Stump11289f42009-09-09 15:08:12 +00006709
Douglas Gregora16548e2009-08-11 05:31:07 +00006710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006711ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006712TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6713 CXXScalarValueInitExpr *E) {
6714 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6715 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006716 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006717
Douglas Gregora16548e2009-08-11 05:31:07 +00006718 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006719 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006720 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006721
Douglas Gregor2b88c112010-09-08 00:15:04 +00006722 return getDerived().RebuildCXXScalarValueInitExpr(T,
6723 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006724 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006725}
Mike Stump11289f42009-09-09 15:08:12 +00006726
Douglas Gregora16548e2009-08-11 05:31:07 +00006727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006728ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006729TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006730 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006731 TypeSourceInfo *AllocTypeInfo
6732 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6733 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006734 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006735
Douglas Gregora16548e2009-08-11 05:31:07 +00006736 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006737 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006738 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006739 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006740
Douglas Gregora16548e2009-08-11 05:31:07 +00006741 // Transform the placement arguments (if any).
6742 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006743 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006744 if (getDerived().TransformExprs(E->getPlacementArgs(),
6745 E->getNumPlacementArgs(), true,
6746 PlacementArgs, &ArgumentChanged))
6747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006748
Douglas Gregorebe10102009-08-20 07:17:43 +00006749 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006750 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006751 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6752 ConstructorArgs, &ArgumentChanged))
6753 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006754
Douglas Gregord2d9da02010-02-26 00:38:10 +00006755 // Transform constructor, new operator, and delete operator.
6756 CXXConstructorDecl *Constructor = 0;
6757 if (E->getConstructor()) {
6758 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006759 getDerived().TransformDecl(E->getLocStart(),
6760 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006761 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006762 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006763 }
6764
6765 FunctionDecl *OperatorNew = 0;
6766 if (E->getOperatorNew()) {
6767 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006768 getDerived().TransformDecl(E->getLocStart(),
6769 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006770 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006771 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006772 }
6773
6774 FunctionDecl *OperatorDelete = 0;
6775 if (E->getOperatorDelete()) {
6776 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006777 getDerived().TransformDecl(E->getLocStart(),
6778 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006779 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006780 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006781 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006782
Douglas Gregora16548e2009-08-11 05:31:07 +00006783 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006784 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006785 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006786 Constructor == E->getConstructor() &&
6787 OperatorNew == E->getOperatorNew() &&
6788 OperatorDelete == E->getOperatorDelete() &&
6789 !ArgumentChanged) {
6790 // Mark any declarations we need as referenced.
6791 // FIXME: instantiation-specific.
6792 if (Constructor)
6793 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6794 if (OperatorNew)
6795 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6796 if (OperatorDelete)
6797 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006798 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006799 }
Mike Stump11289f42009-09-09 15:08:12 +00006800
Douglas Gregor0744ef62010-09-07 21:49:58 +00006801 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006802 if (!ArraySize.get()) {
6803 // If no array size was specified, but the new expression was
6804 // instantiated with an array type (e.g., "new T" where T is
6805 // instantiated with "int[4]"), extract the outer bound from the
6806 // array type as our array size. We do this with constant and
6807 // dependently-sized array types.
6808 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6809 if (!ArrayT) {
6810 // Do nothing
6811 } else if (const ConstantArrayType *ConsArrayT
6812 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006813 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006814 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6815 ConsArrayT->getSize(),
6816 SemaRef.Context.getSizeType(),
6817 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006818 AllocType = ConsArrayT->getElementType();
6819 } else if (const DependentSizedArrayType *DepArrayT
6820 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6821 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006822 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006823 AllocType = DepArrayT->getElementType();
6824 }
6825 }
6826 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006827
Douglas Gregora16548e2009-08-11 05:31:07 +00006828 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6829 E->isGlobalNew(),
6830 /*FIXME:*/E->getLocStart(),
6831 move_arg(PlacementArgs),
6832 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006833 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006834 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006835 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006836 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006837 /*FIXME:*/E->getLocStart(),
6838 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006839 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006840}
Mike Stump11289f42009-09-09 15:08:12 +00006841
Douglas Gregora16548e2009-08-11 05:31:07 +00006842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006843ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006844TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006845 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006846 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006847 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006848
Douglas Gregord2d9da02010-02-26 00:38:10 +00006849 // Transform the delete operator, if known.
6850 FunctionDecl *OperatorDelete = 0;
6851 if (E->getOperatorDelete()) {
6852 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006853 getDerived().TransformDecl(E->getLocStart(),
6854 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006855 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006856 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006857 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006858
Douglas Gregora16548e2009-08-11 05:31:07 +00006859 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006860 Operand.get() == E->getArgument() &&
6861 OperatorDelete == E->getOperatorDelete()) {
6862 // Mark any declarations we need as referenced.
6863 // FIXME: instantiation-specific.
6864 if (OperatorDelete)
6865 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006866
6867 if (!E->getArgument()->isTypeDependent()) {
6868 QualType Destroyed = SemaRef.Context.getBaseElementType(
6869 E->getDestroyedType());
6870 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6871 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6872 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6873 SemaRef.LookupDestructor(Record));
6874 }
6875 }
6876
John McCallc3007a22010-10-26 07:05:15 +00006877 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006878 }
Mike Stump11289f42009-09-09 15:08:12 +00006879
Douglas Gregora16548e2009-08-11 05:31:07 +00006880 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6881 E->isGlobalDelete(),
6882 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006883 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006884}
Mike Stump11289f42009-09-09 15:08:12 +00006885
Douglas Gregora16548e2009-08-11 05:31:07 +00006886template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006887ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006888TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006889 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006890 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006891 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006892 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006893
John McCallba7bf592010-08-24 05:47:05 +00006894 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006895 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006896 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006897 E->getOperatorLoc(),
6898 E->isArrow()? tok::arrow : tok::period,
6899 ObjectTypePtr,
6900 MayBePseudoDestructor);
6901 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006902 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006903
John McCallba7bf592010-08-24 05:47:05 +00006904 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006905 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6906 if (QualifierLoc) {
6907 QualifierLoc
6908 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6909 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006910 return ExprError();
6911 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006912 CXXScopeSpec SS;
6913 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006914
Douglas Gregor678f90d2010-02-25 01:56:36 +00006915 PseudoDestructorTypeStorage Destroyed;
6916 if (E->getDestroyedTypeInfo()) {
6917 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006918 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006919 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006920 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006921 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006922 Destroyed = DestroyedTypeInfo;
6923 } else if (ObjectType->isDependentType()) {
6924 // We aren't likely to be able to resolve the identifier down to a type
6925 // now anyway, so just retain the identifier.
6926 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6927 E->getDestroyedTypeLoc());
6928 } else {
6929 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006930 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006931 *E->getDestroyedTypeIdentifier(),
6932 E->getDestroyedTypeLoc(),
6933 /*Scope=*/0,
6934 SS, ObjectTypePtr,
6935 false);
6936 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006937 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006938
Douglas Gregor678f90d2010-02-25 01:56:36 +00006939 Destroyed
6940 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6941 E->getDestroyedTypeLoc());
6942 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006943
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006944 TypeSourceInfo *ScopeTypeInfo = 0;
6945 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006946 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006947 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006948 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006949 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006950
John McCallb268a282010-08-23 23:25:46 +00006951 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006952 E->getOperatorLoc(),
6953 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006954 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006955 ScopeTypeInfo,
6956 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006957 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006958 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006959}
Mike Stump11289f42009-09-09 15:08:12 +00006960
Douglas Gregorad8a3362009-09-04 17:36:40 +00006961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006962ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006963TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006964 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006965 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6966 Sema::LookupOrdinaryName);
6967
6968 // Transform all the decls.
6969 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6970 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006971 NamedDecl *InstD = static_cast<NamedDecl*>(
6972 getDerived().TransformDecl(Old->getNameLoc(),
6973 *I));
John McCall84d87672009-12-10 09:41:52 +00006974 if (!InstD) {
6975 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6976 // This can happen because of dependent hiding.
6977 if (isa<UsingShadowDecl>(*I))
6978 continue;
6979 else
John McCallfaf5fb42010-08-26 23:41:50 +00006980 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006981 }
John McCalle66edc12009-11-24 19:00:30 +00006982
6983 // Expand using declarations.
6984 if (isa<UsingDecl>(InstD)) {
6985 UsingDecl *UD = cast<UsingDecl>(InstD);
6986 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6987 E = UD->shadow_end(); I != E; ++I)
6988 R.addDecl(*I);
6989 continue;
6990 }
6991
6992 R.addDecl(InstD);
6993 }
6994
6995 // Resolve a kind, but don't do any further analysis. If it's
6996 // ambiguous, the callee needs to deal with it.
6997 R.resolveKind();
6998
6999 // Rebuild the nested-name qualifier, if present.
7000 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007001 if (Old->getQualifierLoc()) {
7002 NestedNameSpecifierLoc QualifierLoc
7003 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7004 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007005 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007006
Douglas Gregor0da1d432011-02-28 20:01:57 +00007007 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007008 }
7009
Douglas Gregor9262f472010-04-27 18:19:34 +00007010 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007011 CXXRecordDecl *NamingClass
7012 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7013 Old->getNameLoc(),
7014 Old->getNamingClass()));
7015 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007016 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007017
Douglas Gregorda7be082010-04-27 16:10:10 +00007018 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007019 }
7020
7021 // If we have no template arguments, it's a normal declaration name.
7022 if (!Old->hasExplicitTemplateArgs())
7023 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7024
7025 // If we have template arguments, rebuild them, then rebuild the
7026 // templateid expression.
7027 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007028 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7029 Old->getNumTemplateArgs(),
7030 TransArgs))
7031 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007032
7033 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7034 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007035}
Mike Stump11289f42009-09-09 15:08:12 +00007036
Douglas Gregora16548e2009-08-11 05:31:07 +00007037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007038ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007039TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007040 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7041 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007042 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007043
Douglas Gregora16548e2009-08-11 05:31:07 +00007044 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007045 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007046 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007047
Mike Stump11289f42009-09-09 15:08:12 +00007048 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007049 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007050 T,
7051 E->getLocEnd());
7052}
Mike Stump11289f42009-09-09 15:08:12 +00007053
Douglas Gregora16548e2009-08-11 05:31:07 +00007054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007055ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007056TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7057 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7058 if (!LhsT)
7059 return ExprError();
7060
7061 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7062 if (!RhsT)
7063 return ExprError();
7064
7065 if (!getDerived().AlwaysRebuild() &&
7066 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7067 return SemaRef.Owned(E);
7068
7069 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7070 E->getLocStart(),
7071 LhsT, RhsT,
7072 E->getLocEnd());
7073}
7074
7075template<typename Derived>
7076ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007077TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7078 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7079 if (!T)
7080 return ExprError();
7081
7082 if (!getDerived().AlwaysRebuild() &&
7083 T == E->getQueriedTypeSourceInfo())
7084 return SemaRef.Owned(E);
7085
7086 ExprResult SubExpr;
7087 {
7088 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7089 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7090 if (SubExpr.isInvalid())
7091 return ExprError();
7092
7093 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7094 return SemaRef.Owned(E);
7095 }
7096
7097 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7098 E->getLocStart(),
7099 T,
7100 SubExpr.get(),
7101 E->getLocEnd());
7102}
7103
7104template<typename Derived>
7105ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007106TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7107 ExprResult SubExpr;
7108 {
7109 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7110 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7111 if (SubExpr.isInvalid())
7112 return ExprError();
7113
7114 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7115 return SemaRef.Owned(E);
7116 }
7117
7118 return getDerived().RebuildExpressionTrait(
7119 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7120}
7121
7122template<typename Derived>
7123ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007124TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007125 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007126 NestedNameSpecifierLoc QualifierLoc
7127 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7128 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007129 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007130
John McCall31f82722010-11-12 08:19:04 +00007131 // TODO: If this is a conversion-function-id, verify that the
7132 // destination type name (if present) resolves the same way after
7133 // instantiation as it did in the local scope.
7134
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007135 DeclarationNameInfo NameInfo
7136 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7137 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007138 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007139
John McCalle66edc12009-11-24 19:00:30 +00007140 if (!E->hasExplicitTemplateArgs()) {
7141 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007142 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007143 // Note: it is sufficient to compare the Name component of NameInfo:
7144 // if name has not changed, DNLoc has not changed either.
7145 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007146 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007147
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007148 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007149 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007150 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007151 }
John McCall6b51f282009-11-23 01:53:49 +00007152
7153 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007154 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7155 E->getNumTemplateArgs(),
7156 TransArgs))
7157 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007158
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007159 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007160 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007161 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007162}
7163
7164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007165ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007166TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007167 // CXXConstructExprs are always implicit, so when we have a
7168 // 1-argument construction we just transform that argument.
7169 if (E->getNumArgs() == 1 ||
7170 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7171 return getDerived().TransformExpr(E->getArg(0));
7172
Douglas Gregora16548e2009-08-11 05:31:07 +00007173 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7174
7175 QualType T = getDerived().TransformType(E->getType());
7176 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007177 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007178
7179 CXXConstructorDecl *Constructor
7180 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007181 getDerived().TransformDecl(E->getLocStart(),
7182 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007183 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007184 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007185
Douglas Gregora16548e2009-08-11 05:31:07 +00007186 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007187 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007188 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7189 &ArgumentChanged))
7190 return ExprError();
7191
Douglas Gregora16548e2009-08-11 05:31:07 +00007192 if (!getDerived().AlwaysRebuild() &&
7193 T == E->getType() &&
7194 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007195 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007196 // Mark the constructor as referenced.
7197 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007198 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007199 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007200 }
Mike Stump11289f42009-09-09 15:08:12 +00007201
Douglas Gregordb121ba2009-12-14 16:27:04 +00007202 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7203 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007204 move_arg(Args),
7205 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007206 E->getConstructionKind(),
7207 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007208}
Mike Stump11289f42009-09-09 15:08:12 +00007209
Douglas Gregora16548e2009-08-11 05:31:07 +00007210/// \brief Transform a C++ temporary-binding expression.
7211///
Douglas Gregor363b1512009-12-24 18:51:59 +00007212/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7213/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007215ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007216TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007217 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007218}
Mike Stump11289f42009-09-09 15:08:12 +00007219
John McCall5d413782010-12-06 08:20:24 +00007220/// \brief Transform a C++ expression that contains cleanups that should
7221/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007222///
John McCall5d413782010-12-06 08:20:24 +00007223/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007224/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007226ExprResult
John McCall5d413782010-12-06 08:20:24 +00007227TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007228 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007229}
Mike Stump11289f42009-09-09 15:08:12 +00007230
Douglas Gregora16548e2009-08-11 05:31:07 +00007231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007232ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007233TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007234 CXXTemporaryObjectExpr *E) {
7235 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7236 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007237 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007238
Douglas Gregora16548e2009-08-11 05:31:07 +00007239 CXXConstructorDecl *Constructor
7240 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007241 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007242 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007243 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007244 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007245
Douglas Gregora16548e2009-08-11 05:31:07 +00007246 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007247 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007248 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007249 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7250 &ArgumentChanged))
7251 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007252
Douglas Gregora16548e2009-08-11 05:31:07 +00007253 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007254 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007255 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007256 !ArgumentChanged) {
7257 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007258 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007259 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007260 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007261
7262 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7263 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007264 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007265 E->getLocEnd());
7266}
Mike Stump11289f42009-09-09 15:08:12 +00007267
Douglas Gregora16548e2009-08-11 05:31:07 +00007268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007269ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007270TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007271 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007272 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7273 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007274 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007275
Douglas Gregora16548e2009-08-11 05:31:07 +00007276 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007277 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007278 Args.reserve(E->arg_size());
7279 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7280 &ArgumentChanged))
7281 return ExprError();
7282
Douglas Gregora16548e2009-08-11 05:31:07 +00007283 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007284 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007285 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007286 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007287
Douglas Gregora16548e2009-08-11 05:31:07 +00007288 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007289 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007290 E->getLParenLoc(),
7291 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007292 E->getRParenLoc());
7293}
Mike Stump11289f42009-09-09 15:08:12 +00007294
Douglas Gregora16548e2009-08-11 05:31:07 +00007295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007296ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007297TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007298 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007299 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007300 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007301 Expr *OldBase;
7302 QualType BaseType;
7303 QualType ObjectType;
7304 if (!E->isImplicitAccess()) {
7305 OldBase = E->getBase();
7306 Base = getDerived().TransformExpr(OldBase);
7307 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007308 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007309
John McCall2d74de92009-12-01 22:10:20 +00007310 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007311 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007312 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007313 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007314 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007315 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007316 ObjectTy,
7317 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007318 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007319 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007320
John McCallba7bf592010-08-24 05:47:05 +00007321 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007322 BaseType = ((Expr*) Base.get())->getType();
7323 } else {
7324 OldBase = 0;
7325 BaseType = getDerived().TransformType(E->getBaseType());
7326 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7327 }
Mike Stump11289f42009-09-09 15:08:12 +00007328
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007329 // Transform the first part of the nested-name-specifier that qualifies
7330 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007331 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007332 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007333 E->getFirstQualifierFoundInScope(),
7334 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007335
Douglas Gregore16af532011-02-28 18:50:33 +00007336 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007337 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007338 QualifierLoc
7339 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7340 ObjectType,
7341 FirstQualifierInScope);
7342 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007343 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007344 }
Mike Stump11289f42009-09-09 15:08:12 +00007345
John McCall31f82722010-11-12 08:19:04 +00007346 // TODO: If this is a conversion-function-id, verify that the
7347 // destination type name (if present) resolves the same way after
7348 // instantiation as it did in the local scope.
7349
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007350 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007351 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007352 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007353 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007354
John McCall2d74de92009-12-01 22:10:20 +00007355 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007356 // This is a reference to a member without an explicitly-specified
7357 // template argument list. Optimize for this common case.
7358 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007359 Base.get() == OldBase &&
7360 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007361 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007362 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007363 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007364 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007365
John McCallb268a282010-08-23 23:25:46 +00007366 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007367 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007368 E->isArrow(),
7369 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007370 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007371 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007372 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007373 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007374 }
7375
John McCall6b51f282009-11-23 01:53:49 +00007376 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007377 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7378 E->getNumTemplateArgs(),
7379 TransArgs))
7380 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007381
John McCallb268a282010-08-23 23:25:46 +00007382 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007383 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007384 E->isArrow(),
7385 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007386 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007387 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007388 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007389 &TransArgs);
7390}
7391
7392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007393ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007394TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007395 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007396 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007397 QualType BaseType;
7398 if (!Old->isImplicitAccess()) {
7399 Base = getDerived().TransformExpr(Old->getBase());
7400 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007401 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007402 BaseType = ((Expr*) Base.get())->getType();
7403 } else {
7404 BaseType = getDerived().TransformType(Old->getBaseType());
7405 }
John McCall10eae182009-11-30 22:42:35 +00007406
Douglas Gregor0da1d432011-02-28 20:01:57 +00007407 NestedNameSpecifierLoc QualifierLoc;
7408 if (Old->getQualifierLoc()) {
7409 QualifierLoc
7410 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7411 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007412 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007413 }
7414
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007415 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007416 Sema::LookupOrdinaryName);
7417
7418 // Transform all the decls.
7419 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7420 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007421 NamedDecl *InstD = static_cast<NamedDecl*>(
7422 getDerived().TransformDecl(Old->getMemberLoc(),
7423 *I));
John McCall84d87672009-12-10 09:41:52 +00007424 if (!InstD) {
7425 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7426 // This can happen because of dependent hiding.
7427 if (isa<UsingShadowDecl>(*I))
7428 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007429 else {
7430 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007431 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007432 }
John McCall84d87672009-12-10 09:41:52 +00007433 }
John McCall10eae182009-11-30 22:42:35 +00007434
7435 // Expand using declarations.
7436 if (isa<UsingDecl>(InstD)) {
7437 UsingDecl *UD = cast<UsingDecl>(InstD);
7438 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7439 E = UD->shadow_end(); I != E; ++I)
7440 R.addDecl(*I);
7441 continue;
7442 }
7443
7444 R.addDecl(InstD);
7445 }
7446
7447 R.resolveKind();
7448
Douglas Gregor9262f472010-04-27 18:19:34 +00007449 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007450 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007451 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007452 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007453 Old->getMemberLoc(),
7454 Old->getNamingClass()));
7455 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007456 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007457
Douglas Gregorda7be082010-04-27 16:10:10 +00007458 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007459 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007460
John McCall10eae182009-11-30 22:42:35 +00007461 TemplateArgumentListInfo TransArgs;
7462 if (Old->hasExplicitTemplateArgs()) {
7463 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7464 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007465 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7466 Old->getNumTemplateArgs(),
7467 TransArgs))
7468 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007469 }
John McCall38836f02010-01-15 08:34:02 +00007470
7471 // FIXME: to do this check properly, we will need to preserve the
7472 // first-qualifier-in-scope here, just in case we had a dependent
7473 // base (and therefore couldn't do the check) and a
7474 // nested-name-qualifier (and therefore could do the lookup).
7475 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007476
John McCallb268a282010-08-23 23:25:46 +00007477 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007478 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007479 Old->getOperatorLoc(),
7480 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007481 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007482 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007483 R,
7484 (Old->hasExplicitTemplateArgs()
7485 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007486}
7487
7488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007489ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007490TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7491 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7492 if (SubExpr.isInvalid())
7493 return ExprError();
7494
7495 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007496 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007497
7498 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7499}
7500
7501template<typename Derived>
7502ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007503TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007504 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7505 if (Pattern.isInvalid())
7506 return ExprError();
7507
7508 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7509 return SemaRef.Owned(E);
7510
Douglas Gregorb8840002011-01-14 21:20:45 +00007511 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7512 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007513}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007514
7515template<typename Derived>
7516ExprResult
7517TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7518 // If E is not value-dependent, then nothing will change when we transform it.
7519 // Note: This is an instantiation-centric view.
7520 if (!E->isValueDependent())
7521 return SemaRef.Owned(E);
7522
7523 // Note: None of the implementations of TryExpandParameterPacks can ever
7524 // produce a diagnostic when given only a single unexpanded parameter pack,
7525 // so
7526 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7527 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007528 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007529 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007530 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7531 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007532 ShouldExpand, RetainExpansion,
7533 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007534 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007535
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007536 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007537 return SemaRef.Owned(E);
7538
7539 // We now know the length of the parameter pack, so build a new expression
7540 // that stores that length.
7541 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7542 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007543 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007544}
7545
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007546template<typename Derived>
7547ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007548TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7549 SubstNonTypeTemplateParmPackExpr *E) {
7550 // Default behavior is to do nothing with this transformation.
7551 return SemaRef.Owned(E);
7552}
7553
7554template<typename Derived>
7555ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007556TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007557 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007558}
7559
Mike Stump11289f42009-09-09 15:08:12 +00007560template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007561ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007562TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007563 TypeSourceInfo *EncodedTypeInfo
7564 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7565 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007566 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007567
Douglas Gregora16548e2009-08-11 05:31:07 +00007568 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007569 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007570 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007571
7572 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007573 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007574 E->getRParenLoc());
7575}
Mike Stump11289f42009-09-09 15:08:12 +00007576
Douglas Gregora16548e2009-08-11 05:31:07 +00007577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007578ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007579TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007580 // Transform arguments.
7581 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007582 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007583 Args.reserve(E->getNumArgs());
7584 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7585 &ArgChanged))
7586 return ExprError();
7587
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007588 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7589 // Class message: transform the receiver type.
7590 TypeSourceInfo *ReceiverTypeInfo
7591 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7592 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007593 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007594
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007595 // If nothing changed, just retain the existing message send.
7596 if (!getDerived().AlwaysRebuild() &&
7597 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007598 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007599
7600 // Build a new class message send.
7601 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7602 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007603 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007604 E->getMethodDecl(),
7605 E->getLeftLoc(),
7606 move_arg(Args),
7607 E->getRightLoc());
7608 }
7609
7610 // Instance message: transform the receiver
7611 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7612 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007613 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007614 = getDerived().TransformExpr(E->getInstanceReceiver());
7615 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007616 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007617
7618 // If nothing changed, just retain the existing message send.
7619 if (!getDerived().AlwaysRebuild() &&
7620 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007621 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007622
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007623 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007624 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007625 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007626 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007627 E->getMethodDecl(),
7628 E->getLeftLoc(),
7629 move_arg(Args),
7630 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007631}
7632
Mike Stump11289f42009-09-09 15:08:12 +00007633template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007634ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007635TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007636 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007637}
7638
Mike Stump11289f42009-09-09 15:08:12 +00007639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007640ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007641TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007642 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007643}
7644
Mike Stump11289f42009-09-09 15:08:12 +00007645template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007646ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007647TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007648 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007649 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007650 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007651 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007652
7653 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007654
Douglas Gregord51d90d2010-04-26 20:11:03 +00007655 // If nothing changed, just retain the existing expression.
7656 if (!getDerived().AlwaysRebuild() &&
7657 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007658 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007659
John McCallb268a282010-08-23 23:25:46 +00007660 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007661 E->getLocation(),
7662 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007663}
7664
Mike Stump11289f42009-09-09 15:08:12 +00007665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007666ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007667TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007668 // 'super' and types never change. Property never changes. Just
7669 // retain the existing expression.
7670 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007671 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007672
Douglas Gregor9faee212010-04-26 20:47:02 +00007673 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007674 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007675 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007676 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007677
Douglas Gregor9faee212010-04-26 20:47:02 +00007678 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007679
Douglas Gregor9faee212010-04-26 20:47:02 +00007680 // If nothing changed, just retain the existing expression.
7681 if (!getDerived().AlwaysRebuild() &&
7682 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007683 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007684
John McCallb7bd14f2010-12-02 01:19:52 +00007685 if (E->isExplicitProperty())
7686 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7687 E->getExplicitProperty(),
7688 E->getLocation());
7689
7690 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7691 E->getType(),
7692 E->getImplicitPropertyGetter(),
7693 E->getImplicitPropertySetter(),
7694 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007695}
7696
Mike Stump11289f42009-09-09 15:08:12 +00007697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007698ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007699TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007700 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007701 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007702 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007703 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007704
Douglas Gregord51d90d2010-04-26 20:11:03 +00007705 // If nothing changed, just retain the existing expression.
7706 if (!getDerived().AlwaysRebuild() &&
7707 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007708 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007709
John McCallb268a282010-08-23 23:25:46 +00007710 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007711 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007712}
7713
Mike Stump11289f42009-09-09 15:08:12 +00007714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007715ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007716TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007717 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007718 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007719 SubExprs.reserve(E->getNumSubExprs());
7720 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7721 SubExprs, &ArgumentChanged))
7722 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007723
Douglas Gregora16548e2009-08-11 05:31:07 +00007724 if (!getDerived().AlwaysRebuild() &&
7725 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007726 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007727
Douglas Gregora16548e2009-08-11 05:31:07 +00007728 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7729 move_arg(SubExprs),
7730 E->getRParenLoc());
7731}
7732
Mike Stump11289f42009-09-09 15:08:12 +00007733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007734ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007735TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007736 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007737
John McCall490112f2011-02-04 18:33:18 +00007738 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7739 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7740
7741 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00007742 // We built a new blockScopeInfo in call to ActOnBlockStart
7743 // in above, CapturesCXXThis need be set here from the block
7744 // expression.
7745 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7746
John McCall490112f2011-02-04 18:33:18 +00007747 llvm::SmallVector<ParmVarDecl*, 4> params;
7748 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007749
7750 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007751 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7752 oldBlock->param_begin(),
7753 oldBlock->param_size(),
7754 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007755 return true;
John McCall490112f2011-02-04 18:33:18 +00007756
7757 const FunctionType *exprFunctionType = E->getFunctionType();
7758 QualType exprResultType = exprFunctionType->getResultType();
7759 if (!exprResultType.isNull()) {
7760 if (!exprResultType->isDependentType())
7761 blockScope->ReturnType = exprResultType;
7762 else if (exprResultType != getSema().Context.DependentTy)
7763 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007764 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007765
7766 // If the return type has not been determined yet, leave it as a dependent
7767 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007768 if (blockScope->ReturnType.isNull())
7769 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007770
7771 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007772 if (blockScope->ReturnType->isObjCObjectType()) {
7773 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007774 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007775 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007776 return ExprError();
7777 }
John McCall3882ace2011-01-05 12:14:39 +00007778
John McCall490112f2011-02-04 18:33:18 +00007779 QualType functionType = getDerived().RebuildFunctionProtoType(
7780 blockScope->ReturnType,
7781 paramTypes.data(),
7782 paramTypes.size(),
7783 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007784 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007785 exprFunctionType->getExtInfo());
7786 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007787
7788 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007789 if (!params.empty())
7790 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007791
7792 // If the return type wasn't explicitly set, it will have been marked as a
7793 // dependent type (DependentTy); clear out the return type setting so
7794 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007795 if (blockScope->ReturnType == getSema().Context.DependentTy)
7796 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007797
John McCall3882ace2011-01-05 12:14:39 +00007798 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007799 StmtResult body = getDerived().TransformStmt(E->getBody());
7800 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007801 return ExprError();
7802
John McCall490112f2011-02-04 18:33:18 +00007803#ifndef NDEBUG
7804 // In builds with assertions, make sure that we captured everything we
7805 // captured before.
7806
John McCall490112f2011-02-04 18:33:18 +00007807 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7808 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007809 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007810
7811 // Ignore parameter packs.
7812 if (isa<ParmVarDecl>(oldCapture) &&
7813 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7814 continue;
7815
7816 VarDecl *newCapture =
7817 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7818 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007819 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007820 }
7821#endif
7822
7823 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7824 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007825}
7826
Mike Stump11289f42009-09-09 15:08:12 +00007827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007828ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007829TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007830 ValueDecl *ND
7831 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7832 E->getDecl()));
7833 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007834 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007835
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007836 if (!getDerived().AlwaysRebuild() &&
7837 ND == E->getDecl()) {
7838 // Mark it referenced in the new context regardless.
7839 // FIXME: this is a bit instantiation-specific.
7840 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7841
John McCallc3007a22010-10-26 07:05:15 +00007842 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007843 }
7844
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007845 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007846 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007847 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007848}
Mike Stump11289f42009-09-09 15:08:12 +00007849
Douglas Gregora16548e2009-08-11 05:31:07 +00007850//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007851// Type reconstruction
7852//===----------------------------------------------------------------------===//
7853
Mike Stump11289f42009-09-09 15:08:12 +00007854template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007855QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7856 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007857 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007858 getDerived().getBaseEntity());
7859}
7860
Mike Stump11289f42009-09-09 15:08:12 +00007861template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007862QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7863 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007864 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007865 getDerived().getBaseEntity());
7866}
7867
Mike Stump11289f42009-09-09 15:08:12 +00007868template<typename Derived>
7869QualType
John McCall70dd5f62009-10-30 00:06:24 +00007870TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7871 bool WrittenAsLValue,
7872 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007873 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007874 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007875}
7876
7877template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007878QualType
John McCall70dd5f62009-10-30 00:06:24 +00007879TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7880 QualType ClassType,
7881 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007882 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007883 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007884}
7885
7886template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007887QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007888TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7889 ArrayType::ArraySizeModifier SizeMod,
7890 const llvm::APInt *Size,
7891 Expr *SizeExpr,
7892 unsigned IndexTypeQuals,
7893 SourceRange BracketsRange) {
7894 if (SizeExpr || !Size)
7895 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7896 IndexTypeQuals, BracketsRange,
7897 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007898
7899 QualType Types[] = {
7900 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7901 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7902 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007903 };
7904 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7905 QualType SizeType;
7906 for (unsigned I = 0; I != NumTypes; ++I)
7907 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7908 SizeType = Types[I];
7909 break;
7910 }
Mike Stump11289f42009-09-09 15:08:12 +00007911
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007912 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7913 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007914 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007915 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007916 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007917}
Mike Stump11289f42009-09-09 15:08:12 +00007918
Douglas Gregord6ff3322009-08-04 16:50:30 +00007919template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007920QualType
7921TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007922 ArrayType::ArraySizeModifier SizeMod,
7923 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007924 unsigned IndexTypeQuals,
7925 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007926 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007927 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007928}
7929
7930template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007931QualType
Mike Stump11289f42009-09-09 15:08:12 +00007932TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007933 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007934 unsigned IndexTypeQuals,
7935 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007936 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007937 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007938}
Mike Stump11289f42009-09-09 15:08:12 +00007939
Douglas Gregord6ff3322009-08-04 16:50:30 +00007940template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007941QualType
7942TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007943 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007944 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007945 unsigned IndexTypeQuals,
7946 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007947 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007948 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007949 IndexTypeQuals, BracketsRange);
7950}
7951
7952template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007953QualType
7954TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007955 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007956 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007957 unsigned IndexTypeQuals,
7958 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007959 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007960 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007961 IndexTypeQuals, BracketsRange);
7962}
7963
7964template<typename Derived>
7965QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007966 unsigned NumElements,
7967 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007968 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007969 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007970}
Mike Stump11289f42009-09-09 15:08:12 +00007971
Douglas Gregord6ff3322009-08-04 16:50:30 +00007972template<typename Derived>
7973QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7974 unsigned NumElements,
7975 SourceLocation AttributeLoc) {
7976 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7977 NumElements, true);
7978 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007979 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7980 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007981 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007982}
Mike Stump11289f42009-09-09 15:08:12 +00007983
Douglas Gregord6ff3322009-08-04 16:50:30 +00007984template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007985QualType
7986TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007987 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007988 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007989 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007990}
Mike Stump11289f42009-09-09 15:08:12 +00007991
Douglas Gregord6ff3322009-08-04 16:50:30 +00007992template<typename Derived>
7993QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007994 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007995 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007996 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007997 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007998 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007999 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00008000 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008001 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008002 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008003 getDerived().getBaseEntity(),
8004 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008005}
Mike Stump11289f42009-09-09 15:08:12 +00008006
Douglas Gregord6ff3322009-08-04 16:50:30 +00008007template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008008QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8009 return SemaRef.Context.getFunctionNoProtoType(T);
8010}
8011
8012template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008013QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8014 assert(D && "no decl found");
8015 if (D->isInvalidDecl()) return QualType();
8016
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008017 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008018 TypeDecl *Ty;
8019 if (isa<UsingDecl>(D)) {
8020 UsingDecl *Using = cast<UsingDecl>(D);
8021 assert(Using->isTypeName() &&
8022 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8023
8024 // A valid resolved using typename decl points to exactly one type decl.
8025 assert(++Using->shadow_begin() == Using->shadow_end());
8026 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008027
John McCallb96ec562009-12-04 22:46:56 +00008028 } else {
8029 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8030 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8031 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8032 }
8033
8034 return SemaRef.Context.getTypeDeclType(Ty);
8035}
8036
8037template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008038QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8039 SourceLocation Loc) {
8040 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008041}
8042
8043template<typename Derived>
8044QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8045 return SemaRef.Context.getTypeOfType(Underlying);
8046}
8047
8048template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008049QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8050 SourceLocation Loc) {
8051 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008052}
8053
8054template<typename Derived>
8055QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008056 TemplateName Template,
8057 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008058 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008059 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008060}
Mike Stump11289f42009-09-09 15:08:12 +00008061
Douglas Gregor1135c352009-08-06 05:28:30 +00008062template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008063TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008064TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008065 bool TemplateKW,
8066 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008067 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008068 Template);
8069}
8070
8071template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008072TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008073TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8074 const IdentifierInfo &Name,
8075 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008076 QualType ObjectType,
8077 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008078 UnqualifiedId TemplateName;
8079 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008080 Sema::TemplateTy Template;
8081 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008082 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008083 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008084 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008085 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008086 /*EnteringContext=*/false,
8087 Template);
John McCall31f82722010-11-12 08:19:04 +00008088 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008089}
Mike Stump11289f42009-09-09 15:08:12 +00008090
Douglas Gregora16548e2009-08-11 05:31:07 +00008091template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008092TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008093TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008094 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008095 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008096 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008097 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008098 // FIXME: Bogus location information.
8099 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8100 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008101 Sema::TemplateTy Template;
8102 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008103 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008104 SS,
8105 Name,
John McCallba7bf592010-08-24 05:47:05 +00008106 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008107 /*EnteringContext=*/false,
8108 Template);
8109 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008110}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008111
Douglas Gregor71395fa2009-11-04 00:56:37 +00008112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008113ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008114TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8115 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008116 Expr *OrigCallee,
8117 Expr *First,
8118 Expr *Second) {
8119 Expr *Callee = OrigCallee->IgnoreParenCasts();
8120 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008121
Douglas Gregora16548e2009-08-11 05:31:07 +00008122 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008123 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008124 if (!First->getType()->isOverloadableType() &&
8125 !Second->getType()->isOverloadableType())
8126 return getSema().CreateBuiltinArraySubscriptExpr(First,
8127 Callee->getLocStart(),
8128 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008129 } else if (Op == OO_Arrow) {
8130 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008131 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8132 } else if (Second == 0 || isPostIncDec) {
8133 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008134 // The argument is not of overloadable type, so try to create a
8135 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008136 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008137 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008138
John McCallb268a282010-08-23 23:25:46 +00008139 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008140 }
8141 } else {
John McCallb268a282010-08-23 23:25:46 +00008142 if (!First->getType()->isOverloadableType() &&
8143 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008144 // Neither of the arguments is an overloadable type, so try to
8145 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008146 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008147 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008148 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008149 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008150 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008151
Douglas Gregora16548e2009-08-11 05:31:07 +00008152 return move(Result);
8153 }
8154 }
Mike Stump11289f42009-09-09 15:08:12 +00008155
8156 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008157 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008158 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008159
John McCallb268a282010-08-23 23:25:46 +00008160 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008161 assert(ULE->requiresADL());
8162
8163 // FIXME: Do we have to check
8164 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008165 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008166 } else {
John McCallb268a282010-08-23 23:25:46 +00008167 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008168 }
Mike Stump11289f42009-09-09 15:08:12 +00008169
Douglas Gregora16548e2009-08-11 05:31:07 +00008170 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008171 Expr *Args[2] = { First, Second };
8172 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008173
Douglas Gregora16548e2009-08-11 05:31:07 +00008174 // Create the overloaded operator invocation for unary operators.
8175 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008176 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008178 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008179 }
Mike Stump11289f42009-09-09 15:08:12 +00008180
Sebastian Redladba46e2009-10-29 20:17:01 +00008181 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00008182 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00008183 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008184 First,
8185 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00008186
Douglas Gregora16548e2009-08-11 05:31:07 +00008187 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008188 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008189 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008190 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8191 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008192 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008193
Mike Stump11289f42009-09-09 15:08:12 +00008194 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008195}
Mike Stump11289f42009-09-09 15:08:12 +00008196
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008198ExprResult
John McCallb268a282010-08-23 23:25:46 +00008199TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008200 SourceLocation OperatorLoc,
8201 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008202 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008203 TypeSourceInfo *ScopeType,
8204 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008205 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008206 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008207 QualType BaseType = Base->getType();
8208 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008209 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008210 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008211 !BaseType->getAs<PointerType>()->getPointeeType()
8212 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008213 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008214 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008215 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008216 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008217 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008218 /*FIXME?*/true);
8219 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008220
Douglas Gregor678f90d2010-02-25 01:56:36 +00008221 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008222 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8223 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8224 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8225 NameInfo.setNamedTypeInfo(DestroyedType);
8226
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008227 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008228
John McCallb268a282010-08-23 23:25:46 +00008229 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008230 OperatorLoc, isArrow,
8231 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008232 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008233 /*TemplateArgs*/ 0);
8234}
8235
Douglas Gregord6ff3322009-08-04 16:50:30 +00008236} // end namespace clang
8237
8238#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H