blob: da60fccf7ed4380e3e640efb399efc23a2631831 [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 }
2571
2572 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2573 << TL.getType() << SS.getRange();
2574 return NestedNameSpecifierLoc();
2575 }
Douglas Gregore16af532011-02-28 18:50:33 +00002576 }
Douglas Gregor14454802011-02-25 02:25:35 +00002577
Douglas Gregore16af532011-02-28 18:50:33 +00002578 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002579 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002580 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002581 }
2582
2583 // Don't rebuild the nested-name-specifier if we don't have to.
2584 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2585 !getDerived().AlwaysRebuild())
2586 return NNS;
2587
2588 // If we can re-use the source-location data from the original
2589 // nested-name-specifier, do so.
2590 if (SS.location_size() == NNS.getDataLength() &&
2591 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2592 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2593
2594 // Allocate new nested-name-specifier location information.
2595 return SS.getWithLocInContext(SemaRef.Context);
2596}
2597
2598template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002599DeclarationNameInfo
2600TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002601::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002602 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002603 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002604 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002605
2606 switch (Name.getNameKind()) {
2607 case DeclarationName::Identifier:
2608 case DeclarationName::ObjCZeroArgSelector:
2609 case DeclarationName::ObjCOneArgSelector:
2610 case DeclarationName::ObjCMultiArgSelector:
2611 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002612 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002613 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002614 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002615
Douglas Gregorf816bd72009-09-03 22:13:48 +00002616 case DeclarationName::CXXConstructorName:
2617 case DeclarationName::CXXDestructorName:
2618 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002619 TypeSourceInfo *NewTInfo;
2620 CanQualType NewCanTy;
2621 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002622 NewTInfo = getDerived().TransformType(OldTInfo);
2623 if (!NewTInfo)
2624 return DeclarationNameInfo();
2625 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002626 }
2627 else {
2628 NewTInfo = 0;
2629 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002630 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002631 if (NewT.isNull())
2632 return DeclarationNameInfo();
2633 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2634 }
Mike Stump11289f42009-09-09 15:08:12 +00002635
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002636 DeclarationName NewName
2637 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2638 NewCanTy);
2639 DeclarationNameInfo NewNameInfo(NameInfo);
2640 NewNameInfo.setName(NewName);
2641 NewNameInfo.setNamedTypeInfo(NewTInfo);
2642 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002643 }
Mike Stump11289f42009-09-09 15:08:12 +00002644 }
2645
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002646 assert(0 && "Unknown name kind.");
2647 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002648}
2649
2650template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002651TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002652TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2653 TemplateName Name,
2654 SourceLocation NameLoc,
2655 QualType ObjectType,
2656 NamedDecl *FirstQualifierInScope) {
2657 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2658 TemplateDecl *Template = QTN->getTemplateDecl();
2659 assert(Template && "qualified template name must refer to a template");
2660
2661 TemplateDecl *TransTemplate
2662 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2663 Template));
2664 if (!TransTemplate)
2665 return TemplateName();
2666
2667 if (!getDerived().AlwaysRebuild() &&
2668 SS.getScopeRep() == QTN->getQualifier() &&
2669 TransTemplate == Template)
2670 return Name;
2671
2672 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2673 TransTemplate);
2674 }
2675
2676 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2677 if (SS.getScopeRep()) {
2678 // These apply to the scope specifier, not the template.
2679 ObjectType = QualType();
2680 FirstQualifierInScope = 0;
2681 }
2682
2683 if (!getDerived().AlwaysRebuild() &&
2684 SS.getScopeRep() == DTN->getQualifier() &&
2685 ObjectType.isNull())
2686 return Name;
2687
2688 if (DTN->isIdentifier()) {
2689 return getDerived().RebuildTemplateName(SS,
2690 *DTN->getIdentifier(),
2691 NameLoc,
2692 ObjectType,
2693 FirstQualifierInScope);
2694 }
2695
2696 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2697 ObjectType);
2698 }
2699
2700 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2701 TemplateDecl *TransTemplate
2702 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2703 Template));
2704 if (!TransTemplate)
2705 return TemplateName();
2706
2707 if (!getDerived().AlwaysRebuild() &&
2708 TransTemplate == Template)
2709 return Name;
2710
2711 return TemplateName(TransTemplate);
2712 }
2713
2714 if (SubstTemplateTemplateParmPackStorage *SubstPack
2715 = Name.getAsSubstTemplateTemplateParmPack()) {
2716 TemplateTemplateParmDecl *TransParam
2717 = cast_or_null<TemplateTemplateParmDecl>(
2718 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2719 if (!TransParam)
2720 return TemplateName();
2721
2722 if (!getDerived().AlwaysRebuild() &&
2723 TransParam == SubstPack->getParameterPack())
2724 return Name;
2725
2726 return getDerived().RebuildTemplateName(TransParam,
2727 SubstPack->getArgumentPack());
2728 }
2729
2730 // These should be getting filtered out before they reach the AST.
2731 llvm_unreachable("overloaded function decl survived to here");
2732 return TemplateName();
2733}
2734
2735template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002736void TreeTransform<Derived>::InventTemplateArgumentLoc(
2737 const TemplateArgument &Arg,
2738 TemplateArgumentLoc &Output) {
2739 SourceLocation Loc = getDerived().getBaseLocation();
2740 switch (Arg.getKind()) {
2741 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002742 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002743 break;
2744
2745 case TemplateArgument::Type:
2746 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002747 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002748
John McCall0ad16662009-10-29 08:12:44 +00002749 break;
2750
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002751 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002752 case TemplateArgument::TemplateExpansion: {
2753 NestedNameSpecifierLocBuilder Builder;
2754 TemplateName Template = Arg.getAsTemplate();
2755 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2756 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2757 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2758 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2759
2760 if (Arg.getKind() == TemplateArgument::Template)
2761 Output = TemplateArgumentLoc(Arg,
2762 Builder.getWithLocInContext(SemaRef.Context),
2763 Loc);
2764 else
2765 Output = TemplateArgumentLoc(Arg,
2766 Builder.getWithLocInContext(SemaRef.Context),
2767 Loc, Loc);
2768
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002769 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002770 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002771
John McCall0ad16662009-10-29 08:12:44 +00002772 case TemplateArgument::Expression:
2773 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2774 break;
2775
2776 case TemplateArgument::Declaration:
2777 case TemplateArgument::Integral:
2778 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002779 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002780 break;
2781 }
2782}
2783
2784template<typename Derived>
2785bool TreeTransform<Derived>::TransformTemplateArgument(
2786 const TemplateArgumentLoc &Input,
2787 TemplateArgumentLoc &Output) {
2788 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002789 switch (Arg.getKind()) {
2790 case TemplateArgument::Null:
2791 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002792 Output = Input;
2793 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002794
Douglas Gregore922c772009-08-04 22:27:00 +00002795 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002796 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002797 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002798 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002799
2800 DI = getDerived().TransformType(DI);
2801 if (!DI) return true;
2802
2803 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2804 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002805 }
Mike Stump11289f42009-09-09 15:08:12 +00002806
Douglas Gregore922c772009-08-04 22:27:00 +00002807 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002808 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002809 DeclarationName Name;
2810 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2811 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002812 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002813 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002814 if (!D) return true;
2815
John McCall0d07eb32009-10-29 18:45:58 +00002816 Expr *SourceExpr = Input.getSourceDeclExpression();
2817 if (SourceExpr) {
2818 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002819 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002820 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002821 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002822 }
2823
2824 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002825 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002826 }
Mike Stump11289f42009-09-09 15:08:12 +00002827
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002828 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002829 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2830 if (QualifierLoc) {
2831 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2832 if (!QualifierLoc)
2833 return true;
2834 }
2835
Douglas Gregordf846d12011-03-02 18:46:51 +00002836 CXXScopeSpec SS;
2837 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002838 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002839 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2840 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002841 if (Template.isNull())
2842 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002843
Douglas Gregor9d802122011-03-02 17:09:35 +00002844 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002845 Input.getTemplateNameLoc());
2846 return false;
2847 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002848
2849 case TemplateArgument::TemplateExpansion:
2850 llvm_unreachable("Caller should expand pack expansions");
2851
Douglas Gregore922c772009-08-04 22:27:00 +00002852 case TemplateArgument::Expression: {
2853 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002854 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002855 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002856
John McCall0ad16662009-10-29 08:12:44 +00002857 Expr *InputExpr = Input.getSourceExpression();
2858 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2859
Chris Lattnercdb591a2011-04-25 20:37:58 +00002860 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002861 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002862 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002863 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002864 }
Mike Stump11289f42009-09-09 15:08:12 +00002865
Douglas Gregore922c772009-08-04 22:27:00 +00002866 case TemplateArgument::Pack: {
2867 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2868 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002869 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002870 AEnd = Arg.pack_end();
2871 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002872
John McCall0ad16662009-10-29 08:12:44 +00002873 // FIXME: preserve source information here when we start
2874 // caring about parameter packs.
2875
John McCall0d07eb32009-10-29 18:45:58 +00002876 TemplateArgumentLoc InputArg;
2877 TemplateArgumentLoc OutputArg;
2878 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2879 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002880 return true;
2881
John McCall0d07eb32009-10-29 18:45:58 +00002882 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002883 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002884
2885 TemplateArgument *TransformedArgsPtr
2886 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2887 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2888 TransformedArgsPtr);
2889 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2890 TransformedArgs.size()),
2891 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002892 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002893 }
2894 }
Mike Stump11289f42009-09-09 15:08:12 +00002895
Douglas Gregore922c772009-08-04 22:27:00 +00002896 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002897 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002898}
2899
Douglas Gregorfe921a72010-12-20 23:36:19 +00002900/// \brief Iterator adaptor that invents template argument location information
2901/// for each of the template arguments in its underlying iterator.
2902template<typename Derived, typename InputIterator>
2903class TemplateArgumentLocInventIterator {
2904 TreeTransform<Derived> &Self;
2905 InputIterator Iter;
2906
2907public:
2908 typedef TemplateArgumentLoc value_type;
2909 typedef TemplateArgumentLoc reference;
2910 typedef typename std::iterator_traits<InputIterator>::difference_type
2911 difference_type;
2912 typedef std::input_iterator_tag iterator_category;
2913
2914 class pointer {
2915 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002916
Douglas Gregorfe921a72010-12-20 23:36:19 +00002917 public:
2918 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2919
2920 const TemplateArgumentLoc *operator->() const { return &Arg; }
2921 };
2922
2923 TemplateArgumentLocInventIterator() { }
2924
2925 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2926 InputIterator Iter)
2927 : Self(Self), Iter(Iter) { }
2928
2929 TemplateArgumentLocInventIterator &operator++() {
2930 ++Iter;
2931 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002932 }
2933
Douglas Gregorfe921a72010-12-20 23:36:19 +00002934 TemplateArgumentLocInventIterator operator++(int) {
2935 TemplateArgumentLocInventIterator Old(*this);
2936 ++(*this);
2937 return Old;
2938 }
2939
2940 reference operator*() const {
2941 TemplateArgumentLoc Result;
2942 Self.InventTemplateArgumentLoc(*Iter, Result);
2943 return Result;
2944 }
2945
2946 pointer operator->() const { return pointer(**this); }
2947
2948 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2949 const TemplateArgumentLocInventIterator &Y) {
2950 return X.Iter == Y.Iter;
2951 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002952
Douglas Gregorfe921a72010-12-20 23:36:19 +00002953 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2954 const TemplateArgumentLocInventIterator &Y) {
2955 return X.Iter != Y.Iter;
2956 }
2957};
2958
Douglas Gregor42cafa82010-12-20 17:42:22 +00002959template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002960template<typename InputIterator>
2961bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2962 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002963 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002964 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002965 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002966 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002967
2968 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2969 // Unpack argument packs, which we translate them into separate
2970 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002971 // FIXME: We could do much better if we could guarantee that the
2972 // TemplateArgumentLocInfo for the pack expansion would be usable for
2973 // all of the template arguments in the argument pack.
2974 typedef TemplateArgumentLocInventIterator<Derived,
2975 TemplateArgument::pack_iterator>
2976 PackLocIterator;
2977 if (TransformTemplateArguments(PackLocIterator(*this,
2978 In.getArgument().pack_begin()),
2979 PackLocIterator(*this,
2980 In.getArgument().pack_end()),
2981 Outputs))
2982 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002983
2984 continue;
2985 }
2986
2987 if (In.getArgument().isPackExpansion()) {
2988 // We have a pack expansion, for which we will be substituting into
2989 // the pattern.
2990 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002991 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002992 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002993 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2994 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002995
2996 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2997 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2998 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2999
3000 // Determine whether the set of unexpanded parameter packs can and should
3001 // be expanded.
3002 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003003 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003004 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003005 if (getDerived().TryExpandParameterPacks(Ellipsis,
3006 Pattern.getSourceRange(),
3007 Unexpanded.data(),
3008 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003009 Expand,
3010 RetainExpansion,
3011 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003012 return true;
3013
3014 if (!Expand) {
3015 // The transform has determined that we should perform a simple
3016 // transformation on the pack expansion, producing another pack
3017 // expansion.
3018 TemplateArgumentLoc OutPattern;
3019 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3020 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3021 return true;
3022
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003023 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3024 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003025 if (Out.getArgument().isNull())
3026 return true;
3027
3028 Outputs.addArgument(Out);
3029 continue;
3030 }
3031
3032 // The transform has determined that we should perform an elementwise
3033 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003034 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003035 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3036
3037 if (getDerived().TransformTemplateArgument(Pattern, Out))
3038 return true;
3039
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003040 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003041 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3042 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003043 if (Out.getArgument().isNull())
3044 return true;
3045 }
3046
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003047 Outputs.addArgument(Out);
3048 }
3049
Douglas Gregor48d24112011-01-10 20:53:55 +00003050 // If we're supposed to retain a pack expansion, do so by temporarily
3051 // forgetting the partially-substituted parameter pack.
3052 if (RetainExpansion) {
3053 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3054
3055 if (getDerived().TransformTemplateArgument(Pattern, Out))
3056 return true;
3057
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003058 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3059 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003060 if (Out.getArgument().isNull())
3061 return true;
3062
3063 Outputs.addArgument(Out);
3064 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003065
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003066 continue;
3067 }
3068
3069 // The simple case:
3070 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003071 return true;
3072
3073 Outputs.addArgument(Out);
3074 }
3075
3076 return false;
3077
3078}
3079
Douglas Gregord6ff3322009-08-04 16:50:30 +00003080//===----------------------------------------------------------------------===//
3081// Type transformation
3082//===----------------------------------------------------------------------===//
3083
3084template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003085QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003086 if (getDerived().AlreadyTransformed(T))
3087 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003088
John McCall550e0c22009-10-21 00:40:46 +00003089 // Temporary workaround. All of these transformations should
3090 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003091 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3092 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003093
John McCall31f82722010-11-12 08:19:04 +00003094 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003095
John McCall550e0c22009-10-21 00:40:46 +00003096 if (!NewDI)
3097 return QualType();
3098
3099 return NewDI->getType();
3100}
3101
3102template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003103TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003104 if (getDerived().AlreadyTransformed(DI->getType()))
3105 return DI;
3106
3107 TypeLocBuilder TLB;
3108
3109 TypeLoc TL = DI->getTypeLoc();
3110 TLB.reserve(TL.getFullDataSize());
3111
John McCall31f82722010-11-12 08:19:04 +00003112 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003113 if (Result.isNull())
3114 return 0;
3115
John McCallbcd03502009-12-07 02:54:59 +00003116 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003117}
3118
3119template<typename Derived>
3120QualType
John McCall31f82722010-11-12 08:19:04 +00003121TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003122 switch (T.getTypeLocClass()) {
3123#define ABSTRACT_TYPELOC(CLASS, PARENT)
3124#define TYPELOC(CLASS, PARENT) \
3125 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003126 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003127#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003128 }
Mike Stump11289f42009-09-09 15:08:12 +00003129
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003130 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003131 return QualType();
3132}
3133
3134/// FIXME: By default, this routine adds type qualifiers only to types
3135/// that can have qualifiers, and silently suppresses those qualifiers
3136/// that are not permitted (e.g., qualifiers on reference or function
3137/// types). This is the right thing for template instantiation, but
3138/// probably not for other clients.
3139template<typename Derived>
3140QualType
3141TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003142 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003143 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003144
John McCall31f82722010-11-12 08:19:04 +00003145 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003146 if (Result.isNull())
3147 return QualType();
3148
3149 // Silently suppress qualifiers if the result type can't be qualified.
3150 // FIXME: this is the right thing for template instantiation, but
3151 // probably not for other clients.
3152 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003153 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003154
John McCallcb0f89a2010-06-05 06:41:15 +00003155 if (!Quals.empty()) {
3156 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3157 TLB.push<QualifiedTypeLoc>(Result);
3158 // No location information to preserve.
3159 }
John McCall550e0c22009-10-21 00:40:46 +00003160
3161 return Result;
3162}
3163
Douglas Gregor14454802011-02-25 02:25:35 +00003164template<typename Derived>
3165TypeLoc
3166TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3167 QualType ObjectType,
3168 NamedDecl *UnqualLookup,
3169 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003170 QualType T = TL.getType();
3171 if (getDerived().AlreadyTransformed(T))
3172 return TL;
3173
3174 TypeLocBuilder TLB;
3175 QualType Result;
3176
3177 if (isa<TemplateSpecializationType>(T)) {
3178 TemplateSpecializationTypeLoc SpecTL
3179 = cast<TemplateSpecializationTypeLoc>(TL);
3180
3181 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003182 getDerived().TransformTemplateName(SS,
3183 SpecTL.getTypePtr()->getTemplateName(),
3184 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003185 ObjectType, UnqualLookup);
3186 if (Template.isNull())
3187 return TypeLoc();
3188
3189 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3190 Template);
3191 } else if (isa<DependentTemplateSpecializationType>(T)) {
3192 DependentTemplateSpecializationTypeLoc SpecTL
3193 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3194
Douglas Gregor5a064722011-02-28 17:23:35 +00003195 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003196 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003197 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003198 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003199 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003200 if (Template.isNull())
3201 return TypeLoc();
3202
Douglas Gregor14454802011-02-25 02:25:35 +00003203 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003204 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003205 Template,
3206 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003207 } else {
3208 // Nothing special needs to be done for these.
3209 Result = getDerived().TransformType(TLB, TL);
3210 }
3211
3212 if (Result.isNull())
3213 return TypeLoc();
3214
3215 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3216}
3217
Douglas Gregor579c15f2011-03-02 18:32:08 +00003218template<typename Derived>
3219TypeSourceInfo *
3220TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3221 QualType ObjectType,
3222 NamedDecl *UnqualLookup,
3223 CXXScopeSpec &SS) {
3224 // FIXME: Painfully copy-paste from the above!
3225
3226 QualType T = TSInfo->getType();
3227 if (getDerived().AlreadyTransformed(T))
3228 return TSInfo;
3229
3230 TypeLocBuilder TLB;
3231 QualType Result;
3232
3233 TypeLoc TL = TSInfo->getTypeLoc();
3234 if (isa<TemplateSpecializationType>(T)) {
3235 TemplateSpecializationTypeLoc SpecTL
3236 = cast<TemplateSpecializationTypeLoc>(TL);
3237
3238 TemplateName Template
3239 = getDerived().TransformTemplateName(SS,
3240 SpecTL.getTypePtr()->getTemplateName(),
3241 SpecTL.getTemplateNameLoc(),
3242 ObjectType, UnqualLookup);
3243 if (Template.isNull())
3244 return 0;
3245
3246 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3247 Template);
3248 } else if (isa<DependentTemplateSpecializationType>(T)) {
3249 DependentTemplateSpecializationTypeLoc SpecTL
3250 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3251
3252 TemplateName Template
3253 = getDerived().RebuildTemplateName(SS,
3254 *SpecTL.getTypePtr()->getIdentifier(),
3255 SpecTL.getNameLoc(),
3256 ObjectType, UnqualLookup);
3257 if (Template.isNull())
3258 return 0;
3259
3260 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3261 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003262 Template,
3263 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003264 } else {
3265 // Nothing special needs to be done for these.
3266 Result = getDerived().TransformType(TLB, TL);
3267 }
3268
3269 if (Result.isNull())
3270 return 0;
3271
3272 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3273}
3274
John McCall550e0c22009-10-21 00:40:46 +00003275template <class TyLoc> static inline
3276QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3277 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3278 NewT.setNameLoc(T.getNameLoc());
3279 return T.getType();
3280}
3281
John McCall550e0c22009-10-21 00:40:46 +00003282template<typename Derived>
3283QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003284 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003285 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3286 NewT.setBuiltinLoc(T.getBuiltinLoc());
3287 if (T.needsExtraLocalData())
3288 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3289 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003290}
Mike Stump11289f42009-09-09 15:08:12 +00003291
Douglas Gregord6ff3322009-08-04 16:50:30 +00003292template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003293QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003294 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003295 // FIXME: recurse?
3296 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003297}
Mike Stump11289f42009-09-09 15:08:12 +00003298
Douglas Gregord6ff3322009-08-04 16:50:30 +00003299template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003300QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003301 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003302 QualType PointeeType
3303 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003304 if (PointeeType.isNull())
3305 return QualType();
3306
3307 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003308 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003309 // A dependent pointer type 'T *' has is being transformed such
3310 // that an Objective-C class type is being replaced for 'T'. The
3311 // resulting pointer type is an ObjCObjectPointerType, not a
3312 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003313 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003314
John McCall8b07ec22010-05-15 11:32:37 +00003315 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3316 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003317 return Result;
3318 }
John McCall31f82722010-11-12 08:19:04 +00003319
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003320 if (getDerived().AlwaysRebuild() ||
3321 PointeeType != TL.getPointeeLoc().getType()) {
3322 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3323 if (Result.isNull())
3324 return QualType();
3325 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003326
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003327 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3328 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003329 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003330}
Mike Stump11289f42009-09-09 15:08:12 +00003331
3332template<typename Derived>
3333QualType
John McCall550e0c22009-10-21 00:40:46 +00003334TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003335 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003336 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003337 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3338 if (PointeeType.isNull())
3339 return QualType();
3340
3341 QualType Result = TL.getType();
3342 if (getDerived().AlwaysRebuild() ||
3343 PointeeType != TL.getPointeeLoc().getType()) {
3344 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003345 TL.getSigilLoc());
3346 if (Result.isNull())
3347 return QualType();
3348 }
3349
Douglas Gregor049211a2010-04-22 16:50:51 +00003350 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003351 NewT.setSigilLoc(TL.getSigilLoc());
3352 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003353}
3354
John McCall70dd5f62009-10-30 00:06:24 +00003355/// Transforms a reference type. Note that somewhat paradoxically we
3356/// don't care whether the type itself is an l-value type or an r-value
3357/// type; we only care if the type was *written* as an l-value type
3358/// or an r-value type.
3359template<typename Derived>
3360QualType
3361TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003362 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003363 const ReferenceType *T = TL.getTypePtr();
3364
3365 // Note that this works with the pointee-as-written.
3366 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3367 if (PointeeType.isNull())
3368 return QualType();
3369
3370 QualType Result = TL.getType();
3371 if (getDerived().AlwaysRebuild() ||
3372 PointeeType != T->getPointeeTypeAsWritten()) {
3373 Result = getDerived().RebuildReferenceType(PointeeType,
3374 T->isSpelledAsLValue(),
3375 TL.getSigilLoc());
3376 if (Result.isNull())
3377 return QualType();
3378 }
3379
3380 // r-value references can be rebuilt as l-value references.
3381 ReferenceTypeLoc NewTL;
3382 if (isa<LValueReferenceType>(Result))
3383 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3384 else
3385 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3386 NewTL.setSigilLoc(TL.getSigilLoc());
3387
3388 return Result;
3389}
3390
Mike Stump11289f42009-09-09 15:08:12 +00003391template<typename Derived>
3392QualType
John McCall550e0c22009-10-21 00:40:46 +00003393TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003394 LValueReferenceTypeLoc TL) {
3395 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003396}
3397
Mike Stump11289f42009-09-09 15:08:12 +00003398template<typename Derived>
3399QualType
John McCall550e0c22009-10-21 00:40:46 +00003400TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003401 RValueReferenceTypeLoc TL) {
3402 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003403}
Mike Stump11289f42009-09-09 15:08:12 +00003404
Douglas Gregord6ff3322009-08-04 16:50:30 +00003405template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003406QualType
John McCall550e0c22009-10-21 00:40:46 +00003407TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003408 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003409 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003410 if (PointeeType.isNull())
3411 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003412
Abramo Bagnara509357842011-03-05 14:42:21 +00003413 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3414 TypeSourceInfo* NewClsTInfo = 0;
3415 if (OldClsTInfo) {
3416 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3417 if (!NewClsTInfo)
3418 return QualType();
3419 }
3420
3421 const MemberPointerType *T = TL.getTypePtr();
3422 QualType OldClsType = QualType(T->getClass(), 0);
3423 QualType NewClsType;
3424 if (NewClsTInfo)
3425 NewClsType = NewClsTInfo->getType();
3426 else {
3427 NewClsType = getDerived().TransformType(OldClsType);
3428 if (NewClsType.isNull())
3429 return QualType();
3430 }
Mike Stump11289f42009-09-09 15:08:12 +00003431
John McCall550e0c22009-10-21 00:40:46 +00003432 QualType Result = TL.getType();
3433 if (getDerived().AlwaysRebuild() ||
3434 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003435 NewClsType != OldClsType) {
3436 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003437 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003438 if (Result.isNull())
3439 return QualType();
3440 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003441
John McCall550e0c22009-10-21 00:40:46 +00003442 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3443 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003444 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003445
3446 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003447}
3448
Mike Stump11289f42009-09-09 15:08:12 +00003449template<typename Derived>
3450QualType
John McCall550e0c22009-10-21 00:40:46 +00003451TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003452 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003453 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003454 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003455 if (ElementType.isNull())
3456 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003457
John McCall550e0c22009-10-21 00:40:46 +00003458 QualType Result = TL.getType();
3459 if (getDerived().AlwaysRebuild() ||
3460 ElementType != T->getElementType()) {
3461 Result = getDerived().RebuildConstantArrayType(ElementType,
3462 T->getSizeModifier(),
3463 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003464 T->getIndexTypeCVRQualifiers(),
3465 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003466 if (Result.isNull())
3467 return QualType();
3468 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003469
John McCall550e0c22009-10-21 00:40:46 +00003470 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3471 NewTL.setLBracketLoc(TL.getLBracketLoc());
3472 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003473
John McCall550e0c22009-10-21 00:40:46 +00003474 Expr *Size = TL.getSizeExpr();
3475 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003476 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003477 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3478 }
3479 NewTL.setSizeExpr(Size);
3480
3481 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003482}
Mike Stump11289f42009-09-09 15:08:12 +00003483
Douglas Gregord6ff3322009-08-04 16:50:30 +00003484template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003485QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003486 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003487 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003488 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003489 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003490 if (ElementType.isNull())
3491 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003492
John McCall550e0c22009-10-21 00:40:46 +00003493 QualType Result = TL.getType();
3494 if (getDerived().AlwaysRebuild() ||
3495 ElementType != T->getElementType()) {
3496 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003497 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003498 T->getIndexTypeCVRQualifiers(),
3499 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003500 if (Result.isNull())
3501 return QualType();
3502 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003503
John McCall550e0c22009-10-21 00:40:46 +00003504 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3505 NewTL.setLBracketLoc(TL.getLBracketLoc());
3506 NewTL.setRBracketLoc(TL.getRBracketLoc());
3507 NewTL.setSizeExpr(0);
3508
3509 return Result;
3510}
3511
3512template<typename Derived>
3513QualType
3514TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003515 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003516 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003517 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3518 if (ElementType.isNull())
3519 return QualType();
3520
3521 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003522 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003523
John McCalldadc5752010-08-24 06:29:42 +00003524 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003525 = getDerived().TransformExpr(T->getSizeExpr());
3526 if (SizeResult.isInvalid())
3527 return QualType();
3528
John McCallb268a282010-08-23 23:25:46 +00003529 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003530
3531 QualType Result = TL.getType();
3532 if (getDerived().AlwaysRebuild() ||
3533 ElementType != T->getElementType() ||
3534 Size != T->getSizeExpr()) {
3535 Result = getDerived().RebuildVariableArrayType(ElementType,
3536 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003537 Size,
John McCall550e0c22009-10-21 00:40:46 +00003538 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003539 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003540 if (Result.isNull())
3541 return QualType();
3542 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003543
John McCall550e0c22009-10-21 00:40:46 +00003544 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3545 NewTL.setLBracketLoc(TL.getLBracketLoc());
3546 NewTL.setRBracketLoc(TL.getRBracketLoc());
3547 NewTL.setSizeExpr(Size);
3548
3549 return Result;
3550}
3551
3552template<typename Derived>
3553QualType
3554TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003555 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003556 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003557 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3558 if (ElementType.isNull())
3559 return QualType();
3560
3561 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003562 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003563
John McCall33ddac02011-01-19 10:06:00 +00003564 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3565 Expr *origSize = TL.getSizeExpr();
3566 if (!origSize) origSize = T->getSizeExpr();
3567
3568 ExprResult sizeResult
3569 = getDerived().TransformExpr(origSize);
3570 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003571 return QualType();
3572
John McCall33ddac02011-01-19 10:06:00 +00003573 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003574
3575 QualType Result = TL.getType();
3576 if (getDerived().AlwaysRebuild() ||
3577 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003578 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003579 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3580 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003581 size,
John McCall550e0c22009-10-21 00:40:46 +00003582 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003583 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003584 if (Result.isNull())
3585 return QualType();
3586 }
John McCall550e0c22009-10-21 00:40:46 +00003587
3588 // We might have any sort of array type now, but fortunately they
3589 // all have the same location layout.
3590 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3591 NewTL.setLBracketLoc(TL.getLBracketLoc());
3592 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003593 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003594
3595 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003596}
Mike Stump11289f42009-09-09 15:08:12 +00003597
3598template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003599QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003600 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003601 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003602 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003603
3604 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003605 QualType ElementType = getDerived().TransformType(T->getElementType());
3606 if (ElementType.isNull())
3607 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003608
Douglas Gregore922c772009-08-04 22:27:00 +00003609 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003610 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003611
John McCalldadc5752010-08-24 06:29:42 +00003612 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003613 if (Size.isInvalid())
3614 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003615
John McCall550e0c22009-10-21 00:40:46 +00003616 QualType Result = TL.getType();
3617 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003618 ElementType != T->getElementType() ||
3619 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003620 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003621 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003622 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003623 if (Result.isNull())
3624 return QualType();
3625 }
John McCall550e0c22009-10-21 00:40:46 +00003626
3627 // Result might be dependent or not.
3628 if (isa<DependentSizedExtVectorType>(Result)) {
3629 DependentSizedExtVectorTypeLoc NewTL
3630 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3631 NewTL.setNameLoc(TL.getNameLoc());
3632 } else {
3633 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3634 NewTL.setNameLoc(TL.getNameLoc());
3635 }
3636
3637 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003638}
Mike Stump11289f42009-09-09 15:08:12 +00003639
3640template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003641QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003642 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003643 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003644 QualType ElementType = getDerived().TransformType(T->getElementType());
3645 if (ElementType.isNull())
3646 return QualType();
3647
John McCall550e0c22009-10-21 00:40:46 +00003648 QualType Result = TL.getType();
3649 if (getDerived().AlwaysRebuild() ||
3650 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003651 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003652 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003653 if (Result.isNull())
3654 return QualType();
3655 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003656
John McCall550e0c22009-10-21 00:40:46 +00003657 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3658 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003659
John McCall550e0c22009-10-21 00:40:46 +00003660 return Result;
3661}
3662
3663template<typename Derived>
3664QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003665 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003666 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003667 QualType ElementType = getDerived().TransformType(T->getElementType());
3668 if (ElementType.isNull())
3669 return QualType();
3670
3671 QualType Result = TL.getType();
3672 if (getDerived().AlwaysRebuild() ||
3673 ElementType != T->getElementType()) {
3674 Result = getDerived().RebuildExtVectorType(ElementType,
3675 T->getNumElements(),
3676 /*FIXME*/ SourceLocation());
3677 if (Result.isNull())
3678 return QualType();
3679 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003680
John McCall550e0c22009-10-21 00:40:46 +00003681 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3682 NewTL.setNameLoc(TL.getNameLoc());
3683
3684 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003685}
Mike Stump11289f42009-09-09 15:08:12 +00003686
3687template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003688ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003689TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003690 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003691 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003692 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003693 TypeSourceInfo *NewDI = 0;
3694
3695 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3696 // If we're substituting into a pack expansion type and we know the
3697 TypeLoc OldTL = OldDI->getTypeLoc();
3698 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3699
3700 TypeLocBuilder TLB;
3701 TypeLoc NewTL = OldDI->getTypeLoc();
3702 TLB.reserve(NewTL.getFullDataSize());
3703
3704 QualType Result = getDerived().TransformType(TLB,
3705 OldExpansionTL.getPatternLoc());
3706 if (Result.isNull())
3707 return 0;
3708
3709 Result = RebuildPackExpansionType(Result,
3710 OldExpansionTL.getPatternLoc().getSourceRange(),
3711 OldExpansionTL.getEllipsisLoc(),
3712 NumExpansions);
3713 if (Result.isNull())
3714 return 0;
3715
3716 PackExpansionTypeLoc NewExpansionTL
3717 = TLB.push<PackExpansionTypeLoc>(Result);
3718 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3719 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3720 } else
3721 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003722 if (!NewDI)
3723 return 0;
3724
John McCall8fb0d9d2011-05-01 22:35:37 +00003725 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003726 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003727
3728 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3729 OldParm->getDeclContext(),
3730 OldParm->getInnerLocStart(),
3731 OldParm->getLocation(),
3732 OldParm->getIdentifier(),
3733 NewDI->getType(),
3734 NewDI,
3735 OldParm->getStorageClass(),
3736 OldParm->getStorageClassAsWritten(),
3737 /* DefArg */ NULL);
3738 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3739 OldParm->getFunctionScopeIndex() + indexAdjustment);
3740 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003741}
3742
3743template<typename Derived>
3744bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003745 TransformFunctionTypeParams(SourceLocation Loc,
3746 ParmVarDecl **Params, unsigned NumParams,
3747 const QualType *ParamTypes,
3748 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3749 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003750 int indexAdjustment = 0;
3751
Douglas Gregordd472162011-01-07 00:20:55 +00003752 for (unsigned i = 0; i != NumParams; ++i) {
3753 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003754 assert(OldParm->getFunctionScopeIndex() == i);
3755
Douglas Gregor715e4612011-01-14 22:40:04 +00003756 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003757 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003758 if (OldParm->isParameterPack()) {
3759 // We have a function parameter pack that may need to be expanded.
3760 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003761
Douglas Gregor5499af42011-01-05 23:12:31 +00003762 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003763 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3764 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3765 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3766 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003767 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3768
Douglas Gregor5499af42011-01-05 23:12:31 +00003769 // Determine whether we should expand the parameter packs.
3770 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003771 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003772 llvm::Optional<unsigned> OrigNumExpansions
3773 = ExpansionTL.getTypePtr()->getNumExpansions();
3774 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003775 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3776 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003777 Unexpanded.data(),
3778 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003779 ShouldExpand,
3780 RetainExpansion,
3781 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003782 return true;
3783 }
3784
3785 if (ShouldExpand) {
3786 // Expand the function parameter pack into multiple, separate
3787 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003788 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003789 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003790 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3791 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003792 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003793 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003794 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003795 if (!NewParm)
3796 return true;
3797
Douglas Gregordd472162011-01-07 00:20:55 +00003798 OutParamTypes.push_back(NewParm->getType());
3799 if (PVars)
3800 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003801 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003802
3803 // If we're supposed to retain a pack expansion, do so by temporarily
3804 // forgetting the partially-substituted parameter pack.
3805 if (RetainExpansion) {
3806 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3807 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003808 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003809 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003810 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003811 if (!NewParm)
3812 return true;
3813
3814 OutParamTypes.push_back(NewParm->getType());
3815 if (PVars)
3816 PVars->push_back(NewParm);
3817 }
3818
John McCall8fb0d9d2011-05-01 22:35:37 +00003819 // The next parameter should have the same adjustment as the
3820 // last thing we pushed, but we post-incremented indexAdjustment
3821 // on every push. Also, if we push nothing, the adjustment should
3822 // go down by one.
3823 indexAdjustment--;
3824
Douglas Gregor5499af42011-01-05 23:12:31 +00003825 // We're done with the pack expansion.
3826 continue;
3827 }
3828
3829 // We'll substitute the parameter now without expanding the pack
3830 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003831 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3832 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003833 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003834 NumExpansions);
3835 } else {
3836 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003837 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003838 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003839 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003840
John McCall58f10c32010-03-11 09:03:00 +00003841 if (!NewParm)
3842 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003843
Douglas Gregordd472162011-01-07 00:20:55 +00003844 OutParamTypes.push_back(NewParm->getType());
3845 if (PVars)
3846 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003847 continue;
3848 }
John McCall58f10c32010-03-11 09:03:00 +00003849
3850 // Deal with the possibility that we don't have a parameter
3851 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003852 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003853 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003854 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003855 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003856 if (const PackExpansionType *Expansion
3857 = dyn_cast<PackExpansionType>(OldType)) {
3858 // We have a function parameter pack that may need to be expanded.
3859 QualType Pattern = Expansion->getPattern();
3860 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3861 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3862
3863 // Determine whether we should expand the parameter packs.
3864 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003865 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003866 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003867 Unexpanded.data(),
3868 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003869 ShouldExpand,
3870 RetainExpansion,
3871 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003872 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003873 }
3874
3875 if (ShouldExpand) {
3876 // Expand the function parameter pack into multiple, separate
3877 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003878 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003879 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3880 QualType NewType = getDerived().TransformType(Pattern);
3881 if (NewType.isNull())
3882 return true;
John McCall58f10c32010-03-11 09:03:00 +00003883
Douglas Gregordd472162011-01-07 00:20:55 +00003884 OutParamTypes.push_back(NewType);
3885 if (PVars)
3886 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003887 }
3888
3889 // We're done with the pack expansion.
3890 continue;
3891 }
3892
Douglas Gregor48d24112011-01-10 20:53:55 +00003893 // If we're supposed to retain a pack expansion, do so by temporarily
3894 // forgetting the partially-substituted parameter pack.
3895 if (RetainExpansion) {
3896 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3897 QualType NewType = getDerived().TransformType(Pattern);
3898 if (NewType.isNull())
3899 return true;
3900
3901 OutParamTypes.push_back(NewType);
3902 if (PVars)
3903 PVars->push_back(0);
3904 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003905
Douglas Gregor5499af42011-01-05 23:12:31 +00003906 // We'll substitute the parameter now without expanding the pack
3907 // expansion.
3908 OldType = Expansion->getPattern();
3909 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003910 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3911 NewType = getDerived().TransformType(OldType);
3912 } else {
3913 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003914 }
3915
Douglas Gregor5499af42011-01-05 23:12:31 +00003916 if (NewType.isNull())
3917 return true;
3918
3919 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003920 NewType = getSema().Context.getPackExpansionType(NewType,
3921 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003922
Douglas Gregordd472162011-01-07 00:20:55 +00003923 OutParamTypes.push_back(NewType);
3924 if (PVars)
3925 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003926 }
3927
John McCall8fb0d9d2011-05-01 22:35:37 +00003928#ifndef NDEBUG
3929 if (PVars) {
3930 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3931 if (ParmVarDecl *parm = (*PVars)[i])
3932 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00003933 }
John McCall8fb0d9d2011-05-01 22:35:37 +00003934#endif
3935
3936 return false;
3937}
John McCall58f10c32010-03-11 09:03:00 +00003938
3939template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003940QualType
John McCall550e0c22009-10-21 00:40:46 +00003941TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003942 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003943 // Transform the parameters and return type.
3944 //
3945 // We instantiate in source order, with the return type first followed by
3946 // the parameters, because users tend to expect this (even if they shouldn't
3947 // rely on it!).
3948 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003949 // When the function has a trailing return type, we instantiate the
3950 // parameters before the return type, since the return type can then refer
3951 // to the parameters themselves (via decltype, sizeof, etc.).
3952 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003953 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003954 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003955 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003956
Douglas Gregor7fb25412010-10-01 18:44:50 +00003957 QualType ResultType;
3958
3959 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003960 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3961 TL.getParmArray(),
3962 TL.getNumArgs(),
3963 TL.getTypePtr()->arg_type_begin(),
3964 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003965 return QualType();
3966
3967 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3968 if (ResultType.isNull())
3969 return QualType();
3970 }
3971 else {
3972 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3973 if (ResultType.isNull())
3974 return QualType();
3975
Douglas Gregordd472162011-01-07 00:20:55 +00003976 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3977 TL.getParmArray(),
3978 TL.getNumArgs(),
3979 TL.getTypePtr()->arg_type_begin(),
3980 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003981 return QualType();
3982 }
3983
John McCall550e0c22009-10-21 00:40:46 +00003984 QualType Result = TL.getType();
3985 if (getDerived().AlwaysRebuild() ||
3986 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003987 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003988 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3989 Result = getDerived().RebuildFunctionProtoType(ResultType,
3990 ParamTypes.data(),
3991 ParamTypes.size(),
3992 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003993 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003994 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003995 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003996 if (Result.isNull())
3997 return QualType();
3998 }
Mike Stump11289f42009-09-09 15:08:12 +00003999
John McCall550e0c22009-10-21 00:40:46 +00004000 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004001 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4002 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004003 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004004 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4005 NewTL.setArg(i, ParamDecls[i]);
4006
4007 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004008}
Mike Stump11289f42009-09-09 15:08:12 +00004009
Douglas Gregord6ff3322009-08-04 16:50:30 +00004010template<typename Derived>
4011QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004012 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004013 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004014 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004015 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4016 if (ResultType.isNull())
4017 return QualType();
4018
4019 QualType Result = TL.getType();
4020 if (getDerived().AlwaysRebuild() ||
4021 ResultType != T->getResultType())
4022 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4023
4024 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004025 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4026 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004027 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004028
4029 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004030}
Mike Stump11289f42009-09-09 15:08:12 +00004031
John McCallb96ec562009-12-04 22:46:56 +00004032template<typename Derived> QualType
4033TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004034 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004035 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004036 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004037 if (!D)
4038 return QualType();
4039
4040 QualType Result = TL.getType();
4041 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4042 Result = getDerived().RebuildUnresolvedUsingType(D);
4043 if (Result.isNull())
4044 return QualType();
4045 }
4046
4047 // We might get an arbitrary type spec type back. We should at
4048 // least always get a type spec type, though.
4049 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4050 NewTL.setNameLoc(TL.getNameLoc());
4051
4052 return Result;
4053}
4054
Douglas Gregord6ff3322009-08-04 16:50:30 +00004055template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004056QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004057 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004058 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004059 TypedefNameDecl *Typedef
4060 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4061 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004062 if (!Typedef)
4063 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004064
John McCall550e0c22009-10-21 00:40:46 +00004065 QualType Result = TL.getType();
4066 if (getDerived().AlwaysRebuild() ||
4067 Typedef != T->getDecl()) {
4068 Result = getDerived().RebuildTypedefType(Typedef);
4069 if (Result.isNull())
4070 return QualType();
4071 }
Mike Stump11289f42009-09-09 15:08:12 +00004072
John McCall550e0c22009-10-21 00:40:46 +00004073 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4074 NewTL.setNameLoc(TL.getNameLoc());
4075
4076 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004077}
Mike Stump11289f42009-09-09 15:08:12 +00004078
Douglas Gregord6ff3322009-08-04 16:50:30 +00004079template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004080QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004081 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004082 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004083 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004084
John McCalldadc5752010-08-24 06:29:42 +00004085 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004086 if (E.isInvalid())
4087 return QualType();
4088
John McCall550e0c22009-10-21 00:40:46 +00004089 QualType Result = TL.getType();
4090 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004091 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004092 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004093 if (Result.isNull())
4094 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004095 }
John McCall550e0c22009-10-21 00:40:46 +00004096 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004097
John McCall550e0c22009-10-21 00:40:46 +00004098 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004099 NewTL.setTypeofLoc(TL.getTypeofLoc());
4100 NewTL.setLParenLoc(TL.getLParenLoc());
4101 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004102
4103 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004104}
Mike Stump11289f42009-09-09 15:08:12 +00004105
4106template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004107QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004108 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004109 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4110 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4111 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004112 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004113
John McCall550e0c22009-10-21 00:40:46 +00004114 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004115 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4116 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004117 if (Result.isNull())
4118 return QualType();
4119 }
Mike Stump11289f42009-09-09 15:08:12 +00004120
John McCall550e0c22009-10-21 00:40:46 +00004121 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004122 NewTL.setTypeofLoc(TL.getTypeofLoc());
4123 NewTL.setLParenLoc(TL.getLParenLoc());
4124 NewTL.setRParenLoc(TL.getRParenLoc());
4125 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004126
4127 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004128}
Mike Stump11289f42009-09-09 15:08:12 +00004129
4130template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004131QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004132 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004133 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004134
Douglas Gregore922c772009-08-04 22:27:00 +00004135 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004136 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004137
John McCalldadc5752010-08-24 06:29:42 +00004138 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004139 if (E.isInvalid())
4140 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004141
John McCall550e0c22009-10-21 00:40:46 +00004142 QualType Result = TL.getType();
4143 if (getDerived().AlwaysRebuild() ||
4144 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004145 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004146 if (Result.isNull())
4147 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004148 }
John McCall550e0c22009-10-21 00:40:46 +00004149 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004150
John McCall550e0c22009-10-21 00:40:46 +00004151 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4152 NewTL.setNameLoc(TL.getNameLoc());
4153
4154 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004155}
4156
4157template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004158QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4159 AutoTypeLoc TL) {
4160 const AutoType *T = TL.getTypePtr();
4161 QualType OldDeduced = T->getDeducedType();
4162 QualType NewDeduced;
4163 if (!OldDeduced.isNull()) {
4164 NewDeduced = getDerived().TransformType(OldDeduced);
4165 if (NewDeduced.isNull())
4166 return QualType();
4167 }
4168
4169 QualType Result = TL.getType();
4170 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4171 Result = getDerived().RebuildAutoType(NewDeduced);
4172 if (Result.isNull())
4173 return QualType();
4174 }
4175
4176 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4177 NewTL.setNameLoc(TL.getNameLoc());
4178
4179 return Result;
4180}
4181
4182template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004183QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004184 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004185 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004186 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004187 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4188 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004189 if (!Record)
4190 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004191
John McCall550e0c22009-10-21 00:40:46 +00004192 QualType Result = TL.getType();
4193 if (getDerived().AlwaysRebuild() ||
4194 Record != T->getDecl()) {
4195 Result = getDerived().RebuildRecordType(Record);
4196 if (Result.isNull())
4197 return QualType();
4198 }
Mike Stump11289f42009-09-09 15:08:12 +00004199
John McCall550e0c22009-10-21 00:40:46 +00004200 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4201 NewTL.setNameLoc(TL.getNameLoc());
4202
4203 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004204}
Mike Stump11289f42009-09-09 15:08:12 +00004205
4206template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004207QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004208 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004209 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004210 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004211 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4212 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004213 if (!Enum)
4214 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004215
John McCall550e0c22009-10-21 00:40:46 +00004216 QualType Result = TL.getType();
4217 if (getDerived().AlwaysRebuild() ||
4218 Enum != T->getDecl()) {
4219 Result = getDerived().RebuildEnumType(Enum);
4220 if (Result.isNull())
4221 return QualType();
4222 }
Mike Stump11289f42009-09-09 15:08:12 +00004223
John McCall550e0c22009-10-21 00:40:46 +00004224 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4225 NewTL.setNameLoc(TL.getNameLoc());
4226
4227 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004228}
John McCallfcc33b02009-09-05 00:15:47 +00004229
John McCalle78aac42010-03-10 03:28:59 +00004230template<typename Derived>
4231QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4232 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004233 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004234 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4235 TL.getTypePtr()->getDecl());
4236 if (!D) return QualType();
4237
4238 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4239 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4240 return T;
4241}
4242
Douglas Gregord6ff3322009-08-04 16:50:30 +00004243template<typename Derived>
4244QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004245 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004246 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004247 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004248}
4249
Mike Stump11289f42009-09-09 15:08:12 +00004250template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004251QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004252 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004253 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004254 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4255
4256 // Substitute into the replacement type, which itself might involve something
4257 // that needs to be transformed. This only tends to occur with default
4258 // template arguments of template template parameters.
4259 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4260 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4261 if (Replacement.isNull())
4262 return QualType();
4263
4264 // Always canonicalize the replacement type.
4265 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4266 QualType Result
4267 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4268 Replacement);
4269
4270 // Propagate type-source information.
4271 SubstTemplateTypeParmTypeLoc NewTL
4272 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4273 NewTL.setNameLoc(TL.getNameLoc());
4274 return Result;
4275
John McCallcebee162009-10-18 09:09:24 +00004276}
4277
4278template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004279QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4280 TypeLocBuilder &TLB,
4281 SubstTemplateTypeParmPackTypeLoc TL) {
4282 return TransformTypeSpecType(TLB, TL);
4283}
4284
4285template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004286QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004287 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004288 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004289 const TemplateSpecializationType *T = TL.getTypePtr();
4290
Douglas Gregordf846d12011-03-02 18:46:51 +00004291 // The nested-name-specifier never matters in a TemplateSpecializationType,
4292 // because we can't have a dependent nested-name-specifier anyway.
4293 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004294 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004295 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4296 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004297 if (Template.isNull())
4298 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004299
John McCall31f82722010-11-12 08:19:04 +00004300 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4301}
4302
Douglas Gregorfe921a72010-12-20 23:36:19 +00004303namespace {
4304 /// \brief Simple iterator that traverses the template arguments in a
4305 /// container that provides a \c getArgLoc() member function.
4306 ///
4307 /// This iterator is intended to be used with the iterator form of
4308 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4309 template<typename ArgLocContainer>
4310 class TemplateArgumentLocContainerIterator {
4311 ArgLocContainer *Container;
4312 unsigned Index;
4313
4314 public:
4315 typedef TemplateArgumentLoc value_type;
4316 typedef TemplateArgumentLoc reference;
4317 typedef int difference_type;
4318 typedef std::input_iterator_tag iterator_category;
4319
4320 class pointer {
4321 TemplateArgumentLoc Arg;
4322
4323 public:
4324 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4325
4326 const TemplateArgumentLoc *operator->() const {
4327 return &Arg;
4328 }
4329 };
4330
4331
4332 TemplateArgumentLocContainerIterator() {}
4333
4334 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4335 unsigned Index)
4336 : Container(&Container), Index(Index) { }
4337
4338 TemplateArgumentLocContainerIterator &operator++() {
4339 ++Index;
4340 return *this;
4341 }
4342
4343 TemplateArgumentLocContainerIterator operator++(int) {
4344 TemplateArgumentLocContainerIterator Old(*this);
4345 ++(*this);
4346 return Old;
4347 }
4348
4349 TemplateArgumentLoc operator*() const {
4350 return Container->getArgLoc(Index);
4351 }
4352
4353 pointer operator->() const {
4354 return pointer(Container->getArgLoc(Index));
4355 }
4356
4357 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004358 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004359 return X.Container == Y.Container && X.Index == Y.Index;
4360 }
4361
4362 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004363 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004364 return !(X == Y);
4365 }
4366 };
4367}
4368
4369
John McCall31f82722010-11-12 08:19:04 +00004370template <typename Derived>
4371QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4372 TypeLocBuilder &TLB,
4373 TemplateSpecializationTypeLoc TL,
4374 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004375 TemplateArgumentListInfo NewTemplateArgs;
4376 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4377 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004378 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4379 ArgIterator;
4380 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4381 ArgIterator(TL, TL.getNumArgs()),
4382 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004383 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004384
John McCall0ad16662009-10-29 08:12:44 +00004385 // FIXME: maybe don't rebuild if all the template arguments are the same.
4386
4387 QualType Result =
4388 getDerived().RebuildTemplateSpecializationType(Template,
4389 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004390 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004391
4392 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004393 // Specializations of template template parameters are represented as
4394 // TemplateSpecializationTypes, and substitution of type alias templates
4395 // within a dependent context can transform them into
4396 // DependentTemplateSpecializationTypes.
4397 if (isa<DependentTemplateSpecializationType>(Result)) {
4398 DependentTemplateSpecializationTypeLoc NewTL
4399 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4400 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4401 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4402 NewTL.setNameLoc(TL.getTemplateNameLoc());
4403 NewTL.setLAngleLoc(TL.getLAngleLoc());
4404 NewTL.setRAngleLoc(TL.getRAngleLoc());
4405 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4406 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4407 return Result;
4408 }
4409
John McCall0ad16662009-10-29 08:12:44 +00004410 TemplateSpecializationTypeLoc NewTL
4411 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4412 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4413 NewTL.setLAngleLoc(TL.getLAngleLoc());
4414 NewTL.setRAngleLoc(TL.getRAngleLoc());
4415 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4416 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004417 }
Mike Stump11289f42009-09-09 15:08:12 +00004418
John McCall0ad16662009-10-29 08:12:44 +00004419 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004420}
Mike Stump11289f42009-09-09 15:08:12 +00004421
Douglas Gregor5a064722011-02-28 17:23:35 +00004422template <typename Derived>
4423QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4424 TypeLocBuilder &TLB,
4425 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004426 TemplateName Template,
4427 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004428 TemplateArgumentListInfo NewTemplateArgs;
4429 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4430 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4431 typedef TemplateArgumentLocContainerIterator<
4432 DependentTemplateSpecializationTypeLoc> ArgIterator;
4433 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4434 ArgIterator(TL, TL.getNumArgs()),
4435 NewTemplateArgs))
4436 return QualType();
4437
4438 // FIXME: maybe don't rebuild if all the template arguments are the same.
4439
4440 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4441 QualType Result
4442 = getSema().Context.getDependentTemplateSpecializationType(
4443 TL.getTypePtr()->getKeyword(),
4444 DTN->getQualifier(),
4445 DTN->getIdentifier(),
4446 NewTemplateArgs);
4447
4448 DependentTemplateSpecializationTypeLoc NewTL
4449 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4450 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004451
Douglas Gregora7a795b2011-03-01 20:11:18 +00004452 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004453 NewTL.setNameLoc(TL.getNameLoc());
4454 NewTL.setLAngleLoc(TL.getLAngleLoc());
4455 NewTL.setRAngleLoc(TL.getRAngleLoc());
4456 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4457 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4458 return Result;
4459 }
4460
4461 QualType Result
4462 = getDerived().RebuildTemplateSpecializationType(Template,
4463 TL.getNameLoc(),
4464 NewTemplateArgs);
4465
4466 if (!Result.isNull()) {
4467 /// FIXME: Wrap this in an elaborated-type-specifier?
4468 TemplateSpecializationTypeLoc NewTL
4469 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4470 NewTL.setTemplateNameLoc(TL.getNameLoc());
4471 NewTL.setLAngleLoc(TL.getLAngleLoc());
4472 NewTL.setRAngleLoc(TL.getRAngleLoc());
4473 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4474 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4475 }
4476
4477 return Result;
4478}
4479
Mike Stump11289f42009-09-09 15:08:12 +00004480template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004481QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004482TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004483 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004484 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004485
Douglas Gregor844cb502011-03-01 18:12:44 +00004486 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004487 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004488 if (TL.getQualifierLoc()) {
4489 QualifierLoc
4490 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4491 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004492 return QualType();
4493 }
Mike Stump11289f42009-09-09 15:08:12 +00004494
John McCall31f82722010-11-12 08:19:04 +00004495 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4496 if (NamedT.isNull())
4497 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004498
Richard Smith3f1b5d02011-05-05 21:57:07 +00004499 // C++0x [dcl.type.elab]p2:
4500 // If the identifier resolves to a typedef-name or the simple-template-id
4501 // resolves to an alias template specialization, the
4502 // elaborated-type-specifier is ill-formed.
4503 if (const TemplateSpecializationType *TST =
4504 NamedT->getAs<TemplateSpecializationType>()) {
4505 TemplateName Template = TST->getTemplateName();
4506 if (TypeAliasTemplateDecl *TAT =
4507 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4508 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4509 diag::err_tag_reference_non_tag) << 4;
4510 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4511 }
4512 }
4513
John McCall550e0c22009-10-21 00:40:46 +00004514 QualType Result = TL.getType();
4515 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004516 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004517 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004518 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004519 T->getKeyword(),
4520 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004521 if (Result.isNull())
4522 return QualType();
4523 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004524
Abramo Bagnara6150c882010-05-11 21:36:43 +00004525 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004526 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004527 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004528 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004529}
Mike Stump11289f42009-09-09 15:08:12 +00004530
4531template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004532QualType TreeTransform<Derived>::TransformAttributedType(
4533 TypeLocBuilder &TLB,
4534 AttributedTypeLoc TL) {
4535 const AttributedType *oldType = TL.getTypePtr();
4536 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4537 if (modifiedType.isNull())
4538 return QualType();
4539
4540 QualType result = TL.getType();
4541
4542 // FIXME: dependent operand expressions?
4543 if (getDerived().AlwaysRebuild() ||
4544 modifiedType != oldType->getModifiedType()) {
4545 // TODO: this is really lame; we should really be rebuilding the
4546 // equivalent type from first principles.
4547 QualType equivalentType
4548 = getDerived().TransformType(oldType->getEquivalentType());
4549 if (equivalentType.isNull())
4550 return QualType();
4551 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4552 modifiedType,
4553 equivalentType);
4554 }
4555
4556 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4557 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4558 if (TL.hasAttrOperand())
4559 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4560 if (TL.hasAttrExprOperand())
4561 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4562 else if (TL.hasAttrEnumOperand())
4563 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4564
4565 return result;
4566}
4567
4568template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004569QualType
4570TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4571 ParenTypeLoc TL) {
4572 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4573 if (Inner.isNull())
4574 return QualType();
4575
4576 QualType Result = TL.getType();
4577 if (getDerived().AlwaysRebuild() ||
4578 Inner != TL.getInnerLoc().getType()) {
4579 Result = getDerived().RebuildParenType(Inner);
4580 if (Result.isNull())
4581 return QualType();
4582 }
4583
4584 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4585 NewTL.setLParenLoc(TL.getLParenLoc());
4586 NewTL.setRParenLoc(TL.getRParenLoc());
4587 return Result;
4588}
4589
4590template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004591QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004592 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004593 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004594
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004595 NestedNameSpecifierLoc QualifierLoc
4596 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4597 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004598 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004599
John McCallc392f372010-06-11 00:33:02 +00004600 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004601 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004602 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004603 QualifierLoc,
4604 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004605 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004606 if (Result.isNull())
4607 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004608
Abramo Bagnarad7548482010-05-19 21:37:53 +00004609 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4610 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004611 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4612
Abramo Bagnarad7548482010-05-19 21:37:53 +00004613 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4614 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004615 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004616 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004617 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4618 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004619 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004620 NewTL.setNameLoc(TL.getNameLoc());
4621 }
John McCall550e0c22009-10-21 00:40:46 +00004622 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004623}
Mike Stump11289f42009-09-09 15:08:12 +00004624
Douglas Gregord6ff3322009-08-04 16:50:30 +00004625template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004626QualType TreeTransform<Derived>::
4627 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004628 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004629 NestedNameSpecifierLoc QualifierLoc;
4630 if (TL.getQualifierLoc()) {
4631 QualifierLoc
4632 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4633 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004634 return QualType();
4635 }
4636
John McCall31f82722010-11-12 08:19:04 +00004637 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004638 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004639}
4640
4641template<typename Derived>
4642QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004643TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4644 DependentTemplateSpecializationTypeLoc TL,
4645 NestedNameSpecifierLoc QualifierLoc) {
4646 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4647
4648 TemplateArgumentListInfo NewTemplateArgs;
4649 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4650 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4651
4652 typedef TemplateArgumentLocContainerIterator<
4653 DependentTemplateSpecializationTypeLoc> ArgIterator;
4654 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4655 ArgIterator(TL, TL.getNumArgs()),
4656 NewTemplateArgs))
4657 return QualType();
4658
4659 QualType Result
4660 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4661 QualifierLoc,
4662 T->getIdentifier(),
4663 TL.getNameLoc(),
4664 NewTemplateArgs);
4665 if (Result.isNull())
4666 return QualType();
4667
4668 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4669 QualType NamedT = ElabT->getNamedType();
4670
4671 // Copy information relevant to the template specialization.
4672 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004673 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004674 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004675 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4676 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004677 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004678 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004679
4680 // Copy information relevant to the elaborated type.
4681 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4682 NewTL.setKeywordLoc(TL.getKeywordLoc());
4683 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004684 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4685 DependentTemplateSpecializationTypeLoc SpecTL
4686 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004687 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004688 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004689 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004690 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4691 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004692 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004693 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004694 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004695 TemplateSpecializationTypeLoc SpecTL
4696 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004697 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004698 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4699 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004700 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004701 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004702 }
4703 return Result;
4704}
4705
4706template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004707QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4708 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004709 QualType Pattern
4710 = getDerived().TransformType(TLB, TL.getPatternLoc());
4711 if (Pattern.isNull())
4712 return QualType();
4713
4714 QualType Result = TL.getType();
4715 if (getDerived().AlwaysRebuild() ||
4716 Pattern != TL.getPatternLoc().getType()) {
4717 Result = getDerived().RebuildPackExpansionType(Pattern,
4718 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004719 TL.getEllipsisLoc(),
4720 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004721 if (Result.isNull())
4722 return QualType();
4723 }
4724
4725 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4726 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4727 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004728}
4729
4730template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004731QualType
4732TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004733 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004734 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004735 TLB.pushFullCopy(TL);
4736 return TL.getType();
4737}
4738
4739template<typename Derived>
4740QualType
4741TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004742 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004743 // ObjCObjectType is never dependent.
4744 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004745 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004746}
Mike Stump11289f42009-09-09 15:08:12 +00004747
4748template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004749QualType
4750TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004751 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004752 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004753 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004754 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004755}
4756
Douglas Gregord6ff3322009-08-04 16:50:30 +00004757//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004758// Statement transformation
4759//===----------------------------------------------------------------------===//
4760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004761StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004762TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004763 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004764}
4765
4766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004767StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004768TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4769 return getDerived().TransformCompoundStmt(S, false);
4770}
4771
4772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004773StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004774TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004775 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004776 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004777 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004778 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004779 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4780 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004781 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004782 if (Result.isInvalid()) {
4783 // Immediately fail if this was a DeclStmt, since it's very
4784 // likely that this will cause problems for future statements.
4785 if (isa<DeclStmt>(*B))
4786 return StmtError();
4787
4788 // Otherwise, just keep processing substatements and fail later.
4789 SubStmtInvalid = true;
4790 continue;
4791 }
Mike Stump11289f42009-09-09 15:08:12 +00004792
Douglas Gregorebe10102009-08-20 07:17:43 +00004793 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4794 Statements.push_back(Result.takeAs<Stmt>());
4795 }
Mike Stump11289f42009-09-09 15:08:12 +00004796
John McCall1ababa62010-08-27 19:56:05 +00004797 if (SubStmtInvalid)
4798 return StmtError();
4799
Douglas Gregorebe10102009-08-20 07:17:43 +00004800 if (!getDerived().AlwaysRebuild() &&
4801 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004802 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004803
4804 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4805 move_arg(Statements),
4806 S->getRBracLoc(),
4807 IsStmtExpr);
4808}
Mike Stump11289f42009-09-09 15:08:12 +00004809
Douglas Gregorebe10102009-08-20 07:17:43 +00004810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004811StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004812TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004813 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004814 {
4815 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004816 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004817
Eli Friedman06577382009-11-19 03:14:00 +00004818 // Transform the left-hand case value.
4819 LHS = getDerived().TransformExpr(S->getLHS());
4820 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004821 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004822
Eli Friedman06577382009-11-19 03:14:00 +00004823 // Transform the right-hand case value (for the GNU case-range extension).
4824 RHS = getDerived().TransformExpr(S->getRHS());
4825 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004826 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004827 }
Mike Stump11289f42009-09-09 15:08:12 +00004828
Douglas Gregorebe10102009-08-20 07:17:43 +00004829 // Build the case statement.
4830 // Case statements are always rebuilt so that they will attached to their
4831 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004832 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004833 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004834 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004835 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004836 S->getColonLoc());
4837 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004838 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004839
Douglas Gregorebe10102009-08-20 07:17:43 +00004840 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004841 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004842 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004843 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004844
Douglas Gregorebe10102009-08-20 07:17:43 +00004845 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004846 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004847}
4848
4849template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004850StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004851TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004852 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004853 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004854 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004855 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004856
Douglas Gregorebe10102009-08-20 07:17:43 +00004857 // Default statements are always rebuilt
4858 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004859 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004860}
Mike Stump11289f42009-09-09 15:08:12 +00004861
Douglas Gregorebe10102009-08-20 07:17:43 +00004862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004863StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004864TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004865 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004866 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004867 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004868
Chris Lattnercab02a62011-02-17 20:34:02 +00004869 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4870 S->getDecl());
4871 if (!LD)
4872 return StmtError();
4873
4874
Douglas Gregorebe10102009-08-20 07:17:43 +00004875 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004876 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004877 cast<LabelDecl>(LD), SourceLocation(),
4878 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004879}
Mike Stump11289f42009-09-09 15:08:12 +00004880
Douglas Gregorebe10102009-08-20 07:17:43 +00004881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004882StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004883TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004884 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004885 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004886 VarDecl *ConditionVar = 0;
4887 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004888 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004889 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004890 getDerived().TransformDefinition(
4891 S->getConditionVariable()->getLocation(),
4892 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004893 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004894 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004895 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004896 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004897
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004898 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004899 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004900
4901 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004902 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004903 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4904 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004905 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004906 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004907
John McCallb268a282010-08-23 23:25:46 +00004908 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004909 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004910 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004911
John McCallb268a282010-08-23 23:25:46 +00004912 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4913 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004914 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004915
Douglas Gregorebe10102009-08-20 07:17:43 +00004916 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004917 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004918 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004919 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004920
Douglas Gregorebe10102009-08-20 07:17:43 +00004921 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004922 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004923 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004924 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004925
Douglas Gregorebe10102009-08-20 07:17:43 +00004926 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004927 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004928 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004929 Then.get() == S->getThen() &&
4930 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004931 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004932
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004933 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004934 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004935 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004936}
4937
4938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004939StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004940TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004941 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004942 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004943 VarDecl *ConditionVar = 0;
4944 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004945 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004946 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004947 getDerived().TransformDefinition(
4948 S->getConditionVariable()->getLocation(),
4949 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004950 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004951 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004952 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004953 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004954
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004955 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004956 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004957 }
Mike Stump11289f42009-09-09 15:08:12 +00004958
Douglas Gregorebe10102009-08-20 07:17:43 +00004959 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004960 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004961 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004962 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004963 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004964 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004965
Douglas Gregorebe10102009-08-20 07:17:43 +00004966 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004967 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004968 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004969 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004970
Douglas Gregorebe10102009-08-20 07:17:43 +00004971 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004972 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4973 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004974}
Mike Stump11289f42009-09-09 15:08:12 +00004975
Douglas Gregorebe10102009-08-20 07:17:43 +00004976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004977StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004978TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004979 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004980 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004981 VarDecl *ConditionVar = 0;
4982 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004983 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004984 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004985 getDerived().TransformDefinition(
4986 S->getConditionVariable()->getLocation(),
4987 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004988 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004989 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004990 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004991 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004992
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004993 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004994 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004995
4996 if (S->getCond()) {
4997 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004998 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4999 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005000 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005001 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005002 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005003 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005004 }
Mike Stump11289f42009-09-09 15:08:12 +00005005
John McCallb268a282010-08-23 23:25:46 +00005006 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5007 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005008 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005009
Douglas Gregorebe10102009-08-20 07:17:43 +00005010 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005011 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005012 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005013 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005014
Douglas Gregorebe10102009-08-20 07:17:43 +00005015 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005016 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005017 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005018 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005019 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005020
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005021 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005022 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005023}
Mike Stump11289f42009-09-09 15:08:12 +00005024
Douglas Gregorebe10102009-08-20 07:17:43 +00005025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005026StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005027TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005028 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005029 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005030 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005031 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005032
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005033 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005034 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005035 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005036 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005037
Douglas Gregorebe10102009-08-20 07:17:43 +00005038 if (!getDerived().AlwaysRebuild() &&
5039 Cond.get() == S->getCond() &&
5040 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005041 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005042
John McCallb268a282010-08-23 23:25:46 +00005043 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5044 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005045 S->getRParenLoc());
5046}
Mike Stump11289f42009-09-09 15:08:12 +00005047
Douglas Gregorebe10102009-08-20 07:17:43 +00005048template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005049StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005050TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005051 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005052 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005053 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005054 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005055
Douglas Gregorebe10102009-08-20 07:17:43 +00005056 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005057 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005058 VarDecl *ConditionVar = 0;
5059 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005060 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005061 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005062 getDerived().TransformDefinition(
5063 S->getConditionVariable()->getLocation(),
5064 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005065 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005066 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005067 } else {
5068 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005069
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005070 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005071 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005072
5073 if (S->getCond()) {
5074 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005075 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5076 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005077 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005078 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005079
John McCallb268a282010-08-23 23:25:46 +00005080 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005081 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005082 }
Mike Stump11289f42009-09-09 15:08:12 +00005083
John McCallb268a282010-08-23 23:25:46 +00005084 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5085 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005086 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005087
Douglas Gregorebe10102009-08-20 07:17:43 +00005088 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005089 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005090 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005091 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005092
John McCallb268a282010-08-23 23:25:46 +00005093 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5094 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005095 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005096
Douglas Gregorebe10102009-08-20 07:17:43 +00005097 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005098 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005099 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005100 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005101
Douglas Gregorebe10102009-08-20 07:17:43 +00005102 if (!getDerived().AlwaysRebuild() &&
5103 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005104 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005105 Inc.get() == S->getInc() &&
5106 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005107 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005108
Douglas Gregorebe10102009-08-20 07:17:43 +00005109 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005110 Init.get(), FullCond, ConditionVar,
5111 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005112}
5113
5114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005115StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005116TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005117 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5118 S->getLabel());
5119 if (!LD)
5120 return StmtError();
5121
Douglas Gregorebe10102009-08-20 07:17:43 +00005122 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005123 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005124 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005125}
5126
5127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005128StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005129TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005130 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005131 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005132 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005133
Douglas Gregorebe10102009-08-20 07:17:43 +00005134 if (!getDerived().AlwaysRebuild() &&
5135 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005136 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005137
5138 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005139 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005140}
5141
5142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005143StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005144TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005145 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005146}
Mike Stump11289f42009-09-09 15:08:12 +00005147
Douglas Gregorebe10102009-08-20 07:17:43 +00005148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005149StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005150TreeTransform<Derived>::TransformBreakStmt(BreakStmt *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>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005157 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005158 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005159 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005160
Mike Stump11289f42009-09-09 15:08:12 +00005161 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005162 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005163 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005164}
Mike Stump11289f42009-09-09 15:08:12 +00005165
Douglas Gregorebe10102009-08-20 07:17:43 +00005166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005167StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005168TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005169 bool DeclChanged = false;
5170 llvm::SmallVector<Decl *, 4> Decls;
5171 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5172 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005173 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5174 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005175 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005176 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005177
Douglas Gregorebe10102009-08-20 07:17:43 +00005178 if (Transformed != *D)
5179 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005180
Douglas Gregorebe10102009-08-20 07:17:43 +00005181 Decls.push_back(Transformed);
5182 }
Mike Stump11289f42009-09-09 15:08:12 +00005183
Douglas Gregorebe10102009-08-20 07:17:43 +00005184 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005185 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005186
5187 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005188 S->getStartLoc(), S->getEndLoc());
5189}
Mike Stump11289f42009-09-09 15:08:12 +00005190
Douglas Gregorebe10102009-08-20 07:17:43 +00005191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005192StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005193TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005194
John McCall37ad5512010-08-23 06:44:23 +00005195 ASTOwningVector<Expr*> Constraints(getSema());
5196 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005197 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005198
John McCalldadc5752010-08-24 06:29:42 +00005199 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005200 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005201
5202 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005203
Anders Carlssonaaeef072010-01-24 05:50:09 +00005204 // Go through the outputs.
5205 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005206 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005207
Anders Carlssonaaeef072010-01-24 05:50:09 +00005208 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005209 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005210
Anders Carlssonaaeef072010-01-24 05:50:09 +00005211 // Transform the output expr.
5212 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005213 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005214 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005215 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005216
Anders Carlssonaaeef072010-01-24 05:50:09 +00005217 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005218
John McCallb268a282010-08-23 23:25:46 +00005219 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005220 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005221
Anders Carlssonaaeef072010-01-24 05:50:09 +00005222 // Go through the inputs.
5223 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005224 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005225
Anders Carlssonaaeef072010-01-24 05:50:09 +00005226 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005227 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005228
Anders Carlssonaaeef072010-01-24 05:50:09 +00005229 // Transform the input expr.
5230 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005231 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005232 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005233 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005234
Anders Carlssonaaeef072010-01-24 05:50:09 +00005235 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005236
John McCallb268a282010-08-23 23:25:46 +00005237 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005238 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005239
Anders Carlssonaaeef072010-01-24 05:50:09 +00005240 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005241 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005242
5243 // Go through the clobbers.
5244 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005245 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005246
5247 // No need to transform the asm string literal.
5248 AsmString = SemaRef.Owned(S->getAsmString());
5249
5250 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5251 S->isSimple(),
5252 S->isVolatile(),
5253 S->getNumOutputs(),
5254 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005255 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005256 move_arg(Constraints),
5257 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005258 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005259 move_arg(Clobbers),
5260 S->getRParenLoc(),
5261 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005262}
5263
5264
5265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005266StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005267TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005268 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005269 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005270 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005271 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005272
Douglas Gregor96c79492010-04-23 22:50:49 +00005273 // Transform the @catch statements (if present).
5274 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005275 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005276 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005277 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005278 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005279 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005280 if (Catch.get() != S->getCatchStmt(I))
5281 AnyCatchChanged = true;
5282 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005283 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005284
Douglas Gregor306de2f2010-04-22 23:59:56 +00005285 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005286 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005287 if (S->getFinallyStmt()) {
5288 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5289 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005290 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005291 }
5292
5293 // If nothing changed, just retain this statement.
5294 if (!getDerived().AlwaysRebuild() &&
5295 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005296 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005297 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005298 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005299
Douglas Gregor306de2f2010-04-22 23:59:56 +00005300 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005301 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5302 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005303}
Mike Stump11289f42009-09-09 15:08:12 +00005304
Douglas Gregorebe10102009-08-20 07:17:43 +00005305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005306StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005307TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005308 // Transform the @catch parameter, if there is one.
5309 VarDecl *Var = 0;
5310 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5311 TypeSourceInfo *TSInfo = 0;
5312 if (FromVar->getTypeSourceInfo()) {
5313 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5314 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005315 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005316 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005317
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005318 QualType T;
5319 if (TSInfo)
5320 T = TSInfo->getType();
5321 else {
5322 T = getDerived().TransformType(FromVar->getType());
5323 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005324 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005325 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005326
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005327 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5328 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005329 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005330 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005331
John McCalldadc5752010-08-24 06:29:42 +00005332 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005333 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005334 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005335
5336 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005337 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005338 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005339}
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregorebe10102009-08-20 07:17:43 +00005341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005342StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005343TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005344 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005345 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005346 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005347 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005348
Douglas Gregor306de2f2010-04-22 23:59:56 +00005349 // If nothing changed, just retain this statement.
5350 if (!getDerived().AlwaysRebuild() &&
5351 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005352 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005353
5354 // Build a new statement.
5355 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005356 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005357}
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregorebe10102009-08-20 07:17:43 +00005359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005360StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005361TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005362 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005363 if (S->getThrowExpr()) {
5364 Operand = getDerived().TransformExpr(S->getThrowExpr());
5365 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005366 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005367 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005368
Douglas Gregor2900c162010-04-22 21:44:01 +00005369 if (!getDerived().AlwaysRebuild() &&
5370 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005371 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005372
John McCallb268a282010-08-23 23:25:46 +00005373 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005374}
Mike Stump11289f42009-09-09 15:08:12 +00005375
Douglas Gregorebe10102009-08-20 07:17:43 +00005376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005377StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005378TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005379 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005380 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005381 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005382 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005383 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005384
Douglas Gregor6148de72010-04-22 22:01:21 +00005385 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005386 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005387 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005388 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005389
Douglas Gregor6148de72010-04-22 22:01:21 +00005390 // If nothing change, just retain the current statement.
5391 if (!getDerived().AlwaysRebuild() &&
5392 Object.get() == S->getSynchExpr() &&
5393 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005394 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005395
5396 // Build a new statement.
5397 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005398 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005399}
5400
5401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005402StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005403TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005404 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005405 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005406 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005407 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005408 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005409
Douglas Gregorf68a5082010-04-22 23:10:45 +00005410 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005411 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005412 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005413 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005414
Douglas Gregorf68a5082010-04-22 23:10:45 +00005415 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005416 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005417 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005418 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005419
Douglas Gregorf68a5082010-04-22 23:10:45 +00005420 // If nothing changed, just retain this statement.
5421 if (!getDerived().AlwaysRebuild() &&
5422 Element.get() == S->getElement() &&
5423 Collection.get() == S->getCollection() &&
5424 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005425 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005426
Douglas Gregorf68a5082010-04-22 23:10:45 +00005427 // Build a new statement.
5428 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5429 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005430 Element.get(),
5431 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005432 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005433 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005434}
5435
5436
5437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005438StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005439TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5440 // Transform the exception declaration, if any.
5441 VarDecl *Var = 0;
5442 if (S->getExceptionDecl()) {
5443 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005444 TypeSourceInfo *T = getDerived().TransformType(
5445 ExceptionDecl->getTypeSourceInfo());
5446 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005447 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005448
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005449 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005450 ExceptionDecl->getInnerLocStart(),
5451 ExceptionDecl->getLocation(),
5452 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005453 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005454 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005455 }
Mike Stump11289f42009-09-09 15:08:12 +00005456
Douglas Gregorebe10102009-08-20 07:17:43 +00005457 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005458 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005459 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005460 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005461
Douglas Gregorebe10102009-08-20 07:17:43 +00005462 if (!getDerived().AlwaysRebuild() &&
5463 !Var &&
5464 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005465 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005466
5467 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5468 Var,
John McCallb268a282010-08-23 23:25:46 +00005469 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005470}
Mike Stump11289f42009-09-09 15:08:12 +00005471
Douglas Gregorebe10102009-08-20 07:17:43 +00005472template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005473StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005474TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5475 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005476 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005477 = getDerived().TransformCompoundStmt(S->getTryBlock());
5478 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005479 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005480
Douglas Gregorebe10102009-08-20 07:17:43 +00005481 // Transform the handlers.
5482 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005483 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005484 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005485 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005486 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5487 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005488 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005489
Douglas Gregorebe10102009-08-20 07:17:43 +00005490 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5491 Handlers.push_back(Handler.takeAs<Stmt>());
5492 }
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregorebe10102009-08-20 07:17:43 +00005494 if (!getDerived().AlwaysRebuild() &&
5495 TryBlock.get() == S->getTryBlock() &&
5496 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005497 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005498
John McCallb268a282010-08-23 23:25:46 +00005499 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005500 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005501}
Mike Stump11289f42009-09-09 15:08:12 +00005502
Richard Smith02e85f32011-04-14 22:09:26 +00005503template<typename Derived>
5504StmtResult
5505TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5506 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5507 if (Range.isInvalid())
5508 return StmtError();
5509
5510 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5511 if (BeginEnd.isInvalid())
5512 return StmtError();
5513
5514 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5515 if (Cond.isInvalid())
5516 return StmtError();
5517
5518 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5519 if (Inc.isInvalid())
5520 return StmtError();
5521
5522 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5523 if (LoopVar.isInvalid())
5524 return StmtError();
5525
5526 StmtResult NewStmt = S;
5527 if (getDerived().AlwaysRebuild() ||
5528 Range.get() != S->getRangeStmt() ||
5529 BeginEnd.get() != S->getBeginEndStmt() ||
5530 Cond.get() != S->getCond() ||
5531 Inc.get() != S->getInc() ||
5532 LoopVar.get() != S->getLoopVarStmt())
5533 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5534 S->getColonLoc(), Range.get(),
5535 BeginEnd.get(), Cond.get(),
5536 Inc.get(), LoopVar.get(),
5537 S->getRParenLoc());
5538
5539 StmtResult Body = getDerived().TransformStmt(S->getBody());
5540 if (Body.isInvalid())
5541 return StmtError();
5542
5543 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5544 // it now so we have a new statement to attach the body to.
5545 if (Body.get() != S->getBody() && NewStmt.get() == S)
5546 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5547 S->getColonLoc(), Range.get(),
5548 BeginEnd.get(), Cond.get(),
5549 Inc.get(), LoopVar.get(),
5550 S->getRParenLoc());
5551
5552 if (NewStmt.get() == S)
5553 return SemaRef.Owned(S);
5554
5555 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5556}
5557
John Wiegley1c0675e2011-04-28 01:08:34 +00005558template<typename Derived>
5559StmtResult
5560TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5561 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5562 if(TryBlock.isInvalid()) return StmtError();
5563
5564 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5565 if(!getDerived().AlwaysRebuild() &&
5566 TryBlock.get() == S->getTryBlock() &&
5567 Handler.get() == S->getHandler())
5568 return SemaRef.Owned(S);
5569
5570 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5571 S->getTryLoc(),
5572 TryBlock.take(),
5573 Handler.take());
5574}
5575
5576template<typename Derived>
5577StmtResult
5578TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5579 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5580 if(Block.isInvalid()) return StmtError();
5581
5582 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5583 Block.take());
5584}
5585
5586template<typename Derived>
5587StmtResult
5588TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5589 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5590 if(FilterExpr.isInvalid()) return StmtError();
5591
5592 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5593 if(Block.isInvalid()) return StmtError();
5594
5595 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5596 FilterExpr.take(),
5597 Block.take());
5598}
5599
5600template<typename Derived>
5601StmtResult
5602TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5603 if(isa<SEHFinallyStmt>(Handler))
5604 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5605 else
5606 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5607}
5608
Douglas Gregorebe10102009-08-20 07:17:43 +00005609//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005610// Expression transformation
5611//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005613ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005614TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005615 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005616}
Mike Stump11289f42009-09-09 15:08:12 +00005617
5618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005619ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005620TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005621 NestedNameSpecifierLoc QualifierLoc;
5622 if (E->getQualifierLoc()) {
5623 QualifierLoc
5624 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5625 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005626 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005627 }
John McCallce546572009-12-08 09:08:17 +00005628
5629 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005630 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5631 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005633 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005634
John McCall815039a2010-08-17 21:27:17 +00005635 DeclarationNameInfo NameInfo = E->getNameInfo();
5636 if (NameInfo.getName()) {
5637 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5638 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005639 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005640 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005641
5642 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005643 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005644 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005645 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005646 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005647
5648 // Mark it referenced in the new context regardless.
5649 // FIXME: this is a bit instantiation-specific.
5650 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5651
John McCallc3007a22010-10-26 07:05:15 +00005652 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005653 }
John McCallce546572009-12-08 09:08:17 +00005654
5655 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005656 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005657 TemplateArgs = &TransArgs;
5658 TransArgs.setLAngleLoc(E->getLAngleLoc());
5659 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005660 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5661 E->getNumTemplateArgs(),
5662 TransArgs))
5663 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005664 }
5665
Douglas Gregorea972d32011-02-28 21:54:11 +00005666 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5667 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005668}
Mike Stump11289f42009-09-09 15:08:12 +00005669
Douglas Gregora16548e2009-08-11 05:31:07 +00005670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005671ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005672TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005673 return SemaRef.Owned(E);
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>::TransformFloatingLiteral(FloatingLiteral *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>::TransformImaginaryLiteral(ImaginaryLiteral *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>::TransformStringLiteral(StringLiteral *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>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005697 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005698}
5699
5700template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005701ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005702TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5703 ExprResult ControllingExpr =
5704 getDerived().TransformExpr(E->getControllingExpr());
5705 if (ControllingExpr.isInvalid())
5706 return ExprError();
5707
5708 llvm::SmallVector<Expr *, 4> AssocExprs;
5709 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5710 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5711 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5712 if (TS) {
5713 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5714 if (!AssocType)
5715 return ExprError();
5716 AssocTypes.push_back(AssocType);
5717 } else {
5718 AssocTypes.push_back(0);
5719 }
5720
5721 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5722 if (AssocExpr.isInvalid())
5723 return ExprError();
5724 AssocExprs.push_back(AssocExpr.release());
5725 }
5726
5727 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5728 E->getDefaultLoc(),
5729 E->getRParenLoc(),
5730 ControllingExpr.release(),
5731 AssocTypes.data(),
5732 AssocExprs.data(),
5733 E->getNumAssocs());
5734}
5735
5736template<typename Derived>
5737ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005738TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005739 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005740 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005741 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005742
Douglas Gregora16548e2009-08-11 05:31:07 +00005743 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005744 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005745
John McCallb268a282010-08-23 23:25:46 +00005746 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005747 E->getRParen());
5748}
5749
Mike Stump11289f42009-09-09 15:08:12 +00005750template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005751ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005752TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005753 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005754 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005755 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005756
Douglas Gregora16548e2009-08-11 05:31:07 +00005757 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005758 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005759
Douglas Gregora16548e2009-08-11 05:31:07 +00005760 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5761 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005762 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005763}
Mike Stump11289f42009-09-09 15:08:12 +00005764
Douglas Gregora16548e2009-08-11 05:31:07 +00005765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005766ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005767TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5768 // Transform the type.
5769 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5770 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005771 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005772
Douglas Gregor882211c2010-04-28 22:16:22 +00005773 // Transform all of the components into components similar to what the
5774 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005775 // FIXME: It would be slightly more efficient in the non-dependent case to
5776 // just map FieldDecls, rather than requiring the rebuilder to look for
5777 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005778 // template code that we don't care.
5779 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005780 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005781 typedef OffsetOfExpr::OffsetOfNode Node;
5782 llvm::SmallVector<Component, 4> Components;
5783 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5784 const Node &ON = E->getComponent(I);
5785 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005786 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005787 Comp.LocStart = ON.getSourceRange().getBegin();
5788 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005789 switch (ON.getKind()) {
5790 case Node::Array: {
5791 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005792 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005793 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005794 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005795
Douglas Gregor882211c2010-04-28 22:16:22 +00005796 ExprChanged = ExprChanged || Index.get() != FromIndex;
5797 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005798 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005799 break;
5800 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005801
Douglas Gregor882211c2010-04-28 22:16:22 +00005802 case Node::Field:
5803 case Node::Identifier:
5804 Comp.isBrackets = false;
5805 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005806 if (!Comp.U.IdentInfo)
5807 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005808
Douglas Gregor882211c2010-04-28 22:16:22 +00005809 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005810
Douglas Gregord1702062010-04-29 00:18:15 +00005811 case Node::Base:
5812 // Will be recomputed during the rebuild.
5813 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005814 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005815
Douglas Gregor882211c2010-04-28 22:16:22 +00005816 Components.push_back(Comp);
5817 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005818
Douglas Gregor882211c2010-04-28 22:16:22 +00005819 // If nothing changed, retain the existing expression.
5820 if (!getDerived().AlwaysRebuild() &&
5821 Type == E->getTypeSourceInfo() &&
5822 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005823 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005824
Douglas Gregor882211c2010-04-28 22:16:22 +00005825 // Build a new offsetof expression.
5826 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5827 Components.data(), Components.size(),
5828 E->getRParenLoc());
5829}
5830
5831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005832ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005833TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5834 assert(getDerived().AlreadyTransformed(E->getType()) &&
5835 "opaque value expression requires transformation");
5836 return SemaRef.Owned(E);
5837}
5838
5839template<typename Derived>
5840ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005841TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5842 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005843 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005844 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005845
John McCallbcd03502009-12-07 02:54:59 +00005846 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005847 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005849
John McCall4c98fd82009-11-04 07:28:41 +00005850 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005851 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005852
Peter Collingbournee190dee2011-03-11 19:24:49 +00005853 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5854 E->getKind(),
5855 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005856 }
Mike Stump11289f42009-09-09 15:08:12 +00005857
John McCalldadc5752010-08-24 06:29:42 +00005858 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005859 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005860 // C++0x [expr.sizeof]p1:
5861 // The operand is either an expression, which is an unevaluated operand
5862 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005863 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005864
Douglas Gregora16548e2009-08-11 05:31:07 +00005865 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5866 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005868
Douglas Gregora16548e2009-08-11 05:31:07 +00005869 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005870 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005871 }
Mike Stump11289f42009-09-09 15:08:12 +00005872
Peter Collingbournee190dee2011-03-11 19:24:49 +00005873 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5874 E->getOperatorLoc(),
5875 E->getKind(),
5876 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005877}
Mike Stump11289f42009-09-09 15:08:12 +00005878
Douglas Gregora16548e2009-08-11 05:31:07 +00005879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005880ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005881TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005882 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005883 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005884 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005885
John McCalldadc5752010-08-24 06:29:42 +00005886 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005887 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005889
5890
Douglas Gregora16548e2009-08-11 05:31:07 +00005891 if (!getDerived().AlwaysRebuild() &&
5892 LHS.get() == E->getLHS() &&
5893 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005894 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005895
John McCallb268a282010-08-23 23:25:46 +00005896 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005898 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005899 E->getRBracketLoc());
5900}
Mike Stump11289f42009-09-09 15:08:12 +00005901
5902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005903ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005904TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005905 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005906 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005907 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005908 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005909
5910 // Transform arguments.
5911 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005912 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005913 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5914 &ArgChanged))
5915 return ExprError();
5916
Douglas Gregora16548e2009-08-11 05:31:07 +00005917 if (!getDerived().AlwaysRebuild() &&
5918 Callee.get() == E->getCallee() &&
5919 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005920 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005921
Douglas Gregora16548e2009-08-11 05:31:07 +00005922 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005923 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005924 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005925 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005926 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005927 E->getRParenLoc());
5928}
Mike Stump11289f42009-09-09 15:08:12 +00005929
5930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005931ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005932TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005933 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005934 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005935 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005936
Douglas Gregorea972d32011-02-28 21:54:11 +00005937 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005938 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005939 QualifierLoc
5940 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5941
5942 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005943 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005944 }
Mike Stump11289f42009-09-09 15:08:12 +00005945
Eli Friedman2cfcef62009-12-04 06:40:45 +00005946 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005947 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5948 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005949 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005950 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005951
John McCall16df1e52010-03-30 21:47:33 +00005952 NamedDecl *FoundDecl = E->getFoundDecl();
5953 if (FoundDecl == E->getMemberDecl()) {
5954 FoundDecl = Member;
5955 } else {
5956 FoundDecl = cast_or_null<NamedDecl>(
5957 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5958 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005959 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005960 }
5961
Douglas Gregora16548e2009-08-11 05:31:07 +00005962 if (!getDerived().AlwaysRebuild() &&
5963 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005964 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005965 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005966 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005967 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005968
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005969 // Mark it referenced in the new context regardless.
5970 // FIXME: this is a bit instantiation-specific.
5971 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005972 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005973 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005974
John McCall6b51f282009-11-23 01:53:49 +00005975 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005976 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005977 TransArgs.setLAngleLoc(E->getLAngleLoc());
5978 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005979 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5980 E->getNumTemplateArgs(),
5981 TransArgs))
5982 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005983 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005984
Douglas Gregora16548e2009-08-11 05:31:07 +00005985 // FIXME: Bogus source location for the operator
5986 SourceLocation FakeOperatorLoc
5987 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5988
John McCall38836f02010-01-15 08:34:02 +00005989 // FIXME: to do this check properly, we will need to preserve the
5990 // first-qualifier-in-scope here, just in case we had a dependent
5991 // base (and therefore couldn't do the check) and a
5992 // nested-name-qualifier (and therefore could do the lookup).
5993 NamedDecl *FirstQualifierInScope = 0;
5994
John McCallb268a282010-08-23 23:25:46 +00005995 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005996 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005997 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005998 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005999 Member,
John McCall16df1e52010-03-30 21:47:33 +00006000 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006001 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006002 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006003 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006004}
Mike Stump11289f42009-09-09 15:08:12 +00006005
Douglas Gregora16548e2009-08-11 05:31:07 +00006006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006007ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006008TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006009 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006010 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006012
John McCalldadc5752010-08-24 06:29:42 +00006013 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006015 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregora16548e2009-08-11 05:31:07 +00006017 if (!getDerived().AlwaysRebuild() &&
6018 LHS.get() == E->getLHS() &&
6019 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006020 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006021
Douglas Gregora16548e2009-08-11 05:31:07 +00006022 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006023 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006024}
6025
Mike Stump11289f42009-09-09 15:08:12 +00006026template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006027ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006028TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006029 CompoundAssignOperator *E) {
6030 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006031}
Mike Stump11289f42009-09-09 15:08:12 +00006032
Douglas Gregora16548e2009-08-11 05:31:07 +00006033template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006034ExprResult TreeTransform<Derived>::
6035TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6036 // Just rebuild the common and RHS expressions and see whether we
6037 // get any changes.
6038
6039 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6040 if (commonExpr.isInvalid())
6041 return ExprError();
6042
6043 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6044 if (rhs.isInvalid())
6045 return ExprError();
6046
6047 if (!getDerived().AlwaysRebuild() &&
6048 commonExpr.get() == e->getCommon() &&
6049 rhs.get() == e->getFalseExpr())
6050 return SemaRef.Owned(e);
6051
6052 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6053 e->getQuestionLoc(),
6054 0,
6055 e->getColonLoc(),
6056 rhs.get());
6057}
6058
6059template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006060ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006061TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006062 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006063 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006064 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006065
John McCalldadc5752010-08-24 06:29:42 +00006066 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006067 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006068 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006069
John McCalldadc5752010-08-24 06:29:42 +00006070 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006071 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006073
Douglas Gregora16548e2009-08-11 05:31:07 +00006074 if (!getDerived().AlwaysRebuild() &&
6075 Cond.get() == E->getCond() &&
6076 LHS.get() == E->getLHS() &&
6077 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006078 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006079
John McCallb268a282010-08-23 23:25:46 +00006080 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006081 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006082 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006083 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006084 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006085}
Mike Stump11289f42009-09-09 15:08:12 +00006086
6087template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006088ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006089TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006090 // Implicit casts are eliminated during transformation, since they
6091 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006092 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006093}
Mike Stump11289f42009-09-09 15:08:12 +00006094
Douglas Gregora16548e2009-08-11 05:31:07 +00006095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006097TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006098 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6099 if (!Type)
6100 return ExprError();
6101
John McCalldadc5752010-08-24 06:29:42 +00006102 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006103 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006104 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006105 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006106
Douglas Gregora16548e2009-08-11 05:31:07 +00006107 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006108 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006109 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006110 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006111
John McCall97513962010-01-15 18:39:57 +00006112 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006113 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006114 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006115 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006116}
Mike Stump11289f42009-09-09 15:08:12 +00006117
Douglas Gregora16548e2009-08-11 05:31:07 +00006118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006119ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006120TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006121 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6122 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6123 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006125
John McCalldadc5752010-08-24 06:29:42 +00006126 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006127 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006128 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006129
Douglas Gregora16548e2009-08-11 05:31:07 +00006130 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006131 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006132 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006133 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006134
John McCall5d7aa7f2010-01-19 22:33:45 +00006135 // Note: the expression type doesn't necessarily match the
6136 // type-as-written, but that's okay, because it should always be
6137 // derivable from the initializer.
6138
John McCalle15bbff2010-01-18 19:35:47 +00006139 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006140 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006141 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006142}
Mike Stump11289f42009-09-09 15:08:12 +00006143
Douglas Gregora16548e2009-08-11 05:31:07 +00006144template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006145ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006146TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006147 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006148 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006149 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006150
Douglas Gregora16548e2009-08-11 05:31:07 +00006151 if (!getDerived().AlwaysRebuild() &&
6152 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006153 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006154
Douglas Gregora16548e2009-08-11 05:31:07 +00006155 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006156 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006157 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006158 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006159 E->getAccessorLoc(),
6160 E->getAccessor());
6161}
Mike Stump11289f42009-09-09 15:08:12 +00006162
Douglas Gregora16548e2009-08-11 05:31:07 +00006163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006164ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006165TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006166 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006167
John McCall37ad5512010-08-23 06:44:23 +00006168 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006169 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6170 Inits, &InitChanged))
6171 return ExprError();
6172
Douglas Gregora16548e2009-08-11 05:31:07 +00006173 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006174 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006175
Douglas Gregora16548e2009-08-11 05:31:07 +00006176 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006177 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006178}
Mike Stump11289f42009-09-09 15:08:12 +00006179
Douglas Gregora16548e2009-08-11 05:31:07 +00006180template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006181ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006182TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006183 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006184
Douglas Gregorebe10102009-08-20 07:17:43 +00006185 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006186 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006187 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006188 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006189
Douglas Gregorebe10102009-08-20 07:17:43 +00006190 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006191 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006192 bool ExprChanged = false;
6193 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6194 DEnd = E->designators_end();
6195 D != DEnd; ++D) {
6196 if (D->isFieldDesignator()) {
6197 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6198 D->getDotLoc(),
6199 D->getFieldLoc()));
6200 continue;
6201 }
Mike Stump11289f42009-09-09 15:08:12 +00006202
Douglas Gregora16548e2009-08-11 05:31:07 +00006203 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006204 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006205 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006207
6208 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006209 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006210
Douglas Gregora16548e2009-08-11 05:31:07 +00006211 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6212 ArrayExprs.push_back(Index.release());
6213 continue;
6214 }
Mike Stump11289f42009-09-09 15:08:12 +00006215
Douglas Gregora16548e2009-08-11 05:31:07 +00006216 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006217 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006218 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6219 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006220 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006221
John McCalldadc5752010-08-24 06:29:42 +00006222 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006223 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006224 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006225
6226 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006227 End.get(),
6228 D->getLBracketLoc(),
6229 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006230
Douglas Gregora16548e2009-08-11 05:31:07 +00006231 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6232 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006233
Douglas Gregora16548e2009-08-11 05:31:07 +00006234 ArrayExprs.push_back(Start.release());
6235 ArrayExprs.push_back(End.release());
6236 }
Mike Stump11289f42009-09-09 15:08:12 +00006237
Douglas Gregora16548e2009-08-11 05:31:07 +00006238 if (!getDerived().AlwaysRebuild() &&
6239 Init.get() == E->getInit() &&
6240 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006241 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006242
Douglas Gregora16548e2009-08-11 05:31:07 +00006243 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6244 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006245 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006246}
Mike Stump11289f42009-09-09 15:08:12 +00006247
Douglas Gregora16548e2009-08-11 05:31:07 +00006248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006249ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006250TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006251 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006252 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006253
Douglas Gregor3da3c062009-10-28 00:29:27 +00006254 // FIXME: Will we ever have proper type location here? Will we actually
6255 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006256 QualType T = getDerived().TransformType(E->getType());
6257 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006258 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006259
Douglas Gregora16548e2009-08-11 05:31:07 +00006260 if (!getDerived().AlwaysRebuild() &&
6261 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006262 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006263
Douglas Gregora16548e2009-08-11 05:31:07 +00006264 return getDerived().RebuildImplicitValueInitExpr(T);
6265}
Mike Stump11289f42009-09-09 15:08:12 +00006266
Douglas Gregora16548e2009-08-11 05:31:07 +00006267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006268ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006269TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006270 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6271 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006273
John McCalldadc5752010-08-24 06:29:42 +00006274 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006275 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006276 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006277
Douglas Gregora16548e2009-08-11 05:31:07 +00006278 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006279 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006280 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006281 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006282
John McCallb268a282010-08-23 23:25:46 +00006283 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006284 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006285}
6286
6287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006288ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006289TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006290 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006291 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006292 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6293 &ArgumentChanged))
6294 return ExprError();
6295
Douglas Gregora16548e2009-08-11 05:31:07 +00006296 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6297 move_arg(Inits),
6298 E->getRParenLoc());
6299}
Mike Stump11289f42009-09-09 15:08:12 +00006300
Douglas Gregora16548e2009-08-11 05:31:07 +00006301/// \brief Transform an address-of-label expression.
6302///
6303/// By default, the transformation of an address-of-label expression always
6304/// rebuilds the expression, so that the label identifier can be resolved to
6305/// the corresponding label statement by semantic analysis.
6306template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006307ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006308TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006309 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6310 E->getLabel());
6311 if (!LD)
6312 return ExprError();
6313
Douglas Gregora16548e2009-08-11 05:31:07 +00006314 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006315 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006316}
Mike Stump11289f42009-09-09 15:08:12 +00006317
6318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006319ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006320TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006321 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006322 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6323 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006324 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006325
Douglas Gregora16548e2009-08-11 05:31:07 +00006326 if (!getDerived().AlwaysRebuild() &&
6327 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006328 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006329
6330 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006331 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006332 E->getRParenLoc());
6333}
Mike Stump11289f42009-09-09 15:08:12 +00006334
Douglas Gregora16548e2009-08-11 05:31:07 +00006335template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006336ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006337TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006338 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006339 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006340 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006341
John McCalldadc5752010-08-24 06:29:42 +00006342 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006343 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006345
John McCalldadc5752010-08-24 06:29:42 +00006346 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006347 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006348 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006349
Douglas Gregora16548e2009-08-11 05:31:07 +00006350 if (!getDerived().AlwaysRebuild() &&
6351 Cond.get() == E->getCond() &&
6352 LHS.get() == E->getLHS() &&
6353 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006354 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006355
Douglas Gregora16548e2009-08-11 05:31:07 +00006356 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006357 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006358 E->getRParenLoc());
6359}
Mike Stump11289f42009-09-09 15:08:12 +00006360
Douglas Gregora16548e2009-08-11 05:31:07 +00006361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006362ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006363TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006364 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006365}
6366
6367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006369TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006370 switch (E->getOperator()) {
6371 case OO_New:
6372 case OO_Delete:
6373 case OO_Array_New:
6374 case OO_Array_Delete:
6375 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006376 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006377
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006378 case OO_Call: {
6379 // This is a call to an object's operator().
6380 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6381
6382 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006383 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006384 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006385 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006386
6387 // FIXME: Poor location information
6388 SourceLocation FakeLParenLoc
6389 = SemaRef.PP.getLocForEndOfToken(
6390 static_cast<Expr *>(Object.get())->getLocEnd());
6391
6392 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006393 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006394 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6395 Args))
6396 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006397
John McCallb268a282010-08-23 23:25:46 +00006398 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006399 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006400 E->getLocEnd());
6401 }
6402
6403#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6404 case OO_##Name:
6405#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6406#include "clang/Basic/OperatorKinds.def"
6407 case OO_Subscript:
6408 // Handled below.
6409 break;
6410
6411 case OO_Conditional:
6412 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006413 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006414
6415 case OO_None:
6416 case NUM_OVERLOADED_OPERATORS:
6417 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006418 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006419 }
6420
John McCalldadc5752010-08-24 06:29:42 +00006421 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006422 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006423 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006424
John McCalldadc5752010-08-24 06:29:42 +00006425 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006426 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006427 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006428
John McCalldadc5752010-08-24 06:29:42 +00006429 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006430 if (E->getNumArgs() == 2) {
6431 Second = getDerived().TransformExpr(E->getArg(1));
6432 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006433 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006434 }
Mike Stump11289f42009-09-09 15:08:12 +00006435
Douglas Gregora16548e2009-08-11 05:31:07 +00006436 if (!getDerived().AlwaysRebuild() &&
6437 Callee.get() == E->getCallee() &&
6438 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006439 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006440 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006441
Douglas Gregora16548e2009-08-11 05:31:07 +00006442 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6443 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006444 Callee.get(),
6445 First.get(),
6446 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006447}
Mike Stump11289f42009-09-09 15:08:12 +00006448
Douglas Gregora16548e2009-08-11 05:31:07 +00006449template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006450ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006451TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6452 return getDerived().TransformCallExpr(E);
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
Peter Collingbourne41f85462011-02-09 21:07:24 +00006457TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6458 // Transform the callee.
6459 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6460 if (Callee.isInvalid())
6461 return ExprError();
6462
6463 // Transform exec config.
6464 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6465 if (EC.isInvalid())
6466 return ExprError();
6467
6468 // Transform arguments.
6469 bool ArgChanged = false;
6470 ASTOwningVector<Expr*> Args(SemaRef);
6471 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6472 &ArgChanged))
6473 return ExprError();
6474
6475 if (!getDerived().AlwaysRebuild() &&
6476 Callee.get() == E->getCallee() &&
6477 !ArgChanged)
6478 return SemaRef.Owned(E);
6479
6480 // FIXME: Wrong source location information for the '('.
6481 SourceLocation FakeLParenLoc
6482 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6483 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6484 move_arg(Args),
6485 E->getRParenLoc(), EC.get());
6486}
6487
6488template<typename Derived>
6489ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006490TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006491 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6492 if (!Type)
6493 return ExprError();
6494
John McCalldadc5752010-08-24 06:29:42 +00006495 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006496 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006497 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006498 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006499
Douglas Gregora16548e2009-08-11 05:31:07 +00006500 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006501 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006502 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006503 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006504
Douglas Gregora16548e2009-08-11 05:31:07 +00006505 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006506 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006507 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6508 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6509 SourceLocation FakeRParenLoc
6510 = SemaRef.PP.getLocForEndOfToken(
6511 E->getSubExpr()->getSourceRange().getEnd());
6512 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006513 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006514 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006515 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006516 FakeRAngleLoc,
6517 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006518 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006519 FakeRParenLoc);
6520}
Mike Stump11289f42009-09-09 15:08:12 +00006521
Douglas Gregora16548e2009-08-11 05:31:07 +00006522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006523ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006524TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6525 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006526}
Mike Stump11289f42009-09-09 15:08:12 +00006527
6528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006529ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006530TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6531 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006532}
6533
Douglas Gregora16548e2009-08-11 05:31:07 +00006534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006535ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006536TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006537 CXXReinterpretCastExpr *E) {
6538 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006539}
Mike Stump11289f42009-09-09 15:08:12 +00006540
Douglas Gregora16548e2009-08-11 05:31:07 +00006541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006542ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006543TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *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
Douglas Gregora16548e2009-08-11 05:31:07 +00006549TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006550 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006551 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6552 if (!Type)
6553 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006554
John McCalldadc5752010-08-24 06:29:42 +00006555 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006556 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006557 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006558 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006559
Douglas Gregora16548e2009-08-11 05:31:07 +00006560 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006561 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006562 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006563 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006564
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006565 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006566 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006567 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006568 E->getRParenLoc());
6569}
Mike Stump11289f42009-09-09 15:08:12 +00006570
Douglas Gregora16548e2009-08-11 05:31:07 +00006571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006572ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006573TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006574 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006575 TypeSourceInfo *TInfo
6576 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6577 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006578 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006579
Douglas Gregora16548e2009-08-11 05:31:07 +00006580 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006581 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006582 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006583
Douglas Gregor9da64192010-04-26 22:37:10 +00006584 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6585 E->getLocStart(),
6586 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006587 E->getLocEnd());
6588 }
Mike Stump11289f42009-09-09 15:08:12 +00006589
Douglas Gregora16548e2009-08-11 05:31:07 +00006590 // We don't know whether the expression is potentially evaluated until
6591 // after we perform semantic analysis, so the expression is potentially
6592 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006593 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006594 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006595
John McCalldadc5752010-08-24 06:29:42 +00006596 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006597 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006598 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006599
Douglas Gregora16548e2009-08-11 05:31:07 +00006600 if (!getDerived().AlwaysRebuild() &&
6601 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006602 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006603
Douglas Gregor9da64192010-04-26 22:37:10 +00006604 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6605 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006606 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006607 E->getLocEnd());
6608}
6609
6610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006611ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006612TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6613 if (E->isTypeOperand()) {
6614 TypeSourceInfo *TInfo
6615 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6616 if (!TInfo)
6617 return ExprError();
6618
6619 if (!getDerived().AlwaysRebuild() &&
6620 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006621 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006622
Douglas Gregor69735112011-03-06 17:40:41 +00006623 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006624 E->getLocStart(),
6625 TInfo,
6626 E->getLocEnd());
6627 }
6628
6629 // We don't know whether the expression is potentially evaluated until
6630 // after we perform semantic analysis, so the expression is potentially
6631 // potentially evaluated.
6632 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6633
6634 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6635 if (SubExpr.isInvalid())
6636 return ExprError();
6637
6638 if (!getDerived().AlwaysRebuild() &&
6639 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006640 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006641
6642 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6643 E->getLocStart(),
6644 SubExpr.get(),
6645 E->getLocEnd());
6646}
6647
6648template<typename Derived>
6649ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006650TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006651 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006652}
Mike Stump11289f42009-09-09 15:08:12 +00006653
Douglas Gregora16548e2009-08-11 05:31:07 +00006654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006655ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006656TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006657 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006658 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006659}
Mike Stump11289f42009-09-09 15:08:12 +00006660
Douglas Gregora16548e2009-08-11 05:31:07 +00006661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006662ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006663TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006664 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6665 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6666 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006667
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006668 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006669 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006670
Douglas Gregorb15af892010-01-07 23:12:05 +00006671 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006672}
Mike Stump11289f42009-09-09 15:08:12 +00006673
Douglas Gregora16548e2009-08-11 05:31:07 +00006674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006675ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006676TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006677 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006678 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006679 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006680
Douglas Gregora16548e2009-08-11 05:31:07 +00006681 if (!getDerived().AlwaysRebuild() &&
6682 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006683 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006684
John McCallb268a282010-08-23 23:25:46 +00006685 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006686}
Mike Stump11289f42009-09-09 15:08:12 +00006687
Douglas Gregora16548e2009-08-11 05:31:07 +00006688template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006689ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006690TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006691 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006692 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6693 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006694 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006696
Chandler Carruth794da4c2010-02-08 06:42:49 +00006697 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006698 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006699 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006700
Douglas Gregor033f6752009-12-23 23:03:06 +00006701 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006702}
Mike Stump11289f42009-09-09 15:08:12 +00006703
Douglas Gregora16548e2009-08-11 05:31:07 +00006704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006705ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006706TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6707 CXXScalarValueInitExpr *E) {
6708 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6709 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006710 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006711
Douglas Gregora16548e2009-08-11 05:31:07 +00006712 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006713 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006714 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006715
Douglas Gregor2b88c112010-09-08 00:15:04 +00006716 return getDerived().RebuildCXXScalarValueInitExpr(T,
6717 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006718 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006719}
Mike Stump11289f42009-09-09 15:08:12 +00006720
Douglas Gregora16548e2009-08-11 05:31:07 +00006721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006722ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006723TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006724 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006725 TypeSourceInfo *AllocTypeInfo
6726 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6727 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006729
Douglas Gregora16548e2009-08-11 05:31:07 +00006730 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006731 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006732 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006734
Douglas Gregora16548e2009-08-11 05:31:07 +00006735 // Transform the placement arguments (if any).
6736 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006737 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006738 if (getDerived().TransformExprs(E->getPlacementArgs(),
6739 E->getNumPlacementArgs(), true,
6740 PlacementArgs, &ArgumentChanged))
6741 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006742
Douglas Gregorebe10102009-08-20 07:17:43 +00006743 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006744 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006745 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6746 ConstructorArgs, &ArgumentChanged))
6747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006748
Douglas Gregord2d9da02010-02-26 00:38:10 +00006749 // Transform constructor, new operator, and delete operator.
6750 CXXConstructorDecl *Constructor = 0;
6751 if (E->getConstructor()) {
6752 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006753 getDerived().TransformDecl(E->getLocStart(),
6754 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006755 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006756 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006757 }
6758
6759 FunctionDecl *OperatorNew = 0;
6760 if (E->getOperatorNew()) {
6761 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006762 getDerived().TransformDecl(E->getLocStart(),
6763 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006764 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006765 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006766 }
6767
6768 FunctionDecl *OperatorDelete = 0;
6769 if (E->getOperatorDelete()) {
6770 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006771 getDerived().TransformDecl(E->getLocStart(),
6772 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006773 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006774 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006775 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006776
Douglas Gregora16548e2009-08-11 05:31:07 +00006777 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006778 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006779 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006780 Constructor == E->getConstructor() &&
6781 OperatorNew == E->getOperatorNew() &&
6782 OperatorDelete == E->getOperatorDelete() &&
6783 !ArgumentChanged) {
6784 // Mark any declarations we need as referenced.
6785 // FIXME: instantiation-specific.
6786 if (Constructor)
6787 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6788 if (OperatorNew)
6789 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6790 if (OperatorDelete)
6791 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006792 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006793 }
Mike Stump11289f42009-09-09 15:08:12 +00006794
Douglas Gregor0744ef62010-09-07 21:49:58 +00006795 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006796 if (!ArraySize.get()) {
6797 // If no array size was specified, but the new expression was
6798 // instantiated with an array type (e.g., "new T" where T is
6799 // instantiated with "int[4]"), extract the outer bound from the
6800 // array type as our array size. We do this with constant and
6801 // dependently-sized array types.
6802 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6803 if (!ArrayT) {
6804 // Do nothing
6805 } else if (const ConstantArrayType *ConsArrayT
6806 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006807 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006808 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6809 ConsArrayT->getSize(),
6810 SemaRef.Context.getSizeType(),
6811 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006812 AllocType = ConsArrayT->getElementType();
6813 } else if (const DependentSizedArrayType *DepArrayT
6814 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6815 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006816 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006817 AllocType = DepArrayT->getElementType();
6818 }
6819 }
6820 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006821
Douglas Gregora16548e2009-08-11 05:31:07 +00006822 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6823 E->isGlobalNew(),
6824 /*FIXME:*/E->getLocStart(),
6825 move_arg(PlacementArgs),
6826 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006827 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006828 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006829 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006830 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006831 /*FIXME:*/E->getLocStart(),
6832 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006833 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006834}
Mike Stump11289f42009-09-09 15:08:12 +00006835
Douglas Gregora16548e2009-08-11 05:31:07 +00006836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006837ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006838TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006839 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006840 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006841 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006842
Douglas Gregord2d9da02010-02-26 00:38:10 +00006843 // Transform the delete operator, if known.
6844 FunctionDecl *OperatorDelete = 0;
6845 if (E->getOperatorDelete()) {
6846 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006847 getDerived().TransformDecl(E->getLocStart(),
6848 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006849 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006850 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006851 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006852
Douglas Gregora16548e2009-08-11 05:31:07 +00006853 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006854 Operand.get() == E->getArgument() &&
6855 OperatorDelete == E->getOperatorDelete()) {
6856 // Mark any declarations we need as referenced.
6857 // FIXME: instantiation-specific.
6858 if (OperatorDelete)
6859 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006860
6861 if (!E->getArgument()->isTypeDependent()) {
6862 QualType Destroyed = SemaRef.Context.getBaseElementType(
6863 E->getDestroyedType());
6864 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6865 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6866 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6867 SemaRef.LookupDestructor(Record));
6868 }
6869 }
6870
John McCallc3007a22010-10-26 07:05:15 +00006871 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006872 }
Mike Stump11289f42009-09-09 15:08:12 +00006873
Douglas Gregora16548e2009-08-11 05:31:07 +00006874 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6875 E->isGlobalDelete(),
6876 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006877 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006878}
Mike Stump11289f42009-09-09 15:08:12 +00006879
Douglas Gregora16548e2009-08-11 05:31:07 +00006880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006881ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006882TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006883 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006884 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006885 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006886 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006887
John McCallba7bf592010-08-24 05:47:05 +00006888 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006889 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006890 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006891 E->getOperatorLoc(),
6892 E->isArrow()? tok::arrow : tok::period,
6893 ObjectTypePtr,
6894 MayBePseudoDestructor);
6895 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006896 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006897
John McCallba7bf592010-08-24 05:47:05 +00006898 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006899 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6900 if (QualifierLoc) {
6901 QualifierLoc
6902 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6903 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006904 return ExprError();
6905 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006906 CXXScopeSpec SS;
6907 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006908
Douglas Gregor678f90d2010-02-25 01:56:36 +00006909 PseudoDestructorTypeStorage Destroyed;
6910 if (E->getDestroyedTypeInfo()) {
6911 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006912 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006913 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006914 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006915 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006916 Destroyed = DestroyedTypeInfo;
6917 } else if (ObjectType->isDependentType()) {
6918 // We aren't likely to be able to resolve the identifier down to a type
6919 // now anyway, so just retain the identifier.
6920 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6921 E->getDestroyedTypeLoc());
6922 } else {
6923 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006924 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006925 *E->getDestroyedTypeIdentifier(),
6926 E->getDestroyedTypeLoc(),
6927 /*Scope=*/0,
6928 SS, ObjectTypePtr,
6929 false);
6930 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006931 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006932
Douglas Gregor678f90d2010-02-25 01:56:36 +00006933 Destroyed
6934 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6935 E->getDestroyedTypeLoc());
6936 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006937
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006938 TypeSourceInfo *ScopeTypeInfo = 0;
6939 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006940 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006941 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006942 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006943 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006944
John McCallb268a282010-08-23 23:25:46 +00006945 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006946 E->getOperatorLoc(),
6947 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006948 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006949 ScopeTypeInfo,
6950 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006951 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006952 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006953}
Mike Stump11289f42009-09-09 15:08:12 +00006954
Douglas Gregorad8a3362009-09-04 17:36:40 +00006955template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006956ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006957TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006958 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006959 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6960 Sema::LookupOrdinaryName);
6961
6962 // Transform all the decls.
6963 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6964 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006965 NamedDecl *InstD = static_cast<NamedDecl*>(
6966 getDerived().TransformDecl(Old->getNameLoc(),
6967 *I));
John McCall84d87672009-12-10 09:41:52 +00006968 if (!InstD) {
6969 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6970 // This can happen because of dependent hiding.
6971 if (isa<UsingShadowDecl>(*I))
6972 continue;
6973 else
John McCallfaf5fb42010-08-26 23:41:50 +00006974 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006975 }
John McCalle66edc12009-11-24 19:00:30 +00006976
6977 // Expand using declarations.
6978 if (isa<UsingDecl>(InstD)) {
6979 UsingDecl *UD = cast<UsingDecl>(InstD);
6980 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6981 E = UD->shadow_end(); I != E; ++I)
6982 R.addDecl(*I);
6983 continue;
6984 }
6985
6986 R.addDecl(InstD);
6987 }
6988
6989 // Resolve a kind, but don't do any further analysis. If it's
6990 // ambiguous, the callee needs to deal with it.
6991 R.resolveKind();
6992
6993 // Rebuild the nested-name qualifier, if present.
6994 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006995 if (Old->getQualifierLoc()) {
6996 NestedNameSpecifierLoc QualifierLoc
6997 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6998 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006999 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007000
Douglas Gregor0da1d432011-02-28 20:01:57 +00007001 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007002 }
7003
Douglas Gregor9262f472010-04-27 18:19:34 +00007004 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007005 CXXRecordDecl *NamingClass
7006 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7007 Old->getNameLoc(),
7008 Old->getNamingClass()));
7009 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007010 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007011
Douglas Gregorda7be082010-04-27 16:10:10 +00007012 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007013 }
7014
7015 // If we have no template arguments, it's a normal declaration name.
7016 if (!Old->hasExplicitTemplateArgs())
7017 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7018
7019 // If we have template arguments, rebuild them, then rebuild the
7020 // templateid expression.
7021 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007022 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7023 Old->getNumTemplateArgs(),
7024 TransArgs))
7025 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007026
7027 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7028 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007029}
Mike Stump11289f42009-09-09 15:08:12 +00007030
Douglas Gregora16548e2009-08-11 05:31:07 +00007031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007032ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007033TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007034 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7035 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007036 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007037
Douglas Gregora16548e2009-08-11 05:31:07 +00007038 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007039 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007040 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007041
Mike Stump11289f42009-09-09 15:08:12 +00007042 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007043 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007044 T,
7045 E->getLocEnd());
7046}
Mike Stump11289f42009-09-09 15:08:12 +00007047
Douglas Gregora16548e2009-08-11 05:31:07 +00007048template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007049ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007050TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7051 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7052 if (!LhsT)
7053 return ExprError();
7054
7055 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7056 if (!RhsT)
7057 return ExprError();
7058
7059 if (!getDerived().AlwaysRebuild() &&
7060 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7061 return SemaRef.Owned(E);
7062
7063 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7064 E->getLocStart(),
7065 LhsT, RhsT,
7066 E->getLocEnd());
7067}
7068
7069template<typename Derived>
7070ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007071TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7072 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7073 if (!T)
7074 return ExprError();
7075
7076 if (!getDerived().AlwaysRebuild() &&
7077 T == E->getQueriedTypeSourceInfo())
7078 return SemaRef.Owned(E);
7079
7080 ExprResult SubExpr;
7081 {
7082 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7083 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7084 if (SubExpr.isInvalid())
7085 return ExprError();
7086
7087 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7088 return SemaRef.Owned(E);
7089 }
7090
7091 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7092 E->getLocStart(),
7093 T,
7094 SubExpr.get(),
7095 E->getLocEnd());
7096}
7097
7098template<typename Derived>
7099ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007100TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7101 ExprResult SubExpr;
7102 {
7103 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7104 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7105 if (SubExpr.isInvalid())
7106 return ExprError();
7107
7108 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7109 return SemaRef.Owned(E);
7110 }
7111
7112 return getDerived().RebuildExpressionTrait(
7113 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7114}
7115
7116template<typename Derived>
7117ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007118TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007119 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007120 NestedNameSpecifierLoc QualifierLoc
7121 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7122 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007123 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007124
John McCall31f82722010-11-12 08:19:04 +00007125 // TODO: If this is a conversion-function-id, verify that the
7126 // destination type name (if present) resolves the same way after
7127 // instantiation as it did in the local scope.
7128
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007129 DeclarationNameInfo NameInfo
7130 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7131 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007133
John McCalle66edc12009-11-24 19:00:30 +00007134 if (!E->hasExplicitTemplateArgs()) {
7135 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007136 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007137 // Note: it is sufficient to compare the Name component of NameInfo:
7138 // if name has not changed, DNLoc has not changed either.
7139 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007140 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007141
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007142 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007143 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007144 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007145 }
John McCall6b51f282009-11-23 01:53:49 +00007146
7147 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007148 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7149 E->getNumTemplateArgs(),
7150 TransArgs))
7151 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007152
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007153 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007154 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007155 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007156}
7157
7158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007159ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007160TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007161 // CXXConstructExprs are always implicit, so when we have a
7162 // 1-argument construction we just transform that argument.
7163 if (E->getNumArgs() == 1 ||
7164 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7165 return getDerived().TransformExpr(E->getArg(0));
7166
Douglas Gregora16548e2009-08-11 05:31:07 +00007167 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7168
7169 QualType T = getDerived().TransformType(E->getType());
7170 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007171 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007172
7173 CXXConstructorDecl *Constructor
7174 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007175 getDerived().TransformDecl(E->getLocStart(),
7176 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007177 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007179
Douglas Gregora16548e2009-08-11 05:31:07 +00007180 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007181 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007182 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7183 &ArgumentChanged))
7184 return ExprError();
7185
Douglas Gregora16548e2009-08-11 05:31:07 +00007186 if (!getDerived().AlwaysRebuild() &&
7187 T == E->getType() &&
7188 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007189 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007190 // Mark the constructor as referenced.
7191 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007192 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007193 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007194 }
Mike Stump11289f42009-09-09 15:08:12 +00007195
Douglas Gregordb121ba2009-12-14 16:27:04 +00007196 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7197 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007198 move_arg(Args),
7199 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007200 E->getConstructionKind(),
7201 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007202}
Mike Stump11289f42009-09-09 15:08:12 +00007203
Douglas Gregora16548e2009-08-11 05:31:07 +00007204/// \brief Transform a C++ temporary-binding expression.
7205///
Douglas Gregor363b1512009-12-24 18:51:59 +00007206/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7207/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007208template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007209ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007210TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007211 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007212}
Mike Stump11289f42009-09-09 15:08:12 +00007213
John McCall5d413782010-12-06 08:20:24 +00007214/// \brief Transform a C++ expression that contains cleanups that should
7215/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007216///
John McCall5d413782010-12-06 08:20:24 +00007217/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007218/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007220ExprResult
John McCall5d413782010-12-06 08:20:24 +00007221TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007222 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007223}
Mike Stump11289f42009-09-09 15:08:12 +00007224
Douglas Gregora16548e2009-08-11 05:31:07 +00007225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007226ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007227TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007228 CXXTemporaryObjectExpr *E) {
7229 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7230 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007231 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007232
Douglas Gregora16548e2009-08-11 05:31:07 +00007233 CXXConstructorDecl *Constructor
7234 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007235 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007236 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007237 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007239
Douglas Gregora16548e2009-08-11 05:31:07 +00007240 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007241 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007242 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007243 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7244 &ArgumentChanged))
7245 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007246
Douglas Gregora16548e2009-08-11 05:31:07 +00007247 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007248 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007249 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007250 !ArgumentChanged) {
7251 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007252 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007253 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007254 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007255
7256 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7257 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007258 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007259 E->getLocEnd());
7260}
Mike Stump11289f42009-09-09 15:08:12 +00007261
Douglas Gregora16548e2009-08-11 05:31:07 +00007262template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007263ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007264TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007265 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007266 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7267 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007269
Douglas Gregora16548e2009-08-11 05:31:07 +00007270 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007271 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007272 Args.reserve(E->arg_size());
7273 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7274 &ArgumentChanged))
7275 return ExprError();
7276
Douglas Gregora16548e2009-08-11 05:31:07 +00007277 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007278 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007279 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007280 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007281
Douglas Gregora16548e2009-08-11 05:31:07 +00007282 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007283 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007284 E->getLParenLoc(),
7285 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007286 E->getRParenLoc());
7287}
Mike Stump11289f42009-09-09 15:08:12 +00007288
Douglas Gregora16548e2009-08-11 05:31:07 +00007289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007290ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007291TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007292 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007293 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007294 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007295 Expr *OldBase;
7296 QualType BaseType;
7297 QualType ObjectType;
7298 if (!E->isImplicitAccess()) {
7299 OldBase = E->getBase();
7300 Base = getDerived().TransformExpr(OldBase);
7301 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007302 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007303
John McCall2d74de92009-12-01 22:10:20 +00007304 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007305 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007306 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007307 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007308 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007309 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007310 ObjectTy,
7311 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007312 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007313 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007314
John McCallba7bf592010-08-24 05:47:05 +00007315 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007316 BaseType = ((Expr*) Base.get())->getType();
7317 } else {
7318 OldBase = 0;
7319 BaseType = getDerived().TransformType(E->getBaseType());
7320 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7321 }
Mike Stump11289f42009-09-09 15:08:12 +00007322
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007323 // Transform the first part of the nested-name-specifier that qualifies
7324 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007325 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007326 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007327 E->getFirstQualifierFoundInScope(),
7328 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007329
Douglas Gregore16af532011-02-28 18:50:33 +00007330 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007331 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007332 QualifierLoc
7333 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7334 ObjectType,
7335 FirstQualifierInScope);
7336 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007337 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007338 }
Mike Stump11289f42009-09-09 15:08:12 +00007339
John McCall31f82722010-11-12 08:19:04 +00007340 // TODO: If this is a conversion-function-id, verify that the
7341 // destination type name (if present) resolves the same way after
7342 // instantiation as it did in the local scope.
7343
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007344 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007345 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007346 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007347 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007348
John McCall2d74de92009-12-01 22:10:20 +00007349 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007350 // This is a reference to a member without an explicitly-specified
7351 // template argument list. Optimize for this common case.
7352 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007353 Base.get() == OldBase &&
7354 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007355 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007356 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007357 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007358 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007359
John McCallb268a282010-08-23 23:25:46 +00007360 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007361 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007362 E->isArrow(),
7363 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007364 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007365 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007366 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007367 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007368 }
7369
John McCall6b51f282009-11-23 01:53:49 +00007370 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007371 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7372 E->getNumTemplateArgs(),
7373 TransArgs))
7374 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007375
John McCallb268a282010-08-23 23:25:46 +00007376 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007377 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007378 E->isArrow(),
7379 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007380 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007381 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007382 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007383 &TransArgs);
7384}
7385
7386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007387ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007388TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007389 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007390 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007391 QualType BaseType;
7392 if (!Old->isImplicitAccess()) {
7393 Base = getDerived().TransformExpr(Old->getBase());
7394 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007395 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007396 BaseType = ((Expr*) Base.get())->getType();
7397 } else {
7398 BaseType = getDerived().TransformType(Old->getBaseType());
7399 }
John McCall10eae182009-11-30 22:42:35 +00007400
Douglas Gregor0da1d432011-02-28 20:01:57 +00007401 NestedNameSpecifierLoc QualifierLoc;
7402 if (Old->getQualifierLoc()) {
7403 QualifierLoc
7404 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7405 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007406 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007407 }
7408
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007409 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007410 Sema::LookupOrdinaryName);
7411
7412 // Transform all the decls.
7413 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7414 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007415 NamedDecl *InstD = static_cast<NamedDecl*>(
7416 getDerived().TransformDecl(Old->getMemberLoc(),
7417 *I));
John McCall84d87672009-12-10 09:41:52 +00007418 if (!InstD) {
7419 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7420 // This can happen because of dependent hiding.
7421 if (isa<UsingShadowDecl>(*I))
7422 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007423 else {
7424 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007425 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007426 }
John McCall84d87672009-12-10 09:41:52 +00007427 }
John McCall10eae182009-11-30 22:42:35 +00007428
7429 // Expand using declarations.
7430 if (isa<UsingDecl>(InstD)) {
7431 UsingDecl *UD = cast<UsingDecl>(InstD);
7432 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7433 E = UD->shadow_end(); I != E; ++I)
7434 R.addDecl(*I);
7435 continue;
7436 }
7437
7438 R.addDecl(InstD);
7439 }
7440
7441 R.resolveKind();
7442
Douglas Gregor9262f472010-04-27 18:19:34 +00007443 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007444 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007445 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007446 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007447 Old->getMemberLoc(),
7448 Old->getNamingClass()));
7449 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007450 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007451
Douglas Gregorda7be082010-04-27 16:10:10 +00007452 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007453 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007454
John McCall10eae182009-11-30 22:42:35 +00007455 TemplateArgumentListInfo TransArgs;
7456 if (Old->hasExplicitTemplateArgs()) {
7457 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7458 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007459 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7460 Old->getNumTemplateArgs(),
7461 TransArgs))
7462 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007463 }
John McCall38836f02010-01-15 08:34:02 +00007464
7465 // FIXME: to do this check properly, we will need to preserve the
7466 // first-qualifier-in-scope here, just in case we had a dependent
7467 // base (and therefore couldn't do the check) and a
7468 // nested-name-qualifier (and therefore could do the lookup).
7469 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007470
John McCallb268a282010-08-23 23:25:46 +00007471 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007472 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007473 Old->getOperatorLoc(),
7474 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007475 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007476 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007477 R,
7478 (Old->hasExplicitTemplateArgs()
7479 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007480}
7481
7482template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007483ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007484TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7485 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7486 if (SubExpr.isInvalid())
7487 return ExprError();
7488
7489 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007490 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007491
7492 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7493}
7494
7495template<typename Derived>
7496ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007497TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007498 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7499 if (Pattern.isInvalid())
7500 return ExprError();
7501
7502 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7503 return SemaRef.Owned(E);
7504
Douglas Gregorb8840002011-01-14 21:20:45 +00007505 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7506 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007507}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007508
7509template<typename Derived>
7510ExprResult
7511TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7512 // If E is not value-dependent, then nothing will change when we transform it.
7513 // Note: This is an instantiation-centric view.
7514 if (!E->isValueDependent())
7515 return SemaRef.Owned(E);
7516
7517 // Note: None of the implementations of TryExpandParameterPacks can ever
7518 // produce a diagnostic when given only a single unexpanded parameter pack,
7519 // so
7520 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7521 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007522 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007523 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007524 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7525 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007526 ShouldExpand, RetainExpansion,
7527 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007528 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007529
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007530 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007531 return SemaRef.Owned(E);
7532
7533 // We now know the length of the parameter pack, so build a new expression
7534 // that stores that length.
7535 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7536 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007537 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007538}
7539
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007540template<typename Derived>
7541ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007542TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7543 SubstNonTypeTemplateParmPackExpr *E) {
7544 // Default behavior is to do nothing with this transformation.
7545 return SemaRef.Owned(E);
7546}
7547
7548template<typename Derived>
7549ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007550TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007551 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007552}
7553
Mike Stump11289f42009-09-09 15:08:12 +00007554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007555ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007556TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007557 TypeSourceInfo *EncodedTypeInfo
7558 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7559 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007560 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007561
Douglas Gregora16548e2009-08-11 05:31:07 +00007562 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007563 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007564 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007565
7566 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007567 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007568 E->getRParenLoc());
7569}
Mike Stump11289f42009-09-09 15:08:12 +00007570
Douglas Gregora16548e2009-08-11 05:31:07 +00007571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007572ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007573TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007574 // Transform arguments.
7575 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007576 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007577 Args.reserve(E->getNumArgs());
7578 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7579 &ArgChanged))
7580 return ExprError();
7581
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007582 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7583 // Class message: transform the receiver type.
7584 TypeSourceInfo *ReceiverTypeInfo
7585 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7586 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007587 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007588
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007589 // If nothing changed, just retain the existing message send.
7590 if (!getDerived().AlwaysRebuild() &&
7591 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007592 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007593
7594 // Build a new class message send.
7595 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7596 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007597 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007598 E->getMethodDecl(),
7599 E->getLeftLoc(),
7600 move_arg(Args),
7601 E->getRightLoc());
7602 }
7603
7604 // Instance message: transform the receiver
7605 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7606 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007607 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007608 = getDerived().TransformExpr(E->getInstanceReceiver());
7609 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007610 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007611
7612 // If nothing changed, just retain the existing message send.
7613 if (!getDerived().AlwaysRebuild() &&
7614 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007615 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007616
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007617 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007618 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007619 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007620 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007621 E->getMethodDecl(),
7622 E->getLeftLoc(),
7623 move_arg(Args),
7624 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007625}
7626
Mike Stump11289f42009-09-09 15:08:12 +00007627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007628ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007629TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007630 return SemaRef.Owned(E);
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>::TransformObjCProtocolExpr(ObjCProtocolExpr *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>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007642 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007643 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007644 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007645 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007646
7647 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007648
Douglas Gregord51d90d2010-04-26 20:11:03 +00007649 // If nothing changed, just retain the existing expression.
7650 if (!getDerived().AlwaysRebuild() &&
7651 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007652 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007653
John McCallb268a282010-08-23 23:25:46 +00007654 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007655 E->getLocation(),
7656 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007657}
7658
Mike Stump11289f42009-09-09 15:08:12 +00007659template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007660ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007661TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007662 // 'super' and types never change. Property never changes. Just
7663 // retain the existing expression.
7664 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007665 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007666
Douglas Gregor9faee212010-04-26 20:47:02 +00007667 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007668 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007669 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007670 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007671
Douglas Gregor9faee212010-04-26 20:47:02 +00007672 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007673
Douglas Gregor9faee212010-04-26 20:47:02 +00007674 // If nothing changed, just retain the existing expression.
7675 if (!getDerived().AlwaysRebuild() &&
7676 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007677 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007678
John McCallb7bd14f2010-12-02 01:19:52 +00007679 if (E->isExplicitProperty())
7680 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7681 E->getExplicitProperty(),
7682 E->getLocation());
7683
7684 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7685 E->getType(),
7686 E->getImplicitPropertyGetter(),
7687 E->getImplicitPropertySetter(),
7688 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007689}
7690
Mike Stump11289f42009-09-09 15:08:12 +00007691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007692ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007693TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007694 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007695 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007696 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007697 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007698
Douglas Gregord51d90d2010-04-26 20:11:03 +00007699 // If nothing changed, just retain the existing expression.
7700 if (!getDerived().AlwaysRebuild() &&
7701 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007702 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007703
John McCallb268a282010-08-23 23:25:46 +00007704 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007705 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007706}
7707
Mike Stump11289f42009-09-09 15:08:12 +00007708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007709ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007710TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007711 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007712 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007713 SubExprs.reserve(E->getNumSubExprs());
7714 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7715 SubExprs, &ArgumentChanged))
7716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007717
Douglas Gregora16548e2009-08-11 05:31:07 +00007718 if (!getDerived().AlwaysRebuild() &&
7719 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007720 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007721
Douglas Gregora16548e2009-08-11 05:31:07 +00007722 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7723 move_arg(SubExprs),
7724 E->getRParenLoc());
7725}
7726
Mike Stump11289f42009-09-09 15:08:12 +00007727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007728ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007729TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007730 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007731
John McCall490112f2011-02-04 18:33:18 +00007732 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7733 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7734
7735 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00007736 // We built a new blockScopeInfo in call to ActOnBlockStart
7737 // in above, CapturesCXXThis need be set here from the block
7738 // expression.
7739 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7740
John McCall490112f2011-02-04 18:33:18 +00007741 llvm::SmallVector<ParmVarDecl*, 4> params;
7742 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007743
7744 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007745 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7746 oldBlock->param_begin(),
7747 oldBlock->param_size(),
7748 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007749 return true;
John McCall490112f2011-02-04 18:33:18 +00007750
7751 const FunctionType *exprFunctionType = E->getFunctionType();
7752 QualType exprResultType = exprFunctionType->getResultType();
7753 if (!exprResultType.isNull()) {
7754 if (!exprResultType->isDependentType())
7755 blockScope->ReturnType = exprResultType;
7756 else if (exprResultType != getSema().Context.DependentTy)
7757 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007758 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007759
7760 // If the return type has not been determined yet, leave it as a dependent
7761 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007762 if (blockScope->ReturnType.isNull())
7763 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007764
7765 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007766 if (blockScope->ReturnType->isObjCObjectType()) {
7767 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007768 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007769 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007770 return ExprError();
7771 }
John McCall3882ace2011-01-05 12:14:39 +00007772
John McCall490112f2011-02-04 18:33:18 +00007773 QualType functionType = getDerived().RebuildFunctionProtoType(
7774 blockScope->ReturnType,
7775 paramTypes.data(),
7776 paramTypes.size(),
7777 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007778 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007779 exprFunctionType->getExtInfo());
7780 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007781
7782 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007783 if (!params.empty())
7784 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007785
7786 // If the return type wasn't explicitly set, it will have been marked as a
7787 // dependent type (DependentTy); clear out the return type setting so
7788 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007789 if (blockScope->ReturnType == getSema().Context.DependentTy)
7790 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007791
John McCall3882ace2011-01-05 12:14:39 +00007792 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007793 StmtResult body = getDerived().TransformStmt(E->getBody());
7794 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007795 return ExprError();
7796
John McCall490112f2011-02-04 18:33:18 +00007797#ifndef NDEBUG
7798 // In builds with assertions, make sure that we captured everything we
7799 // captured before.
7800
John McCall490112f2011-02-04 18:33:18 +00007801 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7802 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007803 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007804
7805 // Ignore parameter packs.
7806 if (isa<ParmVarDecl>(oldCapture) &&
7807 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7808 continue;
7809
7810 VarDecl *newCapture =
7811 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7812 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007813 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007814 }
7815#endif
7816
7817 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7818 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007819}
7820
Mike Stump11289f42009-09-09 15:08:12 +00007821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007822ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007823TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007824 ValueDecl *ND
7825 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7826 E->getDecl()));
7827 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007828 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007829
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007830 if (!getDerived().AlwaysRebuild() &&
7831 ND == E->getDecl()) {
7832 // Mark it referenced in the new context regardless.
7833 // FIXME: this is a bit instantiation-specific.
7834 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7835
John McCallc3007a22010-10-26 07:05:15 +00007836 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007837 }
7838
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007839 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007840 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007841 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007842}
Mike Stump11289f42009-09-09 15:08:12 +00007843
Douglas Gregora16548e2009-08-11 05:31:07 +00007844//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007845// Type reconstruction
7846//===----------------------------------------------------------------------===//
7847
Mike Stump11289f42009-09-09 15:08:12 +00007848template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007849QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7850 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007851 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007852 getDerived().getBaseEntity());
7853}
7854
Mike Stump11289f42009-09-09 15:08:12 +00007855template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007856QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7857 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007858 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007859 getDerived().getBaseEntity());
7860}
7861
Mike Stump11289f42009-09-09 15:08:12 +00007862template<typename Derived>
7863QualType
John McCall70dd5f62009-10-30 00:06:24 +00007864TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7865 bool WrittenAsLValue,
7866 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007867 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007868 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007869}
7870
7871template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007872QualType
John McCall70dd5f62009-10-30 00:06:24 +00007873TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7874 QualType ClassType,
7875 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007876 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007877 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007878}
7879
7880template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007881QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007882TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7883 ArrayType::ArraySizeModifier SizeMod,
7884 const llvm::APInt *Size,
7885 Expr *SizeExpr,
7886 unsigned IndexTypeQuals,
7887 SourceRange BracketsRange) {
7888 if (SizeExpr || !Size)
7889 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7890 IndexTypeQuals, BracketsRange,
7891 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007892
7893 QualType Types[] = {
7894 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7895 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7896 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007897 };
7898 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7899 QualType SizeType;
7900 for (unsigned I = 0; I != NumTypes; ++I)
7901 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7902 SizeType = Types[I];
7903 break;
7904 }
Mike Stump11289f42009-09-09 15:08:12 +00007905
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007906 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7907 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007908 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007909 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007910 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007911}
Mike Stump11289f42009-09-09 15:08:12 +00007912
Douglas Gregord6ff3322009-08-04 16:50:30 +00007913template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007914QualType
7915TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007916 ArrayType::ArraySizeModifier SizeMod,
7917 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007918 unsigned IndexTypeQuals,
7919 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007920 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007921 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007922}
7923
7924template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007925QualType
Mike Stump11289f42009-09-09 15:08:12 +00007926TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007927 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007928 unsigned IndexTypeQuals,
7929 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007930 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007931 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007932}
Mike Stump11289f42009-09-09 15:08:12 +00007933
Douglas Gregord6ff3322009-08-04 16:50:30 +00007934template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007935QualType
7936TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007937 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007938 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007939 unsigned IndexTypeQuals,
7940 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007941 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007942 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007943 IndexTypeQuals, BracketsRange);
7944}
7945
7946template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007947QualType
7948TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007949 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007950 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007951 unsigned IndexTypeQuals,
7952 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007953 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007954 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007955 IndexTypeQuals, BracketsRange);
7956}
7957
7958template<typename Derived>
7959QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007960 unsigned NumElements,
7961 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007962 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007963 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007964}
Mike Stump11289f42009-09-09 15:08:12 +00007965
Douglas Gregord6ff3322009-08-04 16:50:30 +00007966template<typename Derived>
7967QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7968 unsigned NumElements,
7969 SourceLocation AttributeLoc) {
7970 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7971 NumElements, true);
7972 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007973 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7974 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007975 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007976}
Mike Stump11289f42009-09-09 15:08:12 +00007977
Douglas Gregord6ff3322009-08-04 16:50:30 +00007978template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007979QualType
7980TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007981 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007982 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007983 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007984}
Mike Stump11289f42009-09-09 15:08:12 +00007985
Douglas Gregord6ff3322009-08-04 16:50:30 +00007986template<typename Derived>
7987QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007988 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007989 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007990 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007991 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007992 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007993 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007994 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007995 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007996 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007997 getDerived().getBaseEntity(),
7998 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007999}
Mike Stump11289f42009-09-09 15:08:12 +00008000
Douglas Gregord6ff3322009-08-04 16:50:30 +00008001template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008002QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8003 return SemaRef.Context.getFunctionNoProtoType(T);
8004}
8005
8006template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008007QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8008 assert(D && "no decl found");
8009 if (D->isInvalidDecl()) return QualType();
8010
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008011 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008012 TypeDecl *Ty;
8013 if (isa<UsingDecl>(D)) {
8014 UsingDecl *Using = cast<UsingDecl>(D);
8015 assert(Using->isTypeName() &&
8016 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8017
8018 // A valid resolved using typename decl points to exactly one type decl.
8019 assert(++Using->shadow_begin() == Using->shadow_end());
8020 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008021
John McCallb96ec562009-12-04 22:46:56 +00008022 } else {
8023 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8024 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8025 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8026 }
8027
8028 return SemaRef.Context.getTypeDeclType(Ty);
8029}
8030
8031template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008032QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8033 SourceLocation Loc) {
8034 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008035}
8036
8037template<typename Derived>
8038QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8039 return SemaRef.Context.getTypeOfType(Underlying);
8040}
8041
8042template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008043QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8044 SourceLocation Loc) {
8045 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008046}
8047
8048template<typename Derived>
8049QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008050 TemplateName Template,
8051 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008052 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008053 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008054}
Mike Stump11289f42009-09-09 15:08:12 +00008055
Douglas Gregor1135c352009-08-06 05:28:30 +00008056template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008057TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008058TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008059 bool TemplateKW,
8060 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008061 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008062 Template);
8063}
8064
8065template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008066TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008067TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8068 const IdentifierInfo &Name,
8069 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008070 QualType ObjectType,
8071 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008072 UnqualifiedId TemplateName;
8073 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008074 Sema::TemplateTy Template;
8075 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008076 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008077 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008078 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008079 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008080 /*EnteringContext=*/false,
8081 Template);
John McCall31f82722010-11-12 08:19:04 +00008082 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008083}
Mike Stump11289f42009-09-09 15:08:12 +00008084
Douglas Gregora16548e2009-08-11 05:31:07 +00008085template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008086TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008087TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008088 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008089 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008090 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008091 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008092 // FIXME: Bogus location information.
8093 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8094 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008095 Sema::TemplateTy Template;
8096 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008097 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008098 SS,
8099 Name,
John McCallba7bf592010-08-24 05:47:05 +00008100 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008101 /*EnteringContext=*/false,
8102 Template);
8103 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008104}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008105
Douglas Gregor71395fa2009-11-04 00:56:37 +00008106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008107ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008108TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8109 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008110 Expr *OrigCallee,
8111 Expr *First,
8112 Expr *Second) {
8113 Expr *Callee = OrigCallee->IgnoreParenCasts();
8114 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008115
Douglas Gregora16548e2009-08-11 05:31:07 +00008116 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008117 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008118 if (!First->getType()->isOverloadableType() &&
8119 !Second->getType()->isOverloadableType())
8120 return getSema().CreateBuiltinArraySubscriptExpr(First,
8121 Callee->getLocStart(),
8122 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008123 } else if (Op == OO_Arrow) {
8124 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008125 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8126 } else if (Second == 0 || isPostIncDec) {
8127 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008128 // The argument is not of overloadable type, so try to create a
8129 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008130 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008131 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008132
John McCallb268a282010-08-23 23:25:46 +00008133 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008134 }
8135 } else {
John McCallb268a282010-08-23 23:25:46 +00008136 if (!First->getType()->isOverloadableType() &&
8137 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008138 // Neither of the arguments is an overloadable type, so try to
8139 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008140 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008141 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008142 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008143 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008144 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008145
Douglas Gregora16548e2009-08-11 05:31:07 +00008146 return move(Result);
8147 }
8148 }
Mike Stump11289f42009-09-09 15:08:12 +00008149
8150 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008151 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008152 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008153
John McCallb268a282010-08-23 23:25:46 +00008154 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008155 assert(ULE->requiresADL());
8156
8157 // FIXME: Do we have to check
8158 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008159 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008160 } else {
John McCallb268a282010-08-23 23:25:46 +00008161 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008162 }
Mike Stump11289f42009-09-09 15:08:12 +00008163
Douglas Gregora16548e2009-08-11 05:31:07 +00008164 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008165 Expr *Args[2] = { First, Second };
8166 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008167
Douglas Gregora16548e2009-08-11 05:31:07 +00008168 // Create the overloaded operator invocation for unary operators.
8169 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008170 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008171 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008172 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008173 }
Mike Stump11289f42009-09-09 15:08:12 +00008174
Sebastian Redladba46e2009-10-29 20:17:01 +00008175 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00008176 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00008177 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008178 First,
8179 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00008180
Douglas Gregora16548e2009-08-11 05:31:07 +00008181 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008182 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008183 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008184 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8185 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008186 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008187
Mike Stump11289f42009-09-09 15:08:12 +00008188 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008189}
Mike Stump11289f42009-09-09 15:08:12 +00008190
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008192ExprResult
John McCallb268a282010-08-23 23:25:46 +00008193TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008194 SourceLocation OperatorLoc,
8195 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008196 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008197 TypeSourceInfo *ScopeType,
8198 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008199 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008200 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008201 QualType BaseType = Base->getType();
8202 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008203 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008204 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008205 !BaseType->getAs<PointerType>()->getPointeeType()
8206 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008207 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008208 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008209 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008210 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008211 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008212 /*FIXME?*/true);
8213 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008214
Douglas Gregor678f90d2010-02-25 01:56:36 +00008215 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008216 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8217 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8218 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8219 NameInfo.setNamedTypeInfo(DestroyedType);
8220
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008221 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008222
John McCallb268a282010-08-23 23:25:46 +00008223 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008224 OperatorLoc, isArrow,
8225 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008226 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008227 /*TemplateArgs*/ 0);
8228}
8229
Douglas Gregord6ff3322009-08-04 16:50:30 +00008230} // end namespace clang
8231
8232#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H