blob: 76792a0c76c0c0d8e0ee2528ff4705f42566b501 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000024#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000025#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000027#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000030#include "clang/Sema/Ownership.h"
31#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000032#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000033#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000034#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000035#include <algorithm>
36
37namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000038using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000039
Douglas Gregord6ff3322009-08-04 16:50:30 +000040/// \brief A semantic tree transformation that allows one to transform one
41/// abstract syntax tree into another.
42///
Mike Stump11289f42009-09-09 15:08:12 +000043/// A new tree transformation is defined by creating a new subclass \c X of
44/// \c TreeTransform<X> and then overriding certain operations to provide
45/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000046/// instantiation is implemented as a tree transformation where the
47/// transformation of TemplateTypeParmType nodes involves substituting the
48/// template arguments for their corresponding template parameters; a similar
49/// transformation is performed for non-type template parameters and
50/// template template parameters.
51///
52/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000053/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000054/// override any of the transformation or rebuild operators by providing an
55/// operation with the same signature as the default implementation. The
56/// overridding function should not be virtual.
57///
58/// Semantic tree transformations are split into two stages, either of which
59/// can be replaced by a subclass. The "transform" step transforms an AST node
60/// or the parts of an AST node using the various transformation functions,
61/// then passes the pieces on to the "rebuild" step, which constructs a new AST
62/// node of the appropriate kind from the pieces. The default transformation
63/// routines recursively transform the operands to composite AST nodes (e.g.,
64/// the pointee type of a PointerType node) and, if any of those operand nodes
65/// were changed by the transformation, invokes the rebuild operation to create
66/// a new AST node.
67///
Mike Stump11289f42009-09-09 15:08:12 +000068/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000069/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000071/// TransformTemplateName(), or TransformTemplateArgument() with entirely
72/// new implementations.
73///
74/// For more fine-grained transformations, subclasses can replace any of the
75/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000076/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000078/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// parameters. Additionally, subclasses can override the \c RebuildXXX
80/// functions to control how AST nodes are rebuilt when their operands change.
81/// By default, \c TreeTransform will invoke semantic analysis to rebuild
82/// AST nodes. However, certain other tree transformations (e.g, cloning) may
83/// be able to use more efficient rebuild steps.
84///
85/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000086/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000087/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
88/// operands have not changed (\c AlwaysRebuild()), and customize the
89/// default locations and entity names used for type-checking
90/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000091template<typename Derived>
92class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000093 /// \brief Private RAII object that helps us forget and then re-remember
94 /// the template argument corresponding to a partially-substituted parameter
95 /// pack.
96 class ForgetPartiallySubstitutedPackRAII {
97 Derived &Self;
98 TemplateArgument Old;
99
100 public:
101 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
102 Old = Self.ForgetPartiallySubstitutedPack();
103 }
104
105 ~ForgetPartiallySubstitutedPackRAII() {
106 Self.RememberPartiallySubstitutedPack(Old);
107 }
108 };
109
Douglas Gregord6ff3322009-08-04 16:50:30 +0000110protected:
111 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000112
Mike Stump11289f42009-09-09 15:08:12 +0000113public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000115 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000116
Douglas Gregord6ff3322009-08-04 16:50:30 +0000117 /// \brief Retrieves a reference to the derived class.
118 Derived &getDerived() { return static_cast<Derived&>(*this); }
119
120 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000121 const Derived &getDerived() const {
122 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000123 }
124
John McCalldadc5752010-08-24 06:29:42 +0000125 static inline ExprResult Owned(Expr *E) { return E; }
126 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Retrieves a reference to the semantic analysis object used for
129 /// this tree transform.
130 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000131
Douglas Gregord6ff3322009-08-04 16:50:30 +0000132 /// \brief Whether the transformation should always rebuild AST nodes, even
133 /// if none of the children have changed.
134 ///
135 /// Subclasses may override this function to specify when the transformation
136 /// should rebuild all AST nodes.
137 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Returns the location of the entity being transformed, if that
140 /// information was not available elsewhere in the AST.
141 ///
Mike Stump11289f42009-09-09 15:08:12 +0000142 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000143 /// provide an alternative implementation that provides better location
144 /// information.
145 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000146
Douglas Gregord6ff3322009-08-04 16:50:30 +0000147 /// \brief Returns the name of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
150 /// By default, returns an empty name. Subclasses can provide an alternative
151 /// implementation with a more precise name.
152 DeclarationName getBaseEntity() { return DeclarationName(); }
153
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 /// \brief Sets the "base" location and entity when that
155 /// information is known based on another transformation.
156 ///
157 /// By default, the source location and entity are ignored. Subclasses can
158 /// override this function to provide a customized implementation.
159 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000160
Douglas Gregora16548e2009-08-11 05:31:07 +0000161 /// \brief RAII object that temporarily sets the base location and entity
162 /// used for reporting diagnostics in types.
163 class TemporaryBase {
164 TreeTransform &Self;
165 SourceLocation OldLocation;
166 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000167
Douglas Gregora16548e2009-08-11 05:31:07 +0000168 public:
169 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000170 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000171 OldLocation = Self.getDerived().getBaseLocation();
172 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000173
174 if (Location.isValid())
175 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000176 }
Mike Stump11289f42009-09-09 15:08:12 +0000177
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 ~TemporaryBase() {
179 Self.getDerived().setBase(OldLocation, OldEntity);
180 }
181 };
Mike Stump11289f42009-09-09 15:08:12 +0000182
183 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000184 /// transformed.
185 ///
186 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000187 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000188 /// not change. For example, template instantiation need not traverse
189 /// non-dependent types.
190 bool AlreadyTransformed(QualType T) {
191 return T.isNull();
192 }
193
Douglas Gregord196a582009-12-14 19:27:10 +0000194 /// \brief Determine whether the given call argument should be dropped, e.g.,
195 /// because it is a default argument.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine to
198 /// determine which kinds of call arguments get dropped. By default,
199 /// CXXDefaultArgument nodes are dropped (prior to transformation).
200 bool DropCallArgument(Expr *E) {
201 return E->isDefaultArgument();
202 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000203
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000204 /// \brief Determine whether we should expand a pack expansion with the
205 /// given set of parameter packs into separate arguments by repeatedly
206 /// transforming the pattern.
207 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000208 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000209 /// Subclasses can override this routine to provide different behavior.
210 ///
211 /// \param EllipsisLoc The location of the ellipsis that identifies the
212 /// pack expansion.
213 ///
214 /// \param PatternRange The source range that covers the entire pattern of
215 /// the pack expansion.
216 ///
217 /// \param Unexpanded The set of unexpanded parameter packs within the
218 /// pattern.
219 ///
220 /// \param NumUnexpanded The number of unexpanded parameter packs in
221 /// \p Unexpanded.
222 ///
223 /// \param ShouldExpand Will be set to \c true if the transformer should
224 /// expand the corresponding pack expansions into separate arguments. When
225 /// set, \c NumExpansions must also be set.
226 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000227 /// \param RetainExpansion Whether the caller should add an unexpanded
228 /// pack expansion after all of the expanded arguments. This is used
229 /// when extending explicitly-specified template argument packs per
230 /// C++0x [temp.arg.explicit]p9.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000233 /// the expanded form of the corresponding pack expansion. This is both an
234 /// input and an output parameter, which can be set by the caller if the
235 /// number of expansions is known a priori (e.g., due to a prior substitution)
236 /// and will be set by the callee when the number of expansions is known.
237 /// The callee must set this value when \c ShouldExpand is \c true; it may
238 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000239 ///
240 /// \returns true if an error occurred (e.g., because the parameter packs
241 /// are to be instantiated with arguments of different lengths), false
242 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
243 /// must be set.
244 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
245 SourceRange PatternRange,
246 const UnexpandedParameterPack *Unexpanded,
247 unsigned NumUnexpanded,
248 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000249 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000250 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 ShouldExpand = false;
252 return false;
253 }
254
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000255 /// \brief "Forget" about the partially-substituted pack template argument,
256 /// when performing an instantiation that must preserve the parameter pack
257 /// use.
258 ///
259 /// This routine is meant to be overridden by the template instantiator.
260 TemplateArgument ForgetPartiallySubstitutedPack() {
261 return TemplateArgument();
262 }
263
264 /// \brief "Remember" the partially-substituted pack template argument
265 /// after performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
270
Douglas Gregorf3010112011-01-07 16:43:16 +0000271 /// \brief Note to the derived class when a function parameter pack is
272 /// being expanded.
273 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
274
Douglas Gregord6ff3322009-08-04 16:50:30 +0000275 /// \brief Transforms the given type into another type.
276 ///
John McCall550e0c22009-10-21 00:40:46 +0000277 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000278 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000279 /// function. This is expensive, but we don't mind, because
280 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000281 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 ///
283 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000284 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000285
John McCall550e0c22009-10-21 00:40:46 +0000286 /// \brief Transforms the given type-with-location into a new
287 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000288 ///
John McCall550e0c22009-10-21 00:40:46 +0000289 /// By default, this routine transforms a type by delegating to the
290 /// appropriate TransformXXXType to build a new type. Subclasses
291 /// may override this function (to take over all type
292 /// transformations) or some set of the TransformXXXType functions
293 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000294 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000295
296 /// \brief Transform the given type-with-location into a new
297 /// type, collecting location information in the given builder
298 /// as necessary.
299 ///
John McCall31f82722010-11-12 08:19:04 +0000300 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000301
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000302 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000303 ///
Mike Stump11289f42009-09-09 15:08:12 +0000304 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000305 /// appropriate TransformXXXStmt function to transform a specific kind of
306 /// statement or the TransformExpr() function to transform an expression.
307 /// Subclasses may override this function to transform statements using some
308 /// other mechanism.
309 ///
310 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000311 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000312
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000313 /// \brief Transform the given expression.
314 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000315 /// By default, this routine transforms an expression by delegating to the
316 /// appropriate TransformXXXExpr function to build a new expression.
317 /// Subclasses may override this function to transform expressions using some
318 /// other mechanism.
319 ///
320 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000321 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000322
Douglas Gregora3efea12011-01-03 19:04:46 +0000323 /// \brief Transform the given list of expressions.
324 ///
325 /// This routine transforms a list of expressions by invoking
326 /// \c TransformExpr() for each subexpression. However, it also provides
327 /// support for variadic templates by expanding any pack expansions (if the
328 /// derived class permits such expansion) along the way. When pack expansions
329 /// are present, the number of outputs may not equal the number of inputs.
330 ///
331 /// \param Inputs The set of expressions to be transformed.
332 ///
333 /// \param NumInputs The number of expressions in \c Inputs.
334 ///
335 /// \param IsCall If \c true, then this transform is being performed on
336 /// function-call arguments, and any arguments that should be dropped, will
337 /// be.
338 ///
339 /// \param Outputs The transformed input expressions will be added to this
340 /// vector.
341 ///
342 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
343 /// due to transformation.
344 ///
345 /// \returns true if an error occurred, false otherwise.
346 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
347 llvm::SmallVectorImpl<Expr *> &Outputs,
348 bool *ArgChanged = 0);
349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Transform the given declaration, which is referenced from a type
351 /// or expression.
352 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000353 /// By default, acts as the identity function on declarations. Subclasses
354 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000355 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000356
357 /// \brief Transform the definition of the given declaration.
358 ///
Mike Stump11289f42009-09-09 15:08:12 +0000359 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000360 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000361 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
362 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000363 }
Mike Stump11289f42009-09-09 15:08:12 +0000364
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000365 /// \brief Transform the given declaration, which was the first part of a
366 /// nested-name-specifier in a member access expression.
367 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000368 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000369 /// identifier in a nested-name-specifier of a member access expression, e.g.,
370 /// the \c T in \c x->T::member
371 ///
372 /// By default, invokes TransformDecl() to transform the declaration.
373 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000374 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
375 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000376 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000377
Douglas Gregor14454802011-02-25 02:25:35 +0000378 /// \brief Transform the given nested-name-specifier with source-location
379 /// information.
380 ///
381 /// By default, transforms all of the types and declarations within the
382 /// nested-name-specifier. Subclasses may override this function to provide
383 /// alternate behavior.
384 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
385 NestedNameSpecifierLoc NNS,
386 QualType ObjectType = QualType(),
387 NamedDecl *FirstQualifierInScope = 0);
388
Douglas Gregorf816bd72009-09-03 22:13:48 +0000389 /// \brief Transform the given declaration name.
390 ///
391 /// By default, transforms the types of conversion function, constructor,
392 /// and destructor names and then (if needed) rebuilds the declaration name.
393 /// Identifiers and selectors are returned unmodified. Sublcasses may
394 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000395 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000396 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000399 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000400 /// \param SS The nested-name-specifier that qualifies the template
401 /// name. This nested-name-specifier must already have been transformed.
402 ///
403 /// \param Name The template name to transform.
404 ///
405 /// \param NameLoc The source location of the template name.
406 ///
407 /// \param ObjectType If we're translating a template name within a member
408 /// access expression, this is the type of the object whose member template
409 /// is being referenced.
410 ///
411 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
412 /// also refers to a name within the current (lexical) scope, this is the
413 /// declaration it refers to.
414 ///
415 /// By default, transforms the template name by transforming the declarations
416 /// and nested-name-specifiers that occur within the template name.
417 /// Subclasses may override this function to provide alternate behavior.
418 TemplateName TransformTemplateName(CXXScopeSpec &SS,
419 TemplateName Name,
420 SourceLocation NameLoc,
421 QualType ObjectType = QualType(),
422 NamedDecl *FirstQualifierInScope = 0);
423
Douglas Gregord6ff3322009-08-04 16:50:30 +0000424 /// \brief Transform the given template argument.
425 ///
Mike Stump11289f42009-09-09 15:08:12 +0000426 /// By default, this operation transforms the type, expression, or
427 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000428 /// new template argument from the transformed result. Subclasses may
429 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000430 ///
431 /// Returns true if there was an error.
432 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
433 TemplateArgumentLoc &Output);
434
Douglas Gregor62e06f22010-12-20 17:31:10 +0000435 /// \brief Transform the given set of template arguments.
436 ///
437 /// By default, this operation transforms all of the template arguments
438 /// in the input set using \c TransformTemplateArgument(), and appends
439 /// the transformed arguments to the output list.
440 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000441 /// Note that this overload of \c TransformTemplateArguments() is merely
442 /// a convenience function. Subclasses that wish to override this behavior
443 /// should override the iterator-based member template version.
444 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000445 /// \param Inputs The set of template arguments to be transformed.
446 ///
447 /// \param NumInputs The number of template arguments in \p Inputs.
448 ///
449 /// \param Outputs The set of transformed template arguments output by this
450 /// routine.
451 ///
452 /// Returns true if an error occurred.
453 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
454 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000455 TemplateArgumentListInfo &Outputs) {
456 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
457 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000458
459 /// \brief Transform the given set of template arguments.
460 ///
461 /// By default, this operation transforms all of the template arguments
462 /// in the input set using \c TransformTemplateArgument(), and appends
463 /// the transformed arguments to the output list.
464 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000465 /// \param First An iterator to the first template argument.
466 ///
467 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000468 ///
469 /// \param Outputs The set of transformed template arguments output by this
470 /// routine.
471 ///
472 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000473 template<typename InputIterator>
474 bool TransformTemplateArguments(InputIterator First,
475 InputIterator Last,
476 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000477
John McCall0ad16662009-10-29 08:12:44 +0000478 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
479 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
480 TemplateArgumentLoc &ArgLoc);
481
John McCallbcd03502009-12-07 02:54:59 +0000482 /// \brief Fakes up a TypeSourceInfo for a type.
483 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
484 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000485 getDerived().getBaseLocation());
486 }
Mike Stump11289f42009-09-09 15:08:12 +0000487
John McCall550e0c22009-10-21 00:40:46 +0000488#define ABSTRACT_TYPELOC(CLASS, PARENT)
489#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000490 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000491#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000492
John McCall31f82722010-11-12 08:19:04 +0000493 QualType
494 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
495 TemplateSpecializationTypeLoc TL,
496 TemplateName Template);
497
498 QualType
499 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
500 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor5a064722011-02-28 17:23:35 +0000501 TemplateName Template);
502
503 QualType
504 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000505 DependentTemplateSpecializationTypeLoc TL,
506 NestedNameSpecifierLoc QualifierLoc);
507
John McCall58f10c32010-03-11 09:03:00 +0000508 /// \brief Transforms the parameters of a function type into the
509 /// given vectors.
510 ///
511 /// The result vectors should be kept in sync; null entries in the
512 /// variables vector are acceptable.
513 ///
514 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000515 bool TransformFunctionTypeParams(SourceLocation Loc,
516 ParmVarDecl **Params, unsigned NumParams,
517 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000518 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000519 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000520
521 /// \brief Transforms a single function-type parameter. Return null
522 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000523 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
524 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000525
John McCall31f82722010-11-12 08:19:04 +0000526 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000527
John McCalldadc5752010-08-24 06:29:42 +0000528 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
529 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000530
Douglas Gregorebe10102009-08-20 07:17:43 +0000531#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000532 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000533#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000534 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000535#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000536#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000537
Douglas Gregord6ff3322009-08-04 16:50:30 +0000538 /// \brief Build a new pointer type given its pointee type.
539 ///
540 /// By default, performs semantic analysis when building the pointer type.
541 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000542 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000543
544 /// \brief Build a new block pointer type given its pointee type.
545 ///
Mike Stump11289f42009-09-09 15:08:12 +0000546 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000547 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000548 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549
John McCall70dd5f62009-10-30 00:06:24 +0000550 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000551 ///
John McCall70dd5f62009-10-30 00:06:24 +0000552 /// By default, performs semantic analysis when building the
553 /// reference type. Subclasses may override this routine to provide
554 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555 ///
John McCall70dd5f62009-10-30 00:06:24 +0000556 /// \param LValue whether the type was written with an lvalue sigil
557 /// or an rvalue sigil.
558 QualType RebuildReferenceType(QualType ReferentType,
559 bool LValue,
560 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000561
Douglas Gregord6ff3322009-08-04 16:50:30 +0000562 /// \brief Build a new member pointer type given the pointee type and the
563 /// class type it refers into.
564 ///
565 /// By default, performs semantic analysis when building the member pointer
566 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000567 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
568 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000569
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570 /// \brief Build a new array type given the element type, size
571 /// modifier, size of the array (if known), size expression, and index type
572 /// qualifiers.
573 ///
574 /// By default, performs semantic analysis when building the array type.
575 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000576 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000577 QualType RebuildArrayType(QualType ElementType,
578 ArrayType::ArraySizeModifier SizeMod,
579 const llvm::APInt *Size,
580 Expr *SizeExpr,
581 unsigned IndexTypeQuals,
582 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000583
Douglas Gregord6ff3322009-08-04 16:50:30 +0000584 /// \brief Build a new constant array type given the element type, size
585 /// modifier, (known) size of the array, and index type qualifiers.
586 ///
587 /// By default, performs semantic analysis when building the array type.
588 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000589 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000590 ArrayType::ArraySizeModifier SizeMod,
591 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000592 unsigned IndexTypeQuals,
593 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000594
Douglas Gregord6ff3322009-08-04 16:50:30 +0000595 /// \brief Build a new incomplete array type given the element type, size
596 /// modifier, and index type qualifiers.
597 ///
598 /// By default, performs semantic analysis when building the array type.
599 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000600 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000601 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000602 unsigned IndexTypeQuals,
603 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000604
Mike Stump11289f42009-09-09 15:08:12 +0000605 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000606 /// size modifier, size expression, and index type qualifiers.
607 ///
608 /// By default, performs semantic analysis when building the array type.
609 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000610 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000611 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000612 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000613 unsigned IndexTypeQuals,
614 SourceRange BracketsRange);
615
Mike Stump11289f42009-09-09 15:08:12 +0000616 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000617 /// size modifier, size expression, and index type qualifiers.
618 ///
619 /// By default, performs semantic analysis when building the array type.
620 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000621 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000622 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000623 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000624 unsigned IndexTypeQuals,
625 SourceRange BracketsRange);
626
627 /// \brief Build a new vector type given the element type and
628 /// number of elements.
629 ///
630 /// By default, performs semantic analysis when building the vector type.
631 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000632 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000633 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000634
Douglas Gregord6ff3322009-08-04 16:50:30 +0000635 /// \brief Build a new extended vector type given the element type and
636 /// number of elements.
637 ///
638 /// By default, performs semantic analysis when building the vector type.
639 /// Subclasses may override this routine to provide different behavior.
640 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
641 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000642
643 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 /// given the element type and number of elements.
645 ///
646 /// By default, performs semantic analysis when building the vector type.
647 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000648 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000649 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000650 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000651
Douglas Gregord6ff3322009-08-04 16:50:30 +0000652 /// \brief Build a new function type.
653 ///
654 /// By default, performs semantic analysis when building the function type.
655 /// Subclasses may override this routine to provide different behavior.
656 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000657 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000658 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000659 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000660 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000661 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000662
John McCall550e0c22009-10-21 00:40:46 +0000663 /// \brief Build a new unprototyped function type.
664 QualType RebuildFunctionNoProtoType(QualType ResultType);
665
John McCallb96ec562009-12-04 22:46:56 +0000666 /// \brief Rebuild an unresolved typename type, given the decl that
667 /// the UnresolvedUsingTypenameDecl was transformed to.
668 QualType RebuildUnresolvedUsingType(Decl *D);
669
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// \brief Build a new typedef type.
671 QualType RebuildTypedefType(TypedefDecl *Typedef) {
672 return SemaRef.Context.getTypeDeclType(Typedef);
673 }
674
675 /// \brief Build a new class/struct/union type.
676 QualType RebuildRecordType(RecordDecl *Record) {
677 return SemaRef.Context.getTypeDeclType(Record);
678 }
679
680 /// \brief Build a new Enum type.
681 QualType RebuildEnumType(EnumDecl *Enum) {
682 return SemaRef.Context.getTypeDeclType(Enum);
683 }
John McCallfcc33b02009-09-05 00:15:47 +0000684
Mike Stump11289f42009-09-09 15:08:12 +0000685 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000686 ///
687 /// By default, performs semantic analysis when building the typeof type.
688 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000689 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690
Mike Stump11289f42009-09-09 15:08:12 +0000691 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000692 ///
693 /// By default, builds a new TypeOfType with the given underlying type.
694 QualType RebuildTypeOfType(QualType Underlying);
695
Mike Stump11289f42009-09-09 15:08:12 +0000696 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697 ///
698 /// By default, performs semantic analysis when building the decltype type.
699 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000700 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Richard Smith30482bc2011-02-20 03:19:35 +0000702 /// \brief Build a new C++0x auto type.
703 ///
704 /// By default, builds a new AutoType with the given deduced type.
705 QualType RebuildAutoType(QualType Deduced) {
706 return SemaRef.Context.getAutoType(Deduced);
707 }
708
Douglas Gregord6ff3322009-08-04 16:50:30 +0000709 /// \brief Build a new template specialization type.
710 ///
711 /// By default, performs semantic analysis when building the template
712 /// specialization type. Subclasses may override this routine to provide
713 /// different behavior.
714 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000715 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000716 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000717
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000718 /// \brief Build a new parenthesized type.
719 ///
720 /// By default, builds a new ParenType type from the inner type.
721 /// Subclasses may override this routine to provide different behavior.
722 QualType RebuildParenType(QualType InnerType) {
723 return SemaRef.Context.getParenType(InnerType);
724 }
725
Douglas Gregord6ff3322009-08-04 16:50:30 +0000726 /// \brief Build a new qualified name type.
727 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000728 /// By default, builds a new ElaboratedType type from the keyword,
729 /// the nested-name-specifier and the named type.
730 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000731 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
732 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000733 NestedNameSpecifierLoc QualifierLoc,
734 QualType Named) {
735 return SemaRef.Context.getElaboratedType(Keyword,
736 QualifierLoc.getNestedNameSpecifier(),
737 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000738 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739
740 /// \brief Build a new typename type that refers to a template-id.
741 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000742 /// By default, builds a new DependentNameType type from the
743 /// nested-name-specifier and the given type. Subclasses may override
744 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000745 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000746 ElaboratedTypeKeyword Keyword,
747 NestedNameSpecifierLoc QualifierLoc,
748 const IdentifierInfo *Name,
749 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000750 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000751 // Rebuild the template name.
752 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000753 CXXScopeSpec SS;
754 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000755 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000756 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000757
758 if (InstName.isNull())
759 return QualType();
760
761 // If it's still dependent, make a dependent specialization.
762 if (InstName.getAsDependentTemplateName())
763 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
764 QualifierLoc.getNestedNameSpecifier(),
765 Name,
766 Args);
767
768 // Otherwise, make an elaborated type wrapping a non-dependent
769 // specialization.
770 QualType T =
771 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
772 if (T.isNull()) return QualType();
773
774 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
775 return T;
776
777 return SemaRef.Context.getElaboratedType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
779 T);
780 }
781
Douglas Gregord6ff3322009-08-04 16:50:30 +0000782 /// \brief Build a new typename type that refers to an identifier.
783 ///
784 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000785 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000786 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000787 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000788 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000789 NestedNameSpecifierLoc QualifierLoc,
790 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000791 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000792 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000793 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000794
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000795 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000796 // If the name is still dependent, just build a new dependent name type.
797 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000798 return SemaRef.Context.getDependentNameType(Keyword,
799 QualifierLoc.getNestedNameSpecifier(),
800 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000801 }
802
Abramo Bagnara6150c882010-05-11 21:36:43 +0000803 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000804 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000805 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000806
807 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
808
Abramo Bagnarad7548482010-05-19 21:37:53 +0000809 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000810 // into a non-dependent elaborated-type-specifier. Find the tag we're
811 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000812 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000813 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
814 if (!DC)
815 return QualType();
816
John McCallbf8c5192010-05-27 06:40:31 +0000817 if (SemaRef.RequireCompleteDeclContext(SS, DC))
818 return QualType();
819
Douglas Gregore677daf2010-03-31 22:19:08 +0000820 TagDecl *Tag = 0;
821 SemaRef.LookupQualifiedName(Result, DC);
822 switch (Result.getResultKind()) {
823 case LookupResult::NotFound:
824 case LookupResult::NotFoundInCurrentInstantiation:
825 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000826
Douglas Gregore677daf2010-03-31 22:19:08 +0000827 case LookupResult::Found:
828 Tag = Result.getAsSingle<TagDecl>();
829 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000830
Douglas Gregore677daf2010-03-31 22:19:08 +0000831 case LookupResult::FoundOverloaded:
832 case LookupResult::FoundUnresolvedValue:
833 llvm_unreachable("Tag lookup cannot find non-tags");
834 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000835
Douglas Gregore677daf2010-03-31 22:19:08 +0000836 case LookupResult::Ambiguous:
837 // Let the LookupResult structure handle ambiguities.
838 return QualType();
839 }
840
841 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000842 // Check where the name exists but isn't a tag type and use that to emit
843 // better diagnostics.
844 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
845 SemaRef.LookupQualifiedName(Result, DC);
846 switch (Result.getResultKind()) {
847 case LookupResult::Found:
848 case LookupResult::FoundOverloaded:
849 case LookupResult::FoundUnresolvedValue: {
850 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
851 unsigned Kind = 0;
852 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
853 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
854 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
855 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
856 break;
857 }
858 default:
859 // FIXME: Would be nice to highlight just the source range.
860 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
861 << Kind << Id << DC;
862 break;
863 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000864 return QualType();
865 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000866
Abramo Bagnarad7548482010-05-19 21:37:53 +0000867 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
868 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000869 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
870 return QualType();
871 }
872
873 // Build the elaborated-type-specifier type.
874 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000875 return SemaRef.Context.getElaboratedType(Keyword,
876 QualifierLoc.getNestedNameSpecifier(),
877 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000878 }
Mike Stump11289f42009-09-09 15:08:12 +0000879
Douglas Gregor822d0302011-01-12 17:07:58 +0000880 /// \brief Build a new pack expansion type.
881 ///
882 /// By default, builds a new PackExpansionType type from the given pattern.
883 /// Subclasses may override this routine to provide different behavior.
884 QualType RebuildPackExpansionType(QualType Pattern,
885 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000886 SourceLocation EllipsisLoc,
887 llvm::Optional<unsigned> NumExpansions) {
888 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
889 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000890 }
891
Douglas Gregor71dc5092009-08-06 06:41:21 +0000892 /// \brief Build a new template name given a nested name specifier, a flag
893 /// indicating whether the "template" keyword was provided, and the template
894 /// that the template name refers to.
895 ///
896 /// By default, builds the new template name directly. Subclasses may override
897 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000898 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000899 bool TemplateKW,
900 TemplateDecl *Template);
901
Douglas Gregor71dc5092009-08-06 06:41:21 +0000902 /// \brief Build a new template name given a nested name specifier and the
903 /// name that is referred to as a template.
904 ///
905 /// By default, performs semantic analysis to determine whether the name can
906 /// be resolved to a specific template, then builds the appropriate kind of
907 /// template name. Subclasses may override this routine to provide different
908 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000909 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
910 const IdentifierInfo &Name,
911 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000912 QualType ObjectType,
913 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000914
Douglas Gregor71395fa2009-11-04 00:56:37 +0000915 /// \brief Build a new template name given a nested name specifier and the
916 /// overloaded operator name that is referred to as a template.
917 ///
918 /// By default, performs semantic analysis to determine whether the name can
919 /// be resolved to a specific template, then builds the appropriate kind of
920 /// template name. Subclasses may override this routine to provide different
921 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000922 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000923 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000924 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000925 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000926
927 /// \brief Build a new template name given a template template parameter pack
928 /// and the
929 ///
930 /// By default, performs semantic analysis to determine whether the name can
931 /// be resolved to a specific template, then builds the appropriate kind of
932 /// template name. Subclasses may override this routine to provide different
933 /// behavior.
934 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
935 const TemplateArgument &ArgPack) {
936 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
937 }
938
Douglas Gregorebe10102009-08-20 07:17:43 +0000939 /// \brief Build a new compound statement.
940 ///
941 /// By default, performs semantic analysis to build the new statement.
942 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000943 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000944 MultiStmtArg Statements,
945 SourceLocation RBraceLoc,
946 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000947 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000948 IsStmtExpr);
949 }
950
951 /// \brief Build a new case statement.
952 ///
953 /// By default, performs semantic analysis to build the new statement.
954 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000955 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000956 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000957 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000958 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000959 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000960 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000961 ColonLoc);
962 }
Mike Stump11289f42009-09-09 15:08:12 +0000963
Douglas Gregorebe10102009-08-20 07:17:43 +0000964 /// \brief Attach the body to a new case statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000968 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000969 getSema().ActOnCaseStmtBody(S, Body);
970 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000971 }
Mike Stump11289f42009-09-09 15:08:12 +0000972
Douglas Gregorebe10102009-08-20 07:17:43 +0000973 /// \brief Build a new default statement.
974 ///
975 /// By default, performs semantic analysis to build the new statement.
976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000977 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000978 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000979 Stmt *SubStmt) {
980 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000981 /*CurScope=*/0);
982 }
Mike Stump11289f42009-09-09 15:08:12 +0000983
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 /// \brief Build a new label statement.
985 ///
986 /// By default, performs semantic analysis to build the new statement.
987 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +0000988 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
989 SourceLocation ColonLoc, Stmt *SubStmt) {
990 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000991 }
Mike Stump11289f42009-09-09 15:08:12 +0000992
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 /// \brief Build a new "if" statement.
994 ///
995 /// By default, performs semantic analysis to build the new statement.
996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000997 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +0000998 VarDecl *CondVar, Stmt *Then,
999 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001000 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
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 Start building a new switch 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 RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001008 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001009 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001010 CondVar);
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 Attach the body to the 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 RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001018 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001019 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001020 }
1021
1022 /// \brief Build a new while statement.
1023 ///
1024 /// By default, performs semantic analysis to build the new statement.
1025 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001026 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1027 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001028 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001029 }
Mike Stump11289f42009-09-09 15:08:12 +00001030
Douglas Gregorebe10102009-08-20 07:17:43 +00001031 /// \brief Build a new do-while statement.
1032 ///
1033 /// By default, performs semantic analysis to build the new statement.
1034 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001035 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001036 SourceLocation WhileLoc, SourceLocation LParenLoc,
1037 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001038 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1039 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001040 }
1041
1042 /// \brief Build a new for statement.
1043 ///
1044 /// By default, performs semantic analysis to build the new statement.
1045 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001046 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1047 Stmt *Init, Sema::FullExprArg Cond,
1048 VarDecl *CondVar, Sema::FullExprArg Inc,
1049 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001050 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001051 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001052 }
Mike Stump11289f42009-09-09 15:08:12 +00001053
Douglas Gregorebe10102009-08-20 07:17:43 +00001054 /// \brief Build a new goto statement.
1055 ///
1056 /// By default, performs semantic analysis to build the new statement.
1057 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001058 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1059 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001060 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 }
1062
1063 /// \brief Build a new indirect goto statement.
1064 ///
1065 /// By default, performs semantic analysis to build the new statement.
1066 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001067 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001068 SourceLocation StarLoc,
1069 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001070 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001071 }
Mike Stump11289f42009-09-09 15:08:12 +00001072
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 /// \brief Build a new return statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001077 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001078 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 }
Mike Stump11289f42009-09-09 15:08:12 +00001080
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 /// \brief Build a new declaration statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001085 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001086 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001088 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1089 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001090 }
Mike Stump11289f42009-09-09 15:08:12 +00001091
Anders Carlssonaaeef072010-01-24 05:50:09 +00001092 /// \brief Build a new inline asm statement.
1093 ///
1094 /// By default, performs semantic analysis to build the new statement.
1095 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001096 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001097 bool IsSimple,
1098 bool IsVolatile,
1099 unsigned NumOutputs,
1100 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001101 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001102 MultiExprArg Constraints,
1103 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001104 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001105 MultiExprArg Clobbers,
1106 SourceLocation RParenLoc,
1107 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001108 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001109 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001110 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001111 RParenLoc, MSAsm);
1112 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001113
1114 /// \brief Build a new Objective-C @try statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001118 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001119 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001120 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001121 Stmt *Finally) {
1122 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1123 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001124 }
1125
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001126 /// \brief Rebuild an Objective-C exception declaration.
1127 ///
1128 /// By default, performs semantic analysis to build the new declaration.
1129 /// Subclasses may override this routine to provide different behavior.
1130 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1131 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001132 return getSema().BuildObjCExceptionDecl(TInfo, T,
1133 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001134 ExceptionDecl->getLocation());
1135 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001136
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001137 /// \brief Build a new Objective-C @catch statement.
1138 ///
1139 /// By default, performs semantic analysis to build the new statement.
1140 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001141 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001142 SourceLocation RParenLoc,
1143 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001144 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001145 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001146 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001147 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001148
Douglas Gregor306de2f2010-04-22 23:59:56 +00001149 /// \brief Build a new Objective-C @finally statement.
1150 ///
1151 /// By default, performs semantic analysis to build the new statement.
1152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001153 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001154 Stmt *Body) {
1155 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001156 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001157
Douglas Gregor6148de72010-04-22 22:01:21 +00001158 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001159 ///
1160 /// By default, performs semantic analysis to build the new statement.
1161 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001162 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001163 Expr *Operand) {
1164 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001165 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001166
Douglas Gregor6148de72010-04-22 22:01:21 +00001167 /// \brief Build a new Objective-C @synchronized statement.
1168 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001169 /// By default, performs semantic analysis to build the new statement.
1170 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001171 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001172 Expr *Object,
1173 Stmt *Body) {
1174 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1175 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001176 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001177
1178 /// \brief Build a new Objective-C fast enumeration statement.
1179 ///
1180 /// 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 RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001183 SourceLocation LParenLoc,
1184 Stmt *Element,
1185 Expr *Collection,
1186 SourceLocation RParenLoc,
1187 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001188 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001189 Element,
1190 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001191 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001192 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001193 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001194
Douglas Gregorebe10102009-08-20 07:17:43 +00001195 /// \brief Build a new C++ exception declaration.
1196 ///
1197 /// By default, performs semantic analysis to build the new decaration.
1198 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001199 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001200 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001202 SourceLocation Loc) {
1203 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001204 }
1205
1206 /// \brief Build a new C++ catch statement.
1207 ///
1208 /// By default, performs semantic analysis to build the new statement.
1209 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001210 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001211 VarDecl *ExceptionDecl,
1212 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001213 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1214 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001215 }
Mike Stump11289f42009-09-09 15:08:12 +00001216
Douglas Gregorebe10102009-08-20 07:17:43 +00001217 /// \brief Build a new C++ try statement.
1218 ///
1219 /// By default, performs semantic analysis to build the new statement.
1220 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001221 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001222 Stmt *TryBlock,
1223 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001224 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001225 }
Mike Stump11289f42009-09-09 15:08:12 +00001226
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 /// \brief Build a new expression that references a declaration.
1228 ///
1229 /// By default, performs semantic analysis to build the new expression.
1230 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001231 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001232 LookupResult &R,
1233 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001234 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1235 }
1236
1237
1238 /// \brief Build a new expression that references a declaration.
1239 ///
1240 /// By default, performs semantic analysis to build the new expression.
1241 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001242 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001243 ValueDecl *VD,
1244 const DeclarationNameInfo &NameInfo,
1245 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001246 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001247 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001248
1249 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001250
1251 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001252 }
Mike Stump11289f42009-09-09 15:08:12 +00001253
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001255 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001256 /// By default, performs semantic analysis to build the new expression.
1257 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001258 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001260 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 }
1262
Douglas Gregorad8a3362009-09-04 17:36:40 +00001263 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001264 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001265 /// By default, performs semantic analysis to build the new expression.
1266 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001267 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001268 SourceLocation OperatorLoc,
1269 bool isArrow,
1270 CXXScopeSpec &SS,
1271 TypeSourceInfo *ScopeType,
1272 SourceLocation CCLoc,
1273 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001274 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001275
Douglas Gregora16548e2009-08-11 05:31:07 +00001276 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001277 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 /// By default, performs semantic analysis to build the new expression.
1279 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001280 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001281 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001282 Expr *SubExpr) {
1283 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001284 }
Mike Stump11289f42009-09-09 15:08:12 +00001285
Douglas Gregor882211c2010-04-28 22:16:22 +00001286 /// \brief Build a new builtin offsetof expression.
1287 ///
1288 /// By default, performs semantic analysis to build the new expression.
1289 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001290 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001291 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001292 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001293 unsigned NumComponents,
1294 SourceLocation RParenLoc) {
1295 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1296 NumComponents, RParenLoc);
1297 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001298
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001300 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001301 /// By default, performs semantic analysis to build the new expression.
1302 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001303 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001304 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001306 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 }
1308
Mike Stump11289f42009-09-09 15:08:12 +00001309 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 /// argument.
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 RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001316 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001317 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001319 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001320
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 return move(Result);
1322 }
Mike Stump11289f42009-09-09 15:08:12 +00001323
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001325 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 /// By default, performs semantic analysis to build the new expression.
1327 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001328 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001330 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001332 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1333 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 RBracketLoc);
1335 }
1336
1337 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001338 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 /// By default, performs semantic analysis to build the new expression.
1340 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001341 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001343 SourceLocation RParenLoc,
1344 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001345 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001346 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 }
1348
1349 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001350 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 /// By default, performs semantic analysis to build the new expression.
1352 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001353 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001354 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001355 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001356 const DeclarationNameInfo &MemberNameInfo,
1357 ValueDecl *Member,
1358 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001359 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001360 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001361 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001362 // We have a reference to an unnamed field. This is always the
1363 // base of an anonymous struct/union member access, i.e. the
1364 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001365 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001366 assert(Member->getType()->isRecordType() &&
1367 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001368
Douglas Gregorea972d32011-02-28 21:54:11 +00001369 if (getSema().PerformObjectMemberConversion(Base,
1370 QualifierLoc.getNestedNameSpecifier(),
John McCall16df1e52010-03-30 21:47:33 +00001371 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001372 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001373
John McCall7decc9e2010-11-18 06:31:45 +00001374 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001375 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001376 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001377 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001378 cast<FieldDecl>(Member)->getType(),
1379 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001380 return getSema().Owned(ME);
1381 }
Mike Stump11289f42009-09-09 15:08:12 +00001382
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001383 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001384 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001385
John McCallb268a282010-08-23 23:25:46 +00001386 getSema().DefaultFunctionArrayConversion(Base);
1387 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001388
John McCall16df1e52010-03-30 21:47:33 +00001389 // FIXME: this involves duplicating earlier analysis in a lot of
1390 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001391 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001392 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001393 R.resolveKind();
1394
John McCallb268a282010-08-23 23:25:46 +00001395 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001396 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001397 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 }
Mike Stump11289f42009-09-09 15:08:12 +00001399
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001401 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 /// By default, performs semantic analysis to build the new expression.
1403 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001404 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001405 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001406 Expr *LHS, Expr *RHS) {
1407 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 }
1409
1410 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001411 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 /// By default, performs semantic analysis to build the new expression.
1413 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001414 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001415 SourceLocation QuestionLoc,
1416 Expr *LHS,
1417 SourceLocation ColonLoc,
1418 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001419 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1420 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 }
1422
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001424 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001427 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001428 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001430 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001431 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001432 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 }
Mike Stump11289f42009-09-09 15:08:12 +00001434
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001436 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001439 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001440 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001442 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001443 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001444 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 }
Mike Stump11289f42009-09-09 15:08:12 +00001446
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001448 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001451 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 SourceLocation OpLoc,
1453 SourceLocation AccessorLoc,
1454 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001455
John McCall10eae182009-11-30 22:42:35 +00001456 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001457 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001458 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001459 OpLoc, /*IsArrow*/ false,
1460 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001461 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001462 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 }
Mike Stump11289f42009-09-09 15:08:12 +00001464
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001466 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 /// By default, performs semantic analysis to build the new expression.
1468 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001469 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001471 SourceLocation RBraceLoc,
1472 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001473 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001474 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1475 if (Result.isInvalid() || ResultTy->isDependentType())
1476 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001477
Douglas Gregord3d93062009-11-09 17:16:50 +00001478 // Patch in the result type we were given, which may have been computed
1479 // when the initial InitListExpr was built.
1480 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1481 ILE->setType(ResultTy);
1482 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 }
Mike Stump11289f42009-09-09 15:08:12 +00001484
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001486 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001489 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 MultiExprArg ArrayExprs,
1491 SourceLocation EqualOrColonLoc,
1492 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001493 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001494 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001496 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001498 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001499
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 ArrayExprs.release();
1501 return move(Result);
1502 }
Mike Stump11289f42009-09-09 15:08:12 +00001503
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001505 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 /// By default, builds the implicit value initialization without performing
1507 /// any semantic analysis. Subclasses may override this routine to provide
1508 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001509 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1511 }
Mike Stump11289f42009-09-09 15:08:12 +00001512
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001514 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001517 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001518 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001519 SourceLocation RParenLoc) {
1520 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001521 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001522 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 }
1524
1525 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001526 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001529 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 MultiExprArg SubExprs,
1531 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001532 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001533 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 }
Mike Stump11289f42009-09-09 15:08:12 +00001535
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001537 ///
1538 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 /// rather than attempting to map the label statement itself.
1540 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001541 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001542 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001543 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 }
Mike Stump11289f42009-09-09 15:08:12 +00001545
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001547 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 /// By default, performs semantic analysis to build the new expression.
1549 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001550 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001551 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001553 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 }
Mike Stump11289f42009-09-09 15:08:12 +00001555
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 /// \brief Build a new __builtin_choose_expr expression.
1557 ///
1558 /// By default, performs semantic analysis to build the new expression.
1559 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001560 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001561 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 SourceLocation RParenLoc) {
1563 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001564 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 RParenLoc);
1566 }
Mike Stump11289f42009-09-09 15:08:12 +00001567
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 /// \brief Build a new overloaded operator call expression.
1569 ///
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// The semantic analysis provides the behavior of template instantiation,
1572 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001573 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 /// argument-dependent lookup, etc. Subclasses may override this routine to
1575 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001576 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001578 Expr *Callee,
1579 Expr *First,
1580 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001581
1582 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 /// reinterpret_cast.
1584 ///
1585 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001586 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001588 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 Stmt::StmtClass Class,
1590 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001591 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 SourceLocation RAngleLoc,
1593 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001594 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 SourceLocation RParenLoc) {
1596 switch (Class) {
1597 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001598 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001599 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001600 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001601
1602 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001603 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001604 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001605 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001606
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001608 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001609 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001610 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001612
Douglas Gregora16548e2009-08-11 05:31:07 +00001613 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001614 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001615 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001616 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001617
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 default:
1619 assert(false && "Invalid C++ named cast");
1620 break;
1621 }
Mike Stump11289f42009-09-09 15:08:12 +00001622
John McCallfaf5fb42010-08-26 23:41:50 +00001623 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 }
Mike Stump11289f42009-09-09 15:08:12 +00001625
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// \brief Build a new C++ static_cast expression.
1627 ///
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001630 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001632 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 SourceLocation RAngleLoc,
1634 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001635 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001637 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001638 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001639 SourceRange(LAngleLoc, RAngleLoc),
1640 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 }
1642
1643 /// \brief Build a new C++ dynamic_cast expression.
1644 ///
1645 /// By default, performs semantic analysis to build the new expression.
1646 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001647 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001649 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 SourceLocation RAngleLoc,
1651 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001652 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001654 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001655 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001656 SourceRange(LAngleLoc, RAngleLoc),
1657 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 }
1659
1660 /// \brief Build a new C++ reinterpret_cast expression.
1661 ///
1662 /// By default, performs semantic analysis to build the new expression.
1663 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001664 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001666 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 SourceLocation RAngleLoc,
1668 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001669 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001671 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001672 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001673 SourceRange(LAngleLoc, RAngleLoc),
1674 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 }
1676
1677 /// \brief Build a new C++ const_cast expression.
1678 ///
1679 /// By default, performs semantic analysis to build the new expression.
1680 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001681 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001683 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001684 SourceLocation RAngleLoc,
1685 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001686 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001688 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001689 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001690 SourceRange(LAngleLoc, RAngleLoc),
1691 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 }
Mike Stump11289f42009-09-09 15:08:12 +00001693
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 /// \brief Build a new C++ functional-style cast expression.
1695 ///
1696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001698 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1699 SourceLocation LParenLoc,
1700 Expr *Sub,
1701 SourceLocation RParenLoc) {
1702 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001703 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 RParenLoc);
1705 }
Mike Stump11289f42009-09-09 15:08:12 +00001706
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 /// \brief Build a new C++ typeid(type) expression.
1708 ///
1709 /// By default, performs semantic analysis to build the new expression.
1710 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001711 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001712 SourceLocation TypeidLoc,
1713 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001715 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001716 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 }
Mike Stump11289f42009-09-09 15:08:12 +00001718
Francois Pichet9f4f2072010-09-08 12:20:18 +00001719
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 /// \brief Build a new C++ typeid(expr) expression.
1721 ///
1722 /// By default, performs semantic analysis to build the new expression.
1723 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001724 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001725 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001726 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001728 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001729 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001730 }
1731
Francois Pichet9f4f2072010-09-08 12:20:18 +00001732 /// \brief Build a new C++ __uuidof(type) expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
1736 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1737 SourceLocation TypeidLoc,
1738 TypeSourceInfo *Operand,
1739 SourceLocation RParenLoc) {
1740 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1741 RParenLoc);
1742 }
1743
1744 /// \brief Build a new C++ __uuidof(expr) expression.
1745 ///
1746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
1748 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1749 SourceLocation TypeidLoc,
1750 Expr *Operand,
1751 SourceLocation RParenLoc) {
1752 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1753 RParenLoc);
1754 }
1755
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 /// \brief Build a new C++ "this" expression.
1757 ///
1758 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001759 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001761 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001762 QualType ThisType,
1763 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001765 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1766 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 }
1768
1769 /// \brief Build a new C++ throw expression.
1770 ///
1771 /// By default, performs semantic analysis to build the new expression.
1772 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001773 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001774 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 }
1776
1777 /// \brief Build a new C++ default-argument expression.
1778 ///
1779 /// By default, builds a new default-argument expression, which does not
1780 /// require any semantic analysis. Subclasses may override this routine to
1781 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001782 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001783 ParmVarDecl *Param) {
1784 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1785 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 }
1787
1788 /// \brief Build a new C++ zero-initialization expression.
1789 ///
1790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001792 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1793 SourceLocation LParenLoc,
1794 SourceLocation RParenLoc) {
1795 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001796 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001797 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 }
Mike Stump11289f42009-09-09 15:08:12 +00001799
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 /// \brief Build a new C++ "new" 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 RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001805 bool UseGlobal,
1806 SourceLocation PlacementLParen,
1807 MultiExprArg PlacementArgs,
1808 SourceLocation PlacementRParen,
1809 SourceRange TypeIdParens,
1810 QualType AllocatedType,
1811 TypeSourceInfo *AllocatedTypeInfo,
1812 Expr *ArraySize,
1813 SourceLocation ConstructorLParen,
1814 MultiExprArg ConstructorArgs,
1815 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001816 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 PlacementLParen,
1818 move(PlacementArgs),
1819 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001820 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001821 AllocatedType,
1822 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001823 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 ConstructorLParen,
1825 move(ConstructorArgs),
1826 ConstructorRParen);
1827 }
Mike Stump11289f42009-09-09 15:08:12 +00001828
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 /// \brief Build a new C++ "delete" expression.
1830 ///
1831 /// By default, performs semantic analysis to build the new expression.
1832 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001833 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 bool IsGlobalDelete,
1835 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001836 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001837 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001838 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 }
Mike Stump11289f42009-09-09 15:08:12 +00001840
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 /// \brief Build a new unary type trait expression.
1842 ///
1843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001845 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001846 SourceLocation StartLoc,
1847 TypeSourceInfo *T,
1848 SourceLocation RParenLoc) {
1849 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 }
1851
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001852 /// \brief Build a new binary type trait expression.
1853 ///
1854 /// By default, performs semantic analysis to build the new expression.
1855 /// Subclasses may override this routine to provide different behavior.
1856 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1857 SourceLocation StartLoc,
1858 TypeSourceInfo *LhsT,
1859 TypeSourceInfo *RhsT,
1860 SourceLocation RParenLoc) {
1861 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1862 }
1863
Mike Stump11289f42009-09-09 15:08:12 +00001864 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 /// expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001869 ExprResult RebuildDependentScopeDeclRefExpr(
1870 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001871 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001872 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001874 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001875
1876 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001877 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001878 *TemplateArgs);
1879
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001880 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 }
1882
1883 /// \brief Build a new template-id expression.
1884 ///
1885 /// By default, performs semantic analysis to build the new expression.
1886 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001887 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001888 LookupResult &R,
1889 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001890 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001891 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 }
1893
1894 /// \brief Build a new object-construction expression.
1895 ///
1896 /// By default, performs semantic analysis to build the new expression.
1897 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001898 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001899 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 CXXConstructorDecl *Constructor,
1901 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001902 MultiExprArg Args,
1903 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001904 CXXConstructExpr::ConstructionKind ConstructKind,
1905 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001906 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001907 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001908 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001909 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001910
Douglas Gregordb121ba2009-12-14 16:27:04 +00001911 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001912 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001913 RequiresZeroInit, ConstructKind,
1914 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 }
1916
1917 /// \brief Build a new object-construction expression.
1918 ///
1919 /// By default, performs semantic analysis to build the new expression.
1920 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001921 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1922 SourceLocation LParenLoc,
1923 MultiExprArg Args,
1924 SourceLocation RParenLoc) {
1925 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 LParenLoc,
1927 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 RParenLoc);
1929 }
1930
1931 /// \brief Build a new object-construction expression.
1932 ///
1933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001935 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1936 SourceLocation LParenLoc,
1937 MultiExprArg Args,
1938 SourceLocation RParenLoc) {
1939 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 LParenLoc,
1941 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 RParenLoc);
1943 }
Mike Stump11289f42009-09-09 15:08:12 +00001944
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 /// \brief Build a new member reference expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001949 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00001950 QualType BaseType,
1951 bool IsArrow,
1952 SourceLocation OperatorLoc,
1953 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00001954 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001955 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001956 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00001958 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001959
John McCallb268a282010-08-23 23:25:46 +00001960 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001961 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001962 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001963 MemberNameInfo,
1964 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 }
1966
John McCall10eae182009-11-30 22:42:35 +00001967 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001968 ///
1969 /// By default, performs semantic analysis to build the new expression.
1970 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001971 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001972 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001973 SourceLocation OperatorLoc,
1974 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00001975 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00001976 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001977 LookupResult &R,
1978 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001979 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00001980 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001981
John McCallb268a282010-08-23 23:25:46 +00001982 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001983 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001984 SS, FirstQualifierInScope,
1985 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001986 }
Mike Stump11289f42009-09-09 15:08:12 +00001987
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001988 /// \brief Build a new noexcept expression.
1989 ///
1990 /// By default, performs semantic analysis to build the new expression.
1991 /// Subclasses may override this routine to provide different behavior.
1992 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1993 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1994 }
1995
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001996 /// \brief Build a new expression to compute the length of a parameter pack.
1997 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
1998 SourceLocation PackLoc,
1999 SourceLocation RParenLoc,
2000 unsigned Length) {
2001 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2002 OperatorLoc, Pack, PackLoc,
2003 RParenLoc, Length);
2004 }
2005
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 /// \brief Build a new Objective-C @encode expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002010 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002011 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002013 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002015 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002016
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002017 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002018 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002019 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002020 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002021 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002022 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002023 MultiExprArg Args,
2024 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002025 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2026 ReceiverTypeInfo->getType(),
2027 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002028 Sel, Method, LBracLoc, SelectorLoc,
2029 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002030 }
2031
2032 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002033 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002034 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002035 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002036 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002037 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002038 MultiExprArg Args,
2039 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002040 return SemaRef.BuildInstanceMessage(Receiver,
2041 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002042 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002043 Sel, Method, LBracLoc, SelectorLoc,
2044 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002045 }
2046
Douglas Gregord51d90d2010-04-26 20:11:03 +00002047 /// \brief Build a new Objective-C ivar reference expression.
2048 ///
2049 /// By default, performs semantic analysis to build the new expression.
2050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002051 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002052 SourceLocation IvarLoc,
2053 bool IsArrow, bool IsFreeIvar) {
2054 // FIXME: We lose track of the IsFreeIvar bit.
2055 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002056 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002057 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2058 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002059 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002060 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002061 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002062 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002063 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002064 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002065
Douglas Gregord51d90d2010-04-26 20:11:03 +00002066 if (Result.get())
2067 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002068
John McCallb268a282010-08-23 23:25:46 +00002069 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002070 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002071 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002072 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002073 /*TemplateArgs=*/0);
2074 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002075
2076 /// \brief Build a new Objective-C property reference expression.
2077 ///
2078 /// By default, performs semantic analysis to build the new expression.
2079 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002080 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002081 ObjCPropertyDecl *Property,
2082 SourceLocation PropertyLoc) {
2083 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002084 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002085 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2086 Sema::LookupMemberName);
2087 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002088 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002089 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002090 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002091 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002092 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002093
Douglas Gregor9faee212010-04-26 20:47:02 +00002094 if (Result.get())
2095 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002096
John McCallb268a282010-08-23 23:25:46 +00002097 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002098 /*FIXME:*/PropertyLoc, IsArrow,
2099 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002100 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002101 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002102 /*TemplateArgs=*/0);
2103 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002104
John McCallb7bd14f2010-12-02 01:19:52 +00002105 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002106 ///
2107 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002108 /// Subclasses may override this routine to provide different behavior.
2109 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2110 ObjCMethodDecl *Getter,
2111 ObjCMethodDecl *Setter,
2112 SourceLocation PropertyLoc) {
2113 // Since these expressions can only be value-dependent, we do not
2114 // need to perform semantic analysis again.
2115 return Owned(
2116 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2117 VK_LValue, OK_ObjCProperty,
2118 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002119 }
2120
Douglas Gregord51d90d2010-04-26 20:11:03 +00002121 /// \brief Build a new Objective-C "isa" expression.
2122 ///
2123 /// By default, performs semantic analysis to build the new expression.
2124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002125 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002126 bool IsArrow) {
2127 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002128 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002129 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2130 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002131 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002132 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002133 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002134 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002135 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002136
Douglas Gregord51d90d2010-04-26 20:11:03 +00002137 if (Result.get())
2138 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002139
John McCallb268a282010-08-23 23:25:46 +00002140 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002141 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002142 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002143 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002144 /*TemplateArgs=*/0);
2145 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002146
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 /// \brief Build a new shuffle vector expression.
2148 ///
2149 /// By default, performs semantic analysis to build the new expression.
2150 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002151 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002152 MultiExprArg SubExprs,
2153 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002155 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2157 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2158 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2159 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002160
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 // Build a reference to the __builtin_shufflevector builtin
2162 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002163 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002165 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002167
2168 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 unsigned NumSubExprs = SubExprs.size();
2170 Expr **Subs = (Expr **)SubExprs.release();
2171 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2172 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002173 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002174 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002176 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002177
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002179 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002181 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002182
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002184 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 }
John McCall31f82722010-11-12 08:19:04 +00002186
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002187 /// \brief Build a new template argument pack expansion.
2188 ///
2189 /// By default, performs semantic analysis to build a new pack expansion
2190 /// for a template argument. Subclasses may override this routine to provide
2191 /// different behavior.
2192 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002193 SourceLocation EllipsisLoc,
2194 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002195 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002196 case TemplateArgument::Expression: {
2197 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002198 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2199 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002200 if (Result.isInvalid())
2201 return TemplateArgumentLoc();
2202
2203 return TemplateArgumentLoc(Result.get(), Result.get());
2204 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002205
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002206 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002207 return TemplateArgumentLoc(TemplateArgument(
2208 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002209 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002210 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002211 Pattern.getTemplateNameLoc(),
2212 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002213
2214 case TemplateArgument::Null:
2215 case TemplateArgument::Integral:
2216 case TemplateArgument::Declaration:
2217 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002218 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002219 llvm_unreachable("Pack expansion pattern has no parameter packs");
2220
2221 case TemplateArgument::Type:
2222 if (TypeSourceInfo *Expansion
2223 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002224 EllipsisLoc,
2225 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002226 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2227 Expansion);
2228 break;
2229 }
2230
2231 return TemplateArgumentLoc();
2232 }
2233
Douglas Gregor968f23a2011-01-03 19:31:53 +00002234 /// \brief Build a new expression pack expansion.
2235 ///
2236 /// By default, performs semantic analysis to build a new pack expansion
2237 /// for an expression. Subclasses may override this routine to provide
2238 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002239 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2240 llvm::Optional<unsigned> NumExpansions) {
2241 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002242 }
2243
John McCall31f82722010-11-12 08:19:04 +00002244private:
Douglas Gregor14454802011-02-25 02:25:35 +00002245 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2246 QualType ObjectType,
2247 NamedDecl *FirstQualifierInScope,
2248 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002249
2250 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2251 QualType ObjectType,
2252 NamedDecl *FirstQualifierInScope,
2253 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002254};
Douglas Gregora16548e2009-08-11 05:31:07 +00002255
Douglas Gregorebe10102009-08-20 07:17:43 +00002256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002257StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002258 if (!S)
2259 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002260
Douglas Gregorebe10102009-08-20 07:17:43 +00002261 switch (S->getStmtClass()) {
2262 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002263
Douglas Gregorebe10102009-08-20 07:17:43 +00002264 // Transform individual statement nodes
2265#define STMT(Node, Parent) \
2266 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002267#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002268#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002269#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002270
Douglas Gregorebe10102009-08-20 07:17:43 +00002271 // Transform expressions by calling TransformExpr.
2272#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002273#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002274#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002275#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002276 {
John McCalldadc5752010-08-24 06:29:42 +00002277 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002278 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002279 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002280
John McCallb268a282010-08-23 23:25:46 +00002281 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002282 }
Mike Stump11289f42009-09-09 15:08:12 +00002283 }
2284
John McCallc3007a22010-10-26 07:05:15 +00002285 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002286}
Mike Stump11289f42009-09-09 15:08:12 +00002287
2288
Douglas Gregore922c772009-08-04 22:27:00 +00002289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002290ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 if (!E)
2292 return SemaRef.Owned(E);
2293
2294 switch (E->getStmtClass()) {
2295 case Stmt::NoStmtClass: break;
2296#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002297#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002298#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002299 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002300#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002301 }
2302
John McCallc3007a22010-10-26 07:05:15 +00002303 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002304}
2305
2306template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002307bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2308 unsigned NumInputs,
2309 bool IsCall,
2310 llvm::SmallVectorImpl<Expr *> &Outputs,
2311 bool *ArgChanged) {
2312 for (unsigned I = 0; I != NumInputs; ++I) {
2313 // If requested, drop call arguments that need to be dropped.
2314 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2315 if (ArgChanged)
2316 *ArgChanged = true;
2317
2318 break;
2319 }
2320
Douglas Gregor968f23a2011-01-03 19:31:53 +00002321 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2322 Expr *Pattern = Expansion->getPattern();
2323
2324 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2325 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2326 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2327
2328 // Determine whether the set of unexpanded parameter packs can and should
2329 // be expanded.
2330 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002331 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002332 llvm::Optional<unsigned> OrigNumExpansions
2333 = Expansion->getNumExpansions();
2334 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002335 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2336 Pattern->getSourceRange(),
2337 Unexpanded.data(),
2338 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002339 Expand, RetainExpansion,
2340 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002341 return true;
2342
2343 if (!Expand) {
2344 // The transform has determined that we should perform a simple
2345 // transformation on the pack expansion, producing another pack
2346 // expansion.
2347 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2348 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2349 if (OutPattern.isInvalid())
2350 return true;
2351
2352 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002353 Expansion->getEllipsisLoc(),
2354 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002355 if (Out.isInvalid())
2356 return true;
2357
2358 if (ArgChanged)
2359 *ArgChanged = true;
2360 Outputs.push_back(Out.get());
2361 continue;
2362 }
2363
2364 // The transform has determined that we should perform an elementwise
2365 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002366 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002367 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2368 ExprResult Out = getDerived().TransformExpr(Pattern);
2369 if (Out.isInvalid())
2370 return true;
2371
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002372 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002373 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2374 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002375 if (Out.isInvalid())
2376 return true;
2377 }
2378
Douglas Gregor968f23a2011-01-03 19:31:53 +00002379 if (ArgChanged)
2380 *ArgChanged = true;
2381 Outputs.push_back(Out.get());
2382 }
2383
2384 continue;
2385 }
2386
Douglas Gregora3efea12011-01-03 19:04:46 +00002387 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2388 if (Result.isInvalid())
2389 return true;
2390
2391 if (Result.get() != Inputs[I] && ArgChanged)
2392 *ArgChanged = true;
2393
2394 Outputs.push_back(Result.get());
2395 }
2396
2397 return false;
2398}
2399
2400template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002401NestedNameSpecifierLoc
2402TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2403 NestedNameSpecifierLoc NNS,
2404 QualType ObjectType,
2405 NamedDecl *FirstQualifierInScope) {
2406 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2407 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2408 Qualifier = Qualifier.getPrefix())
2409 Qualifiers.push_back(Qualifier);
2410
2411 CXXScopeSpec SS;
2412 while (!Qualifiers.empty()) {
2413 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2414 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2415
2416 switch (QNNS->getKind()) {
2417 case NestedNameSpecifier::Identifier:
2418 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2419 *QNNS->getAsIdentifier(),
2420 Q.getLocalBeginLoc(),
2421 Q.getLocalEndLoc(),
2422 ObjectType, false, SS,
2423 FirstQualifierInScope, false))
2424 return NestedNameSpecifierLoc();
2425
2426 break;
2427
2428 case NestedNameSpecifier::Namespace: {
2429 NamespaceDecl *NS
2430 = cast_or_null<NamespaceDecl>(
2431 getDerived().TransformDecl(
2432 Q.getLocalBeginLoc(),
2433 QNNS->getAsNamespace()));
2434 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2435 break;
2436 }
2437
2438 case NestedNameSpecifier::NamespaceAlias: {
2439 NamespaceAliasDecl *Alias
2440 = cast_or_null<NamespaceAliasDecl>(
2441 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2442 QNNS->getAsNamespaceAlias()));
2443 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2444 Q.getLocalEndLoc());
2445 break;
2446 }
2447
2448 case NestedNameSpecifier::Global:
2449 // There is no meaningful transformation that one could perform on the
2450 // global scope.
2451 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2452 break;
2453
2454 case NestedNameSpecifier::TypeSpecWithTemplate:
2455 case NestedNameSpecifier::TypeSpec: {
2456 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2457 FirstQualifierInScope, SS);
2458
2459 if (!TL)
2460 return NestedNameSpecifierLoc();
2461
2462 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2463 (SemaRef.getLangOptions().CPlusPlus0x &&
2464 TL.getType()->isEnumeralType())) {
2465 assert(!TL.getType().hasLocalQualifiers() &&
2466 "Can't get cv-qualifiers here");
2467 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2468 Q.getLocalEndLoc());
2469 break;
2470 }
2471
2472 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2473 << TL.getType() << SS.getRange();
2474 return NestedNameSpecifierLoc();
2475 }
Douglas Gregore16af532011-02-28 18:50:33 +00002476 }
Douglas Gregor14454802011-02-25 02:25:35 +00002477
Douglas Gregore16af532011-02-28 18:50:33 +00002478 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002479 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002480 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002481 }
2482
2483 // Don't rebuild the nested-name-specifier if we don't have to.
2484 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2485 !getDerived().AlwaysRebuild())
2486 return NNS;
2487
2488 // If we can re-use the source-location data from the original
2489 // nested-name-specifier, do so.
2490 if (SS.location_size() == NNS.getDataLength() &&
2491 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2492 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2493
2494 // Allocate new nested-name-specifier location information.
2495 return SS.getWithLocInContext(SemaRef.Context);
2496}
2497
2498template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002499DeclarationNameInfo
2500TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002501::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002502 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002503 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002504 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002505
2506 switch (Name.getNameKind()) {
2507 case DeclarationName::Identifier:
2508 case DeclarationName::ObjCZeroArgSelector:
2509 case DeclarationName::ObjCOneArgSelector:
2510 case DeclarationName::ObjCMultiArgSelector:
2511 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002512 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002513 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002514 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002515
Douglas Gregorf816bd72009-09-03 22:13:48 +00002516 case DeclarationName::CXXConstructorName:
2517 case DeclarationName::CXXDestructorName:
2518 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002519 TypeSourceInfo *NewTInfo;
2520 CanQualType NewCanTy;
2521 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002522 NewTInfo = getDerived().TransformType(OldTInfo);
2523 if (!NewTInfo)
2524 return DeclarationNameInfo();
2525 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002526 }
2527 else {
2528 NewTInfo = 0;
2529 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002530 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002531 if (NewT.isNull())
2532 return DeclarationNameInfo();
2533 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2534 }
Mike Stump11289f42009-09-09 15:08:12 +00002535
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002536 DeclarationName NewName
2537 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2538 NewCanTy);
2539 DeclarationNameInfo NewNameInfo(NameInfo);
2540 NewNameInfo.setName(NewName);
2541 NewNameInfo.setNamedTypeInfo(NewTInfo);
2542 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002543 }
Mike Stump11289f42009-09-09 15:08:12 +00002544 }
2545
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002546 assert(0 && "Unknown name kind.");
2547 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002548}
2549
2550template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002551TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002552TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2553 TemplateName Name,
2554 SourceLocation NameLoc,
2555 QualType ObjectType,
2556 NamedDecl *FirstQualifierInScope) {
2557 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2558 TemplateDecl *Template = QTN->getTemplateDecl();
2559 assert(Template && "qualified template name must refer to a template");
2560
2561 TemplateDecl *TransTemplate
2562 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2563 Template));
2564 if (!TransTemplate)
2565 return TemplateName();
2566
2567 if (!getDerived().AlwaysRebuild() &&
2568 SS.getScopeRep() == QTN->getQualifier() &&
2569 TransTemplate == Template)
2570 return Name;
2571
2572 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2573 TransTemplate);
2574 }
2575
2576 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2577 if (SS.getScopeRep()) {
2578 // These apply to the scope specifier, not the template.
2579 ObjectType = QualType();
2580 FirstQualifierInScope = 0;
2581 }
2582
2583 if (!getDerived().AlwaysRebuild() &&
2584 SS.getScopeRep() == DTN->getQualifier() &&
2585 ObjectType.isNull())
2586 return Name;
2587
2588 if (DTN->isIdentifier()) {
2589 return getDerived().RebuildTemplateName(SS,
2590 *DTN->getIdentifier(),
2591 NameLoc,
2592 ObjectType,
2593 FirstQualifierInScope);
2594 }
2595
2596 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2597 ObjectType);
2598 }
2599
2600 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2601 TemplateDecl *TransTemplate
2602 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2603 Template));
2604 if (!TransTemplate)
2605 return TemplateName();
2606
2607 if (!getDerived().AlwaysRebuild() &&
2608 TransTemplate == Template)
2609 return Name;
2610
2611 return TemplateName(TransTemplate);
2612 }
2613
2614 if (SubstTemplateTemplateParmPackStorage *SubstPack
2615 = Name.getAsSubstTemplateTemplateParmPack()) {
2616 TemplateTemplateParmDecl *TransParam
2617 = cast_or_null<TemplateTemplateParmDecl>(
2618 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2619 if (!TransParam)
2620 return TemplateName();
2621
2622 if (!getDerived().AlwaysRebuild() &&
2623 TransParam == SubstPack->getParameterPack())
2624 return Name;
2625
2626 return getDerived().RebuildTemplateName(TransParam,
2627 SubstPack->getArgumentPack());
2628 }
2629
2630 // These should be getting filtered out before they reach the AST.
2631 llvm_unreachable("overloaded function decl survived to here");
2632 return TemplateName();
2633}
2634
2635template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002636void TreeTransform<Derived>::InventTemplateArgumentLoc(
2637 const TemplateArgument &Arg,
2638 TemplateArgumentLoc &Output) {
2639 SourceLocation Loc = getDerived().getBaseLocation();
2640 switch (Arg.getKind()) {
2641 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002642 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002643 break;
2644
2645 case TemplateArgument::Type:
2646 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002647 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002648
John McCall0ad16662009-10-29 08:12:44 +00002649 break;
2650
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002651 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002652 case TemplateArgument::TemplateExpansion: {
2653 NestedNameSpecifierLocBuilder Builder;
2654 TemplateName Template = Arg.getAsTemplate();
2655 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2656 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2657 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2658 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2659
2660 if (Arg.getKind() == TemplateArgument::Template)
2661 Output = TemplateArgumentLoc(Arg,
2662 Builder.getWithLocInContext(SemaRef.Context),
2663 Loc);
2664 else
2665 Output = TemplateArgumentLoc(Arg,
2666 Builder.getWithLocInContext(SemaRef.Context),
2667 Loc, Loc);
2668
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002669 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002670 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002671
John McCall0ad16662009-10-29 08:12:44 +00002672 case TemplateArgument::Expression:
2673 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2674 break;
2675
2676 case TemplateArgument::Declaration:
2677 case TemplateArgument::Integral:
2678 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002679 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002680 break;
2681 }
2682}
2683
2684template<typename Derived>
2685bool TreeTransform<Derived>::TransformTemplateArgument(
2686 const TemplateArgumentLoc &Input,
2687 TemplateArgumentLoc &Output) {
2688 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002689 switch (Arg.getKind()) {
2690 case TemplateArgument::Null:
2691 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002692 Output = Input;
2693 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002694
Douglas Gregore922c772009-08-04 22:27:00 +00002695 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002696 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002697 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002698 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002699
2700 DI = getDerived().TransformType(DI);
2701 if (!DI) return true;
2702
2703 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2704 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002705 }
Mike Stump11289f42009-09-09 15:08:12 +00002706
Douglas Gregore922c772009-08-04 22:27:00 +00002707 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002708 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002709 DeclarationName Name;
2710 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2711 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002712 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002713 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002714 if (!D) return true;
2715
John McCall0d07eb32009-10-29 18:45:58 +00002716 Expr *SourceExpr = Input.getSourceDeclExpression();
2717 if (SourceExpr) {
2718 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002719 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002720 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002721 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002722 }
2723
2724 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002725 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002726 }
Mike Stump11289f42009-09-09 15:08:12 +00002727
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002728 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002729 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2730 if (QualifierLoc) {
2731 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2732 if (!QualifierLoc)
2733 return true;
2734 }
2735
Douglas Gregordf846d12011-03-02 18:46:51 +00002736 CXXScopeSpec SS;
2737 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002738 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002739 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2740 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002741 if (Template.isNull())
2742 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002743
Douglas Gregor9d802122011-03-02 17:09:35 +00002744 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002745 Input.getTemplateNameLoc());
2746 return false;
2747 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002748
2749 case TemplateArgument::TemplateExpansion:
2750 llvm_unreachable("Caller should expand pack expansions");
2751
Douglas Gregore922c772009-08-04 22:27:00 +00002752 case TemplateArgument::Expression: {
2753 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002754 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002755 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002756
John McCall0ad16662009-10-29 08:12:44 +00002757 Expr *InputExpr = Input.getSourceExpression();
2758 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2759
John McCalldadc5752010-08-24 06:29:42 +00002760 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002761 = getDerived().TransformExpr(InputExpr);
2762 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002763 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002764 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002765 }
Mike Stump11289f42009-09-09 15:08:12 +00002766
Douglas Gregore922c772009-08-04 22:27:00 +00002767 case TemplateArgument::Pack: {
2768 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2769 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002770 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002771 AEnd = Arg.pack_end();
2772 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002773
John McCall0ad16662009-10-29 08:12:44 +00002774 // FIXME: preserve source information here when we start
2775 // caring about parameter packs.
2776
John McCall0d07eb32009-10-29 18:45:58 +00002777 TemplateArgumentLoc InputArg;
2778 TemplateArgumentLoc OutputArg;
2779 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2780 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002781 return true;
2782
John McCall0d07eb32009-10-29 18:45:58 +00002783 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002784 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002785
2786 TemplateArgument *TransformedArgsPtr
2787 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2788 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2789 TransformedArgsPtr);
2790 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2791 TransformedArgs.size()),
2792 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002793 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002794 }
2795 }
Mike Stump11289f42009-09-09 15:08:12 +00002796
Douglas Gregore922c772009-08-04 22:27:00 +00002797 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002798 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002799}
2800
Douglas Gregorfe921a72010-12-20 23:36:19 +00002801/// \brief Iterator adaptor that invents template argument location information
2802/// for each of the template arguments in its underlying iterator.
2803template<typename Derived, typename InputIterator>
2804class TemplateArgumentLocInventIterator {
2805 TreeTransform<Derived> &Self;
2806 InputIterator Iter;
2807
2808public:
2809 typedef TemplateArgumentLoc value_type;
2810 typedef TemplateArgumentLoc reference;
2811 typedef typename std::iterator_traits<InputIterator>::difference_type
2812 difference_type;
2813 typedef std::input_iterator_tag iterator_category;
2814
2815 class pointer {
2816 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002817
Douglas Gregorfe921a72010-12-20 23:36:19 +00002818 public:
2819 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2820
2821 const TemplateArgumentLoc *operator->() const { return &Arg; }
2822 };
2823
2824 TemplateArgumentLocInventIterator() { }
2825
2826 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2827 InputIterator Iter)
2828 : Self(Self), Iter(Iter) { }
2829
2830 TemplateArgumentLocInventIterator &operator++() {
2831 ++Iter;
2832 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002833 }
2834
Douglas Gregorfe921a72010-12-20 23:36:19 +00002835 TemplateArgumentLocInventIterator operator++(int) {
2836 TemplateArgumentLocInventIterator Old(*this);
2837 ++(*this);
2838 return Old;
2839 }
2840
2841 reference operator*() const {
2842 TemplateArgumentLoc Result;
2843 Self.InventTemplateArgumentLoc(*Iter, Result);
2844 return Result;
2845 }
2846
2847 pointer operator->() const { return pointer(**this); }
2848
2849 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2850 const TemplateArgumentLocInventIterator &Y) {
2851 return X.Iter == Y.Iter;
2852 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002853
Douglas Gregorfe921a72010-12-20 23:36:19 +00002854 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2855 const TemplateArgumentLocInventIterator &Y) {
2856 return X.Iter != Y.Iter;
2857 }
2858};
2859
Douglas Gregor42cafa82010-12-20 17:42:22 +00002860template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002861template<typename InputIterator>
2862bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2863 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002864 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002865 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002866 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002867 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002868
2869 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2870 // Unpack argument packs, which we translate them into separate
2871 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002872 // FIXME: We could do much better if we could guarantee that the
2873 // TemplateArgumentLocInfo for the pack expansion would be usable for
2874 // all of the template arguments in the argument pack.
2875 typedef TemplateArgumentLocInventIterator<Derived,
2876 TemplateArgument::pack_iterator>
2877 PackLocIterator;
2878 if (TransformTemplateArguments(PackLocIterator(*this,
2879 In.getArgument().pack_begin()),
2880 PackLocIterator(*this,
2881 In.getArgument().pack_end()),
2882 Outputs))
2883 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002884
2885 continue;
2886 }
2887
2888 if (In.getArgument().isPackExpansion()) {
2889 // We have a pack expansion, for which we will be substituting into
2890 // the pattern.
2891 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002892 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002893 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002894 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2895 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002896
2897 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2898 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2899 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2900
2901 // Determine whether the set of unexpanded parameter packs can and should
2902 // be expanded.
2903 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002904 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002905 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002906 if (getDerived().TryExpandParameterPacks(Ellipsis,
2907 Pattern.getSourceRange(),
2908 Unexpanded.data(),
2909 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002910 Expand,
2911 RetainExpansion,
2912 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002913 return true;
2914
2915 if (!Expand) {
2916 // The transform has determined that we should perform a simple
2917 // transformation on the pack expansion, producing another pack
2918 // expansion.
2919 TemplateArgumentLoc OutPattern;
2920 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2921 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2922 return true;
2923
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002924 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2925 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002926 if (Out.getArgument().isNull())
2927 return true;
2928
2929 Outputs.addArgument(Out);
2930 continue;
2931 }
2932
2933 // The transform has determined that we should perform an elementwise
2934 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002935 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002936 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2937
2938 if (getDerived().TransformTemplateArgument(Pattern, Out))
2939 return true;
2940
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002941 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002942 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2943 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002944 if (Out.getArgument().isNull())
2945 return true;
2946 }
2947
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002948 Outputs.addArgument(Out);
2949 }
2950
Douglas Gregor48d24112011-01-10 20:53:55 +00002951 // If we're supposed to retain a pack expansion, do so by temporarily
2952 // forgetting the partially-substituted parameter pack.
2953 if (RetainExpansion) {
2954 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2955
2956 if (getDerived().TransformTemplateArgument(Pattern, Out))
2957 return true;
2958
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002959 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2960 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002961 if (Out.getArgument().isNull())
2962 return true;
2963
2964 Outputs.addArgument(Out);
2965 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002966
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002967 continue;
2968 }
2969
2970 // The simple case:
2971 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002972 return true;
2973
2974 Outputs.addArgument(Out);
2975 }
2976
2977 return false;
2978
2979}
2980
Douglas Gregord6ff3322009-08-04 16:50:30 +00002981//===----------------------------------------------------------------------===//
2982// Type transformation
2983//===----------------------------------------------------------------------===//
2984
2985template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002986QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002987 if (getDerived().AlreadyTransformed(T))
2988 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002989
John McCall550e0c22009-10-21 00:40:46 +00002990 // Temporary workaround. All of these transformations should
2991 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00002992 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2993 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002994
John McCall31f82722010-11-12 08:19:04 +00002995 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002996
John McCall550e0c22009-10-21 00:40:46 +00002997 if (!NewDI)
2998 return QualType();
2999
3000 return NewDI->getType();
3001}
3002
3003template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003004TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003005 if (getDerived().AlreadyTransformed(DI->getType()))
3006 return DI;
3007
3008 TypeLocBuilder TLB;
3009
3010 TypeLoc TL = DI->getTypeLoc();
3011 TLB.reserve(TL.getFullDataSize());
3012
John McCall31f82722010-11-12 08:19:04 +00003013 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003014 if (Result.isNull())
3015 return 0;
3016
John McCallbcd03502009-12-07 02:54:59 +00003017 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003018}
3019
3020template<typename Derived>
3021QualType
John McCall31f82722010-11-12 08:19:04 +00003022TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003023 switch (T.getTypeLocClass()) {
3024#define ABSTRACT_TYPELOC(CLASS, PARENT)
3025#define TYPELOC(CLASS, PARENT) \
3026 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003027 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003028#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003029 }
Mike Stump11289f42009-09-09 15:08:12 +00003030
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003031 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003032 return QualType();
3033}
3034
3035/// FIXME: By default, this routine adds type qualifiers only to types
3036/// that can have qualifiers, and silently suppresses those qualifiers
3037/// that are not permitted (e.g., qualifiers on reference or function
3038/// types). This is the right thing for template instantiation, but
3039/// probably not for other clients.
3040template<typename Derived>
3041QualType
3042TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003043 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003044 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003045
John McCall31f82722010-11-12 08:19:04 +00003046 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003047 if (Result.isNull())
3048 return QualType();
3049
3050 // Silently suppress qualifiers if the result type can't be qualified.
3051 // FIXME: this is the right thing for template instantiation, but
3052 // probably not for other clients.
3053 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003054 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003055
John McCallcb0f89a2010-06-05 06:41:15 +00003056 if (!Quals.empty()) {
3057 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3058 TLB.push<QualifiedTypeLoc>(Result);
3059 // No location information to preserve.
3060 }
John McCall550e0c22009-10-21 00:40:46 +00003061
3062 return Result;
3063}
3064
Douglas Gregor14454802011-02-25 02:25:35 +00003065template<typename Derived>
3066TypeLoc
3067TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3068 QualType ObjectType,
3069 NamedDecl *UnqualLookup,
3070 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003071 QualType T = TL.getType();
3072 if (getDerived().AlreadyTransformed(T))
3073 return TL;
3074
3075 TypeLocBuilder TLB;
3076 QualType Result;
3077
3078 if (isa<TemplateSpecializationType>(T)) {
3079 TemplateSpecializationTypeLoc SpecTL
3080 = cast<TemplateSpecializationTypeLoc>(TL);
3081
3082 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003083 getDerived().TransformTemplateName(SS,
3084 SpecTL.getTypePtr()->getTemplateName(),
3085 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003086 ObjectType, UnqualLookup);
3087 if (Template.isNull())
3088 return TypeLoc();
3089
3090 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3091 Template);
3092 } else if (isa<DependentTemplateSpecializationType>(T)) {
3093 DependentTemplateSpecializationTypeLoc SpecTL
3094 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3095
Douglas Gregor5a064722011-02-28 17:23:35 +00003096 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003097 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003098 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003099 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003100 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003101 if (Template.isNull())
3102 return TypeLoc();
3103
Douglas Gregor14454802011-02-25 02:25:35 +00003104 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003105 SpecTL,
3106 Template);
Douglas Gregor14454802011-02-25 02:25:35 +00003107 } else {
3108 // Nothing special needs to be done for these.
3109 Result = getDerived().TransformType(TLB, TL);
3110 }
3111
3112 if (Result.isNull())
3113 return TypeLoc();
3114
3115 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3116}
3117
Douglas Gregor579c15f2011-03-02 18:32:08 +00003118template<typename Derived>
3119TypeSourceInfo *
3120TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3121 QualType ObjectType,
3122 NamedDecl *UnqualLookup,
3123 CXXScopeSpec &SS) {
3124 // FIXME: Painfully copy-paste from the above!
3125
3126 QualType T = TSInfo->getType();
3127 if (getDerived().AlreadyTransformed(T))
3128 return TSInfo;
3129
3130 TypeLocBuilder TLB;
3131 QualType Result;
3132
3133 TypeLoc TL = TSInfo->getTypeLoc();
3134 if (isa<TemplateSpecializationType>(T)) {
3135 TemplateSpecializationTypeLoc SpecTL
3136 = cast<TemplateSpecializationTypeLoc>(TL);
3137
3138 TemplateName Template
3139 = getDerived().TransformTemplateName(SS,
3140 SpecTL.getTypePtr()->getTemplateName(),
3141 SpecTL.getTemplateNameLoc(),
3142 ObjectType, UnqualLookup);
3143 if (Template.isNull())
3144 return 0;
3145
3146 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3147 Template);
3148 } else if (isa<DependentTemplateSpecializationType>(T)) {
3149 DependentTemplateSpecializationTypeLoc SpecTL
3150 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3151
3152 TemplateName Template
3153 = getDerived().RebuildTemplateName(SS,
3154 *SpecTL.getTypePtr()->getIdentifier(),
3155 SpecTL.getNameLoc(),
3156 ObjectType, UnqualLookup);
3157 if (Template.isNull())
3158 return 0;
3159
3160 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3161 SpecTL,
3162 Template);
3163 } else {
3164 // Nothing special needs to be done for these.
3165 Result = getDerived().TransformType(TLB, TL);
3166 }
3167
3168 if (Result.isNull())
3169 return 0;
3170
3171 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3172}
3173
John McCall550e0c22009-10-21 00:40:46 +00003174template <class TyLoc> static inline
3175QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3176 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3177 NewT.setNameLoc(T.getNameLoc());
3178 return T.getType();
3179}
3180
John McCall550e0c22009-10-21 00:40:46 +00003181template<typename Derived>
3182QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003183 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003184 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3185 NewT.setBuiltinLoc(T.getBuiltinLoc());
3186 if (T.needsExtraLocalData())
3187 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3188 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003189}
Mike Stump11289f42009-09-09 15:08:12 +00003190
Douglas Gregord6ff3322009-08-04 16:50:30 +00003191template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003192QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003193 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003194 // FIXME: recurse?
3195 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003196}
Mike Stump11289f42009-09-09 15:08:12 +00003197
Douglas Gregord6ff3322009-08-04 16:50:30 +00003198template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003199QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003200 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003201 QualType PointeeType
3202 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003203 if (PointeeType.isNull())
3204 return QualType();
3205
3206 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003207 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003208 // A dependent pointer type 'T *' has is being transformed such
3209 // that an Objective-C class type is being replaced for 'T'. The
3210 // resulting pointer type is an ObjCObjectPointerType, not a
3211 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003212 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003213
John McCall8b07ec22010-05-15 11:32:37 +00003214 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3215 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003216 return Result;
3217 }
John McCall31f82722010-11-12 08:19:04 +00003218
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003219 if (getDerived().AlwaysRebuild() ||
3220 PointeeType != TL.getPointeeLoc().getType()) {
3221 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3222 if (Result.isNull())
3223 return QualType();
3224 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003225
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003226 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3227 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003228 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003229}
Mike Stump11289f42009-09-09 15:08:12 +00003230
3231template<typename Derived>
3232QualType
John McCall550e0c22009-10-21 00:40:46 +00003233TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003234 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003235 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003236 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3237 if (PointeeType.isNull())
3238 return QualType();
3239
3240 QualType Result = TL.getType();
3241 if (getDerived().AlwaysRebuild() ||
3242 PointeeType != TL.getPointeeLoc().getType()) {
3243 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003244 TL.getSigilLoc());
3245 if (Result.isNull())
3246 return QualType();
3247 }
3248
Douglas Gregor049211a2010-04-22 16:50:51 +00003249 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003250 NewT.setSigilLoc(TL.getSigilLoc());
3251 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003252}
3253
John McCall70dd5f62009-10-30 00:06:24 +00003254/// Transforms a reference type. Note that somewhat paradoxically we
3255/// don't care whether the type itself is an l-value type or an r-value
3256/// type; we only care if the type was *written* as an l-value type
3257/// or an r-value type.
3258template<typename Derived>
3259QualType
3260TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003261 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003262 const ReferenceType *T = TL.getTypePtr();
3263
3264 // Note that this works with the pointee-as-written.
3265 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3266 if (PointeeType.isNull())
3267 return QualType();
3268
3269 QualType Result = TL.getType();
3270 if (getDerived().AlwaysRebuild() ||
3271 PointeeType != T->getPointeeTypeAsWritten()) {
3272 Result = getDerived().RebuildReferenceType(PointeeType,
3273 T->isSpelledAsLValue(),
3274 TL.getSigilLoc());
3275 if (Result.isNull())
3276 return QualType();
3277 }
3278
3279 // r-value references can be rebuilt as l-value references.
3280 ReferenceTypeLoc NewTL;
3281 if (isa<LValueReferenceType>(Result))
3282 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3283 else
3284 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3285 NewTL.setSigilLoc(TL.getSigilLoc());
3286
3287 return Result;
3288}
3289
Mike Stump11289f42009-09-09 15:08:12 +00003290template<typename Derived>
3291QualType
John McCall550e0c22009-10-21 00:40:46 +00003292TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003293 LValueReferenceTypeLoc TL) {
3294 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003295}
3296
Mike Stump11289f42009-09-09 15:08:12 +00003297template<typename Derived>
3298QualType
John McCall550e0c22009-10-21 00:40:46 +00003299TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003300 RValueReferenceTypeLoc TL) {
3301 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003302}
Mike Stump11289f42009-09-09 15:08:12 +00003303
Douglas Gregord6ff3322009-08-04 16:50:30 +00003304template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003305QualType
John McCall550e0c22009-10-21 00:40:46 +00003306TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003307 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003308 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003309
3310 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003311 if (PointeeType.isNull())
3312 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003313
John McCall550e0c22009-10-21 00:40:46 +00003314 // TODO: preserve source information for this.
3315 QualType ClassType
3316 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003317 if (ClassType.isNull())
3318 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003319
John McCall550e0c22009-10-21 00:40:46 +00003320 QualType Result = TL.getType();
3321 if (getDerived().AlwaysRebuild() ||
3322 PointeeType != T->getPointeeType() ||
3323 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003324 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3325 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003326 if (Result.isNull())
3327 return QualType();
3328 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003329
John McCall550e0c22009-10-21 00:40:46 +00003330 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3331 NewTL.setSigilLoc(TL.getSigilLoc());
3332
3333 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003334}
3335
Mike Stump11289f42009-09-09 15:08:12 +00003336template<typename Derived>
3337QualType
John McCall550e0c22009-10-21 00:40:46 +00003338TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003339 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003340 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003341 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003342 if (ElementType.isNull())
3343 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003344
John McCall550e0c22009-10-21 00:40:46 +00003345 QualType Result = TL.getType();
3346 if (getDerived().AlwaysRebuild() ||
3347 ElementType != T->getElementType()) {
3348 Result = getDerived().RebuildConstantArrayType(ElementType,
3349 T->getSizeModifier(),
3350 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003351 T->getIndexTypeCVRQualifiers(),
3352 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003353 if (Result.isNull())
3354 return QualType();
3355 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003356
John McCall550e0c22009-10-21 00:40:46 +00003357 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3358 NewTL.setLBracketLoc(TL.getLBracketLoc());
3359 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003360
John McCall550e0c22009-10-21 00:40:46 +00003361 Expr *Size = TL.getSizeExpr();
3362 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003363 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003364 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3365 }
3366 NewTL.setSizeExpr(Size);
3367
3368 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003369}
Mike Stump11289f42009-09-09 15:08:12 +00003370
Douglas Gregord6ff3322009-08-04 16:50:30 +00003371template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003372QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003373 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003374 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003375 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003376 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003377 if (ElementType.isNull())
3378 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003379
John McCall550e0c22009-10-21 00:40:46 +00003380 QualType Result = TL.getType();
3381 if (getDerived().AlwaysRebuild() ||
3382 ElementType != T->getElementType()) {
3383 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003384 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003385 T->getIndexTypeCVRQualifiers(),
3386 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003387 if (Result.isNull())
3388 return QualType();
3389 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003390
John McCall550e0c22009-10-21 00:40:46 +00003391 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3392 NewTL.setLBracketLoc(TL.getLBracketLoc());
3393 NewTL.setRBracketLoc(TL.getRBracketLoc());
3394 NewTL.setSizeExpr(0);
3395
3396 return Result;
3397}
3398
3399template<typename Derived>
3400QualType
3401TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003402 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003403 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003404 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3405 if (ElementType.isNull())
3406 return QualType();
3407
3408 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003409 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003410
John McCalldadc5752010-08-24 06:29:42 +00003411 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003412 = getDerived().TransformExpr(T->getSizeExpr());
3413 if (SizeResult.isInvalid())
3414 return QualType();
3415
John McCallb268a282010-08-23 23:25:46 +00003416 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003417
3418 QualType Result = TL.getType();
3419 if (getDerived().AlwaysRebuild() ||
3420 ElementType != T->getElementType() ||
3421 Size != T->getSizeExpr()) {
3422 Result = getDerived().RebuildVariableArrayType(ElementType,
3423 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003424 Size,
John McCall550e0c22009-10-21 00:40:46 +00003425 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003426 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003427 if (Result.isNull())
3428 return QualType();
3429 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003430
John McCall550e0c22009-10-21 00:40:46 +00003431 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3432 NewTL.setLBracketLoc(TL.getLBracketLoc());
3433 NewTL.setRBracketLoc(TL.getRBracketLoc());
3434 NewTL.setSizeExpr(Size);
3435
3436 return Result;
3437}
3438
3439template<typename Derived>
3440QualType
3441TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003442 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003443 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003444 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3445 if (ElementType.isNull())
3446 return QualType();
3447
3448 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003449 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003450
John McCall33ddac02011-01-19 10:06:00 +00003451 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3452 Expr *origSize = TL.getSizeExpr();
3453 if (!origSize) origSize = T->getSizeExpr();
3454
3455 ExprResult sizeResult
3456 = getDerived().TransformExpr(origSize);
3457 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003458 return QualType();
3459
John McCall33ddac02011-01-19 10:06:00 +00003460 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003461
3462 QualType Result = TL.getType();
3463 if (getDerived().AlwaysRebuild() ||
3464 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003465 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003466 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3467 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003468 size,
John McCall550e0c22009-10-21 00:40:46 +00003469 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003470 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003471 if (Result.isNull())
3472 return QualType();
3473 }
John McCall550e0c22009-10-21 00:40:46 +00003474
3475 // We might have any sort of array type now, but fortunately they
3476 // all have the same location layout.
3477 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3478 NewTL.setLBracketLoc(TL.getLBracketLoc());
3479 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003480 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003481
3482 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003483}
Mike Stump11289f42009-09-09 15:08:12 +00003484
3485template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003486QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003487 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003488 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003489 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003490
3491 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003492 QualType ElementType = getDerived().TransformType(T->getElementType());
3493 if (ElementType.isNull())
3494 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003495
Douglas Gregore922c772009-08-04 22:27:00 +00003496 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003497 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003498
John McCalldadc5752010-08-24 06:29:42 +00003499 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003500 if (Size.isInvalid())
3501 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003502
John McCall550e0c22009-10-21 00:40:46 +00003503 QualType Result = TL.getType();
3504 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003505 ElementType != T->getElementType() ||
3506 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003507 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003508 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003509 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003510 if (Result.isNull())
3511 return QualType();
3512 }
John McCall550e0c22009-10-21 00:40:46 +00003513
3514 // Result might be dependent or not.
3515 if (isa<DependentSizedExtVectorType>(Result)) {
3516 DependentSizedExtVectorTypeLoc NewTL
3517 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3518 NewTL.setNameLoc(TL.getNameLoc());
3519 } else {
3520 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3521 NewTL.setNameLoc(TL.getNameLoc());
3522 }
3523
3524 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003525}
Mike Stump11289f42009-09-09 15:08:12 +00003526
3527template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003528QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003529 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003530 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003531 QualType ElementType = getDerived().TransformType(T->getElementType());
3532 if (ElementType.isNull())
3533 return QualType();
3534
John McCall550e0c22009-10-21 00:40:46 +00003535 QualType Result = TL.getType();
3536 if (getDerived().AlwaysRebuild() ||
3537 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003538 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003539 T->getVectorKind());
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 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3545 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003546
John McCall550e0c22009-10-21 00:40:46 +00003547 return Result;
3548}
3549
3550template<typename Derived>
3551QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003552 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003553 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003554 QualType ElementType = getDerived().TransformType(T->getElementType());
3555 if (ElementType.isNull())
3556 return QualType();
3557
3558 QualType Result = TL.getType();
3559 if (getDerived().AlwaysRebuild() ||
3560 ElementType != T->getElementType()) {
3561 Result = getDerived().RebuildExtVectorType(ElementType,
3562 T->getNumElements(),
3563 /*FIXME*/ SourceLocation());
3564 if (Result.isNull())
3565 return QualType();
3566 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003567
John McCall550e0c22009-10-21 00:40:46 +00003568 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3569 NewTL.setNameLoc(TL.getNameLoc());
3570
3571 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003572}
Mike Stump11289f42009-09-09 15:08:12 +00003573
3574template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003575ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003576TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3577 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003578 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003579 TypeSourceInfo *NewDI = 0;
3580
3581 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3582 // If we're substituting into a pack expansion type and we know the
3583 TypeLoc OldTL = OldDI->getTypeLoc();
3584 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3585
3586 TypeLocBuilder TLB;
3587 TypeLoc NewTL = OldDI->getTypeLoc();
3588 TLB.reserve(NewTL.getFullDataSize());
3589
3590 QualType Result = getDerived().TransformType(TLB,
3591 OldExpansionTL.getPatternLoc());
3592 if (Result.isNull())
3593 return 0;
3594
3595 Result = RebuildPackExpansionType(Result,
3596 OldExpansionTL.getPatternLoc().getSourceRange(),
3597 OldExpansionTL.getEllipsisLoc(),
3598 NumExpansions);
3599 if (Result.isNull())
3600 return 0;
3601
3602 PackExpansionTypeLoc NewExpansionTL
3603 = TLB.push<PackExpansionTypeLoc>(Result);
3604 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3605 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3606 } else
3607 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003608 if (!NewDI)
3609 return 0;
3610
3611 if (NewDI == OldDI)
3612 return OldParm;
3613 else
3614 return ParmVarDecl::Create(SemaRef.Context,
3615 OldParm->getDeclContext(),
3616 OldParm->getLocation(),
3617 OldParm->getIdentifier(),
3618 NewDI->getType(),
3619 NewDI,
3620 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003621 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003622 /* DefArg */ NULL);
3623}
3624
3625template<typename Derived>
3626bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003627 TransformFunctionTypeParams(SourceLocation Loc,
3628 ParmVarDecl **Params, unsigned NumParams,
3629 const QualType *ParamTypes,
3630 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3631 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3632 for (unsigned i = 0; i != NumParams; ++i) {
3633 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003634 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003635 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003636 if (OldParm->isParameterPack()) {
3637 // We have a function parameter pack that may need to be expanded.
3638 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003639
Douglas Gregor5499af42011-01-05 23:12:31 +00003640 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003641 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3642 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3643 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3644 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003645 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3646
Douglas Gregor5499af42011-01-05 23:12:31 +00003647 // Determine whether we should expand the parameter packs.
3648 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003649 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003650 llvm::Optional<unsigned> OrigNumExpansions
3651 = ExpansionTL.getTypePtr()->getNumExpansions();
3652 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003653 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3654 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003655 Unexpanded.data(),
3656 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003657 ShouldExpand,
3658 RetainExpansion,
3659 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003660 return true;
3661 }
3662
3663 if (ShouldExpand) {
3664 // Expand the function parameter pack into multiple, separate
3665 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003666 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003667 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003668 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3669 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003670 = getDerived().TransformFunctionTypeParam(OldParm,
3671 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003672 if (!NewParm)
3673 return true;
3674
Douglas Gregordd472162011-01-07 00:20:55 +00003675 OutParamTypes.push_back(NewParm->getType());
3676 if (PVars)
3677 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003678 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003679
3680 // If we're supposed to retain a pack expansion, do so by temporarily
3681 // forgetting the partially-substituted parameter pack.
3682 if (RetainExpansion) {
3683 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3684 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003685 = getDerived().TransformFunctionTypeParam(OldParm,
3686 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003687 if (!NewParm)
3688 return true;
3689
3690 OutParamTypes.push_back(NewParm->getType());
3691 if (PVars)
3692 PVars->push_back(NewParm);
3693 }
3694
Douglas Gregor5499af42011-01-05 23:12:31 +00003695 // We're done with the pack expansion.
3696 continue;
3697 }
3698
3699 // We'll substitute the parameter now without expanding the pack
3700 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003701 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3702 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3703 NumExpansions);
3704 } else {
3705 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3706 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003707 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003708
John McCall58f10c32010-03-11 09:03:00 +00003709 if (!NewParm)
3710 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003711
Douglas Gregordd472162011-01-07 00:20:55 +00003712 OutParamTypes.push_back(NewParm->getType());
3713 if (PVars)
3714 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003715 continue;
3716 }
John McCall58f10c32010-03-11 09:03:00 +00003717
3718 // Deal with the possibility that we don't have a parameter
3719 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003720 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003721 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003722 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003723 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003724 if (const PackExpansionType *Expansion
3725 = dyn_cast<PackExpansionType>(OldType)) {
3726 // We have a function parameter pack that may need to be expanded.
3727 QualType Pattern = Expansion->getPattern();
3728 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3729 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3730
3731 // Determine whether we should expand the parameter packs.
3732 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003733 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003734 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003735 Unexpanded.data(),
3736 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003737 ShouldExpand,
3738 RetainExpansion,
3739 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003740 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003741 }
3742
3743 if (ShouldExpand) {
3744 // Expand the function parameter pack into multiple, separate
3745 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003746 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003747 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3748 QualType NewType = getDerived().TransformType(Pattern);
3749 if (NewType.isNull())
3750 return true;
John McCall58f10c32010-03-11 09:03:00 +00003751
Douglas Gregordd472162011-01-07 00:20:55 +00003752 OutParamTypes.push_back(NewType);
3753 if (PVars)
3754 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003755 }
3756
3757 // We're done with the pack expansion.
3758 continue;
3759 }
3760
Douglas Gregor48d24112011-01-10 20:53:55 +00003761 // If we're supposed to retain a pack expansion, do so by temporarily
3762 // forgetting the partially-substituted parameter pack.
3763 if (RetainExpansion) {
3764 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3765 QualType NewType = getDerived().TransformType(Pattern);
3766 if (NewType.isNull())
3767 return true;
3768
3769 OutParamTypes.push_back(NewType);
3770 if (PVars)
3771 PVars->push_back(0);
3772 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003773
Douglas Gregor5499af42011-01-05 23:12:31 +00003774 // We'll substitute the parameter now without expanding the pack
3775 // expansion.
3776 OldType = Expansion->getPattern();
3777 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003778 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3779 NewType = getDerived().TransformType(OldType);
3780 } else {
3781 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003782 }
3783
Douglas Gregor5499af42011-01-05 23:12:31 +00003784 if (NewType.isNull())
3785 return true;
3786
3787 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003788 NewType = getSema().Context.getPackExpansionType(NewType,
3789 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003790
Douglas Gregordd472162011-01-07 00:20:55 +00003791 OutParamTypes.push_back(NewType);
3792 if (PVars)
3793 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003794 }
3795
3796 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003797 }
John McCall58f10c32010-03-11 09:03:00 +00003798
3799template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003800QualType
John McCall550e0c22009-10-21 00:40:46 +00003801TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003802 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003803 // Transform the parameters and return type.
3804 //
3805 // We instantiate in source order, with the return type first followed by
3806 // the parameters, because users tend to expect this (even if they shouldn't
3807 // rely on it!).
3808 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003809 // When the function has a trailing return type, we instantiate the
3810 // parameters before the return type, since the return type can then refer
3811 // to the parameters themselves (via decltype, sizeof, etc.).
3812 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003813 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003814 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003815 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003816
Douglas Gregor7fb25412010-10-01 18:44:50 +00003817 QualType ResultType;
3818
3819 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003820 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3821 TL.getParmArray(),
3822 TL.getNumArgs(),
3823 TL.getTypePtr()->arg_type_begin(),
3824 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003825 return QualType();
3826
3827 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3828 if (ResultType.isNull())
3829 return QualType();
3830 }
3831 else {
3832 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3833 if (ResultType.isNull())
3834 return QualType();
3835
Douglas Gregordd472162011-01-07 00:20:55 +00003836 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3837 TL.getParmArray(),
3838 TL.getNumArgs(),
3839 TL.getTypePtr()->arg_type_begin(),
3840 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003841 return QualType();
3842 }
3843
John McCall550e0c22009-10-21 00:40:46 +00003844 QualType Result = TL.getType();
3845 if (getDerived().AlwaysRebuild() ||
3846 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003847 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003848 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3849 Result = getDerived().RebuildFunctionProtoType(ResultType,
3850 ParamTypes.data(),
3851 ParamTypes.size(),
3852 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003853 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003854 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003855 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003856 if (Result.isNull())
3857 return QualType();
3858 }
Mike Stump11289f42009-09-09 15:08:12 +00003859
John McCall550e0c22009-10-21 00:40:46 +00003860 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3861 NewTL.setLParenLoc(TL.getLParenLoc());
3862 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003863 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003864 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3865 NewTL.setArg(i, ParamDecls[i]);
3866
3867 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003868}
Mike Stump11289f42009-09-09 15:08:12 +00003869
Douglas Gregord6ff3322009-08-04 16:50:30 +00003870template<typename Derived>
3871QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003872 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003873 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003874 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003875 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3876 if (ResultType.isNull())
3877 return QualType();
3878
3879 QualType Result = TL.getType();
3880 if (getDerived().AlwaysRebuild() ||
3881 ResultType != T->getResultType())
3882 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3883
3884 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3885 NewTL.setLParenLoc(TL.getLParenLoc());
3886 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003887 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003888
3889 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003890}
Mike Stump11289f42009-09-09 15:08:12 +00003891
John McCallb96ec562009-12-04 22:46:56 +00003892template<typename Derived> QualType
3893TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003894 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003895 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003896 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003897 if (!D)
3898 return QualType();
3899
3900 QualType Result = TL.getType();
3901 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3902 Result = getDerived().RebuildUnresolvedUsingType(D);
3903 if (Result.isNull())
3904 return QualType();
3905 }
3906
3907 // We might get an arbitrary type spec type back. We should at
3908 // least always get a type spec type, though.
3909 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3910 NewTL.setNameLoc(TL.getNameLoc());
3911
3912 return Result;
3913}
3914
Douglas Gregord6ff3322009-08-04 16:50:30 +00003915template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003916QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003917 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003918 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003919 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003920 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3921 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003922 if (!Typedef)
3923 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003924
John McCall550e0c22009-10-21 00:40:46 +00003925 QualType Result = TL.getType();
3926 if (getDerived().AlwaysRebuild() ||
3927 Typedef != T->getDecl()) {
3928 Result = getDerived().RebuildTypedefType(Typedef);
3929 if (Result.isNull())
3930 return QualType();
3931 }
Mike Stump11289f42009-09-09 15:08:12 +00003932
John McCall550e0c22009-10-21 00:40:46 +00003933 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3934 NewTL.setNameLoc(TL.getNameLoc());
3935
3936 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003937}
Mike Stump11289f42009-09-09 15:08:12 +00003938
Douglas Gregord6ff3322009-08-04 16:50:30 +00003939template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003940QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003941 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003942 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003943 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003944
John McCalldadc5752010-08-24 06:29:42 +00003945 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003946 if (E.isInvalid())
3947 return QualType();
3948
John McCall550e0c22009-10-21 00:40:46 +00003949 QualType Result = TL.getType();
3950 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003951 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003952 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003953 if (Result.isNull())
3954 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003955 }
John McCall550e0c22009-10-21 00:40:46 +00003956 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003957
John McCall550e0c22009-10-21 00:40:46 +00003958 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003959 NewTL.setTypeofLoc(TL.getTypeofLoc());
3960 NewTL.setLParenLoc(TL.getLParenLoc());
3961 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003962
3963 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003964}
Mike Stump11289f42009-09-09 15:08:12 +00003965
3966template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003967QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003968 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003969 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3970 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3971 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003972 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003973
John McCall550e0c22009-10-21 00:40:46 +00003974 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003975 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3976 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003977 if (Result.isNull())
3978 return QualType();
3979 }
Mike Stump11289f42009-09-09 15:08:12 +00003980
John McCall550e0c22009-10-21 00:40:46 +00003981 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003982 NewTL.setTypeofLoc(TL.getTypeofLoc());
3983 NewTL.setLParenLoc(TL.getLParenLoc());
3984 NewTL.setRParenLoc(TL.getRParenLoc());
3985 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003986
3987 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003988}
Mike Stump11289f42009-09-09 15:08:12 +00003989
3990template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003991QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003992 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003993 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003994
Douglas Gregore922c772009-08-04 22:27:00 +00003995 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003996 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003997
John McCalldadc5752010-08-24 06:29:42 +00003998 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003999 if (E.isInvalid())
4000 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004001
John McCall550e0c22009-10-21 00:40:46 +00004002 QualType Result = TL.getType();
4003 if (getDerived().AlwaysRebuild() ||
4004 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004005 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004006 if (Result.isNull())
4007 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004008 }
John McCall550e0c22009-10-21 00:40:46 +00004009 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004010
John McCall550e0c22009-10-21 00:40:46 +00004011 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4012 NewTL.setNameLoc(TL.getNameLoc());
4013
4014 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004015}
4016
4017template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004018QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4019 AutoTypeLoc TL) {
4020 const AutoType *T = TL.getTypePtr();
4021 QualType OldDeduced = T->getDeducedType();
4022 QualType NewDeduced;
4023 if (!OldDeduced.isNull()) {
4024 NewDeduced = getDerived().TransformType(OldDeduced);
4025 if (NewDeduced.isNull())
4026 return QualType();
4027 }
4028
4029 QualType Result = TL.getType();
4030 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4031 Result = getDerived().RebuildAutoType(NewDeduced);
4032 if (Result.isNull())
4033 return QualType();
4034 }
4035
4036 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4037 NewTL.setNameLoc(TL.getNameLoc());
4038
4039 return Result;
4040}
4041
4042template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004043QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004044 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004045 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004046 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004047 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4048 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004049 if (!Record)
4050 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004051
John McCall550e0c22009-10-21 00:40:46 +00004052 QualType Result = TL.getType();
4053 if (getDerived().AlwaysRebuild() ||
4054 Record != T->getDecl()) {
4055 Result = getDerived().RebuildRecordType(Record);
4056 if (Result.isNull())
4057 return QualType();
4058 }
Mike Stump11289f42009-09-09 15:08:12 +00004059
John McCall550e0c22009-10-21 00:40:46 +00004060 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4061 NewTL.setNameLoc(TL.getNameLoc());
4062
4063 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004064}
Mike Stump11289f42009-09-09 15:08:12 +00004065
4066template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004067QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004068 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004069 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004070 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004071 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4072 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004073 if (!Enum)
4074 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004075
John McCall550e0c22009-10-21 00:40:46 +00004076 QualType Result = TL.getType();
4077 if (getDerived().AlwaysRebuild() ||
4078 Enum != T->getDecl()) {
4079 Result = getDerived().RebuildEnumType(Enum);
4080 if (Result.isNull())
4081 return QualType();
4082 }
Mike Stump11289f42009-09-09 15:08:12 +00004083
John McCall550e0c22009-10-21 00:40:46 +00004084 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4085 NewTL.setNameLoc(TL.getNameLoc());
4086
4087 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004088}
John McCallfcc33b02009-09-05 00:15:47 +00004089
John McCalle78aac42010-03-10 03:28:59 +00004090template<typename Derived>
4091QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4092 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004093 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004094 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4095 TL.getTypePtr()->getDecl());
4096 if (!D) return QualType();
4097
4098 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4099 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4100 return T;
4101}
4102
Douglas Gregord6ff3322009-08-04 16:50:30 +00004103template<typename Derived>
4104QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004105 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004106 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004107 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004108}
4109
Mike Stump11289f42009-09-09 15:08:12 +00004110template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004111QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004112 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004113 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004114 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004115}
4116
4117template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004118QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4119 TypeLocBuilder &TLB,
4120 SubstTemplateTypeParmPackTypeLoc TL) {
4121 return TransformTypeSpecType(TLB, TL);
4122}
4123
4124template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004125QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004126 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004127 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004128 const TemplateSpecializationType *T = TL.getTypePtr();
4129
Douglas Gregordf846d12011-03-02 18:46:51 +00004130 // The nested-name-specifier never matters in a TemplateSpecializationType,
4131 // because we can't have a dependent nested-name-specifier anyway.
4132 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004133 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004134 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4135 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004136 if (Template.isNull())
4137 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004138
John McCall31f82722010-11-12 08:19:04 +00004139 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4140}
4141
Douglas Gregorfe921a72010-12-20 23:36:19 +00004142namespace {
4143 /// \brief Simple iterator that traverses the template arguments in a
4144 /// container that provides a \c getArgLoc() member function.
4145 ///
4146 /// This iterator is intended to be used with the iterator form of
4147 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4148 template<typename ArgLocContainer>
4149 class TemplateArgumentLocContainerIterator {
4150 ArgLocContainer *Container;
4151 unsigned Index;
4152
4153 public:
4154 typedef TemplateArgumentLoc value_type;
4155 typedef TemplateArgumentLoc reference;
4156 typedef int difference_type;
4157 typedef std::input_iterator_tag iterator_category;
4158
4159 class pointer {
4160 TemplateArgumentLoc Arg;
4161
4162 public:
4163 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4164
4165 const TemplateArgumentLoc *operator->() const {
4166 return &Arg;
4167 }
4168 };
4169
4170
4171 TemplateArgumentLocContainerIterator() {}
4172
4173 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4174 unsigned Index)
4175 : Container(&Container), Index(Index) { }
4176
4177 TemplateArgumentLocContainerIterator &operator++() {
4178 ++Index;
4179 return *this;
4180 }
4181
4182 TemplateArgumentLocContainerIterator operator++(int) {
4183 TemplateArgumentLocContainerIterator Old(*this);
4184 ++(*this);
4185 return Old;
4186 }
4187
4188 TemplateArgumentLoc operator*() const {
4189 return Container->getArgLoc(Index);
4190 }
4191
4192 pointer operator->() const {
4193 return pointer(Container->getArgLoc(Index));
4194 }
4195
4196 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004197 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004198 return X.Container == Y.Container && X.Index == Y.Index;
4199 }
4200
4201 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004202 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004203 return !(X == Y);
4204 }
4205 };
4206}
4207
4208
John McCall31f82722010-11-12 08:19:04 +00004209template <typename Derived>
4210QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4211 TypeLocBuilder &TLB,
4212 TemplateSpecializationTypeLoc TL,
4213 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004214 TemplateArgumentListInfo NewTemplateArgs;
4215 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4216 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004217 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4218 ArgIterator;
4219 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4220 ArgIterator(TL, TL.getNumArgs()),
4221 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004222 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004223
John McCall0ad16662009-10-29 08:12:44 +00004224 // FIXME: maybe don't rebuild if all the template arguments are the same.
4225
4226 QualType Result =
4227 getDerived().RebuildTemplateSpecializationType(Template,
4228 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004229 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004230
4231 if (!Result.isNull()) {
4232 TemplateSpecializationTypeLoc NewTL
4233 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4234 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4235 NewTL.setLAngleLoc(TL.getLAngleLoc());
4236 NewTL.setRAngleLoc(TL.getRAngleLoc());
4237 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4238 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004239 }
Mike Stump11289f42009-09-09 15:08:12 +00004240
John McCall0ad16662009-10-29 08:12:44 +00004241 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004242}
Mike Stump11289f42009-09-09 15:08:12 +00004243
Douglas Gregor5a064722011-02-28 17:23:35 +00004244template <typename Derived>
4245QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4246 TypeLocBuilder &TLB,
4247 DependentTemplateSpecializationTypeLoc TL,
4248 TemplateName Template) {
4249 TemplateArgumentListInfo NewTemplateArgs;
4250 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4251 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4252 typedef TemplateArgumentLocContainerIterator<
4253 DependentTemplateSpecializationTypeLoc> ArgIterator;
4254 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4255 ArgIterator(TL, TL.getNumArgs()),
4256 NewTemplateArgs))
4257 return QualType();
4258
4259 // FIXME: maybe don't rebuild if all the template arguments are the same.
4260
4261 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4262 QualType Result
4263 = getSema().Context.getDependentTemplateSpecializationType(
4264 TL.getTypePtr()->getKeyword(),
4265 DTN->getQualifier(),
4266 DTN->getIdentifier(),
4267 NewTemplateArgs);
4268
4269 DependentTemplateSpecializationTypeLoc NewTL
4270 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4271 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004272
Douglas Gregora7a795b2011-03-01 20:11:18 +00004273 CXXScopeSpec SS;
Douglas Gregord4c41bc2011-03-02 18:52:42 +00004274 SS.Adopt(TL.getQualifierLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004275 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004276 NewTL.setNameLoc(TL.getNameLoc());
4277 NewTL.setLAngleLoc(TL.getLAngleLoc());
4278 NewTL.setRAngleLoc(TL.getRAngleLoc());
4279 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4280 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4281 return Result;
4282 }
4283
4284 QualType Result
4285 = getDerived().RebuildTemplateSpecializationType(Template,
4286 TL.getNameLoc(),
4287 NewTemplateArgs);
4288
4289 if (!Result.isNull()) {
4290 /// FIXME: Wrap this in an elaborated-type-specifier?
4291 TemplateSpecializationTypeLoc NewTL
4292 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4293 NewTL.setTemplateNameLoc(TL.getNameLoc());
4294 NewTL.setLAngleLoc(TL.getLAngleLoc());
4295 NewTL.setRAngleLoc(TL.getRAngleLoc());
4296 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4297 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4298 }
4299
4300 return Result;
4301}
4302
Mike Stump11289f42009-09-09 15:08:12 +00004303template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004304QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004305TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004306 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004307 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004308
Douglas Gregor844cb502011-03-01 18:12:44 +00004309 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004310 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004311 if (TL.getQualifierLoc()) {
4312 QualifierLoc
4313 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4314 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004315 return QualType();
4316 }
Mike Stump11289f42009-09-09 15:08:12 +00004317
John McCall31f82722010-11-12 08:19:04 +00004318 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4319 if (NamedT.isNull())
4320 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004321
John McCall550e0c22009-10-21 00:40:46 +00004322 QualType Result = TL.getType();
4323 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004324 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004325 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004326 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004327 T->getKeyword(),
4328 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004329 if (Result.isNull())
4330 return QualType();
4331 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004332
Abramo Bagnara6150c882010-05-11 21:36:43 +00004333 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004334 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004335 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004336 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004337}
Mike Stump11289f42009-09-09 15:08:12 +00004338
4339template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004340QualType TreeTransform<Derived>::TransformAttributedType(
4341 TypeLocBuilder &TLB,
4342 AttributedTypeLoc TL) {
4343 const AttributedType *oldType = TL.getTypePtr();
4344 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4345 if (modifiedType.isNull())
4346 return QualType();
4347
4348 QualType result = TL.getType();
4349
4350 // FIXME: dependent operand expressions?
4351 if (getDerived().AlwaysRebuild() ||
4352 modifiedType != oldType->getModifiedType()) {
4353 // TODO: this is really lame; we should really be rebuilding the
4354 // equivalent type from first principles.
4355 QualType equivalentType
4356 = getDerived().TransformType(oldType->getEquivalentType());
4357 if (equivalentType.isNull())
4358 return QualType();
4359 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4360 modifiedType,
4361 equivalentType);
4362 }
4363
4364 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4365 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4366 if (TL.hasAttrOperand())
4367 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4368 if (TL.hasAttrExprOperand())
4369 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4370 else if (TL.hasAttrEnumOperand())
4371 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4372
4373 return result;
4374}
4375
4376template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004377QualType
4378TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4379 ParenTypeLoc TL) {
4380 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4381 if (Inner.isNull())
4382 return QualType();
4383
4384 QualType Result = TL.getType();
4385 if (getDerived().AlwaysRebuild() ||
4386 Inner != TL.getInnerLoc().getType()) {
4387 Result = getDerived().RebuildParenType(Inner);
4388 if (Result.isNull())
4389 return QualType();
4390 }
4391
4392 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4393 NewTL.setLParenLoc(TL.getLParenLoc());
4394 NewTL.setRParenLoc(TL.getRParenLoc());
4395 return Result;
4396}
4397
4398template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004399QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004400 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004401 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004402
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004403 NestedNameSpecifierLoc QualifierLoc
4404 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4405 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004406 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004407
John McCallc392f372010-06-11 00:33:02 +00004408 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004409 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004410 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004411 QualifierLoc,
4412 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004413 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004414 if (Result.isNull())
4415 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004416
Abramo Bagnarad7548482010-05-19 21:37:53 +00004417 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4418 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004419 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4420
Abramo Bagnarad7548482010-05-19 21:37:53 +00004421 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4422 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004423 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004424 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004425 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4426 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004427 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004428 NewTL.setNameLoc(TL.getNameLoc());
4429 }
John McCall550e0c22009-10-21 00:40:46 +00004430 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004431}
Mike Stump11289f42009-09-09 15:08:12 +00004432
Douglas Gregord6ff3322009-08-04 16:50:30 +00004433template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004434QualType TreeTransform<Derived>::
4435 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004436 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004437 NestedNameSpecifierLoc QualifierLoc;
4438 if (TL.getQualifierLoc()) {
4439 QualifierLoc
4440 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4441 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004442 return QualType();
4443 }
4444
John McCall31f82722010-11-12 08:19:04 +00004445 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004446 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004447}
4448
4449template<typename Derived>
4450QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004451TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4452 DependentTemplateSpecializationTypeLoc TL,
4453 NestedNameSpecifierLoc QualifierLoc) {
4454 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4455
4456 TemplateArgumentListInfo NewTemplateArgs;
4457 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4458 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4459
4460 typedef TemplateArgumentLocContainerIterator<
4461 DependentTemplateSpecializationTypeLoc> ArgIterator;
4462 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4463 ArgIterator(TL, TL.getNumArgs()),
4464 NewTemplateArgs))
4465 return QualType();
4466
4467 QualType Result
4468 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4469 QualifierLoc,
4470 T->getIdentifier(),
4471 TL.getNameLoc(),
4472 NewTemplateArgs);
4473 if (Result.isNull())
4474 return QualType();
4475
4476 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4477 QualType NamedT = ElabT->getNamedType();
4478
4479 // Copy information relevant to the template specialization.
4480 TemplateSpecializationTypeLoc NamedTL
4481 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4482 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4483 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4484 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4485 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4486
4487 // Copy information relevant to the elaborated type.
4488 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4489 NewTL.setKeywordLoc(TL.getKeywordLoc());
4490 NewTL.setQualifierLoc(QualifierLoc);
4491 } else {
4492 TypeLoc NewTL(Result, TL.getOpaqueData());
4493 TLB.pushFullCopy(NewTL);
4494 }
4495 return Result;
4496}
4497
4498template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004499QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4500 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004501 QualType Pattern
4502 = getDerived().TransformType(TLB, TL.getPatternLoc());
4503 if (Pattern.isNull())
4504 return QualType();
4505
4506 QualType Result = TL.getType();
4507 if (getDerived().AlwaysRebuild() ||
4508 Pattern != TL.getPatternLoc().getType()) {
4509 Result = getDerived().RebuildPackExpansionType(Pattern,
4510 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004511 TL.getEllipsisLoc(),
4512 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004513 if (Result.isNull())
4514 return QualType();
4515 }
4516
4517 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4518 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4519 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004520}
4521
4522template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004523QualType
4524TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004525 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004526 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004527 TLB.pushFullCopy(TL);
4528 return TL.getType();
4529}
4530
4531template<typename Derived>
4532QualType
4533TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004534 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004535 // ObjCObjectType is never dependent.
4536 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004537 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004538}
Mike Stump11289f42009-09-09 15:08:12 +00004539
4540template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004541QualType
4542TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004543 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004544 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004545 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004546 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004547}
4548
Douglas Gregord6ff3322009-08-04 16:50:30 +00004549//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004550// Statement transformation
4551//===----------------------------------------------------------------------===//
4552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004553StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004554TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004555 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004556}
4557
4558template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004559StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004560TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4561 return getDerived().TransformCompoundStmt(S, false);
4562}
4563
4564template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004565StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004566TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004567 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004568 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004569 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004570 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004571 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4572 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004573 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004574 if (Result.isInvalid()) {
4575 // Immediately fail if this was a DeclStmt, since it's very
4576 // likely that this will cause problems for future statements.
4577 if (isa<DeclStmt>(*B))
4578 return StmtError();
4579
4580 // Otherwise, just keep processing substatements and fail later.
4581 SubStmtInvalid = true;
4582 continue;
4583 }
Mike Stump11289f42009-09-09 15:08:12 +00004584
Douglas Gregorebe10102009-08-20 07:17:43 +00004585 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4586 Statements.push_back(Result.takeAs<Stmt>());
4587 }
Mike Stump11289f42009-09-09 15:08:12 +00004588
John McCall1ababa62010-08-27 19:56:05 +00004589 if (SubStmtInvalid)
4590 return StmtError();
4591
Douglas Gregorebe10102009-08-20 07:17:43 +00004592 if (!getDerived().AlwaysRebuild() &&
4593 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004594 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004595
4596 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4597 move_arg(Statements),
4598 S->getRBracLoc(),
4599 IsStmtExpr);
4600}
Mike Stump11289f42009-09-09 15:08:12 +00004601
Douglas Gregorebe10102009-08-20 07:17:43 +00004602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004603StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004604TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004605 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004606 {
4607 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004608 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004609
Eli Friedman06577382009-11-19 03:14:00 +00004610 // Transform the left-hand case value.
4611 LHS = getDerived().TransformExpr(S->getLHS());
4612 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004613 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004614
Eli Friedman06577382009-11-19 03:14:00 +00004615 // Transform the right-hand case value (for the GNU case-range extension).
4616 RHS = getDerived().TransformExpr(S->getRHS());
4617 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004618 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004619 }
Mike Stump11289f42009-09-09 15:08:12 +00004620
Douglas Gregorebe10102009-08-20 07:17:43 +00004621 // Build the case statement.
4622 // Case statements are always rebuilt so that they will attached to their
4623 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004624 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004625 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004626 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004627 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004628 S->getColonLoc());
4629 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004630 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004631
Douglas Gregorebe10102009-08-20 07:17:43 +00004632 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004633 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004634 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004635 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004636
Douglas Gregorebe10102009-08-20 07:17:43 +00004637 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004638 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004639}
4640
4641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004642StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004643TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004644 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004645 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004646 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004647 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004648
Douglas Gregorebe10102009-08-20 07:17:43 +00004649 // Default statements are always rebuilt
4650 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004651 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004652}
Mike Stump11289f42009-09-09 15:08:12 +00004653
Douglas Gregorebe10102009-08-20 07:17:43 +00004654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004655StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004656TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004657 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004658 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004659 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004660
Chris Lattnercab02a62011-02-17 20:34:02 +00004661 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4662 S->getDecl());
4663 if (!LD)
4664 return StmtError();
4665
4666
Douglas Gregorebe10102009-08-20 07:17:43 +00004667 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004668 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004669 cast<LabelDecl>(LD), SourceLocation(),
4670 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004671}
Mike Stump11289f42009-09-09 15:08:12 +00004672
Douglas Gregorebe10102009-08-20 07:17:43 +00004673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004674StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004675TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004676 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004677 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004678 VarDecl *ConditionVar = 0;
4679 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004680 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004681 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004682 getDerived().TransformDefinition(
4683 S->getConditionVariable()->getLocation(),
4684 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004685 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004686 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004687 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004688 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004689
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004690 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004691 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004692
4693 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004694 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004695 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4696 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004697 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004698 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004699
John McCallb268a282010-08-23 23:25:46 +00004700 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004701 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004702 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004703
John McCallb268a282010-08-23 23:25:46 +00004704 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4705 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004706 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004707
Douglas Gregorebe10102009-08-20 07:17:43 +00004708 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004709 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004710 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004711 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004712
Douglas Gregorebe10102009-08-20 07:17:43 +00004713 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004714 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004715 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004716 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004717
Douglas Gregorebe10102009-08-20 07:17:43 +00004718 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004719 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004720 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004721 Then.get() == S->getThen() &&
4722 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004723 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004724
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004725 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004726 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004727 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004728}
4729
4730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004731StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004732TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004733 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004734 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004735 VarDecl *ConditionVar = 0;
4736 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004737 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004738 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004739 getDerived().TransformDefinition(
4740 S->getConditionVariable()->getLocation(),
4741 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004742 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004743 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004744 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004745 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004746
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004747 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004748 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004749 }
Mike Stump11289f42009-09-09 15:08:12 +00004750
Douglas Gregorebe10102009-08-20 07:17:43 +00004751 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004752 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004753 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004754 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004755 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004756 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004757
Douglas Gregorebe10102009-08-20 07:17:43 +00004758 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004759 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004760 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004761 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004762
Douglas Gregorebe10102009-08-20 07:17:43 +00004763 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004764 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4765 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004766}
Mike Stump11289f42009-09-09 15:08:12 +00004767
Douglas Gregorebe10102009-08-20 07:17:43 +00004768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004769StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004770TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004771 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004772 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004773 VarDecl *ConditionVar = 0;
4774 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004775 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004776 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004777 getDerived().TransformDefinition(
4778 S->getConditionVariable()->getLocation(),
4779 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004780 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004781 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004782 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004783 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004784
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004785 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004786 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004787
4788 if (S->getCond()) {
4789 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004790 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4791 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004792 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004793 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004794 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004795 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004796 }
Mike Stump11289f42009-09-09 15:08:12 +00004797
John McCallb268a282010-08-23 23:25:46 +00004798 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4799 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004800 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004801
Douglas Gregorebe10102009-08-20 07:17:43 +00004802 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004803 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004804 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004805 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregorebe10102009-08-20 07:17:43 +00004807 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004808 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004809 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004810 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004811 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004812
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004813 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004814 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004815}
Mike Stump11289f42009-09-09 15:08:12 +00004816
Douglas Gregorebe10102009-08-20 07:17:43 +00004817template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004818StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004819TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004820 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004821 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004822 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004823 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004824
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004825 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004826 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004827 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004828 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004829
Douglas Gregorebe10102009-08-20 07:17:43 +00004830 if (!getDerived().AlwaysRebuild() &&
4831 Cond.get() == S->getCond() &&
4832 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004833 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004834
John McCallb268a282010-08-23 23:25:46 +00004835 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4836 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004837 S->getRParenLoc());
4838}
Mike Stump11289f42009-09-09 15:08:12 +00004839
Douglas Gregorebe10102009-08-20 07:17:43 +00004840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004841StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004842TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004843 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004844 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004845 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004846 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004847
Douglas Gregorebe10102009-08-20 07:17:43 +00004848 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004849 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004850 VarDecl *ConditionVar = 0;
4851 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004852 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004853 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004854 getDerived().TransformDefinition(
4855 S->getConditionVariable()->getLocation(),
4856 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004857 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004858 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004859 } else {
4860 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004861
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004862 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004863 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004864
4865 if (S->getCond()) {
4866 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004867 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4868 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004869 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004870 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004871
John McCallb268a282010-08-23 23:25:46 +00004872 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004873 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004874 }
Mike Stump11289f42009-09-09 15:08:12 +00004875
John McCallb268a282010-08-23 23:25:46 +00004876 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4877 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004878 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004879
Douglas Gregorebe10102009-08-20 07:17:43 +00004880 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004881 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004882 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004883 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004884
John McCallb268a282010-08-23 23:25:46 +00004885 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4886 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004887 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004888
Douglas Gregorebe10102009-08-20 07:17:43 +00004889 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004890 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004891 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004892 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004893
Douglas Gregorebe10102009-08-20 07:17:43 +00004894 if (!getDerived().AlwaysRebuild() &&
4895 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004896 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004897 Inc.get() == S->getInc() &&
4898 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004899 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004900
Douglas Gregorebe10102009-08-20 07:17:43 +00004901 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004902 Init.get(), FullCond, ConditionVar,
4903 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004904}
4905
4906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004907StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004908TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00004909 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
4910 S->getLabel());
4911 if (!LD)
4912 return StmtError();
4913
Douglas Gregorebe10102009-08-20 07:17:43 +00004914 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004915 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004916 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00004917}
4918
4919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004920StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004921TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004922 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004923 if (Target.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() &&
4927 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004928 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004929
4930 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004931 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004932}
4933
4934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004935StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004936TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004937 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004938}
Mike Stump11289f42009-09-09 15:08:12 +00004939
Douglas Gregorebe10102009-08-20 07:17:43 +00004940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004941StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004942TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004943 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004944}
Mike Stump11289f42009-09-09 15:08:12 +00004945
Douglas Gregorebe10102009-08-20 07:17:43 +00004946template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004947StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004948TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004949 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004950 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004951 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004952
Mike Stump11289f42009-09-09 15:08:12 +00004953 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004954 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004955 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004956}
Mike Stump11289f42009-09-09 15:08:12 +00004957
Douglas Gregorebe10102009-08-20 07:17:43 +00004958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004959StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004960TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004961 bool DeclChanged = false;
4962 llvm::SmallVector<Decl *, 4> Decls;
4963 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4964 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004965 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4966 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004967 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004968 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004969
Douglas Gregorebe10102009-08-20 07:17:43 +00004970 if (Transformed != *D)
4971 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004972
Douglas Gregorebe10102009-08-20 07:17:43 +00004973 Decls.push_back(Transformed);
4974 }
Mike Stump11289f42009-09-09 15:08:12 +00004975
Douglas Gregorebe10102009-08-20 07:17:43 +00004976 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004977 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004978
4979 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004980 S->getStartLoc(), S->getEndLoc());
4981}
Mike Stump11289f42009-09-09 15:08:12 +00004982
Douglas Gregorebe10102009-08-20 07:17:43 +00004983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004984StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004985TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004986
John McCall37ad5512010-08-23 06:44:23 +00004987 ASTOwningVector<Expr*> Constraints(getSema());
4988 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004989 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004990
John McCalldadc5752010-08-24 06:29:42 +00004991 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004992 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004993
4994 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004995
Anders Carlssonaaeef072010-01-24 05:50:09 +00004996 // Go through the outputs.
4997 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004998 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004999
Anders Carlssonaaeef072010-01-24 05:50:09 +00005000 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005001 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005002
Anders Carlssonaaeef072010-01-24 05:50:09 +00005003 // Transform the output expr.
5004 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005005 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005006 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005007 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005008
Anders Carlssonaaeef072010-01-24 05:50:09 +00005009 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005010
John McCallb268a282010-08-23 23:25:46 +00005011 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005012 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005013
Anders Carlssonaaeef072010-01-24 05:50:09 +00005014 // Go through the inputs.
5015 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005016 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005017
Anders Carlssonaaeef072010-01-24 05:50:09 +00005018 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005019 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005020
Anders Carlssonaaeef072010-01-24 05:50:09 +00005021 // Transform the input expr.
5022 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005023 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005024 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005025 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005026
Anders Carlssonaaeef072010-01-24 05:50:09 +00005027 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005028
John McCallb268a282010-08-23 23:25:46 +00005029 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005030 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005031
Anders Carlssonaaeef072010-01-24 05:50:09 +00005032 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005033 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005034
5035 // Go through the clobbers.
5036 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005037 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005038
5039 // No need to transform the asm string literal.
5040 AsmString = SemaRef.Owned(S->getAsmString());
5041
5042 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5043 S->isSimple(),
5044 S->isVolatile(),
5045 S->getNumOutputs(),
5046 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005047 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005048 move_arg(Constraints),
5049 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005050 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005051 move_arg(Clobbers),
5052 S->getRParenLoc(),
5053 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005054}
5055
5056
5057template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005058StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005059TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005060 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005061 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005062 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005063 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005064
Douglas Gregor96c79492010-04-23 22:50:49 +00005065 // Transform the @catch statements (if present).
5066 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005067 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005068 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005069 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005070 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005071 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005072 if (Catch.get() != S->getCatchStmt(I))
5073 AnyCatchChanged = true;
5074 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005075 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005076
Douglas Gregor306de2f2010-04-22 23:59:56 +00005077 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005078 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005079 if (S->getFinallyStmt()) {
5080 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5081 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005082 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005083 }
5084
5085 // If nothing changed, just retain this statement.
5086 if (!getDerived().AlwaysRebuild() &&
5087 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005088 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005089 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005090 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005091
Douglas Gregor306de2f2010-04-22 23:59:56 +00005092 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005093 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5094 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005095}
Mike Stump11289f42009-09-09 15:08:12 +00005096
Douglas Gregorebe10102009-08-20 07:17:43 +00005097template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005098StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005099TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005100 // Transform the @catch parameter, if there is one.
5101 VarDecl *Var = 0;
5102 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5103 TypeSourceInfo *TSInfo = 0;
5104 if (FromVar->getTypeSourceInfo()) {
5105 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5106 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005107 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005108 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005109
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005110 QualType T;
5111 if (TSInfo)
5112 T = TSInfo->getType();
5113 else {
5114 T = getDerived().TransformType(FromVar->getType());
5115 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005116 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005117 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005118
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005119 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5120 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005121 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005122 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005123
John McCalldadc5752010-08-24 06:29:42 +00005124 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005125 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005126 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005127
5128 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005129 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005130 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005131}
Mike Stump11289f42009-09-09 15:08:12 +00005132
Douglas Gregorebe10102009-08-20 07:17:43 +00005133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005134StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005135TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005136 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005137 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005138 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005139 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005140
Douglas Gregor306de2f2010-04-22 23:59:56 +00005141 // If nothing changed, just retain this statement.
5142 if (!getDerived().AlwaysRebuild() &&
5143 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005144 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005145
5146 // Build a new statement.
5147 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005148 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005149}
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregorebe10102009-08-20 07:17:43 +00005151template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005152StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005153TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005154 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005155 if (S->getThrowExpr()) {
5156 Operand = getDerived().TransformExpr(S->getThrowExpr());
5157 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005158 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005159 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005160
Douglas Gregor2900c162010-04-22 21:44:01 +00005161 if (!getDerived().AlwaysRebuild() &&
5162 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005163 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005164
John McCallb268a282010-08-23 23:25:46 +00005165 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005166}
Mike Stump11289f42009-09-09 15:08:12 +00005167
Douglas Gregorebe10102009-08-20 07:17:43 +00005168template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005169StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005170TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005171 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005172 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005173 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005174 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005175 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005176
Douglas Gregor6148de72010-04-22 22:01:21 +00005177 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005178 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005179 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005180 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005181
Douglas Gregor6148de72010-04-22 22:01:21 +00005182 // If nothing change, just retain the current statement.
5183 if (!getDerived().AlwaysRebuild() &&
5184 Object.get() == S->getSynchExpr() &&
5185 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005186 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005187
5188 // Build a new statement.
5189 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005190 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005191}
5192
5193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005194StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005195TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005196 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005197 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005198 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005199 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005200 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005201
Douglas Gregorf68a5082010-04-22 23:10:45 +00005202 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005203 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005204 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005205 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005206
Douglas Gregorf68a5082010-04-22 23:10:45 +00005207 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005208 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005209 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005210 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005211
Douglas Gregorf68a5082010-04-22 23:10:45 +00005212 // If nothing changed, just retain this statement.
5213 if (!getDerived().AlwaysRebuild() &&
5214 Element.get() == S->getElement() &&
5215 Collection.get() == S->getCollection() &&
5216 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005217 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005218
Douglas Gregorf68a5082010-04-22 23:10:45 +00005219 // Build a new statement.
5220 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5221 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005222 Element.get(),
5223 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005224 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005225 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005226}
5227
5228
5229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005230StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005231TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5232 // Transform the exception declaration, if any.
5233 VarDecl *Var = 0;
5234 if (S->getExceptionDecl()) {
5235 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005236 TypeSourceInfo *T = getDerived().TransformType(
5237 ExceptionDecl->getTypeSourceInfo());
5238 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005239 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005240
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005241 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005242 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005243 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005244 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005245 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005246 }
Mike Stump11289f42009-09-09 15:08:12 +00005247
Douglas Gregorebe10102009-08-20 07:17:43 +00005248 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005249 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005250 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005251 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005252
Douglas Gregorebe10102009-08-20 07:17:43 +00005253 if (!getDerived().AlwaysRebuild() &&
5254 !Var &&
5255 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005256 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005257
5258 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5259 Var,
John McCallb268a282010-08-23 23:25:46 +00005260 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005261}
Mike Stump11289f42009-09-09 15:08:12 +00005262
Douglas Gregorebe10102009-08-20 07:17:43 +00005263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005264StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005265TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5266 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005267 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005268 = getDerived().TransformCompoundStmt(S->getTryBlock());
5269 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005270 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005271
Douglas Gregorebe10102009-08-20 07:17:43 +00005272 // Transform the handlers.
5273 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005274 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005275 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005276 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005277 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5278 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005279 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005280
Douglas Gregorebe10102009-08-20 07:17:43 +00005281 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5282 Handlers.push_back(Handler.takeAs<Stmt>());
5283 }
Mike Stump11289f42009-09-09 15:08:12 +00005284
Douglas Gregorebe10102009-08-20 07:17:43 +00005285 if (!getDerived().AlwaysRebuild() &&
5286 TryBlock.get() == S->getTryBlock() &&
5287 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005288 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005289
John McCallb268a282010-08-23 23:25:46 +00005290 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005291 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005292}
Mike Stump11289f42009-09-09 15:08:12 +00005293
Douglas Gregorebe10102009-08-20 07:17:43 +00005294//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005295// Expression transformation
5296//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005297template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005298ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005299TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005300 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005301}
Mike Stump11289f42009-09-09 15:08:12 +00005302
5303template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005304ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005305TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005306 NestedNameSpecifierLoc QualifierLoc;
5307 if (E->getQualifierLoc()) {
5308 QualifierLoc
5309 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5310 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005311 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005312 }
John McCallce546572009-12-08 09:08:17 +00005313
5314 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005315 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5316 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005317 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005318 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005319
John McCall815039a2010-08-17 21:27:17 +00005320 DeclarationNameInfo NameInfo = E->getNameInfo();
5321 if (NameInfo.getName()) {
5322 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5323 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005324 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005325 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005326
5327 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005328 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005329 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005330 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005331 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005332
5333 // Mark it referenced in the new context regardless.
5334 // FIXME: this is a bit instantiation-specific.
5335 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5336
John McCallc3007a22010-10-26 07:05:15 +00005337 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005338 }
John McCallce546572009-12-08 09:08:17 +00005339
5340 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005341 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005342 TemplateArgs = &TransArgs;
5343 TransArgs.setLAngleLoc(E->getLAngleLoc());
5344 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005345 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5346 E->getNumTemplateArgs(),
5347 TransArgs))
5348 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005349 }
5350
Douglas Gregorea972d32011-02-28 21:54:11 +00005351 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5352 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005353}
Mike Stump11289f42009-09-09 15:08:12 +00005354
Douglas Gregora16548e2009-08-11 05:31:07 +00005355template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005356ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005357TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005358 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005359}
Mike Stump11289f42009-09-09 15:08:12 +00005360
Douglas Gregora16548e2009-08-11 05:31:07 +00005361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005362ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005363TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005364 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005365}
Mike Stump11289f42009-09-09 15:08:12 +00005366
Douglas Gregora16548e2009-08-11 05:31:07 +00005367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005369TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005370 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005371}
Mike Stump11289f42009-09-09 15:08:12 +00005372
Douglas Gregora16548e2009-08-11 05:31:07 +00005373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005374ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005375TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005376 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005377}
Mike Stump11289f42009-09-09 15:08:12 +00005378
Douglas Gregora16548e2009-08-11 05:31:07 +00005379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005380ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005381TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005382 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005383}
5384
5385template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005386ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005387TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005388 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005389 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005390 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005391
Douglas Gregora16548e2009-08-11 05:31:07 +00005392 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005393 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005394
John McCallb268a282010-08-23 23:25:46 +00005395 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 E->getRParen());
5397}
5398
Mike Stump11289f42009-09-09 15:08:12 +00005399template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005400ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005401TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005402 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005403 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005404 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005405
Douglas Gregora16548e2009-08-11 05:31:07 +00005406 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005407 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005408
Douglas Gregora16548e2009-08-11 05:31:07 +00005409 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5410 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005411 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005412}
Mike Stump11289f42009-09-09 15:08:12 +00005413
Douglas Gregora16548e2009-08-11 05:31:07 +00005414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005415ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005416TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5417 // Transform the type.
5418 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5419 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005420 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005421
Douglas Gregor882211c2010-04-28 22:16:22 +00005422 // Transform all of the components into components similar to what the
5423 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005424 // FIXME: It would be slightly more efficient in the non-dependent case to
5425 // just map FieldDecls, rather than requiring the rebuilder to look for
5426 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005427 // template code that we don't care.
5428 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005429 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005430 typedef OffsetOfExpr::OffsetOfNode Node;
5431 llvm::SmallVector<Component, 4> Components;
5432 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5433 const Node &ON = E->getComponent(I);
5434 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005435 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005436 Comp.LocStart = ON.getRange().getBegin();
5437 Comp.LocEnd = ON.getRange().getEnd();
5438 switch (ON.getKind()) {
5439 case Node::Array: {
5440 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005441 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005442 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005443 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005444
Douglas Gregor882211c2010-04-28 22:16:22 +00005445 ExprChanged = ExprChanged || Index.get() != FromIndex;
5446 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005447 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005448 break;
5449 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005450
Douglas Gregor882211c2010-04-28 22:16:22 +00005451 case Node::Field:
5452 case Node::Identifier:
5453 Comp.isBrackets = false;
5454 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005455 if (!Comp.U.IdentInfo)
5456 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005457
Douglas Gregor882211c2010-04-28 22:16:22 +00005458 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005459
Douglas Gregord1702062010-04-29 00:18:15 +00005460 case Node::Base:
5461 // Will be recomputed during the rebuild.
5462 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005463 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005464
Douglas Gregor882211c2010-04-28 22:16:22 +00005465 Components.push_back(Comp);
5466 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005467
Douglas Gregor882211c2010-04-28 22:16:22 +00005468 // If nothing changed, retain the existing expression.
5469 if (!getDerived().AlwaysRebuild() &&
5470 Type == E->getTypeSourceInfo() &&
5471 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005472 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005473
Douglas Gregor882211c2010-04-28 22:16:22 +00005474 // Build a new offsetof expression.
5475 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5476 Components.data(), Components.size(),
5477 E->getRParenLoc());
5478}
5479
5480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005481ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005482TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5483 assert(getDerived().AlreadyTransformed(E->getType()) &&
5484 "opaque value expression requires transformation");
5485 return SemaRef.Owned(E);
5486}
5487
5488template<typename Derived>
5489ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005490TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005491 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005492 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005493
John McCallbcd03502009-12-07 02:54:59 +00005494 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005495 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005496 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005497
John McCall4c98fd82009-11-04 07:28:41 +00005498 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005499 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005500
John McCall4c98fd82009-11-04 07:28:41 +00005501 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005502 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005503 E->getSourceRange());
5504 }
Mike Stump11289f42009-09-09 15:08:12 +00005505
John McCalldadc5752010-08-24 06:29:42 +00005506 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005507 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005508 // C++0x [expr.sizeof]p1:
5509 // The operand is either an expression, which is an unevaluated operand
5510 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005511 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005512
Douglas Gregora16548e2009-08-11 05:31:07 +00005513 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5514 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005515 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005516
Douglas Gregora16548e2009-08-11 05:31:07 +00005517 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005518 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005519 }
Mike Stump11289f42009-09-09 15:08:12 +00005520
John McCallb268a282010-08-23 23:25:46 +00005521 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 E->isSizeOf(),
5523 E->getSourceRange());
5524}
Mike Stump11289f42009-09-09 15:08:12 +00005525
Douglas Gregora16548e2009-08-11 05:31:07 +00005526template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005527ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005528TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005529 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005530 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005531 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005532
John McCalldadc5752010-08-24 06:29:42 +00005533 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005534 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005535 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005536
5537
Douglas Gregora16548e2009-08-11 05:31:07 +00005538 if (!getDerived().AlwaysRebuild() &&
5539 LHS.get() == E->getLHS() &&
5540 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005541 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005542
John McCallb268a282010-08-23 23:25:46 +00005543 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005544 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005545 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005546 E->getRBracketLoc());
5547}
Mike Stump11289f42009-09-09 15:08:12 +00005548
5549template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005550ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005551TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005552 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005553 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005554 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005555 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005556
5557 // Transform arguments.
5558 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005559 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005560 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5561 &ArgChanged))
5562 return ExprError();
5563
Douglas Gregora16548e2009-08-11 05:31:07 +00005564 if (!getDerived().AlwaysRebuild() &&
5565 Callee.get() == E->getCallee() &&
5566 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005567 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005568
Douglas Gregora16548e2009-08-11 05:31:07 +00005569 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005570 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005571 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005572 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005573 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005574 E->getRParenLoc());
5575}
Mike Stump11289f42009-09-09 15:08:12 +00005576
5577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005578ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005579TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005580 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005582 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005583
Douglas Gregorea972d32011-02-28 21:54:11 +00005584 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005585 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005586 QualifierLoc
5587 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5588
5589 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005590 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005591 }
Mike Stump11289f42009-09-09 15:08:12 +00005592
Eli Friedman2cfcef62009-12-04 06:40:45 +00005593 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005594 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5595 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005596 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005597 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005598
John McCall16df1e52010-03-30 21:47:33 +00005599 NamedDecl *FoundDecl = E->getFoundDecl();
5600 if (FoundDecl == E->getMemberDecl()) {
5601 FoundDecl = Member;
5602 } else {
5603 FoundDecl = cast_or_null<NamedDecl>(
5604 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5605 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005606 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005607 }
5608
Douglas Gregora16548e2009-08-11 05:31:07 +00005609 if (!getDerived().AlwaysRebuild() &&
5610 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005611 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005612 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005613 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005614 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005615
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005616 // Mark it referenced in the new context regardless.
5617 // FIXME: this is a bit instantiation-specific.
5618 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005619 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005620 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005621
John McCall6b51f282009-11-23 01:53:49 +00005622 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005623 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005624 TransArgs.setLAngleLoc(E->getLAngleLoc());
5625 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005626 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5627 E->getNumTemplateArgs(),
5628 TransArgs))
5629 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005630 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005631
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 // FIXME: Bogus source location for the operator
5633 SourceLocation FakeOperatorLoc
5634 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5635
John McCall38836f02010-01-15 08:34:02 +00005636 // FIXME: to do this check properly, we will need to preserve the
5637 // first-qualifier-in-scope here, just in case we had a dependent
5638 // base (and therefore couldn't do the check) and a
5639 // nested-name-qualifier (and therefore could do the lookup).
5640 NamedDecl *FirstQualifierInScope = 0;
5641
John McCallb268a282010-08-23 23:25:46 +00005642 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005643 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005644 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005645 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005646 Member,
John McCall16df1e52010-03-30 21:47:33 +00005647 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005648 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005649 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005650 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005651}
Mike Stump11289f42009-09-09 15:08:12 +00005652
Douglas Gregora16548e2009-08-11 05:31:07 +00005653template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005654ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005655TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005656 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005659
John McCalldadc5752010-08-24 06:29:42 +00005660 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005661 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005662 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005663
Douglas Gregora16548e2009-08-11 05:31:07 +00005664 if (!getDerived().AlwaysRebuild() &&
5665 LHS.get() == E->getLHS() &&
5666 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005667 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005668
Douglas Gregora16548e2009-08-11 05:31:07 +00005669 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005670 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005671}
5672
Mike Stump11289f42009-09-09 15:08:12 +00005673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005674ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005675TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005676 CompoundAssignOperator *E) {
5677 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005678}
Mike Stump11289f42009-09-09 15:08:12 +00005679
Douglas Gregora16548e2009-08-11 05:31:07 +00005680template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005681ExprResult TreeTransform<Derived>::
5682TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5683 // Just rebuild the common and RHS expressions and see whether we
5684 // get any changes.
5685
5686 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5687 if (commonExpr.isInvalid())
5688 return ExprError();
5689
5690 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5691 if (rhs.isInvalid())
5692 return ExprError();
5693
5694 if (!getDerived().AlwaysRebuild() &&
5695 commonExpr.get() == e->getCommon() &&
5696 rhs.get() == e->getFalseExpr())
5697 return SemaRef.Owned(e);
5698
5699 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5700 e->getQuestionLoc(),
5701 0,
5702 e->getColonLoc(),
5703 rhs.get());
5704}
5705
5706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005707ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005708TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005709 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005710 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005711 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005712
John McCalldadc5752010-08-24 06:29:42 +00005713 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005715 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005716
John McCalldadc5752010-08-24 06:29:42 +00005717 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005718 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005719 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005720
Douglas Gregora16548e2009-08-11 05:31:07 +00005721 if (!getDerived().AlwaysRebuild() &&
5722 Cond.get() == E->getCond() &&
5723 LHS.get() == E->getLHS() &&
5724 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005725 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005726
John McCallb268a282010-08-23 23:25:46 +00005727 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005728 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005729 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005730 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005731 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005732}
Mike Stump11289f42009-09-09 15:08:12 +00005733
5734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005736TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005737 // Implicit casts are eliminated during transformation, since they
5738 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005739 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005740}
Mike Stump11289f42009-09-09 15:08:12 +00005741
Douglas Gregora16548e2009-08-11 05:31:07 +00005742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005743ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005744TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005745 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5746 if (!Type)
5747 return ExprError();
5748
John McCalldadc5752010-08-24 06:29:42 +00005749 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005750 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005751 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005752 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005753
Douglas Gregora16548e2009-08-11 05:31:07 +00005754 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005755 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005756 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005757 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005758
John McCall97513962010-01-15 18:39:57 +00005759 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005760 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005761 E->getRParenLoc(),
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
John McCall47f29ea2009-12-08 09:21:05 +00005767TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005768 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5769 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5770 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005771 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005772
John McCalldadc5752010-08-24 06:29:42 +00005773 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005774 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005775 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005776
Douglas Gregora16548e2009-08-11 05:31:07 +00005777 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005778 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005779 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005780 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005781
John McCall5d7aa7f2010-01-19 22:33:45 +00005782 // Note: the expression type doesn't necessarily match the
5783 // type-as-written, but that's okay, because it should always be
5784 // derivable from the initializer.
5785
John McCalle15bbff2010-01-18 19:35:47 +00005786 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005787 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005788 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005789}
Mike Stump11289f42009-09-09 15:08:12 +00005790
Douglas Gregora16548e2009-08-11 05:31:07 +00005791template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005792ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005793TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005794 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005795 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005796 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005797
Douglas Gregora16548e2009-08-11 05:31:07 +00005798 if (!getDerived().AlwaysRebuild() &&
5799 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005800 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005801
Douglas Gregora16548e2009-08-11 05:31:07 +00005802 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005803 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005804 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005805 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005806 E->getAccessorLoc(),
5807 E->getAccessor());
5808}
Mike Stump11289f42009-09-09 15:08:12 +00005809
Douglas Gregora16548e2009-08-11 05:31:07 +00005810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005811ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005812TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005813 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005814
John McCall37ad5512010-08-23 06:44:23 +00005815 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005816 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5817 Inits, &InitChanged))
5818 return ExprError();
5819
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005821 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005822
Douglas Gregora16548e2009-08-11 05:31:07 +00005823 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005824 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005825}
Mike Stump11289f42009-09-09 15:08:12 +00005826
Douglas Gregora16548e2009-08-11 05:31:07 +00005827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005828ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005829TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005830 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005831
Douglas Gregorebe10102009-08-20 07:17:43 +00005832 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005833 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005834 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005835 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005836
Douglas Gregorebe10102009-08-20 07:17:43 +00005837 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005838 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005839 bool ExprChanged = false;
5840 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5841 DEnd = E->designators_end();
5842 D != DEnd; ++D) {
5843 if (D->isFieldDesignator()) {
5844 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5845 D->getDotLoc(),
5846 D->getFieldLoc()));
5847 continue;
5848 }
Mike Stump11289f42009-09-09 15:08:12 +00005849
Douglas Gregora16548e2009-08-11 05:31:07 +00005850 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005851 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005852 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005853 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005854
5855 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005856 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005857
Douglas Gregora16548e2009-08-11 05:31:07 +00005858 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5859 ArrayExprs.push_back(Index.release());
5860 continue;
5861 }
Mike Stump11289f42009-09-09 15:08:12 +00005862
Douglas Gregora16548e2009-08-11 05:31:07 +00005863 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005864 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005865 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5866 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005868
John McCalldadc5752010-08-24 06:29:42 +00005869 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005870 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005871 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005872
5873 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005874 End.get(),
5875 D->getLBracketLoc(),
5876 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005877
Douglas Gregora16548e2009-08-11 05:31:07 +00005878 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5879 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005880
Douglas Gregora16548e2009-08-11 05:31:07 +00005881 ArrayExprs.push_back(Start.release());
5882 ArrayExprs.push_back(End.release());
5883 }
Mike Stump11289f42009-09-09 15:08:12 +00005884
Douglas Gregora16548e2009-08-11 05:31:07 +00005885 if (!getDerived().AlwaysRebuild() &&
5886 Init.get() == E->getInit() &&
5887 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005888 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005889
Douglas Gregora16548e2009-08-11 05:31:07 +00005890 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5891 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005892 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005893}
Mike Stump11289f42009-09-09 15:08:12 +00005894
Douglas Gregora16548e2009-08-11 05:31:07 +00005895template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005896ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005897TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005898 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005899 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005900
Douglas Gregor3da3c062009-10-28 00:29:27 +00005901 // FIXME: Will we ever have proper type location here? Will we actually
5902 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005903 QualType T = getDerived().TransformType(E->getType());
5904 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005905 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005906
Douglas Gregora16548e2009-08-11 05:31:07 +00005907 if (!getDerived().AlwaysRebuild() &&
5908 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005909 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005910
Douglas Gregora16548e2009-08-11 05:31:07 +00005911 return getDerived().RebuildImplicitValueInitExpr(T);
5912}
Mike Stump11289f42009-09-09 15:08:12 +00005913
Douglas Gregora16548e2009-08-11 05:31:07 +00005914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005915ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005916TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005917 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5918 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005919 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005920
John McCalldadc5752010-08-24 06:29:42 +00005921 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005922 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005923 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005924
Douglas Gregora16548e2009-08-11 05:31:07 +00005925 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005926 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005927 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005928 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005929
John McCallb268a282010-08-23 23:25:46 +00005930 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005931 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005932}
5933
5934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005935ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005936TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005937 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005938 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005939 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5940 &ArgumentChanged))
5941 return ExprError();
5942
Douglas Gregora16548e2009-08-11 05:31:07 +00005943 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5944 move_arg(Inits),
5945 E->getRParenLoc());
5946}
Mike Stump11289f42009-09-09 15:08:12 +00005947
Douglas Gregora16548e2009-08-11 05:31:07 +00005948/// \brief Transform an address-of-label expression.
5949///
5950/// By default, the transformation of an address-of-label expression always
5951/// rebuilds the expression, so that the label identifier can be resolved to
5952/// the corresponding label statement by semantic analysis.
5953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005954ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005955TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005956 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
5957 E->getLabel());
5958 if (!LD)
5959 return ExprError();
5960
Douglas Gregora16548e2009-08-11 05:31:07 +00005961 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005962 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00005963}
Mike Stump11289f42009-09-09 15:08:12 +00005964
5965template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005966ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005967TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005968 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005969 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5970 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005971 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005972
Douglas Gregora16548e2009-08-11 05:31:07 +00005973 if (!getDerived().AlwaysRebuild() &&
5974 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005975 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005976
5977 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005978 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005979 E->getRParenLoc());
5980}
Mike Stump11289f42009-09-09 15:08:12 +00005981
Douglas Gregora16548e2009-08-11 05:31:07 +00005982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005983ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005984TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005985 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005986 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005987 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005988
John McCalldadc5752010-08-24 06:29:42 +00005989 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005990 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005991 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005992
John McCalldadc5752010-08-24 06:29:42 +00005993 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005994 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005995 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005996
Douglas Gregora16548e2009-08-11 05:31:07 +00005997 if (!getDerived().AlwaysRebuild() &&
5998 Cond.get() == E->getCond() &&
5999 LHS.get() == E->getLHS() &&
6000 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006001 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006002
Douglas Gregora16548e2009-08-11 05:31:07 +00006003 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006004 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006005 E->getRParenLoc());
6006}
Mike Stump11289f42009-09-09 15:08:12 +00006007
Douglas Gregora16548e2009-08-11 05:31:07 +00006008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006009ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006010TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006011 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006012}
6013
6014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006015ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006016TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006017 switch (E->getOperator()) {
6018 case OO_New:
6019 case OO_Delete:
6020 case OO_Array_New:
6021 case OO_Array_Delete:
6022 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006023 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006024
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006025 case OO_Call: {
6026 // This is a call to an object's operator().
6027 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6028
6029 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006030 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006031 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006032 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006033
6034 // FIXME: Poor location information
6035 SourceLocation FakeLParenLoc
6036 = SemaRef.PP.getLocForEndOfToken(
6037 static_cast<Expr *>(Object.get())->getLocEnd());
6038
6039 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006040 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006041 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6042 Args))
6043 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006044
John McCallb268a282010-08-23 23:25:46 +00006045 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006046 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006047 E->getLocEnd());
6048 }
6049
6050#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6051 case OO_##Name:
6052#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6053#include "clang/Basic/OperatorKinds.def"
6054 case OO_Subscript:
6055 // Handled below.
6056 break;
6057
6058 case OO_Conditional:
6059 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006060 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006061
6062 case OO_None:
6063 case NUM_OVERLOADED_OPERATORS:
6064 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006065 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006066 }
6067
John McCalldadc5752010-08-24 06:29:42 +00006068 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006069 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006070 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006071
John McCalldadc5752010-08-24 06:29:42 +00006072 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006073 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006074 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006075
John McCalldadc5752010-08-24 06:29:42 +00006076 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006077 if (E->getNumArgs() == 2) {
6078 Second = getDerived().TransformExpr(E->getArg(1));
6079 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006080 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006081 }
Mike Stump11289f42009-09-09 15:08:12 +00006082
Douglas Gregora16548e2009-08-11 05:31:07 +00006083 if (!getDerived().AlwaysRebuild() &&
6084 Callee.get() == E->getCallee() &&
6085 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006086 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006087 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006088
Douglas Gregora16548e2009-08-11 05:31:07 +00006089 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6090 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006091 Callee.get(),
6092 First.get(),
6093 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006094}
Mike Stump11289f42009-09-09 15:08:12 +00006095
Douglas Gregora16548e2009-08-11 05:31:07 +00006096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006097ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006098TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6099 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006100}
Mike Stump11289f42009-09-09 15:08:12 +00006101
Douglas Gregora16548e2009-08-11 05:31:07 +00006102template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006103ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006104TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6105 // Transform the callee.
6106 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6107 if (Callee.isInvalid())
6108 return ExprError();
6109
6110 // Transform exec config.
6111 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6112 if (EC.isInvalid())
6113 return ExprError();
6114
6115 // Transform arguments.
6116 bool ArgChanged = false;
6117 ASTOwningVector<Expr*> Args(SemaRef);
6118 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6119 &ArgChanged))
6120 return ExprError();
6121
6122 if (!getDerived().AlwaysRebuild() &&
6123 Callee.get() == E->getCallee() &&
6124 !ArgChanged)
6125 return SemaRef.Owned(E);
6126
6127 // FIXME: Wrong source location information for the '('.
6128 SourceLocation FakeLParenLoc
6129 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6130 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6131 move_arg(Args),
6132 E->getRParenLoc(), EC.get());
6133}
6134
6135template<typename Derived>
6136ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006137TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006138 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6139 if (!Type)
6140 return ExprError();
6141
John McCalldadc5752010-08-24 06:29:42 +00006142 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006143 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006144 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006145 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006146
Douglas Gregora16548e2009-08-11 05:31:07 +00006147 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006148 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006149 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006150 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006151
Douglas Gregora16548e2009-08-11 05:31:07 +00006152 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006153 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006154 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6155 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6156 SourceLocation FakeRParenLoc
6157 = SemaRef.PP.getLocForEndOfToken(
6158 E->getSubExpr()->getSourceRange().getEnd());
6159 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006160 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006161 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006162 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006163 FakeRAngleLoc,
6164 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006165 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006166 FakeRParenLoc);
6167}
Mike Stump11289f42009-09-09 15:08:12 +00006168
Douglas Gregora16548e2009-08-11 05:31:07 +00006169template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006170ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006171TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6172 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006173}
Mike Stump11289f42009-09-09 15:08:12 +00006174
6175template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006176ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006177TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6178 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006179}
6180
Douglas Gregora16548e2009-08-11 05:31:07 +00006181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006182ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006183TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006184 CXXReinterpretCastExpr *E) {
6185 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006186}
Mike Stump11289f42009-09-09 15:08:12 +00006187
Douglas Gregora16548e2009-08-11 05:31:07 +00006188template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006189ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006190TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6191 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006192}
Mike Stump11289f42009-09-09 15:08:12 +00006193
Douglas Gregora16548e2009-08-11 05:31:07 +00006194template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006195ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006196TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006197 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006198 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6199 if (!Type)
6200 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006201
John McCalldadc5752010-08-24 06:29:42 +00006202 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006203 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006204 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006206
Douglas Gregora16548e2009-08-11 05:31:07 +00006207 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006208 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006209 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006210 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006211
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006212 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006213 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006214 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006215 E->getRParenLoc());
6216}
Mike Stump11289f42009-09-09 15:08:12 +00006217
Douglas Gregora16548e2009-08-11 05:31:07 +00006218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006219ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006220TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006221 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006222 TypeSourceInfo *TInfo
6223 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6224 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006225 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006226
Douglas Gregora16548e2009-08-11 05:31:07 +00006227 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006228 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006229 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006230
Douglas Gregor9da64192010-04-26 22:37:10 +00006231 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6232 E->getLocStart(),
6233 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006234 E->getLocEnd());
6235 }
Mike Stump11289f42009-09-09 15:08:12 +00006236
Douglas Gregora16548e2009-08-11 05:31:07 +00006237 // We don't know whether the expression is potentially evaluated until
6238 // after we perform semantic analysis, so the expression is potentially
6239 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006240 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006241 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006242
John McCalldadc5752010-08-24 06:29:42 +00006243 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006244 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006245 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006246
Douglas Gregora16548e2009-08-11 05:31:07 +00006247 if (!getDerived().AlwaysRebuild() &&
6248 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006249 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006250
Douglas Gregor9da64192010-04-26 22:37:10 +00006251 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6252 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006253 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006254 E->getLocEnd());
6255}
6256
6257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006258ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006259TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6260 if (E->isTypeOperand()) {
6261 TypeSourceInfo *TInfo
6262 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6263 if (!TInfo)
6264 return ExprError();
6265
6266 if (!getDerived().AlwaysRebuild() &&
6267 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006268 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006269
6270 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6271 E->getLocStart(),
6272 TInfo,
6273 E->getLocEnd());
6274 }
6275
6276 // We don't know whether the expression is potentially evaluated until
6277 // after we perform semantic analysis, so the expression is potentially
6278 // potentially evaluated.
6279 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6280
6281 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6282 if (SubExpr.isInvalid())
6283 return ExprError();
6284
6285 if (!getDerived().AlwaysRebuild() &&
6286 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006287 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006288
6289 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6290 E->getLocStart(),
6291 SubExpr.get(),
6292 E->getLocEnd());
6293}
6294
6295template<typename Derived>
6296ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006297TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006298 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006299}
Mike Stump11289f42009-09-09 15:08:12 +00006300
Douglas Gregora16548e2009-08-11 05:31:07 +00006301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006302ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006303TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006304 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006305 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006306}
Mike Stump11289f42009-09-09 15:08:12 +00006307
Douglas Gregora16548e2009-08-11 05:31:07 +00006308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006309ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006310TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006311 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6312 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6313 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006314
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006315 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006316 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006317
Douglas Gregorb15af892010-01-07 23:12:05 +00006318 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006319}
Mike Stump11289f42009-09-09 15:08:12 +00006320
Douglas Gregora16548e2009-08-11 05:31:07 +00006321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006322ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006323TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006324 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006325 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006326 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006327
Douglas Gregora16548e2009-08-11 05:31:07 +00006328 if (!getDerived().AlwaysRebuild() &&
6329 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006330 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006331
John McCallb268a282010-08-23 23:25:46 +00006332 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006333}
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>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006338 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006339 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6340 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006341 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006342 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006343
Chandler Carruth794da4c2010-02-08 06:42:49 +00006344 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006345 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006346 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006347
Douglas Gregor033f6752009-12-23 23:03:06 +00006348 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006349}
Mike Stump11289f42009-09-09 15:08:12 +00006350
Douglas Gregora16548e2009-08-11 05:31:07 +00006351template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006352ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006353TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6354 CXXScalarValueInitExpr *E) {
6355 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6356 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006357 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006358
Douglas Gregora16548e2009-08-11 05:31:07 +00006359 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006360 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006361 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006362
Douglas Gregor2b88c112010-09-08 00:15:04 +00006363 return getDerived().RebuildCXXScalarValueInitExpr(T,
6364 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006365 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006366}
Mike Stump11289f42009-09-09 15:08:12 +00006367
Douglas Gregora16548e2009-08-11 05:31:07 +00006368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006369ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006370TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006371 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006372 TypeSourceInfo *AllocTypeInfo
6373 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6374 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006375 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006376
Douglas Gregora16548e2009-08-11 05:31:07 +00006377 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006378 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006379 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006380 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006381
Douglas Gregora16548e2009-08-11 05:31:07 +00006382 // Transform the placement arguments (if any).
6383 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006384 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006385 if (getDerived().TransformExprs(E->getPlacementArgs(),
6386 E->getNumPlacementArgs(), true,
6387 PlacementArgs, &ArgumentChanged))
6388 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006389
Douglas Gregorebe10102009-08-20 07:17:43 +00006390 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006391 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006392 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6393 ConstructorArgs, &ArgumentChanged))
6394 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006395
Douglas Gregord2d9da02010-02-26 00:38:10 +00006396 // Transform constructor, new operator, and delete operator.
6397 CXXConstructorDecl *Constructor = 0;
6398 if (E->getConstructor()) {
6399 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006400 getDerived().TransformDecl(E->getLocStart(),
6401 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006402 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006403 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006404 }
6405
6406 FunctionDecl *OperatorNew = 0;
6407 if (E->getOperatorNew()) {
6408 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006409 getDerived().TransformDecl(E->getLocStart(),
6410 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006411 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006412 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006413 }
6414
6415 FunctionDecl *OperatorDelete = 0;
6416 if (E->getOperatorDelete()) {
6417 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006418 getDerived().TransformDecl(E->getLocStart(),
6419 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006420 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006421 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006422 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006423
Douglas Gregora16548e2009-08-11 05:31:07 +00006424 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006425 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006426 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006427 Constructor == E->getConstructor() &&
6428 OperatorNew == E->getOperatorNew() &&
6429 OperatorDelete == E->getOperatorDelete() &&
6430 !ArgumentChanged) {
6431 // Mark any declarations we need as referenced.
6432 // FIXME: instantiation-specific.
6433 if (Constructor)
6434 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6435 if (OperatorNew)
6436 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6437 if (OperatorDelete)
6438 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006439 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006440 }
Mike Stump11289f42009-09-09 15:08:12 +00006441
Douglas Gregor0744ef62010-09-07 21:49:58 +00006442 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006443 if (!ArraySize.get()) {
6444 // If no array size was specified, but the new expression was
6445 // instantiated with an array type (e.g., "new T" where T is
6446 // instantiated with "int[4]"), extract the outer bound from the
6447 // array type as our array size. We do this with constant and
6448 // dependently-sized array types.
6449 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6450 if (!ArrayT) {
6451 // Do nothing
6452 } else if (const ConstantArrayType *ConsArrayT
6453 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006454 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006455 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6456 ConsArrayT->getSize(),
6457 SemaRef.Context.getSizeType(),
6458 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006459 AllocType = ConsArrayT->getElementType();
6460 } else if (const DependentSizedArrayType *DepArrayT
6461 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6462 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006463 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006464 AllocType = DepArrayT->getElementType();
6465 }
6466 }
6467 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006468
Douglas Gregora16548e2009-08-11 05:31:07 +00006469 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6470 E->isGlobalNew(),
6471 /*FIXME:*/E->getLocStart(),
6472 move_arg(PlacementArgs),
6473 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006474 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006475 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006476 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006477 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006478 /*FIXME:*/E->getLocStart(),
6479 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006480 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006481}
Mike Stump11289f42009-09-09 15:08:12 +00006482
Douglas Gregora16548e2009-08-11 05:31:07 +00006483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006484ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006485TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006486 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006487 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006489
Douglas Gregord2d9da02010-02-26 00:38:10 +00006490 // Transform the delete operator, if known.
6491 FunctionDecl *OperatorDelete = 0;
6492 if (E->getOperatorDelete()) {
6493 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006494 getDerived().TransformDecl(E->getLocStart(),
6495 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006496 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006497 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006498 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006499
Douglas Gregora16548e2009-08-11 05:31:07 +00006500 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006501 Operand.get() == E->getArgument() &&
6502 OperatorDelete == E->getOperatorDelete()) {
6503 // Mark any declarations we need as referenced.
6504 // FIXME: instantiation-specific.
6505 if (OperatorDelete)
6506 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006507
6508 if (!E->getArgument()->isTypeDependent()) {
6509 QualType Destroyed = SemaRef.Context.getBaseElementType(
6510 E->getDestroyedType());
6511 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6512 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6513 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6514 SemaRef.LookupDestructor(Record));
6515 }
6516 }
6517
John McCallc3007a22010-10-26 07:05:15 +00006518 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006519 }
Mike Stump11289f42009-09-09 15:08:12 +00006520
Douglas Gregora16548e2009-08-11 05:31:07 +00006521 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6522 E->isGlobalDelete(),
6523 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006524 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006525}
Mike Stump11289f42009-09-09 15:08:12 +00006526
Douglas Gregora16548e2009-08-11 05:31:07 +00006527template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006528ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006529TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006530 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006531 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006532 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006533 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006534
John McCallba7bf592010-08-24 05:47:05 +00006535 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006536 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006537 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006538 E->getOperatorLoc(),
6539 E->isArrow()? tok::arrow : tok::period,
6540 ObjectTypePtr,
6541 MayBePseudoDestructor);
6542 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006543 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006544
John McCallba7bf592010-08-24 05:47:05 +00006545 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006546 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6547 if (QualifierLoc) {
6548 QualifierLoc
6549 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6550 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006551 return ExprError();
6552 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006553 CXXScopeSpec SS;
6554 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006555
Douglas Gregor678f90d2010-02-25 01:56:36 +00006556 PseudoDestructorTypeStorage Destroyed;
6557 if (E->getDestroyedTypeInfo()) {
6558 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006559 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006560 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006561 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006562 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006563 Destroyed = DestroyedTypeInfo;
6564 } else if (ObjectType->isDependentType()) {
6565 // We aren't likely to be able to resolve the identifier down to a type
6566 // now anyway, so just retain the identifier.
6567 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6568 E->getDestroyedTypeLoc());
6569 } else {
6570 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006571 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006572 *E->getDestroyedTypeIdentifier(),
6573 E->getDestroyedTypeLoc(),
6574 /*Scope=*/0,
6575 SS, ObjectTypePtr,
6576 false);
6577 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006578 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006579
Douglas Gregor678f90d2010-02-25 01:56:36 +00006580 Destroyed
6581 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6582 E->getDestroyedTypeLoc());
6583 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006584
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006585 TypeSourceInfo *ScopeTypeInfo = 0;
6586 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006587 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006588 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006589 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006590 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006591
John McCallb268a282010-08-23 23:25:46 +00006592 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006593 E->getOperatorLoc(),
6594 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006595 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006596 ScopeTypeInfo,
6597 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006598 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006599 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006600}
Mike Stump11289f42009-09-09 15:08:12 +00006601
Douglas Gregorad8a3362009-09-04 17:36:40 +00006602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006603ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006604TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006605 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006606 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6607 Sema::LookupOrdinaryName);
6608
6609 // Transform all the decls.
6610 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6611 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006612 NamedDecl *InstD = static_cast<NamedDecl*>(
6613 getDerived().TransformDecl(Old->getNameLoc(),
6614 *I));
John McCall84d87672009-12-10 09:41:52 +00006615 if (!InstD) {
6616 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6617 // This can happen because of dependent hiding.
6618 if (isa<UsingShadowDecl>(*I))
6619 continue;
6620 else
John McCallfaf5fb42010-08-26 23:41:50 +00006621 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006622 }
John McCalle66edc12009-11-24 19:00:30 +00006623
6624 // Expand using declarations.
6625 if (isa<UsingDecl>(InstD)) {
6626 UsingDecl *UD = cast<UsingDecl>(InstD);
6627 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6628 E = UD->shadow_end(); I != E; ++I)
6629 R.addDecl(*I);
6630 continue;
6631 }
6632
6633 R.addDecl(InstD);
6634 }
6635
6636 // Resolve a kind, but don't do any further analysis. If it's
6637 // ambiguous, the callee needs to deal with it.
6638 R.resolveKind();
6639
6640 // Rebuild the nested-name qualifier, if present.
6641 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006642 if (Old->getQualifierLoc()) {
6643 NestedNameSpecifierLoc QualifierLoc
6644 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6645 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006646 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006647
Douglas Gregor0da1d432011-02-28 20:01:57 +00006648 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006649 }
6650
Douglas Gregor9262f472010-04-27 18:19:34 +00006651 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006652 CXXRecordDecl *NamingClass
6653 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6654 Old->getNameLoc(),
6655 Old->getNamingClass()));
6656 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006657 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006658
Douglas Gregorda7be082010-04-27 16:10:10 +00006659 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006660 }
6661
6662 // If we have no template arguments, it's a normal declaration name.
6663 if (!Old->hasExplicitTemplateArgs())
6664 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6665
6666 // If we have template arguments, rebuild them, then rebuild the
6667 // templateid expression.
6668 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006669 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6670 Old->getNumTemplateArgs(),
6671 TransArgs))
6672 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006673
6674 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6675 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006676}
Mike Stump11289f42009-09-09 15:08:12 +00006677
Douglas Gregora16548e2009-08-11 05:31:07 +00006678template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006679ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006680TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006681 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6682 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006683 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006684
Douglas Gregora16548e2009-08-11 05:31:07 +00006685 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006686 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006687 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006688
Mike Stump11289f42009-09-09 15:08:12 +00006689 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006690 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006691 T,
6692 E->getLocEnd());
6693}
Mike Stump11289f42009-09-09 15:08:12 +00006694
Douglas Gregora16548e2009-08-11 05:31:07 +00006695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006696ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006697TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6698 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6699 if (!LhsT)
6700 return ExprError();
6701
6702 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6703 if (!RhsT)
6704 return ExprError();
6705
6706 if (!getDerived().AlwaysRebuild() &&
6707 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6708 return SemaRef.Owned(E);
6709
6710 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6711 E->getLocStart(),
6712 LhsT, RhsT,
6713 E->getLocEnd());
6714}
6715
6716template<typename Derived>
6717ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006718TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006719 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006720 NestedNameSpecifierLoc QualifierLoc
6721 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6722 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006723 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006724
John McCall31f82722010-11-12 08:19:04 +00006725 // TODO: If this is a conversion-function-id, verify that the
6726 // destination type name (if present) resolves the same way after
6727 // instantiation as it did in the local scope.
6728
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006729 DeclarationNameInfo NameInfo
6730 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6731 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006733
John McCalle66edc12009-11-24 19:00:30 +00006734 if (!E->hasExplicitTemplateArgs()) {
6735 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006736 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006737 // Note: it is sufficient to compare the Name component of NameInfo:
6738 // if name has not changed, DNLoc has not changed either.
6739 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006740 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006741
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006742 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006743 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006744 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006745 }
John McCall6b51f282009-11-23 01:53:49 +00006746
6747 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006748 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6749 E->getNumTemplateArgs(),
6750 TransArgs))
6751 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006752
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006753 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006754 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006755 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006756}
6757
6758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006759ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006760TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006761 // CXXConstructExprs are always implicit, so when we have a
6762 // 1-argument construction we just transform that argument.
6763 if (E->getNumArgs() == 1 ||
6764 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6765 return getDerived().TransformExpr(E->getArg(0));
6766
Douglas Gregora16548e2009-08-11 05:31:07 +00006767 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6768
6769 QualType T = getDerived().TransformType(E->getType());
6770 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006771 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006772
6773 CXXConstructorDecl *Constructor
6774 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006775 getDerived().TransformDecl(E->getLocStart(),
6776 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006777 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006778 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006779
Douglas Gregora16548e2009-08-11 05:31:07 +00006780 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006781 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006782 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6783 &ArgumentChanged))
6784 return ExprError();
6785
Douglas Gregora16548e2009-08-11 05:31:07 +00006786 if (!getDerived().AlwaysRebuild() &&
6787 T == E->getType() &&
6788 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006789 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006790 // Mark the constructor as referenced.
6791 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006792 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006793 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006794 }
Mike Stump11289f42009-09-09 15:08:12 +00006795
Douglas Gregordb121ba2009-12-14 16:27:04 +00006796 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6797 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006798 move_arg(Args),
6799 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006800 E->getConstructionKind(),
6801 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006802}
Mike Stump11289f42009-09-09 15:08:12 +00006803
Douglas Gregora16548e2009-08-11 05:31:07 +00006804/// \brief Transform a C++ temporary-binding expression.
6805///
Douglas Gregor363b1512009-12-24 18:51:59 +00006806/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6807/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006809ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006810TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006811 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006812}
Mike Stump11289f42009-09-09 15:08:12 +00006813
John McCall5d413782010-12-06 08:20:24 +00006814/// \brief Transform a C++ expression that contains cleanups that should
6815/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006816///
John McCall5d413782010-12-06 08:20:24 +00006817/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006818/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006820ExprResult
John McCall5d413782010-12-06 08:20:24 +00006821TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006822 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006823}
Mike Stump11289f42009-09-09 15:08:12 +00006824
Douglas Gregora16548e2009-08-11 05:31:07 +00006825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006826ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006827TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006828 CXXTemporaryObjectExpr *E) {
6829 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6830 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006831 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006832
Douglas Gregora16548e2009-08-11 05:31:07 +00006833 CXXConstructorDecl *Constructor
6834 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006835 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006836 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006837 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006838 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006839
Douglas Gregora16548e2009-08-11 05:31:07 +00006840 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006841 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006842 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006843 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6844 &ArgumentChanged))
6845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006846
Douglas Gregora16548e2009-08-11 05:31:07 +00006847 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006848 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006849 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006850 !ArgumentChanged) {
6851 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006852 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006853 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006854 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006855
6856 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6857 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006858 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006859 E->getLocEnd());
6860}
Mike Stump11289f42009-09-09 15:08:12 +00006861
Douglas Gregora16548e2009-08-11 05:31:07 +00006862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006863ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006864TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006865 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006866 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6867 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006868 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006869
Douglas Gregora16548e2009-08-11 05:31:07 +00006870 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006871 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006872 Args.reserve(E->arg_size());
6873 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6874 &ArgumentChanged))
6875 return ExprError();
6876
Douglas Gregora16548e2009-08-11 05:31:07 +00006877 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006878 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006879 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006880 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006881
Douglas Gregora16548e2009-08-11 05:31:07 +00006882 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006883 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006884 E->getLParenLoc(),
6885 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006886 E->getRParenLoc());
6887}
Mike Stump11289f42009-09-09 15:08:12 +00006888
Douglas Gregora16548e2009-08-11 05:31:07 +00006889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006890ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006891TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006892 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006893 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006894 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006895 Expr *OldBase;
6896 QualType BaseType;
6897 QualType ObjectType;
6898 if (!E->isImplicitAccess()) {
6899 OldBase = E->getBase();
6900 Base = getDerived().TransformExpr(OldBase);
6901 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006902 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006903
John McCall2d74de92009-12-01 22:10:20 +00006904 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006905 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006906 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006907 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006908 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006909 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006910 ObjectTy,
6911 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006912 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006913 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006914
John McCallba7bf592010-08-24 05:47:05 +00006915 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006916 BaseType = ((Expr*) Base.get())->getType();
6917 } else {
6918 OldBase = 0;
6919 BaseType = getDerived().TransformType(E->getBaseType());
6920 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6921 }
Mike Stump11289f42009-09-09 15:08:12 +00006922
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006923 // Transform the first part of the nested-name-specifier that qualifies
6924 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006925 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006926 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00006927 E->getFirstQualifierFoundInScope(),
6928 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00006929
Douglas Gregore16af532011-02-28 18:50:33 +00006930 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006931 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00006932 QualifierLoc
6933 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
6934 ObjectType,
6935 FirstQualifierInScope);
6936 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006937 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006938 }
Mike Stump11289f42009-09-09 15:08:12 +00006939
John McCall31f82722010-11-12 08:19:04 +00006940 // TODO: If this is a conversion-function-id, verify that the
6941 // destination type name (if present) resolves the same way after
6942 // instantiation as it did in the local scope.
6943
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006944 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006945 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006946 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006947 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006948
John McCall2d74de92009-12-01 22:10:20 +00006949 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006950 // This is a reference to a member without an explicitly-specified
6951 // template argument list. Optimize for this common case.
6952 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006953 Base.get() == OldBase &&
6954 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00006955 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006956 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006957 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006958 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006959
John McCallb268a282010-08-23 23:25:46 +00006960 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006961 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006962 E->isArrow(),
6963 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00006964 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00006965 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006966 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006967 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006968 }
6969
John McCall6b51f282009-11-23 01:53:49 +00006970 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006971 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6972 E->getNumTemplateArgs(),
6973 TransArgs))
6974 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006975
John McCallb268a282010-08-23 23:25:46 +00006976 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006977 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006978 E->isArrow(),
6979 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00006980 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00006981 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006982 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006983 &TransArgs);
6984}
6985
6986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006987ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006988TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006989 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006990 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006991 QualType BaseType;
6992 if (!Old->isImplicitAccess()) {
6993 Base = getDerived().TransformExpr(Old->getBase());
6994 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006995 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006996 BaseType = ((Expr*) Base.get())->getType();
6997 } else {
6998 BaseType = getDerived().TransformType(Old->getBaseType());
6999 }
John McCall10eae182009-11-30 22:42:35 +00007000
Douglas Gregor0da1d432011-02-28 20:01:57 +00007001 NestedNameSpecifierLoc QualifierLoc;
7002 if (Old->getQualifierLoc()) {
7003 QualifierLoc
7004 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7005 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007006 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007007 }
7008
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007009 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007010 Sema::LookupOrdinaryName);
7011
7012 // Transform all the decls.
7013 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7014 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007015 NamedDecl *InstD = static_cast<NamedDecl*>(
7016 getDerived().TransformDecl(Old->getMemberLoc(),
7017 *I));
John McCall84d87672009-12-10 09:41:52 +00007018 if (!InstD) {
7019 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7020 // This can happen because of dependent hiding.
7021 if (isa<UsingShadowDecl>(*I))
7022 continue;
7023 else
John McCallfaf5fb42010-08-26 23:41:50 +00007024 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007025 }
John McCall10eae182009-11-30 22:42:35 +00007026
7027 // Expand using declarations.
7028 if (isa<UsingDecl>(InstD)) {
7029 UsingDecl *UD = cast<UsingDecl>(InstD);
7030 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7031 E = UD->shadow_end(); I != E; ++I)
7032 R.addDecl(*I);
7033 continue;
7034 }
7035
7036 R.addDecl(InstD);
7037 }
7038
7039 R.resolveKind();
7040
Douglas Gregor9262f472010-04-27 18:19:34 +00007041 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007042 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007043 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007044 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007045 Old->getMemberLoc(),
7046 Old->getNamingClass()));
7047 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007048 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007049
Douglas Gregorda7be082010-04-27 16:10:10 +00007050 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007051 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007052
John McCall10eae182009-11-30 22:42:35 +00007053 TemplateArgumentListInfo TransArgs;
7054 if (Old->hasExplicitTemplateArgs()) {
7055 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7056 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007057 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7058 Old->getNumTemplateArgs(),
7059 TransArgs))
7060 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007061 }
John McCall38836f02010-01-15 08:34:02 +00007062
7063 // FIXME: to do this check properly, we will need to preserve the
7064 // first-qualifier-in-scope here, just in case we had a dependent
7065 // base (and therefore couldn't do the check) and a
7066 // nested-name-qualifier (and therefore could do the lookup).
7067 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007068
John McCallb268a282010-08-23 23:25:46 +00007069 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007070 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007071 Old->getOperatorLoc(),
7072 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007073 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007074 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007075 R,
7076 (Old->hasExplicitTemplateArgs()
7077 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007078}
7079
7080template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007081ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007082TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7083 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7084 if (SubExpr.isInvalid())
7085 return ExprError();
7086
7087 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007088 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007089
7090 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7091}
7092
7093template<typename Derived>
7094ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007095TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007096 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7097 if (Pattern.isInvalid())
7098 return ExprError();
7099
7100 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7101 return SemaRef.Owned(E);
7102
Douglas Gregorb8840002011-01-14 21:20:45 +00007103 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7104 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007105}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007106
7107template<typename Derived>
7108ExprResult
7109TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7110 // If E is not value-dependent, then nothing will change when we transform it.
7111 // Note: This is an instantiation-centric view.
7112 if (!E->isValueDependent())
7113 return SemaRef.Owned(E);
7114
7115 // Note: None of the implementations of TryExpandParameterPacks can ever
7116 // produce a diagnostic when given only a single unexpanded parameter pack,
7117 // so
7118 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7119 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007120 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007121 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007122 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7123 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007124 ShouldExpand, RetainExpansion,
7125 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007126 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007127
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007128 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007129 return SemaRef.Owned(E);
7130
7131 // We now know the length of the parameter pack, so build a new expression
7132 // that stores that length.
7133 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7134 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007135 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007136}
7137
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007138template<typename Derived>
7139ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007140TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7141 SubstNonTypeTemplateParmPackExpr *E) {
7142 // Default behavior is to do nothing with this transformation.
7143 return SemaRef.Owned(E);
7144}
7145
7146template<typename Derived>
7147ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007148TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007149 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007150}
7151
Mike Stump11289f42009-09-09 15:08:12 +00007152template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007153ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007154TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007155 TypeSourceInfo *EncodedTypeInfo
7156 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7157 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007158 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007159
Douglas Gregora16548e2009-08-11 05:31:07 +00007160 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007161 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007162 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007163
7164 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007165 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007166 E->getRParenLoc());
7167}
Mike Stump11289f42009-09-09 15:08:12 +00007168
Douglas Gregora16548e2009-08-11 05:31:07 +00007169template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007170ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007171TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007172 // Transform arguments.
7173 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007174 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007175 Args.reserve(E->getNumArgs());
7176 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7177 &ArgChanged))
7178 return ExprError();
7179
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007180 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7181 // Class message: transform the receiver type.
7182 TypeSourceInfo *ReceiverTypeInfo
7183 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7184 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007185 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007186
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007187 // If nothing changed, just retain the existing message send.
7188 if (!getDerived().AlwaysRebuild() &&
7189 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007190 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007191
7192 // Build a new class message send.
7193 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7194 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007195 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007196 E->getMethodDecl(),
7197 E->getLeftLoc(),
7198 move_arg(Args),
7199 E->getRightLoc());
7200 }
7201
7202 // Instance message: transform the receiver
7203 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7204 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007205 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007206 = getDerived().TransformExpr(E->getInstanceReceiver());
7207 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007208 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007209
7210 // If nothing changed, just retain the existing message send.
7211 if (!getDerived().AlwaysRebuild() &&
7212 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007213 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007214
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007215 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007216 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007217 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007218 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007219 E->getMethodDecl(),
7220 E->getLeftLoc(),
7221 move_arg(Args),
7222 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007223}
7224
Mike Stump11289f42009-09-09 15:08:12 +00007225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007226ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007227TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007228 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007229}
7230
Mike Stump11289f42009-09-09 15:08:12 +00007231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007232ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007233TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007234 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007235}
7236
Mike Stump11289f42009-09-09 15:08:12 +00007237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007239TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007240 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007241 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007242 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007243 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007244
7245 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007246
Douglas Gregord51d90d2010-04-26 20:11:03 +00007247 // If nothing changed, just retain the existing expression.
7248 if (!getDerived().AlwaysRebuild() &&
7249 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007250 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007251
John McCallb268a282010-08-23 23:25:46 +00007252 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007253 E->getLocation(),
7254 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007255}
7256
Mike Stump11289f42009-09-09 15:08:12 +00007257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007258ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007259TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007260 // 'super' and types never change. Property never changes. Just
7261 // retain the existing expression.
7262 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007263 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007264
Douglas Gregor9faee212010-04-26 20:47:02 +00007265 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007266 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007267 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007268 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007269
Douglas Gregor9faee212010-04-26 20:47:02 +00007270 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007271
Douglas Gregor9faee212010-04-26 20:47:02 +00007272 // If nothing changed, just retain the existing expression.
7273 if (!getDerived().AlwaysRebuild() &&
7274 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007275 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007276
John McCallb7bd14f2010-12-02 01:19:52 +00007277 if (E->isExplicitProperty())
7278 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7279 E->getExplicitProperty(),
7280 E->getLocation());
7281
7282 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7283 E->getType(),
7284 E->getImplicitPropertyGetter(),
7285 E->getImplicitPropertySetter(),
7286 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007287}
7288
Mike Stump11289f42009-09-09 15:08:12 +00007289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007290ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007291TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007292 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007293 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007294 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007295 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007296
Douglas Gregord51d90d2010-04-26 20:11:03 +00007297 // If nothing changed, just retain the existing expression.
7298 if (!getDerived().AlwaysRebuild() &&
7299 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007300 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007301
John McCallb268a282010-08-23 23:25:46 +00007302 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007303 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007304}
7305
Mike Stump11289f42009-09-09 15:08:12 +00007306template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007307ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007308TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007309 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007310 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007311 SubExprs.reserve(E->getNumSubExprs());
7312 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7313 SubExprs, &ArgumentChanged))
7314 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007315
Douglas Gregora16548e2009-08-11 05:31:07 +00007316 if (!getDerived().AlwaysRebuild() &&
7317 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007318 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007319
Douglas Gregora16548e2009-08-11 05:31:07 +00007320 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7321 move_arg(SubExprs),
7322 E->getRParenLoc());
7323}
7324
Mike Stump11289f42009-09-09 15:08:12 +00007325template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007326ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007327TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007328 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007329
John McCall490112f2011-02-04 18:33:18 +00007330 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7331 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7332
7333 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7334 llvm::SmallVector<ParmVarDecl*, 4> params;
7335 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007336
7337 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007338 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7339 oldBlock->param_begin(),
7340 oldBlock->param_size(),
7341 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007342 return true;
John McCall490112f2011-02-04 18:33:18 +00007343
7344 const FunctionType *exprFunctionType = E->getFunctionType();
7345 QualType exprResultType = exprFunctionType->getResultType();
7346 if (!exprResultType.isNull()) {
7347 if (!exprResultType->isDependentType())
7348 blockScope->ReturnType = exprResultType;
7349 else if (exprResultType != getSema().Context.DependentTy)
7350 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007351 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007352
7353 // If the return type has not been determined yet, leave it as a dependent
7354 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007355 if (blockScope->ReturnType.isNull())
7356 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007357
7358 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007359 if (blockScope->ReturnType->isObjCObjectType()) {
7360 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007361 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007362 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007363 return ExprError();
7364 }
John McCall3882ace2011-01-05 12:14:39 +00007365
John McCall490112f2011-02-04 18:33:18 +00007366 QualType functionType = getDerived().RebuildFunctionProtoType(
7367 blockScope->ReturnType,
7368 paramTypes.data(),
7369 paramTypes.size(),
7370 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007371 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007372 exprFunctionType->getExtInfo());
7373 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007374
7375 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007376 if (!params.empty())
7377 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007378
7379 // If the return type wasn't explicitly set, it will have been marked as a
7380 // dependent type (DependentTy); clear out the return type setting so
7381 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007382 if (blockScope->ReturnType == getSema().Context.DependentTy)
7383 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007384
John McCall3882ace2011-01-05 12:14:39 +00007385 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007386 StmtResult body = getDerived().TransformStmt(E->getBody());
7387 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007388 return ExprError();
7389
John McCall490112f2011-02-04 18:33:18 +00007390#ifndef NDEBUG
7391 // In builds with assertions, make sure that we captured everything we
7392 // captured before.
7393
7394 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7395
7396 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7397 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007398 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007399
7400 // Ignore parameter packs.
7401 if (isa<ParmVarDecl>(oldCapture) &&
7402 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7403 continue;
7404
7405 VarDecl *newCapture =
7406 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7407 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007408 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007409 }
7410#endif
7411
7412 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7413 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007414}
7415
Mike Stump11289f42009-09-09 15:08:12 +00007416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007417ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007418TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007419 ValueDecl *ND
7420 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7421 E->getDecl()));
7422 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007423 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007424
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007425 if (!getDerived().AlwaysRebuild() &&
7426 ND == E->getDecl()) {
7427 // Mark it referenced in the new context regardless.
7428 // FIXME: this is a bit instantiation-specific.
7429 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7430
John McCallc3007a22010-10-26 07:05:15 +00007431 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007432 }
7433
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007434 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007435 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007436 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007437}
Mike Stump11289f42009-09-09 15:08:12 +00007438
Douglas Gregora16548e2009-08-11 05:31:07 +00007439//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007440// Type reconstruction
7441//===----------------------------------------------------------------------===//
7442
Mike Stump11289f42009-09-09 15:08:12 +00007443template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007444QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7445 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007446 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007447 getDerived().getBaseEntity());
7448}
7449
Mike Stump11289f42009-09-09 15:08:12 +00007450template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007451QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7452 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007453 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007454 getDerived().getBaseEntity());
7455}
7456
Mike Stump11289f42009-09-09 15:08:12 +00007457template<typename Derived>
7458QualType
John McCall70dd5f62009-10-30 00:06:24 +00007459TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7460 bool WrittenAsLValue,
7461 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007462 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007463 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007464}
7465
7466template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007467QualType
John McCall70dd5f62009-10-30 00:06:24 +00007468TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7469 QualType ClassType,
7470 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007471 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007472 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007473}
7474
7475template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007476QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007477TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7478 ArrayType::ArraySizeModifier SizeMod,
7479 const llvm::APInt *Size,
7480 Expr *SizeExpr,
7481 unsigned IndexTypeQuals,
7482 SourceRange BracketsRange) {
7483 if (SizeExpr || !Size)
7484 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7485 IndexTypeQuals, BracketsRange,
7486 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007487
7488 QualType Types[] = {
7489 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7490 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7491 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007492 };
7493 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7494 QualType SizeType;
7495 for (unsigned I = 0; I != NumTypes; ++I)
7496 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7497 SizeType = Types[I];
7498 break;
7499 }
Mike Stump11289f42009-09-09 15:08:12 +00007500
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007501 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7502 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007503 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007504 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007505 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007506}
Mike Stump11289f42009-09-09 15:08:12 +00007507
Douglas Gregord6ff3322009-08-04 16:50:30 +00007508template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007509QualType
7510TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007511 ArrayType::ArraySizeModifier SizeMod,
7512 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007513 unsigned IndexTypeQuals,
7514 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007515 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007516 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007517}
7518
7519template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007520QualType
Mike Stump11289f42009-09-09 15:08:12 +00007521TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007522 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007523 unsigned IndexTypeQuals,
7524 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007525 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007526 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007527}
Mike Stump11289f42009-09-09 15:08:12 +00007528
Douglas Gregord6ff3322009-08-04 16:50:30 +00007529template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007530QualType
7531TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007532 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007533 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007534 unsigned IndexTypeQuals,
7535 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007536 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007537 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007538 IndexTypeQuals, BracketsRange);
7539}
7540
7541template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007542QualType
7543TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007544 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007545 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007546 unsigned IndexTypeQuals,
7547 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007548 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007549 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007550 IndexTypeQuals, BracketsRange);
7551}
7552
7553template<typename Derived>
7554QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007555 unsigned NumElements,
7556 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007557 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007558 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007559}
Mike Stump11289f42009-09-09 15:08:12 +00007560
Douglas Gregord6ff3322009-08-04 16:50:30 +00007561template<typename Derived>
7562QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7563 unsigned NumElements,
7564 SourceLocation AttributeLoc) {
7565 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7566 NumElements, true);
7567 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007568 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7569 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007570 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007571}
Mike Stump11289f42009-09-09 15:08:12 +00007572
Douglas Gregord6ff3322009-08-04 16:50:30 +00007573template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007574QualType
7575TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007576 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007577 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007578 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007579}
Mike Stump11289f42009-09-09 15:08:12 +00007580
Douglas Gregord6ff3322009-08-04 16:50:30 +00007581template<typename Derived>
7582QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007583 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007584 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007585 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007586 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007587 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007588 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007589 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007590 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007591 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007592 getDerived().getBaseEntity(),
7593 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007594}
Mike Stump11289f42009-09-09 15:08:12 +00007595
Douglas Gregord6ff3322009-08-04 16:50:30 +00007596template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007597QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7598 return SemaRef.Context.getFunctionNoProtoType(T);
7599}
7600
7601template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007602QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7603 assert(D && "no decl found");
7604 if (D->isInvalidDecl()) return QualType();
7605
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007606 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007607 TypeDecl *Ty;
7608 if (isa<UsingDecl>(D)) {
7609 UsingDecl *Using = cast<UsingDecl>(D);
7610 assert(Using->isTypeName() &&
7611 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7612
7613 // A valid resolved using typename decl points to exactly one type decl.
7614 assert(++Using->shadow_begin() == Using->shadow_end());
7615 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007616
John McCallb96ec562009-12-04 22:46:56 +00007617 } else {
7618 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7619 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7620 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7621 }
7622
7623 return SemaRef.Context.getTypeDeclType(Ty);
7624}
7625
7626template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007627QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7628 SourceLocation Loc) {
7629 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007630}
7631
7632template<typename Derived>
7633QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7634 return SemaRef.Context.getTypeOfType(Underlying);
7635}
7636
7637template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007638QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7639 SourceLocation Loc) {
7640 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007641}
7642
7643template<typename Derived>
7644QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007645 TemplateName Template,
7646 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00007647 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00007648 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007649}
Mike Stump11289f42009-09-09 15:08:12 +00007650
Douglas Gregor1135c352009-08-06 05:28:30 +00007651template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007652TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007653TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007654 bool TemplateKW,
7655 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007656 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007657 Template);
7658}
7659
7660template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007661TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007662TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
7663 const IdentifierInfo &Name,
7664 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00007665 QualType ObjectType,
7666 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007667 UnqualifiedId TemplateName;
7668 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00007669 Sema::TemplateTy Template;
7670 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007671 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007672 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00007673 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00007674 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007675 /*EnteringContext=*/false,
7676 Template);
John McCall31f82722010-11-12 08:19:04 +00007677 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007678}
Mike Stump11289f42009-09-09 15:08:12 +00007679
Douglas Gregora16548e2009-08-11 05:31:07 +00007680template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007681TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007682TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007683 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00007684 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007685 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00007686 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00007687 // FIXME: Bogus location information.
7688 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
7689 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007690 Sema::TemplateTy Template;
7691 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007692 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007693 SS,
7694 Name,
John McCallba7bf592010-08-24 05:47:05 +00007695 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007696 /*EnteringContext=*/false,
7697 Template);
7698 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007699}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007700
Douglas Gregor71395fa2009-11-04 00:56:37 +00007701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007702ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007703TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7704 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007705 Expr *OrigCallee,
7706 Expr *First,
7707 Expr *Second) {
7708 Expr *Callee = OrigCallee->IgnoreParenCasts();
7709 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007710
Douglas Gregora16548e2009-08-11 05:31:07 +00007711 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007712 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007713 if (!First->getType()->isOverloadableType() &&
7714 !Second->getType()->isOverloadableType())
7715 return getSema().CreateBuiltinArraySubscriptExpr(First,
7716 Callee->getLocStart(),
7717 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007718 } else if (Op == OO_Arrow) {
7719 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007720 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7721 } else if (Second == 0 || isPostIncDec) {
7722 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007723 // The argument is not of overloadable type, so try to create a
7724 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007725 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007726 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007727
John McCallb268a282010-08-23 23:25:46 +00007728 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007729 }
7730 } else {
John McCallb268a282010-08-23 23:25:46 +00007731 if (!First->getType()->isOverloadableType() &&
7732 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007733 // Neither of the arguments is an overloadable type, so try to
7734 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007735 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007736 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007737 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007738 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007739 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007740
Douglas Gregora16548e2009-08-11 05:31:07 +00007741 return move(Result);
7742 }
7743 }
Mike Stump11289f42009-09-09 15:08:12 +00007744
7745 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007746 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007747 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007748
John McCallb268a282010-08-23 23:25:46 +00007749 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007750 assert(ULE->requiresADL());
7751
7752 // FIXME: Do we have to check
7753 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007754 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007755 } else {
John McCallb268a282010-08-23 23:25:46 +00007756 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007757 }
Mike Stump11289f42009-09-09 15:08:12 +00007758
Douglas Gregora16548e2009-08-11 05:31:07 +00007759 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007760 Expr *Args[2] = { First, Second };
7761 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007762
Douglas Gregora16548e2009-08-11 05:31:07 +00007763 // Create the overloaded operator invocation for unary operators.
7764 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007765 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007766 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007767 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007768 }
Mike Stump11289f42009-09-09 15:08:12 +00007769
Sebastian Redladba46e2009-10-29 20:17:01 +00007770 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007771 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007772 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007773 First,
7774 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007775
Douglas Gregora16548e2009-08-11 05:31:07 +00007776 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007777 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007778 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007779 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7780 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007781 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007782
Mike Stump11289f42009-09-09 15:08:12 +00007783 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007784}
Mike Stump11289f42009-09-09 15:08:12 +00007785
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007787ExprResult
John McCallb268a282010-08-23 23:25:46 +00007788TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007789 SourceLocation OperatorLoc,
7790 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00007791 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007792 TypeSourceInfo *ScopeType,
7793 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007794 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007795 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00007796 QualType BaseType = Base->getType();
7797 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007798 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007799 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007800 !BaseType->getAs<PointerType>()->getPointeeType()
7801 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007802 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007803 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007804 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007805 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007806 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007807 /*FIXME?*/true);
7808 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007809
Douglas Gregor678f90d2010-02-25 01:56:36 +00007810 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007811 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7812 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7813 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7814 NameInfo.setNamedTypeInfo(DestroyedType);
7815
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007816 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007817
John McCallb268a282010-08-23 23:25:46 +00007818 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007819 OperatorLoc, isArrow,
7820 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007821 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007822 /*TemplateArgs*/ 0);
7823}
7824
Douglas Gregord6ff3322009-08-04 16:50:30 +00007825} // end namespace clang
7826
7827#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H