blob: bd28991e4bb1c117118b3f02ffaa2f7a48a5e2d1 [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 Gregor23648d72011-03-04 18:53:13 +0000501 TemplateName Template,
502 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000503
504 QualType
505 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000506 DependentTemplateSpecializationTypeLoc TL,
507 NestedNameSpecifierLoc QualifierLoc);
508
John McCall58f10c32010-03-11 09:03:00 +0000509 /// \brief Transforms the parameters of a function type into the
510 /// given vectors.
511 ///
512 /// The result vectors should be kept in sync; null entries in the
513 /// variables vector are acceptable.
514 ///
515 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000516 bool TransformFunctionTypeParams(SourceLocation Loc,
517 ParmVarDecl **Params, unsigned NumParams,
518 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000519 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000520 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000521
522 /// \brief Transforms a single function-type parameter. Return null
523 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000524 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
525 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000526
John McCall31f82722010-11-12 08:19:04 +0000527 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000528
John McCalldadc5752010-08-24 06:29:42 +0000529 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
530 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000531
Douglas Gregorebe10102009-08-20 07:17:43 +0000532#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000533 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000534#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000535 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000536#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000537#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000538
Douglas Gregord6ff3322009-08-04 16:50:30 +0000539 /// \brief Build a new pointer type given its pointee type.
540 ///
541 /// By default, performs semantic analysis when building the pointer type.
542 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000543 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
545 /// \brief Build a new block pointer type given its pointee type.
546 ///
Mike Stump11289f42009-09-09 15:08:12 +0000547 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000548 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000549 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000550
John McCall70dd5f62009-10-30 00:06:24 +0000551 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552 ///
John McCall70dd5f62009-10-30 00:06:24 +0000553 /// By default, performs semantic analysis when building the
554 /// reference type. Subclasses may override this routine to provide
555 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556 ///
John McCall70dd5f62009-10-30 00:06:24 +0000557 /// \param LValue whether the type was written with an lvalue sigil
558 /// or an rvalue sigil.
559 QualType RebuildReferenceType(QualType ReferentType,
560 bool LValue,
561 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000562
Douglas Gregord6ff3322009-08-04 16:50:30 +0000563 /// \brief Build a new member pointer type given the pointee type and the
564 /// class type it refers into.
565 ///
566 /// By default, performs semantic analysis when building the member pointer
567 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000568 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
569 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000570
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// \brief Build a new array type given the element type, size
572 /// modifier, size of the array (if known), size expression, and index type
573 /// qualifiers.
574 ///
575 /// By default, performs semantic analysis when building the array type.
576 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000577 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578 QualType RebuildArrayType(QualType ElementType,
579 ArrayType::ArraySizeModifier SizeMod,
580 const llvm::APInt *Size,
581 Expr *SizeExpr,
582 unsigned IndexTypeQuals,
583 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000584
Douglas Gregord6ff3322009-08-04 16:50:30 +0000585 /// \brief Build a new constant array type given the element type, size
586 /// modifier, (known) size of the array, and index type qualifiers.
587 ///
588 /// By default, performs semantic analysis when building the array type.
589 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000590 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000591 ArrayType::ArraySizeModifier SizeMod,
592 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000593 unsigned IndexTypeQuals,
594 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000595
Douglas Gregord6ff3322009-08-04 16:50:30 +0000596 /// \brief Build a new incomplete array type given the element type, size
597 /// modifier, and index type qualifiers.
598 ///
599 /// By default, performs semantic analysis when building the array type.
600 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000601 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000602 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000603 unsigned IndexTypeQuals,
604 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000605
Mike Stump11289f42009-09-09 15:08:12 +0000606 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000607 /// size modifier, size expression, and index type qualifiers.
608 ///
609 /// By default, performs semantic analysis when building the array type.
610 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000611 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000612 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000613 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000614 unsigned IndexTypeQuals,
615 SourceRange BracketsRange);
616
Mike Stump11289f42009-09-09 15:08:12 +0000617 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000618 /// size modifier, size expression, and index type qualifiers.
619 ///
620 /// By default, performs semantic analysis when building the array type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000622 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000623 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000624 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000625 unsigned IndexTypeQuals,
626 SourceRange BracketsRange);
627
628 /// \brief Build a new vector type given the element type and
629 /// number of elements.
630 ///
631 /// By default, performs semantic analysis when building the vector type.
632 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000633 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000634 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000635
Douglas Gregord6ff3322009-08-04 16:50:30 +0000636 /// \brief Build a new extended vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
641 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
642 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000643
644 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645 /// given the element type and number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000649 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000650 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000652
Douglas Gregord6ff3322009-08-04 16:50:30 +0000653 /// \brief Build a new function type.
654 ///
655 /// By default, performs semantic analysis when building the function type.
656 /// Subclasses may override this routine to provide different behavior.
657 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000658 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000660 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000661 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000662 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000663
John McCall550e0c22009-10-21 00:40:46 +0000664 /// \brief Build a new unprototyped function type.
665 QualType RebuildFunctionNoProtoType(QualType ResultType);
666
John McCallb96ec562009-12-04 22:46:56 +0000667 /// \brief Rebuild an unresolved typename type, given the decl that
668 /// the UnresolvedUsingTypenameDecl was transformed to.
669 QualType RebuildUnresolvedUsingType(Decl *D);
670
Douglas Gregord6ff3322009-08-04 16:50:30 +0000671 /// \brief Build a new typedef type.
672 QualType RebuildTypedefType(TypedefDecl *Typedef) {
673 return SemaRef.Context.getTypeDeclType(Typedef);
674 }
675
676 /// \brief Build a new class/struct/union type.
677 QualType RebuildRecordType(RecordDecl *Record) {
678 return SemaRef.Context.getTypeDeclType(Record);
679 }
680
681 /// \brief Build a new Enum type.
682 QualType RebuildEnumType(EnumDecl *Enum) {
683 return SemaRef.Context.getTypeDeclType(Enum);
684 }
John McCallfcc33b02009-09-05 00:15:47 +0000685
Mike Stump11289f42009-09-09 15:08:12 +0000686 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000687 ///
688 /// By default, performs semantic analysis when building the typeof type.
689 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000690 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691
Mike Stump11289f42009-09-09 15:08:12 +0000692 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693 ///
694 /// By default, builds a new TypeOfType with the given underlying type.
695 QualType RebuildTypeOfType(QualType Underlying);
696
Mike Stump11289f42009-09-09 15:08:12 +0000697 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000698 ///
699 /// By default, performs semantic analysis when building the decltype type.
700 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000701 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000702
Richard Smith30482bc2011-02-20 03:19:35 +0000703 /// \brief Build a new C++0x auto type.
704 ///
705 /// By default, builds a new AutoType with the given deduced type.
706 QualType RebuildAutoType(QualType Deduced) {
707 return SemaRef.Context.getAutoType(Deduced);
708 }
709
Douglas Gregord6ff3322009-08-04 16:50:30 +0000710 /// \brief Build a new template specialization type.
711 ///
712 /// By default, performs semantic analysis when building the template
713 /// specialization type. Subclasses may override this routine to provide
714 /// different behavior.
715 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000716 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000717 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000718
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000719 /// \brief Build a new parenthesized type.
720 ///
721 /// By default, builds a new ParenType type from the inner type.
722 /// Subclasses may override this routine to provide different behavior.
723 QualType RebuildParenType(QualType InnerType) {
724 return SemaRef.Context.getParenType(InnerType);
725 }
726
Douglas Gregord6ff3322009-08-04 16:50:30 +0000727 /// \brief Build a new qualified name type.
728 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000729 /// By default, builds a new ElaboratedType type from the keyword,
730 /// the nested-name-specifier and the named type.
731 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000732 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
733 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000734 NestedNameSpecifierLoc QualifierLoc,
735 QualType Named) {
736 return SemaRef.Context.getElaboratedType(Keyword,
737 QualifierLoc.getNestedNameSpecifier(),
738 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000739 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740
741 /// \brief Build a new typename type that refers to a template-id.
742 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000743 /// By default, builds a new DependentNameType type from the
744 /// nested-name-specifier and the given type. Subclasses may override
745 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000746 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000747 ElaboratedTypeKeyword Keyword,
748 NestedNameSpecifierLoc QualifierLoc,
749 const IdentifierInfo *Name,
750 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000751 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000752 // Rebuild the template name.
753 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000754 CXXScopeSpec SS;
755 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000756 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000757 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000758
759 if (InstName.isNull())
760 return QualType();
761
762 // If it's still dependent, make a dependent specialization.
763 if (InstName.getAsDependentTemplateName())
764 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
765 QualifierLoc.getNestedNameSpecifier(),
766 Name,
767 Args);
768
769 // Otherwise, make an elaborated type wrapping a non-dependent
770 // specialization.
771 QualType T =
772 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
773 if (T.isNull()) return QualType();
774
775 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
776 return T;
777
778 return SemaRef.Context.getElaboratedType(Keyword,
779 QualifierLoc.getNestedNameSpecifier(),
780 T);
781 }
782
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783 /// \brief Build a new typename type that refers to an identifier.
784 ///
785 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000786 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000787 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000788 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000789 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000790 NestedNameSpecifierLoc QualifierLoc,
791 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000792 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000793 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000794 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000795
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000796 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000797 // If the name is still dependent, just build a new dependent name type.
798 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000799 return SemaRef.Context.getDependentNameType(Keyword,
800 QualifierLoc.getNestedNameSpecifier(),
801 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000802 }
803
Abramo Bagnara6150c882010-05-11 21:36:43 +0000804 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000805 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000806 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000807
808 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
809
Abramo Bagnarad7548482010-05-19 21:37:53 +0000810 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000811 // into a non-dependent elaborated-type-specifier. Find the tag we're
812 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000813 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000814 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
815 if (!DC)
816 return QualType();
817
John McCallbf8c5192010-05-27 06:40:31 +0000818 if (SemaRef.RequireCompleteDeclContext(SS, DC))
819 return QualType();
820
Douglas Gregore677daf2010-03-31 22:19:08 +0000821 TagDecl *Tag = 0;
822 SemaRef.LookupQualifiedName(Result, DC);
823 switch (Result.getResultKind()) {
824 case LookupResult::NotFound:
825 case LookupResult::NotFoundInCurrentInstantiation:
826 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000827
Douglas Gregore677daf2010-03-31 22:19:08 +0000828 case LookupResult::Found:
829 Tag = Result.getAsSingle<TagDecl>();
830 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000831
Douglas Gregore677daf2010-03-31 22:19:08 +0000832 case LookupResult::FoundOverloaded:
833 case LookupResult::FoundUnresolvedValue:
834 llvm_unreachable("Tag lookup cannot find non-tags");
835 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000836
Douglas Gregore677daf2010-03-31 22:19:08 +0000837 case LookupResult::Ambiguous:
838 // Let the LookupResult structure handle ambiguities.
839 return QualType();
840 }
841
842 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000843 // Check where the name exists but isn't a tag type and use that to emit
844 // better diagnostics.
845 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
846 SemaRef.LookupQualifiedName(Result, DC);
847 switch (Result.getResultKind()) {
848 case LookupResult::Found:
849 case LookupResult::FoundOverloaded:
850 case LookupResult::FoundUnresolvedValue: {
851 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
852 unsigned Kind = 0;
853 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
854 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
855 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
856 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
857 break;
858 }
859 default:
860 // FIXME: Would be nice to highlight just the source range.
861 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
862 << Kind << Id << DC;
863 break;
864 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000865 return QualType();
866 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000867
Abramo Bagnarad7548482010-05-19 21:37:53 +0000868 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
869 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000870 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
871 return QualType();
872 }
873
874 // Build the elaborated-type-specifier type.
875 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000876 return SemaRef.Context.getElaboratedType(Keyword,
877 QualifierLoc.getNestedNameSpecifier(),
878 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000879 }
Mike Stump11289f42009-09-09 15:08:12 +0000880
Douglas Gregor822d0302011-01-12 17:07:58 +0000881 /// \brief Build a new pack expansion type.
882 ///
883 /// By default, builds a new PackExpansionType type from the given pattern.
884 /// Subclasses may override this routine to provide different behavior.
885 QualType RebuildPackExpansionType(QualType Pattern,
886 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000887 SourceLocation EllipsisLoc,
888 llvm::Optional<unsigned> NumExpansions) {
889 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
890 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000891 }
892
Douglas Gregor71dc5092009-08-06 06:41:21 +0000893 /// \brief Build a new template name given a nested name specifier, a flag
894 /// indicating whether the "template" keyword was provided, and the template
895 /// that the template name refers to.
896 ///
897 /// By default, builds the new template name directly. Subclasses may override
898 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000899 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000900 bool TemplateKW,
901 TemplateDecl *Template);
902
Douglas Gregor71dc5092009-08-06 06:41:21 +0000903 /// \brief Build a new template name given a nested name specifier and the
904 /// name that is referred to as a template.
905 ///
906 /// By default, performs semantic analysis to determine whether the name can
907 /// be resolved to a specific template, then builds the appropriate kind of
908 /// template name. Subclasses may override this routine to provide different
909 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000910 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
911 const IdentifierInfo &Name,
912 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000913 QualType ObjectType,
914 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000915
Douglas Gregor71395fa2009-11-04 00:56:37 +0000916 /// \brief Build a new template name given a nested name specifier and the
917 /// overloaded operator name that is referred to as a template.
918 ///
919 /// By default, performs semantic analysis to determine whether the name can
920 /// be resolved to a specific template, then builds the appropriate kind of
921 /// template name. Subclasses may override this routine to provide different
922 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000923 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000924 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000925 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000926 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000927
928 /// \brief Build a new template name given a template template parameter pack
929 /// and the
930 ///
931 /// By default, performs semantic analysis to determine whether the name can
932 /// be resolved to a specific template, then builds the appropriate kind of
933 /// template name. Subclasses may override this routine to provide different
934 /// behavior.
935 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
936 const TemplateArgument &ArgPack) {
937 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
938 }
939
Douglas Gregorebe10102009-08-20 07:17:43 +0000940 /// \brief Build a new compound statement.
941 ///
942 /// By default, performs semantic analysis to build the new statement.
943 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000944 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000945 MultiStmtArg Statements,
946 SourceLocation RBraceLoc,
947 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000948 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000949 IsStmtExpr);
950 }
951
952 /// \brief Build a new case statement.
953 ///
954 /// By default, performs semantic analysis to build the new statement.
955 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000956 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000957 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000958 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000959 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000960 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000961 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000962 ColonLoc);
963 }
Mike Stump11289f42009-09-09 15:08:12 +0000964
Douglas Gregorebe10102009-08-20 07:17:43 +0000965 /// \brief Attach the body to a new case statement.
966 ///
967 /// By default, performs semantic analysis to build the new statement.
968 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000969 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000970 getSema().ActOnCaseStmtBody(S, Body);
971 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000972 }
Mike Stump11289f42009-09-09 15:08:12 +0000973
Douglas Gregorebe10102009-08-20 07:17:43 +0000974 /// \brief Build a new default statement.
975 ///
976 /// By default, performs semantic analysis to build the new statement.
977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000978 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000979 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000980 Stmt *SubStmt) {
981 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000982 /*CurScope=*/0);
983 }
Mike Stump11289f42009-09-09 15:08:12 +0000984
Douglas Gregorebe10102009-08-20 07:17:43 +0000985 /// \brief Build a new label statement.
986 ///
987 /// By default, performs semantic analysis to build the new statement.
988 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +0000989 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
990 SourceLocation ColonLoc, Stmt *SubStmt) {
991 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000992 }
Mike Stump11289f42009-09-09 15:08:12 +0000993
Douglas Gregorebe10102009-08-20 07:17:43 +0000994 /// \brief Build a new "if" statement.
995 ///
996 /// By default, performs semantic analysis to build the new statement.
997 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000998 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +0000999 VarDecl *CondVar, Stmt *Then,
1000 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001001 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001002 }
Mike Stump11289f42009-09-09 15:08:12 +00001003
Douglas Gregorebe10102009-08-20 07:17:43 +00001004 /// \brief Start building a new switch statement.
1005 ///
1006 /// By default, performs semantic analysis to build the new statement.
1007 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001008 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001009 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001010 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001011 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001012 }
Mike Stump11289f42009-09-09 15:08:12 +00001013
Douglas Gregorebe10102009-08-20 07:17:43 +00001014 /// \brief Attach the body to the switch statement.
1015 ///
1016 /// By default, performs semantic analysis to build the new statement.
1017 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001018 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001019 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001020 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001021 }
1022
1023 /// \brief Build a new while statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001027 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1028 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001029 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001030 }
Mike Stump11289f42009-09-09 15:08:12 +00001031
Douglas Gregorebe10102009-08-20 07:17:43 +00001032 /// \brief Build a new do-while statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001036 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001037 SourceLocation WhileLoc, SourceLocation LParenLoc,
1038 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001039 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1040 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 }
1042
1043 /// \brief Build a new for statement.
1044 ///
1045 /// By default, performs semantic analysis to build the new statement.
1046 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001047 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1048 Stmt *Init, Sema::FullExprArg Cond,
1049 VarDecl *CondVar, Sema::FullExprArg Inc,
1050 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001051 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001052 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001053 }
Mike Stump11289f42009-09-09 15:08:12 +00001054
Douglas Gregorebe10102009-08-20 07:17:43 +00001055 /// \brief Build a new goto statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001059 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1060 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001061 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 }
1063
1064 /// \brief Build a new indirect goto statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001068 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001069 SourceLocation StarLoc,
1070 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001071 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001072 }
Mike Stump11289f42009-09-09 15:08:12 +00001073
Douglas Gregorebe10102009-08-20 07:17:43 +00001074 /// \brief Build a new return statement.
1075 ///
1076 /// By default, performs semantic analysis to build the new statement.
1077 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001078 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001079 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 }
Mike Stump11289f42009-09-09 15:08:12 +00001081
Douglas Gregorebe10102009-08-20 07:17:43 +00001082 /// \brief Build a new declaration statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001086 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001087 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001088 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001089 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1090 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 }
Mike Stump11289f42009-09-09 15:08:12 +00001092
Anders Carlssonaaeef072010-01-24 05:50:09 +00001093 /// \brief Build a new inline asm statement.
1094 ///
1095 /// By default, performs semantic analysis to build the new statement.
1096 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001097 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001098 bool IsSimple,
1099 bool IsVolatile,
1100 unsigned NumOutputs,
1101 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001102 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001103 MultiExprArg Constraints,
1104 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001105 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001106 MultiExprArg Clobbers,
1107 SourceLocation RParenLoc,
1108 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001109 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001110 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001111 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001112 RParenLoc, MSAsm);
1113 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001114
1115 /// \brief Build a new Objective-C @try statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001119 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001120 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001121 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001122 Stmt *Finally) {
1123 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1124 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001125 }
1126
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001127 /// \brief Rebuild an Objective-C exception declaration.
1128 ///
1129 /// By default, performs semantic analysis to build the new declaration.
1130 /// Subclasses may override this routine to provide different behavior.
1131 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1132 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001133 return getSema().BuildObjCExceptionDecl(TInfo, T,
1134 ExceptionDecl->getInnerLocStart(),
1135 ExceptionDecl->getLocation(),
1136 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001137 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001138
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001139 /// \brief Build a new Objective-C @catch statement.
1140 ///
1141 /// By default, performs semantic analysis to build the new statement.
1142 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001143 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001144 SourceLocation RParenLoc,
1145 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001146 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001147 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001148 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001149 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001150
Douglas Gregor306de2f2010-04-22 23:59:56 +00001151 /// \brief Build a new Objective-C @finally statement.
1152 ///
1153 /// By default, performs semantic analysis to build the new statement.
1154 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001155 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001156 Stmt *Body) {
1157 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001158 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001159
Douglas Gregor6148de72010-04-22 22:01:21 +00001160 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001165 Expr *Operand) {
1166 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001167 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001168
Douglas Gregor6148de72010-04-22 22:01:21 +00001169 /// \brief Build a new Objective-C @synchronized statement.
1170 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001171 /// By default, performs semantic analysis to build the new statement.
1172 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001173 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001174 Expr *Object,
1175 Stmt *Body) {
1176 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1177 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001178 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001179
1180 /// \brief Build a new Objective-C fast enumeration statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001185 SourceLocation LParenLoc,
1186 Stmt *Element,
1187 Expr *Collection,
1188 SourceLocation RParenLoc,
1189 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001190 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001191 Element,
1192 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001193 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001194 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001195 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001196
Douglas Gregorebe10102009-08-20 07:17:43 +00001197 /// \brief Build a new C++ exception declaration.
1198 ///
1199 /// By default, performs semantic analysis to build the new decaration.
1200 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001201 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001202 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001203 SourceLocation StartLoc,
1204 SourceLocation IdLoc,
1205 IdentifierInfo *Id) {
1206 return getSema().BuildExceptionDeclaration(0, Declarator,
1207 StartLoc, IdLoc, Id);
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 }
1209
1210 /// \brief Build a new C++ catch statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001214 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001215 VarDecl *ExceptionDecl,
1216 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001217 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1218 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregorebe10102009-08-20 07:17:43 +00001221 /// \brief Build a new C++ try statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001225 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001226 Stmt *TryBlock,
1227 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001228 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001229 }
Mike Stump11289f42009-09-09 15:08:12 +00001230
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 /// \brief Build a new expression that references a declaration.
1232 ///
1233 /// By default, performs semantic analysis to build the new expression.
1234 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001235 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001236 LookupResult &R,
1237 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001238 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1239 }
1240
1241
1242 /// \brief Build a new expression that references a declaration.
1243 ///
1244 /// By default, performs semantic analysis to build the new expression.
1245 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001246 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001247 ValueDecl *VD,
1248 const DeclarationNameInfo &NameInfo,
1249 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001250 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001251 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001252
1253 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001254
1255 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001259 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001260 /// By default, performs semantic analysis to build the new expression.
1261 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001262 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001263 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001264 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001265 }
1266
Douglas Gregorad8a3362009-09-04 17:36:40 +00001267 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001268 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001269 /// By default, performs semantic analysis to build the new expression.
1270 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001271 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001272 SourceLocation OperatorLoc,
1273 bool isArrow,
1274 CXXScopeSpec &SS,
1275 TypeSourceInfo *ScopeType,
1276 SourceLocation CCLoc,
1277 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001278 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001279
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001281 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 /// By default, performs semantic analysis to build the new expression.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001285 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001286 Expr *SubExpr) {
1287 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 }
Mike Stump11289f42009-09-09 15:08:12 +00001289
Douglas Gregor882211c2010-04-28 22:16:22 +00001290 /// \brief Build a new builtin offsetof expression.
1291 ///
1292 /// By default, performs semantic analysis to build the new expression.
1293 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001294 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001295 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001296 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001297 unsigned NumComponents,
1298 SourceLocation RParenLoc) {
1299 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1300 NumComponents, RParenLoc);
1301 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001302
Peter Collingbournee190dee2011-03-11 19:24:49 +00001303 /// \brief Build a new sizeof, alignof or vec_step expression with a
1304 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001305 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 /// By default, performs semantic analysis to build the new expression.
1307 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001308 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1309 SourceLocation OpLoc,
1310 UnaryExprOrTypeTrait ExprKind,
1311 SourceRange R) {
1312 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 }
1314
Peter Collingbournee190dee2011-03-11 19:24:49 +00001315 /// \brief Build a new sizeof, alignof or vec step expression with an
1316 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001317 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 /// By default, performs semantic analysis to build the new expression.
1319 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001320 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1321 UnaryExprOrTypeTrait ExprKind,
1322 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001323 ExprResult Result
Peter Collingbournee190dee2011-03-11 19:24:49 +00001324 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001326 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001327
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 return move(Result);
1329 }
Mike Stump11289f42009-09-09 15:08:12 +00001330
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001332 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// By default, performs semantic analysis to build the new expression.
1334 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001335 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001337 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001339 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1340 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 RBracketLoc);
1342 }
1343
1344 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001345 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 /// By default, performs semantic analysis to build the new expression.
1347 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001348 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001350 SourceLocation RParenLoc,
1351 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001352 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001353 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 }
1355
1356 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001357 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 /// By default, performs semantic analysis to build the new expression.
1359 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001360 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001361 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001362 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001363 const DeclarationNameInfo &MemberNameInfo,
1364 ValueDecl *Member,
1365 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001366 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001367 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001368 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001369 // We have a reference to an unnamed field. This is always the
1370 // base of an anonymous struct/union member access, i.e. the
1371 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001372 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001373 assert(Member->getType()->isRecordType() &&
1374 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001375
Douglas Gregorea972d32011-02-28 21:54:11 +00001376 if (getSema().PerformObjectMemberConversion(Base,
1377 QualifierLoc.getNestedNameSpecifier(),
John McCall16df1e52010-03-30 21:47:33 +00001378 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001379 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001380
John McCall7decc9e2010-11-18 06:31:45 +00001381 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001382 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001383 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001384 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001385 cast<FieldDecl>(Member)->getType(),
1386 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001387 return getSema().Owned(ME);
1388 }
Mike Stump11289f42009-09-09 15:08:12 +00001389
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001390 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001391 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001392
John McCallb268a282010-08-23 23:25:46 +00001393 getSema().DefaultFunctionArrayConversion(Base);
1394 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001395
John McCall16df1e52010-03-30 21:47:33 +00001396 // FIXME: this involves duplicating earlier analysis in a lot of
1397 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001398 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001399 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001400 R.resolveKind();
1401
John McCallb268a282010-08-23 23:25:46 +00001402 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001403 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001404 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 }
Mike Stump11289f42009-09-09 15:08:12 +00001406
Douglas Gregora16548e2009-08-11 05:31:07 +00001407 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001408 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001411 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001412 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001413 Expr *LHS, Expr *RHS) {
1414 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 }
1416
1417 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001418 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 /// By default, performs semantic analysis to build the new expression.
1420 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001421 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001422 SourceLocation QuestionLoc,
1423 Expr *LHS,
1424 SourceLocation ColonLoc,
1425 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001426 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1427 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 }
1429
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001431 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 /// By default, performs semantic analysis to build the new expression.
1433 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001434 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001435 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001437 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001438 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001439 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 }
Mike Stump11289f42009-09-09 15:08:12 +00001441
Douglas Gregora16548e2009-08-11 05:31:07 +00001442 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001443 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 /// By default, performs semantic analysis to build the new expression.
1445 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001446 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001447 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001449 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001450 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001451 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 }
Mike Stump11289f42009-09-09 15:08:12 +00001453
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001455 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 /// By default, performs semantic analysis to build the new expression.
1457 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001458 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001459 SourceLocation OpLoc,
1460 SourceLocation AccessorLoc,
1461 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001462
John McCall10eae182009-11-30 22:42:35 +00001463 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001464 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001465 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001466 OpLoc, /*IsArrow*/ false,
1467 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001468 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001469 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 }
Mike Stump11289f42009-09-09 15:08:12 +00001471
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001473 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001476 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001478 SourceLocation RBraceLoc,
1479 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001480 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001481 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1482 if (Result.isInvalid() || ResultTy->isDependentType())
1483 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001484
Douglas Gregord3d93062009-11-09 17:16:50 +00001485 // Patch in the result type we were given, which may have been computed
1486 // when the initial InitListExpr was built.
1487 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1488 ILE->setType(ResultTy);
1489 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 }
Mike Stump11289f42009-09-09 15:08:12 +00001491
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001493 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 /// By default, performs semantic analysis to build the new expression.
1495 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001496 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 MultiExprArg ArrayExprs,
1498 SourceLocation EqualOrColonLoc,
1499 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001500 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001501 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001503 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001506
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 ArrayExprs.release();
1508 return move(Result);
1509 }
Mike Stump11289f42009-09-09 15:08:12 +00001510
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001512 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// By default, builds the implicit value initialization without performing
1514 /// any semantic analysis. Subclasses may override this routine to provide
1515 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001516 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1518 }
Mike Stump11289f42009-09-09 15:08:12 +00001519
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001521 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001524 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001525 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001526 SourceLocation RParenLoc) {
1527 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001528 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001529 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 }
1531
1532 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001533 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 /// By default, performs semantic analysis to build the new expression.
1535 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001536 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 MultiExprArg SubExprs,
1538 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001539 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001540 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 }
Mike Stump11289f42009-09-09 15:08:12 +00001542
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001544 ///
1545 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 /// rather than attempting to map the label statement itself.
1547 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001548 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001549 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001550 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 }
Mike Stump11289f42009-09-09 15:08:12 +00001552
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001554 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 /// By default, performs semantic analysis to build the new expression.
1556 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001557 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001558 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001560 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 }
Mike Stump11289f42009-09-09 15:08:12 +00001562
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 /// \brief Build a new __builtin_choose_expr expression.
1564 ///
1565 /// By default, performs semantic analysis to build the new expression.
1566 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001567 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001568 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 SourceLocation RParenLoc) {
1570 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001571 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 RParenLoc);
1573 }
Mike Stump11289f42009-09-09 15:08:12 +00001574
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 /// \brief Build a new overloaded operator call expression.
1576 ///
1577 /// By default, performs semantic analysis to build the new expression.
1578 /// The semantic analysis provides the behavior of template instantiation,
1579 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001580 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 /// argument-dependent lookup, etc. Subclasses may override this routine to
1582 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001583 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001585 Expr *Callee,
1586 Expr *First,
1587 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001588
1589 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 /// reinterpret_cast.
1591 ///
1592 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001593 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001595 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 Stmt::StmtClass Class,
1597 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001598 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 SourceLocation RAngleLoc,
1600 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001601 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 SourceLocation RParenLoc) {
1603 switch (Class) {
1604 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001605 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001606 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001607 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001608
1609 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001610 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001611 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001612 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001613
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001615 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001616 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001617 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001619
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001621 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001622 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001623 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001624
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 default:
1626 assert(false && "Invalid C++ named cast");
1627 break;
1628 }
Mike Stump11289f42009-09-09 15:08:12 +00001629
John McCallfaf5fb42010-08-26 23:41:50 +00001630 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 }
Mike Stump11289f42009-09-09 15:08:12 +00001632
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 /// \brief Build a new C++ static_cast expression.
1634 ///
1635 /// By default, performs semantic analysis to build the new expression.
1636 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001637 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001639 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SourceLocation RAngleLoc,
1641 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001642 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001644 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001645 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001646 SourceRange(LAngleLoc, RAngleLoc),
1647 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 }
1649
1650 /// \brief Build a new C++ dynamic_cast expression.
1651 ///
1652 /// By default, performs semantic analysis to build the new expression.
1653 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001654 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001656 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 SourceLocation RAngleLoc,
1658 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001659 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001661 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001662 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001663 SourceRange(LAngleLoc, RAngleLoc),
1664 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 }
1666
1667 /// \brief Build a new C++ reinterpret_cast expression.
1668 ///
1669 /// By default, performs semantic analysis to build the new expression.
1670 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001671 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001673 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 SourceLocation RAngleLoc,
1675 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001676 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001678 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001679 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001680 SourceRange(LAngleLoc, RAngleLoc),
1681 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 }
1683
1684 /// \brief Build a new C++ const_cast expression.
1685 ///
1686 /// By default, performs semantic analysis to build the new expression.
1687 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001688 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001690 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 SourceLocation RAngleLoc,
1692 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001693 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001695 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001696 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001697 SourceRange(LAngleLoc, RAngleLoc),
1698 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001699 }
Mike Stump11289f42009-09-09 15:08:12 +00001700
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 /// \brief Build a new C++ functional-style cast expression.
1702 ///
1703 /// By default, performs semantic analysis to build the new expression.
1704 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001705 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1706 SourceLocation LParenLoc,
1707 Expr *Sub,
1708 SourceLocation RParenLoc) {
1709 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001710 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 RParenLoc);
1712 }
Mike Stump11289f42009-09-09 15:08:12 +00001713
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 /// \brief Build a new C++ typeid(type) expression.
1715 ///
1716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001718 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001719 SourceLocation TypeidLoc,
1720 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001722 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001723 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 }
Mike Stump11289f42009-09-09 15:08:12 +00001725
Francois Pichet9f4f2072010-09-08 12:20:18 +00001726
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 /// \brief Build a new C++ typeid(expr) expression.
1728 ///
1729 /// By default, performs semantic analysis to build the new expression.
1730 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001731 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001732 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001733 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001734 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001735 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001736 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001737 }
1738
Francois Pichet9f4f2072010-09-08 12:20:18 +00001739 /// \brief Build a new C++ __uuidof(type) expression.
1740 ///
1741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
1743 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1744 SourceLocation TypeidLoc,
1745 TypeSourceInfo *Operand,
1746 SourceLocation RParenLoc) {
1747 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1748 RParenLoc);
1749 }
1750
1751 /// \brief Build a new C++ __uuidof(expr) expression.
1752 ///
1753 /// By default, performs semantic analysis to build the new expression.
1754 /// Subclasses may override this routine to provide different behavior.
1755 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1756 SourceLocation TypeidLoc,
1757 Expr *Operand,
1758 SourceLocation RParenLoc) {
1759 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1760 RParenLoc);
1761 }
1762
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 /// \brief Build a new C++ "this" expression.
1764 ///
1765 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001766 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001768 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001769 QualType ThisType,
1770 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001772 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1773 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 }
1775
1776 /// \brief Build a new C++ throw expression.
1777 ///
1778 /// By default, performs semantic analysis to build the new expression.
1779 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001780 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001781 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 }
1783
1784 /// \brief Build a new C++ default-argument expression.
1785 ///
1786 /// By default, builds a new default-argument expression, which does not
1787 /// require any semantic analysis. Subclasses may override this routine to
1788 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001789 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001790 ParmVarDecl *Param) {
1791 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1792 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 }
1794
1795 /// \brief Build a new C++ zero-initialization expression.
1796 ///
1797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001799 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1800 SourceLocation LParenLoc,
1801 SourceLocation RParenLoc) {
1802 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001803 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001804 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 }
Mike Stump11289f42009-09-09 15:08:12 +00001806
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 /// \brief Build a new C++ "new" expression.
1808 ///
1809 /// By default, performs semantic analysis to build the new expression.
1810 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001811 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001812 bool UseGlobal,
1813 SourceLocation PlacementLParen,
1814 MultiExprArg PlacementArgs,
1815 SourceLocation PlacementRParen,
1816 SourceRange TypeIdParens,
1817 QualType AllocatedType,
1818 TypeSourceInfo *AllocatedTypeInfo,
1819 Expr *ArraySize,
1820 SourceLocation ConstructorLParen,
1821 MultiExprArg ConstructorArgs,
1822 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001823 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 PlacementLParen,
1825 move(PlacementArgs),
1826 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001827 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001828 AllocatedType,
1829 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001830 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 ConstructorLParen,
1832 move(ConstructorArgs),
1833 ConstructorRParen);
1834 }
Mike Stump11289f42009-09-09 15:08:12 +00001835
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 /// \brief Build a new C++ "delete" expression.
1837 ///
1838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001840 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 bool IsGlobalDelete,
1842 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001843 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001845 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 }
Mike Stump11289f42009-09-09 15:08:12 +00001847
Douglas Gregora16548e2009-08-11 05:31:07 +00001848 /// \brief Build a new unary type trait expression.
1849 ///
1850 /// By default, performs semantic analysis to build the new expression.
1851 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001852 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001853 SourceLocation StartLoc,
1854 TypeSourceInfo *T,
1855 SourceLocation RParenLoc) {
1856 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001857 }
1858
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001859 /// \brief Build a new binary type trait expression.
1860 ///
1861 /// By default, performs semantic analysis to build the new expression.
1862 /// Subclasses may override this routine to provide different behavior.
1863 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1864 SourceLocation StartLoc,
1865 TypeSourceInfo *LhsT,
1866 TypeSourceInfo *RhsT,
1867 SourceLocation RParenLoc) {
1868 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1869 }
1870
Mike Stump11289f42009-09-09 15:08:12 +00001871 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001872 /// expression.
1873 ///
1874 /// By default, performs semantic analysis to build the new expression.
1875 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001876 ExprResult RebuildDependentScopeDeclRefExpr(
1877 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001878 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001879 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001881 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001882
1883 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001884 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001885 *TemplateArgs);
1886
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001887 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 }
1889
1890 /// \brief Build a new template-id expression.
1891 ///
1892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001894 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001895 LookupResult &R,
1896 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001897 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001898 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 }
1900
1901 /// \brief Build a new object-construction expression.
1902 ///
1903 /// By default, performs semantic analysis to build the new expression.
1904 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001905 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001906 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001907 CXXConstructorDecl *Constructor,
1908 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001909 MultiExprArg Args,
1910 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001911 CXXConstructExpr::ConstructionKind ConstructKind,
1912 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001913 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001914 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001915 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001916 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001917
Douglas Gregordb121ba2009-12-14 16:27:04 +00001918 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001919 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001920 RequiresZeroInit, ConstructKind,
1921 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 }
1923
1924 /// \brief Build a new object-construction expression.
1925 ///
1926 /// By default, performs semantic analysis to build the new expression.
1927 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001928 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1929 SourceLocation LParenLoc,
1930 MultiExprArg Args,
1931 SourceLocation RParenLoc) {
1932 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 LParenLoc,
1934 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 RParenLoc);
1936 }
1937
1938 /// \brief Build a new object-construction expression.
1939 ///
1940 /// By default, performs semantic analysis to build the new expression.
1941 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001942 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1943 SourceLocation LParenLoc,
1944 MultiExprArg Args,
1945 SourceLocation RParenLoc) {
1946 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 LParenLoc,
1948 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 RParenLoc);
1950 }
Mike Stump11289f42009-09-09 15:08:12 +00001951
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 /// \brief Build a new member reference expression.
1953 ///
1954 /// By default, performs semantic analysis to build the new expression.
1955 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001956 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00001957 QualType BaseType,
1958 bool IsArrow,
1959 SourceLocation OperatorLoc,
1960 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00001961 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001962 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001963 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00001965 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001966
John McCallb268a282010-08-23 23:25:46 +00001967 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001968 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001969 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001970 MemberNameInfo,
1971 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 }
1973
John McCall10eae182009-11-30 22:42:35 +00001974 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001975 ///
1976 /// By default, performs semantic analysis to build the new expression.
1977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001978 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001979 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001980 SourceLocation OperatorLoc,
1981 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00001982 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00001983 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001984 LookupResult &R,
1985 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001986 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00001987 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001988
John McCallb268a282010-08-23 23:25:46 +00001989 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001990 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001991 SS, FirstQualifierInScope,
1992 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001993 }
Mike Stump11289f42009-09-09 15:08:12 +00001994
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001995 /// \brief Build a new noexcept expression.
1996 ///
1997 /// By default, performs semantic analysis to build the new expression.
1998 /// Subclasses may override this routine to provide different behavior.
1999 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2000 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2001 }
2002
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002003 /// \brief Build a new expression to compute the length of a parameter pack.
2004 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2005 SourceLocation PackLoc,
2006 SourceLocation RParenLoc,
2007 unsigned Length) {
2008 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2009 OperatorLoc, Pack, PackLoc,
2010 RParenLoc, Length);
2011 }
2012
Douglas Gregora16548e2009-08-11 05:31:07 +00002013 /// \brief Build a new Objective-C @encode expression.
2014 ///
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002017 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002018 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002020 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002022 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002023
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002024 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002025 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002026 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002027 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002028 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002029 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002030 MultiExprArg Args,
2031 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002032 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2033 ReceiverTypeInfo->getType(),
2034 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002035 Sel, Method, LBracLoc, SelectorLoc,
2036 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002037 }
2038
2039 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002040 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002041 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002042 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002043 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002044 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002045 MultiExprArg Args,
2046 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002047 return SemaRef.BuildInstanceMessage(Receiver,
2048 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002049 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002050 Sel, Method, LBracLoc, SelectorLoc,
2051 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002052 }
2053
Douglas Gregord51d90d2010-04-26 20:11:03 +00002054 /// \brief Build a new Objective-C ivar reference expression.
2055 ///
2056 /// By default, performs semantic analysis to build the new expression.
2057 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002058 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002059 SourceLocation IvarLoc,
2060 bool IsArrow, bool IsFreeIvar) {
2061 // FIXME: We lose track of the IsFreeIvar bit.
2062 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002063 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002064 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2065 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002066 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002067 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002068 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002069 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002070 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002071 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002072
Douglas Gregord51d90d2010-04-26 20:11:03 +00002073 if (Result.get())
2074 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002075
John McCallb268a282010-08-23 23:25:46 +00002076 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002077 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002078 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002079 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002080 /*TemplateArgs=*/0);
2081 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002082
2083 /// \brief Build a new Objective-C property reference expression.
2084 ///
2085 /// By default, performs semantic analysis to build the new expression.
2086 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002087 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002088 ObjCPropertyDecl *Property,
2089 SourceLocation PropertyLoc) {
2090 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002091 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002092 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2093 Sema::LookupMemberName);
2094 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002095 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002096 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002097 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002098 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002099 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002100
Douglas Gregor9faee212010-04-26 20:47:02 +00002101 if (Result.get())
2102 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002103
John McCallb268a282010-08-23 23:25:46 +00002104 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002105 /*FIXME:*/PropertyLoc, IsArrow,
2106 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002107 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002108 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002109 /*TemplateArgs=*/0);
2110 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002111
John McCallb7bd14f2010-12-02 01:19:52 +00002112 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002113 ///
2114 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002115 /// Subclasses may override this routine to provide different behavior.
2116 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2117 ObjCMethodDecl *Getter,
2118 ObjCMethodDecl *Setter,
2119 SourceLocation PropertyLoc) {
2120 // Since these expressions can only be value-dependent, we do not
2121 // need to perform semantic analysis again.
2122 return Owned(
2123 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2124 VK_LValue, OK_ObjCProperty,
2125 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002126 }
2127
Douglas Gregord51d90d2010-04-26 20:11:03 +00002128 /// \brief Build a new Objective-C "isa" expression.
2129 ///
2130 /// By default, performs semantic analysis to build the new expression.
2131 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002132 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002133 bool IsArrow) {
2134 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002135 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002136 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2137 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002138 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002139 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002140 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002141 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002142 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002143
Douglas Gregord51d90d2010-04-26 20:11:03 +00002144 if (Result.get())
2145 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002146
John McCallb268a282010-08-23 23:25:46 +00002147 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002148 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002149 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002150 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002151 /*TemplateArgs=*/0);
2152 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002153
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 /// \brief Build a new shuffle vector expression.
2155 ///
2156 /// By default, performs semantic analysis to build the new expression.
2157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002158 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002159 MultiExprArg SubExprs,
2160 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002162 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2164 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2165 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2166 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002167
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 // Build a reference to the __builtin_shufflevector builtin
2169 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002170 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002172 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002174
2175 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 unsigned NumSubExprs = SubExprs.size();
2177 Expr **Subs = (Expr **)SubExprs.release();
2178 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2179 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002180 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002181 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002184
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002186 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002188 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002189
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002191 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 }
John McCall31f82722010-11-12 08:19:04 +00002193
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002194 /// \brief Build a new template argument pack expansion.
2195 ///
2196 /// By default, performs semantic analysis to build a new pack expansion
2197 /// for a template argument. Subclasses may override this routine to provide
2198 /// different behavior.
2199 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002200 SourceLocation EllipsisLoc,
2201 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002202 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002203 case TemplateArgument::Expression: {
2204 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002205 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2206 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002207 if (Result.isInvalid())
2208 return TemplateArgumentLoc();
2209
2210 return TemplateArgumentLoc(Result.get(), Result.get());
2211 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002212
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002213 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002214 return TemplateArgumentLoc(TemplateArgument(
2215 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002216 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002217 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002218 Pattern.getTemplateNameLoc(),
2219 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002220
2221 case TemplateArgument::Null:
2222 case TemplateArgument::Integral:
2223 case TemplateArgument::Declaration:
2224 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002225 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002226 llvm_unreachable("Pack expansion pattern has no parameter packs");
2227
2228 case TemplateArgument::Type:
2229 if (TypeSourceInfo *Expansion
2230 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002231 EllipsisLoc,
2232 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002233 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2234 Expansion);
2235 break;
2236 }
2237
2238 return TemplateArgumentLoc();
2239 }
2240
Douglas Gregor968f23a2011-01-03 19:31:53 +00002241 /// \brief Build a new expression pack expansion.
2242 ///
2243 /// By default, performs semantic analysis to build a new pack expansion
2244 /// for an expression. Subclasses may override this routine to provide
2245 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002246 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2247 llvm::Optional<unsigned> NumExpansions) {
2248 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002249 }
2250
John McCall31f82722010-11-12 08:19:04 +00002251private:
Douglas Gregor14454802011-02-25 02:25:35 +00002252 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2253 QualType ObjectType,
2254 NamedDecl *FirstQualifierInScope,
2255 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002256
2257 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2258 QualType ObjectType,
2259 NamedDecl *FirstQualifierInScope,
2260 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002261};
Douglas Gregora16548e2009-08-11 05:31:07 +00002262
Douglas Gregorebe10102009-08-20 07:17:43 +00002263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002264StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002265 if (!S)
2266 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002267
Douglas Gregorebe10102009-08-20 07:17:43 +00002268 switch (S->getStmtClass()) {
2269 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002270
Douglas Gregorebe10102009-08-20 07:17:43 +00002271 // Transform individual statement nodes
2272#define STMT(Node, Parent) \
2273 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002274#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002275#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002276#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002277
Douglas Gregorebe10102009-08-20 07:17:43 +00002278 // Transform expressions by calling TransformExpr.
2279#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002280#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002281#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002282#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002283 {
John McCalldadc5752010-08-24 06:29:42 +00002284 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002285 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002286 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002287
John McCallb268a282010-08-23 23:25:46 +00002288 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002289 }
Mike Stump11289f42009-09-09 15:08:12 +00002290 }
2291
John McCallc3007a22010-10-26 07:05:15 +00002292 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002293}
Mike Stump11289f42009-09-09 15:08:12 +00002294
2295
Douglas Gregore922c772009-08-04 22:27:00 +00002296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002297ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002298 if (!E)
2299 return SemaRef.Owned(E);
2300
2301 switch (E->getStmtClass()) {
2302 case Stmt::NoStmtClass: break;
2303#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002304#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002305#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002306 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002307#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002308 }
2309
John McCallc3007a22010-10-26 07:05:15 +00002310 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002311}
2312
2313template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002314bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2315 unsigned NumInputs,
2316 bool IsCall,
2317 llvm::SmallVectorImpl<Expr *> &Outputs,
2318 bool *ArgChanged) {
2319 for (unsigned I = 0; I != NumInputs; ++I) {
2320 // If requested, drop call arguments that need to be dropped.
2321 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2322 if (ArgChanged)
2323 *ArgChanged = true;
2324
2325 break;
2326 }
2327
Douglas Gregor968f23a2011-01-03 19:31:53 +00002328 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2329 Expr *Pattern = Expansion->getPattern();
2330
2331 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2332 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2333 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2334
2335 // Determine whether the set of unexpanded parameter packs can and should
2336 // be expanded.
2337 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002338 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002339 llvm::Optional<unsigned> OrigNumExpansions
2340 = Expansion->getNumExpansions();
2341 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002342 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2343 Pattern->getSourceRange(),
2344 Unexpanded.data(),
2345 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002346 Expand, RetainExpansion,
2347 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002348 return true;
2349
2350 if (!Expand) {
2351 // The transform has determined that we should perform a simple
2352 // transformation on the pack expansion, producing another pack
2353 // expansion.
2354 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2355 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2356 if (OutPattern.isInvalid())
2357 return true;
2358
2359 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002360 Expansion->getEllipsisLoc(),
2361 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002362 if (Out.isInvalid())
2363 return true;
2364
2365 if (ArgChanged)
2366 *ArgChanged = true;
2367 Outputs.push_back(Out.get());
2368 continue;
2369 }
2370
2371 // The transform has determined that we should perform an elementwise
2372 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002373 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002374 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2375 ExprResult Out = getDerived().TransformExpr(Pattern);
2376 if (Out.isInvalid())
2377 return true;
2378
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002379 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002380 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2381 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002382 if (Out.isInvalid())
2383 return true;
2384 }
2385
Douglas Gregor968f23a2011-01-03 19:31:53 +00002386 if (ArgChanged)
2387 *ArgChanged = true;
2388 Outputs.push_back(Out.get());
2389 }
2390
2391 continue;
2392 }
2393
Douglas Gregora3efea12011-01-03 19:04:46 +00002394 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2395 if (Result.isInvalid())
2396 return true;
2397
2398 if (Result.get() != Inputs[I] && ArgChanged)
2399 *ArgChanged = true;
2400
2401 Outputs.push_back(Result.get());
2402 }
2403
2404 return false;
2405}
2406
2407template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002408NestedNameSpecifierLoc
2409TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2410 NestedNameSpecifierLoc NNS,
2411 QualType ObjectType,
2412 NamedDecl *FirstQualifierInScope) {
2413 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2414 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2415 Qualifier = Qualifier.getPrefix())
2416 Qualifiers.push_back(Qualifier);
2417
2418 CXXScopeSpec SS;
2419 while (!Qualifiers.empty()) {
2420 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2421 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2422
2423 switch (QNNS->getKind()) {
2424 case NestedNameSpecifier::Identifier:
2425 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2426 *QNNS->getAsIdentifier(),
2427 Q.getLocalBeginLoc(),
2428 Q.getLocalEndLoc(),
2429 ObjectType, false, SS,
2430 FirstQualifierInScope, false))
2431 return NestedNameSpecifierLoc();
2432
2433 break;
2434
2435 case NestedNameSpecifier::Namespace: {
2436 NamespaceDecl *NS
2437 = cast_or_null<NamespaceDecl>(
2438 getDerived().TransformDecl(
2439 Q.getLocalBeginLoc(),
2440 QNNS->getAsNamespace()));
2441 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2442 break;
2443 }
2444
2445 case NestedNameSpecifier::NamespaceAlias: {
2446 NamespaceAliasDecl *Alias
2447 = cast_or_null<NamespaceAliasDecl>(
2448 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2449 QNNS->getAsNamespaceAlias()));
2450 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2451 Q.getLocalEndLoc());
2452 break;
2453 }
2454
2455 case NestedNameSpecifier::Global:
2456 // There is no meaningful transformation that one could perform on the
2457 // global scope.
2458 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2459 break;
2460
2461 case NestedNameSpecifier::TypeSpecWithTemplate:
2462 case NestedNameSpecifier::TypeSpec: {
2463 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2464 FirstQualifierInScope, SS);
2465
2466 if (!TL)
2467 return NestedNameSpecifierLoc();
2468
2469 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2470 (SemaRef.getLangOptions().CPlusPlus0x &&
2471 TL.getType()->isEnumeralType())) {
2472 assert(!TL.getType().hasLocalQualifiers() &&
2473 "Can't get cv-qualifiers here");
2474 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2475 Q.getLocalEndLoc());
2476 break;
2477 }
2478
2479 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2480 << TL.getType() << SS.getRange();
2481 return NestedNameSpecifierLoc();
2482 }
Douglas Gregore16af532011-02-28 18:50:33 +00002483 }
Douglas Gregor14454802011-02-25 02:25:35 +00002484
Douglas Gregore16af532011-02-28 18:50:33 +00002485 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002486 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002487 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002488 }
2489
2490 // Don't rebuild the nested-name-specifier if we don't have to.
2491 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2492 !getDerived().AlwaysRebuild())
2493 return NNS;
2494
2495 // If we can re-use the source-location data from the original
2496 // nested-name-specifier, do so.
2497 if (SS.location_size() == NNS.getDataLength() &&
2498 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2499 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2500
2501 // Allocate new nested-name-specifier location information.
2502 return SS.getWithLocInContext(SemaRef.Context);
2503}
2504
2505template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002506DeclarationNameInfo
2507TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002508::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002509 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002510 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002511 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002512
2513 switch (Name.getNameKind()) {
2514 case DeclarationName::Identifier:
2515 case DeclarationName::ObjCZeroArgSelector:
2516 case DeclarationName::ObjCOneArgSelector:
2517 case DeclarationName::ObjCMultiArgSelector:
2518 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002519 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002520 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002521 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002522
Douglas Gregorf816bd72009-09-03 22:13:48 +00002523 case DeclarationName::CXXConstructorName:
2524 case DeclarationName::CXXDestructorName:
2525 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002526 TypeSourceInfo *NewTInfo;
2527 CanQualType NewCanTy;
2528 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002529 NewTInfo = getDerived().TransformType(OldTInfo);
2530 if (!NewTInfo)
2531 return DeclarationNameInfo();
2532 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002533 }
2534 else {
2535 NewTInfo = 0;
2536 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002537 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002538 if (NewT.isNull())
2539 return DeclarationNameInfo();
2540 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2541 }
Mike Stump11289f42009-09-09 15:08:12 +00002542
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002543 DeclarationName NewName
2544 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2545 NewCanTy);
2546 DeclarationNameInfo NewNameInfo(NameInfo);
2547 NewNameInfo.setName(NewName);
2548 NewNameInfo.setNamedTypeInfo(NewTInfo);
2549 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002550 }
Mike Stump11289f42009-09-09 15:08:12 +00002551 }
2552
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002553 assert(0 && "Unknown name kind.");
2554 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002555}
2556
2557template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002558TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002559TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2560 TemplateName Name,
2561 SourceLocation NameLoc,
2562 QualType ObjectType,
2563 NamedDecl *FirstQualifierInScope) {
2564 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2565 TemplateDecl *Template = QTN->getTemplateDecl();
2566 assert(Template && "qualified template name must refer to a template");
2567
2568 TemplateDecl *TransTemplate
2569 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2570 Template));
2571 if (!TransTemplate)
2572 return TemplateName();
2573
2574 if (!getDerived().AlwaysRebuild() &&
2575 SS.getScopeRep() == QTN->getQualifier() &&
2576 TransTemplate == Template)
2577 return Name;
2578
2579 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2580 TransTemplate);
2581 }
2582
2583 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2584 if (SS.getScopeRep()) {
2585 // These apply to the scope specifier, not the template.
2586 ObjectType = QualType();
2587 FirstQualifierInScope = 0;
2588 }
2589
2590 if (!getDerived().AlwaysRebuild() &&
2591 SS.getScopeRep() == DTN->getQualifier() &&
2592 ObjectType.isNull())
2593 return Name;
2594
2595 if (DTN->isIdentifier()) {
2596 return getDerived().RebuildTemplateName(SS,
2597 *DTN->getIdentifier(),
2598 NameLoc,
2599 ObjectType,
2600 FirstQualifierInScope);
2601 }
2602
2603 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2604 ObjectType);
2605 }
2606
2607 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2608 TemplateDecl *TransTemplate
2609 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2610 Template));
2611 if (!TransTemplate)
2612 return TemplateName();
2613
2614 if (!getDerived().AlwaysRebuild() &&
2615 TransTemplate == Template)
2616 return Name;
2617
2618 return TemplateName(TransTemplate);
2619 }
2620
2621 if (SubstTemplateTemplateParmPackStorage *SubstPack
2622 = Name.getAsSubstTemplateTemplateParmPack()) {
2623 TemplateTemplateParmDecl *TransParam
2624 = cast_or_null<TemplateTemplateParmDecl>(
2625 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2626 if (!TransParam)
2627 return TemplateName();
2628
2629 if (!getDerived().AlwaysRebuild() &&
2630 TransParam == SubstPack->getParameterPack())
2631 return Name;
2632
2633 return getDerived().RebuildTemplateName(TransParam,
2634 SubstPack->getArgumentPack());
2635 }
2636
2637 // These should be getting filtered out before they reach the AST.
2638 llvm_unreachable("overloaded function decl survived to here");
2639 return TemplateName();
2640}
2641
2642template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002643void TreeTransform<Derived>::InventTemplateArgumentLoc(
2644 const TemplateArgument &Arg,
2645 TemplateArgumentLoc &Output) {
2646 SourceLocation Loc = getDerived().getBaseLocation();
2647 switch (Arg.getKind()) {
2648 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002649 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002650 break;
2651
2652 case TemplateArgument::Type:
2653 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002654 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002655
John McCall0ad16662009-10-29 08:12:44 +00002656 break;
2657
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002658 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002659 case TemplateArgument::TemplateExpansion: {
2660 NestedNameSpecifierLocBuilder Builder;
2661 TemplateName Template = Arg.getAsTemplate();
2662 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2663 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2664 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2665 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2666
2667 if (Arg.getKind() == TemplateArgument::Template)
2668 Output = TemplateArgumentLoc(Arg,
2669 Builder.getWithLocInContext(SemaRef.Context),
2670 Loc);
2671 else
2672 Output = TemplateArgumentLoc(Arg,
2673 Builder.getWithLocInContext(SemaRef.Context),
2674 Loc, Loc);
2675
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002676 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002677 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002678
John McCall0ad16662009-10-29 08:12:44 +00002679 case TemplateArgument::Expression:
2680 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2681 break;
2682
2683 case TemplateArgument::Declaration:
2684 case TemplateArgument::Integral:
2685 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002686 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002687 break;
2688 }
2689}
2690
2691template<typename Derived>
2692bool TreeTransform<Derived>::TransformTemplateArgument(
2693 const TemplateArgumentLoc &Input,
2694 TemplateArgumentLoc &Output) {
2695 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002696 switch (Arg.getKind()) {
2697 case TemplateArgument::Null:
2698 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002699 Output = Input;
2700 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002701
Douglas Gregore922c772009-08-04 22:27:00 +00002702 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002703 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002704 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002705 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002706
2707 DI = getDerived().TransformType(DI);
2708 if (!DI) return true;
2709
2710 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2711 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002712 }
Mike Stump11289f42009-09-09 15:08:12 +00002713
Douglas Gregore922c772009-08-04 22:27:00 +00002714 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002715 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002716 DeclarationName Name;
2717 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2718 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002719 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002720 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002721 if (!D) return true;
2722
John McCall0d07eb32009-10-29 18:45:58 +00002723 Expr *SourceExpr = Input.getSourceDeclExpression();
2724 if (SourceExpr) {
2725 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002726 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002727 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002728 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002729 }
2730
2731 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002732 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002733 }
Mike Stump11289f42009-09-09 15:08:12 +00002734
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002735 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002736 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2737 if (QualifierLoc) {
2738 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2739 if (!QualifierLoc)
2740 return true;
2741 }
2742
Douglas Gregordf846d12011-03-02 18:46:51 +00002743 CXXScopeSpec SS;
2744 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002745 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002746 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2747 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002748 if (Template.isNull())
2749 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002750
Douglas Gregor9d802122011-03-02 17:09:35 +00002751 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002752 Input.getTemplateNameLoc());
2753 return false;
2754 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002755
2756 case TemplateArgument::TemplateExpansion:
2757 llvm_unreachable("Caller should expand pack expansions");
2758
Douglas Gregore922c772009-08-04 22:27:00 +00002759 case TemplateArgument::Expression: {
2760 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002761 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002762 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002763
John McCall0ad16662009-10-29 08:12:44 +00002764 Expr *InputExpr = Input.getSourceExpression();
2765 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2766
John McCalldadc5752010-08-24 06:29:42 +00002767 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002768 = getDerived().TransformExpr(InputExpr);
2769 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002770 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002771 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002772 }
Mike Stump11289f42009-09-09 15:08:12 +00002773
Douglas Gregore922c772009-08-04 22:27:00 +00002774 case TemplateArgument::Pack: {
2775 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2776 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002777 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002778 AEnd = Arg.pack_end();
2779 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002780
John McCall0ad16662009-10-29 08:12:44 +00002781 // FIXME: preserve source information here when we start
2782 // caring about parameter packs.
2783
John McCall0d07eb32009-10-29 18:45:58 +00002784 TemplateArgumentLoc InputArg;
2785 TemplateArgumentLoc OutputArg;
2786 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2787 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002788 return true;
2789
John McCall0d07eb32009-10-29 18:45:58 +00002790 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002791 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002792
2793 TemplateArgument *TransformedArgsPtr
2794 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2795 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2796 TransformedArgsPtr);
2797 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2798 TransformedArgs.size()),
2799 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002800 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002801 }
2802 }
Mike Stump11289f42009-09-09 15:08:12 +00002803
Douglas Gregore922c772009-08-04 22:27:00 +00002804 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002805 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002806}
2807
Douglas Gregorfe921a72010-12-20 23:36:19 +00002808/// \brief Iterator adaptor that invents template argument location information
2809/// for each of the template arguments in its underlying iterator.
2810template<typename Derived, typename InputIterator>
2811class TemplateArgumentLocInventIterator {
2812 TreeTransform<Derived> &Self;
2813 InputIterator Iter;
2814
2815public:
2816 typedef TemplateArgumentLoc value_type;
2817 typedef TemplateArgumentLoc reference;
2818 typedef typename std::iterator_traits<InputIterator>::difference_type
2819 difference_type;
2820 typedef std::input_iterator_tag iterator_category;
2821
2822 class pointer {
2823 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002824
Douglas Gregorfe921a72010-12-20 23:36:19 +00002825 public:
2826 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2827
2828 const TemplateArgumentLoc *operator->() const { return &Arg; }
2829 };
2830
2831 TemplateArgumentLocInventIterator() { }
2832
2833 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2834 InputIterator Iter)
2835 : Self(Self), Iter(Iter) { }
2836
2837 TemplateArgumentLocInventIterator &operator++() {
2838 ++Iter;
2839 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002840 }
2841
Douglas Gregorfe921a72010-12-20 23:36:19 +00002842 TemplateArgumentLocInventIterator operator++(int) {
2843 TemplateArgumentLocInventIterator Old(*this);
2844 ++(*this);
2845 return Old;
2846 }
2847
2848 reference operator*() const {
2849 TemplateArgumentLoc Result;
2850 Self.InventTemplateArgumentLoc(*Iter, Result);
2851 return Result;
2852 }
2853
2854 pointer operator->() const { return pointer(**this); }
2855
2856 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2857 const TemplateArgumentLocInventIterator &Y) {
2858 return X.Iter == Y.Iter;
2859 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002860
Douglas Gregorfe921a72010-12-20 23:36:19 +00002861 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2862 const TemplateArgumentLocInventIterator &Y) {
2863 return X.Iter != Y.Iter;
2864 }
2865};
2866
Douglas Gregor42cafa82010-12-20 17:42:22 +00002867template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002868template<typename InputIterator>
2869bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2870 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002871 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002872 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002873 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002874 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002875
2876 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2877 // Unpack argument packs, which we translate them into separate
2878 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002879 // FIXME: We could do much better if we could guarantee that the
2880 // TemplateArgumentLocInfo for the pack expansion would be usable for
2881 // all of the template arguments in the argument pack.
2882 typedef TemplateArgumentLocInventIterator<Derived,
2883 TemplateArgument::pack_iterator>
2884 PackLocIterator;
2885 if (TransformTemplateArguments(PackLocIterator(*this,
2886 In.getArgument().pack_begin()),
2887 PackLocIterator(*this,
2888 In.getArgument().pack_end()),
2889 Outputs))
2890 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002891
2892 continue;
2893 }
2894
2895 if (In.getArgument().isPackExpansion()) {
2896 // We have a pack expansion, for which we will be substituting into
2897 // the pattern.
2898 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002899 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002900 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002901 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2902 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002903
2904 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2905 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2906 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2907
2908 // Determine whether the set of unexpanded parameter packs can and should
2909 // be expanded.
2910 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002911 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002912 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002913 if (getDerived().TryExpandParameterPacks(Ellipsis,
2914 Pattern.getSourceRange(),
2915 Unexpanded.data(),
2916 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002917 Expand,
2918 RetainExpansion,
2919 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002920 return true;
2921
2922 if (!Expand) {
2923 // The transform has determined that we should perform a simple
2924 // transformation on the pack expansion, producing another pack
2925 // expansion.
2926 TemplateArgumentLoc OutPattern;
2927 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2928 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2929 return true;
2930
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002931 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2932 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002933 if (Out.getArgument().isNull())
2934 return true;
2935
2936 Outputs.addArgument(Out);
2937 continue;
2938 }
2939
2940 // The transform has determined that we should perform an elementwise
2941 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002942 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002943 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2944
2945 if (getDerived().TransformTemplateArgument(Pattern, Out))
2946 return true;
2947
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002948 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002949 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2950 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002951 if (Out.getArgument().isNull())
2952 return true;
2953 }
2954
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002955 Outputs.addArgument(Out);
2956 }
2957
Douglas Gregor48d24112011-01-10 20:53:55 +00002958 // If we're supposed to retain a pack expansion, do so by temporarily
2959 // forgetting the partially-substituted parameter pack.
2960 if (RetainExpansion) {
2961 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2962
2963 if (getDerived().TransformTemplateArgument(Pattern, Out))
2964 return true;
2965
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002966 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2967 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002968 if (Out.getArgument().isNull())
2969 return true;
2970
2971 Outputs.addArgument(Out);
2972 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002973
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002974 continue;
2975 }
2976
2977 // The simple case:
2978 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002979 return true;
2980
2981 Outputs.addArgument(Out);
2982 }
2983
2984 return false;
2985
2986}
2987
Douglas Gregord6ff3322009-08-04 16:50:30 +00002988//===----------------------------------------------------------------------===//
2989// Type transformation
2990//===----------------------------------------------------------------------===//
2991
2992template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002993QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002994 if (getDerived().AlreadyTransformed(T))
2995 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002996
John McCall550e0c22009-10-21 00:40:46 +00002997 // Temporary workaround. All of these transformations should
2998 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00002999 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3000 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003001
John McCall31f82722010-11-12 08:19:04 +00003002 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003003
John McCall550e0c22009-10-21 00:40:46 +00003004 if (!NewDI)
3005 return QualType();
3006
3007 return NewDI->getType();
3008}
3009
3010template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003011TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003012 if (getDerived().AlreadyTransformed(DI->getType()))
3013 return DI;
3014
3015 TypeLocBuilder TLB;
3016
3017 TypeLoc TL = DI->getTypeLoc();
3018 TLB.reserve(TL.getFullDataSize());
3019
John McCall31f82722010-11-12 08:19:04 +00003020 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003021 if (Result.isNull())
3022 return 0;
3023
John McCallbcd03502009-12-07 02:54:59 +00003024 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003025}
3026
3027template<typename Derived>
3028QualType
John McCall31f82722010-11-12 08:19:04 +00003029TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003030 switch (T.getTypeLocClass()) {
3031#define ABSTRACT_TYPELOC(CLASS, PARENT)
3032#define TYPELOC(CLASS, PARENT) \
3033 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003034 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003035#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003036 }
Mike Stump11289f42009-09-09 15:08:12 +00003037
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003038 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003039 return QualType();
3040}
3041
3042/// FIXME: By default, this routine adds type qualifiers only to types
3043/// that can have qualifiers, and silently suppresses those qualifiers
3044/// that are not permitted (e.g., qualifiers on reference or function
3045/// types). This is the right thing for template instantiation, but
3046/// probably not for other clients.
3047template<typename Derived>
3048QualType
3049TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003050 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003051 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003052
John McCall31f82722010-11-12 08:19:04 +00003053 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003054 if (Result.isNull())
3055 return QualType();
3056
3057 // Silently suppress qualifiers if the result type can't be qualified.
3058 // FIXME: this is the right thing for template instantiation, but
3059 // probably not for other clients.
3060 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003061 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003062
John McCallcb0f89a2010-06-05 06:41:15 +00003063 if (!Quals.empty()) {
3064 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3065 TLB.push<QualifiedTypeLoc>(Result);
3066 // No location information to preserve.
3067 }
John McCall550e0c22009-10-21 00:40:46 +00003068
3069 return Result;
3070}
3071
Douglas Gregor14454802011-02-25 02:25:35 +00003072template<typename Derived>
3073TypeLoc
3074TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3075 QualType ObjectType,
3076 NamedDecl *UnqualLookup,
3077 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003078 QualType T = TL.getType();
3079 if (getDerived().AlreadyTransformed(T))
3080 return TL;
3081
3082 TypeLocBuilder TLB;
3083 QualType Result;
3084
3085 if (isa<TemplateSpecializationType>(T)) {
3086 TemplateSpecializationTypeLoc SpecTL
3087 = cast<TemplateSpecializationTypeLoc>(TL);
3088
3089 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003090 getDerived().TransformTemplateName(SS,
3091 SpecTL.getTypePtr()->getTemplateName(),
3092 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003093 ObjectType, UnqualLookup);
3094 if (Template.isNull())
3095 return TypeLoc();
3096
3097 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3098 Template);
3099 } else if (isa<DependentTemplateSpecializationType>(T)) {
3100 DependentTemplateSpecializationTypeLoc SpecTL
3101 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3102
Douglas Gregor5a064722011-02-28 17:23:35 +00003103 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003104 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003105 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003106 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003107 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003108 if (Template.isNull())
3109 return TypeLoc();
3110
Douglas Gregor14454802011-02-25 02:25:35 +00003111 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003112 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003113 Template,
3114 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003115 } else {
3116 // Nothing special needs to be done for these.
3117 Result = getDerived().TransformType(TLB, TL);
3118 }
3119
3120 if (Result.isNull())
3121 return TypeLoc();
3122
3123 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3124}
3125
Douglas Gregor579c15f2011-03-02 18:32:08 +00003126template<typename Derived>
3127TypeSourceInfo *
3128TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3129 QualType ObjectType,
3130 NamedDecl *UnqualLookup,
3131 CXXScopeSpec &SS) {
3132 // FIXME: Painfully copy-paste from the above!
3133
3134 QualType T = TSInfo->getType();
3135 if (getDerived().AlreadyTransformed(T))
3136 return TSInfo;
3137
3138 TypeLocBuilder TLB;
3139 QualType Result;
3140
3141 TypeLoc TL = TSInfo->getTypeLoc();
3142 if (isa<TemplateSpecializationType>(T)) {
3143 TemplateSpecializationTypeLoc SpecTL
3144 = cast<TemplateSpecializationTypeLoc>(TL);
3145
3146 TemplateName Template
3147 = getDerived().TransformTemplateName(SS,
3148 SpecTL.getTypePtr()->getTemplateName(),
3149 SpecTL.getTemplateNameLoc(),
3150 ObjectType, UnqualLookup);
3151 if (Template.isNull())
3152 return 0;
3153
3154 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3155 Template);
3156 } else if (isa<DependentTemplateSpecializationType>(T)) {
3157 DependentTemplateSpecializationTypeLoc SpecTL
3158 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3159
3160 TemplateName Template
3161 = getDerived().RebuildTemplateName(SS,
3162 *SpecTL.getTypePtr()->getIdentifier(),
3163 SpecTL.getNameLoc(),
3164 ObjectType, UnqualLookup);
3165 if (Template.isNull())
3166 return 0;
3167
3168 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3169 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003170 Template,
3171 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003172 } else {
3173 // Nothing special needs to be done for these.
3174 Result = getDerived().TransformType(TLB, TL);
3175 }
3176
3177 if (Result.isNull())
3178 return 0;
3179
3180 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3181}
3182
John McCall550e0c22009-10-21 00:40:46 +00003183template <class TyLoc> static inline
3184QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3185 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3186 NewT.setNameLoc(T.getNameLoc());
3187 return T.getType();
3188}
3189
John McCall550e0c22009-10-21 00:40:46 +00003190template<typename Derived>
3191QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003192 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003193 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3194 NewT.setBuiltinLoc(T.getBuiltinLoc());
3195 if (T.needsExtraLocalData())
3196 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3197 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003198}
Mike Stump11289f42009-09-09 15:08:12 +00003199
Douglas Gregord6ff3322009-08-04 16:50:30 +00003200template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003201QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003202 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003203 // FIXME: recurse?
3204 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003205}
Mike Stump11289f42009-09-09 15:08:12 +00003206
Douglas Gregord6ff3322009-08-04 16:50:30 +00003207template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003208QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003209 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003210 QualType PointeeType
3211 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003212 if (PointeeType.isNull())
3213 return QualType();
3214
3215 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003216 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003217 // A dependent pointer type 'T *' has is being transformed such
3218 // that an Objective-C class type is being replaced for 'T'. The
3219 // resulting pointer type is an ObjCObjectPointerType, not a
3220 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003221 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003222
John McCall8b07ec22010-05-15 11:32:37 +00003223 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3224 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003225 return Result;
3226 }
John McCall31f82722010-11-12 08:19:04 +00003227
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003228 if (getDerived().AlwaysRebuild() ||
3229 PointeeType != TL.getPointeeLoc().getType()) {
3230 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3231 if (Result.isNull())
3232 return QualType();
3233 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003234
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003235 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3236 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003237 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003238}
Mike Stump11289f42009-09-09 15:08:12 +00003239
3240template<typename Derived>
3241QualType
John McCall550e0c22009-10-21 00:40:46 +00003242TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003243 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003244 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003245 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3246 if (PointeeType.isNull())
3247 return QualType();
3248
3249 QualType Result = TL.getType();
3250 if (getDerived().AlwaysRebuild() ||
3251 PointeeType != TL.getPointeeLoc().getType()) {
3252 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003253 TL.getSigilLoc());
3254 if (Result.isNull())
3255 return QualType();
3256 }
3257
Douglas Gregor049211a2010-04-22 16:50:51 +00003258 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003259 NewT.setSigilLoc(TL.getSigilLoc());
3260 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003261}
3262
John McCall70dd5f62009-10-30 00:06:24 +00003263/// Transforms a reference type. Note that somewhat paradoxically we
3264/// don't care whether the type itself is an l-value type or an r-value
3265/// type; we only care if the type was *written* as an l-value type
3266/// or an r-value type.
3267template<typename Derived>
3268QualType
3269TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003270 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003271 const ReferenceType *T = TL.getTypePtr();
3272
3273 // Note that this works with the pointee-as-written.
3274 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3275 if (PointeeType.isNull())
3276 return QualType();
3277
3278 QualType Result = TL.getType();
3279 if (getDerived().AlwaysRebuild() ||
3280 PointeeType != T->getPointeeTypeAsWritten()) {
3281 Result = getDerived().RebuildReferenceType(PointeeType,
3282 T->isSpelledAsLValue(),
3283 TL.getSigilLoc());
3284 if (Result.isNull())
3285 return QualType();
3286 }
3287
3288 // r-value references can be rebuilt as l-value references.
3289 ReferenceTypeLoc NewTL;
3290 if (isa<LValueReferenceType>(Result))
3291 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3292 else
3293 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3294 NewTL.setSigilLoc(TL.getSigilLoc());
3295
3296 return Result;
3297}
3298
Mike Stump11289f42009-09-09 15:08:12 +00003299template<typename Derived>
3300QualType
John McCall550e0c22009-10-21 00:40:46 +00003301TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003302 LValueReferenceTypeLoc TL) {
3303 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003304}
3305
Mike Stump11289f42009-09-09 15:08:12 +00003306template<typename Derived>
3307QualType
John McCall550e0c22009-10-21 00:40:46 +00003308TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003309 RValueReferenceTypeLoc TL) {
3310 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003311}
Mike Stump11289f42009-09-09 15:08:12 +00003312
Douglas Gregord6ff3322009-08-04 16:50:30 +00003313template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003314QualType
John McCall550e0c22009-10-21 00:40:46 +00003315TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003316 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003317 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003318 if (PointeeType.isNull())
3319 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003320
Abramo Bagnara509357842011-03-05 14:42:21 +00003321 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3322 TypeSourceInfo* NewClsTInfo = 0;
3323 if (OldClsTInfo) {
3324 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3325 if (!NewClsTInfo)
3326 return QualType();
3327 }
3328
3329 const MemberPointerType *T = TL.getTypePtr();
3330 QualType OldClsType = QualType(T->getClass(), 0);
3331 QualType NewClsType;
3332 if (NewClsTInfo)
3333 NewClsType = NewClsTInfo->getType();
3334 else {
3335 NewClsType = getDerived().TransformType(OldClsType);
3336 if (NewClsType.isNull())
3337 return QualType();
3338 }
Mike Stump11289f42009-09-09 15:08:12 +00003339
John McCall550e0c22009-10-21 00:40:46 +00003340 QualType Result = TL.getType();
3341 if (getDerived().AlwaysRebuild() ||
3342 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003343 NewClsType != OldClsType) {
3344 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003345 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003346 if (Result.isNull())
3347 return QualType();
3348 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003349
John McCall550e0c22009-10-21 00:40:46 +00003350 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3351 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003352 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003353
3354 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003355}
3356
Mike Stump11289f42009-09-09 15:08:12 +00003357template<typename Derived>
3358QualType
John McCall550e0c22009-10-21 00:40:46 +00003359TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003360 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003361 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003362 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003363 if (ElementType.isNull())
3364 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003365
John McCall550e0c22009-10-21 00:40:46 +00003366 QualType Result = TL.getType();
3367 if (getDerived().AlwaysRebuild() ||
3368 ElementType != T->getElementType()) {
3369 Result = getDerived().RebuildConstantArrayType(ElementType,
3370 T->getSizeModifier(),
3371 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003372 T->getIndexTypeCVRQualifiers(),
3373 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003374 if (Result.isNull())
3375 return QualType();
3376 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003377
John McCall550e0c22009-10-21 00:40:46 +00003378 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3379 NewTL.setLBracketLoc(TL.getLBracketLoc());
3380 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003381
John McCall550e0c22009-10-21 00:40:46 +00003382 Expr *Size = TL.getSizeExpr();
3383 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003384 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003385 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3386 }
3387 NewTL.setSizeExpr(Size);
3388
3389 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003390}
Mike Stump11289f42009-09-09 15:08:12 +00003391
Douglas Gregord6ff3322009-08-04 16:50:30 +00003392template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003393QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003394 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003395 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003396 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003397 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003398 if (ElementType.isNull())
3399 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003400
John McCall550e0c22009-10-21 00:40:46 +00003401 QualType Result = TL.getType();
3402 if (getDerived().AlwaysRebuild() ||
3403 ElementType != T->getElementType()) {
3404 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003405 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003406 T->getIndexTypeCVRQualifiers(),
3407 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003408 if (Result.isNull())
3409 return QualType();
3410 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003411
John McCall550e0c22009-10-21 00:40:46 +00003412 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3413 NewTL.setLBracketLoc(TL.getLBracketLoc());
3414 NewTL.setRBracketLoc(TL.getRBracketLoc());
3415 NewTL.setSizeExpr(0);
3416
3417 return Result;
3418}
3419
3420template<typename Derived>
3421QualType
3422TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003423 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003424 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003425 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3426 if (ElementType.isNull())
3427 return QualType();
3428
3429 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003430 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003431
John McCalldadc5752010-08-24 06:29:42 +00003432 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003433 = getDerived().TransformExpr(T->getSizeExpr());
3434 if (SizeResult.isInvalid())
3435 return QualType();
3436
John McCallb268a282010-08-23 23:25:46 +00003437 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003438
3439 QualType Result = TL.getType();
3440 if (getDerived().AlwaysRebuild() ||
3441 ElementType != T->getElementType() ||
3442 Size != T->getSizeExpr()) {
3443 Result = getDerived().RebuildVariableArrayType(ElementType,
3444 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003445 Size,
John McCall550e0c22009-10-21 00:40:46 +00003446 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003447 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003448 if (Result.isNull())
3449 return QualType();
3450 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003451
John McCall550e0c22009-10-21 00:40:46 +00003452 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3453 NewTL.setLBracketLoc(TL.getLBracketLoc());
3454 NewTL.setRBracketLoc(TL.getRBracketLoc());
3455 NewTL.setSizeExpr(Size);
3456
3457 return Result;
3458}
3459
3460template<typename Derived>
3461QualType
3462TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003463 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003464 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003465 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3466 if (ElementType.isNull())
3467 return QualType();
3468
3469 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003470 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003471
John McCall33ddac02011-01-19 10:06:00 +00003472 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3473 Expr *origSize = TL.getSizeExpr();
3474 if (!origSize) origSize = T->getSizeExpr();
3475
3476 ExprResult sizeResult
3477 = getDerived().TransformExpr(origSize);
3478 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003479 return QualType();
3480
John McCall33ddac02011-01-19 10:06:00 +00003481 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003482
3483 QualType Result = TL.getType();
3484 if (getDerived().AlwaysRebuild() ||
3485 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003486 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003487 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3488 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003489 size,
John McCall550e0c22009-10-21 00:40:46 +00003490 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003491 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003492 if (Result.isNull())
3493 return QualType();
3494 }
John McCall550e0c22009-10-21 00:40:46 +00003495
3496 // We might have any sort of array type now, but fortunately they
3497 // all have the same location layout.
3498 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3499 NewTL.setLBracketLoc(TL.getLBracketLoc());
3500 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003501 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003502
3503 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003504}
Mike Stump11289f42009-09-09 15:08:12 +00003505
3506template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003507QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003508 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003509 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003510 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003511
3512 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003513 QualType ElementType = getDerived().TransformType(T->getElementType());
3514 if (ElementType.isNull())
3515 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003516
Douglas Gregore922c772009-08-04 22:27:00 +00003517 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003518 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003519
John McCalldadc5752010-08-24 06:29:42 +00003520 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003521 if (Size.isInvalid())
3522 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003523
John McCall550e0c22009-10-21 00:40:46 +00003524 QualType Result = TL.getType();
3525 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003526 ElementType != T->getElementType() ||
3527 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003528 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003529 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003530 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003531 if (Result.isNull())
3532 return QualType();
3533 }
John McCall550e0c22009-10-21 00:40:46 +00003534
3535 // Result might be dependent or not.
3536 if (isa<DependentSizedExtVectorType>(Result)) {
3537 DependentSizedExtVectorTypeLoc NewTL
3538 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3539 NewTL.setNameLoc(TL.getNameLoc());
3540 } else {
3541 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3542 NewTL.setNameLoc(TL.getNameLoc());
3543 }
3544
3545 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003546}
Mike Stump11289f42009-09-09 15:08:12 +00003547
3548template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003549QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003550 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003551 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003552 QualType ElementType = getDerived().TransformType(T->getElementType());
3553 if (ElementType.isNull())
3554 return QualType();
3555
John McCall550e0c22009-10-21 00:40:46 +00003556 QualType Result = TL.getType();
3557 if (getDerived().AlwaysRebuild() ||
3558 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003559 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003560 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003561 if (Result.isNull())
3562 return QualType();
3563 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003564
John McCall550e0c22009-10-21 00:40:46 +00003565 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3566 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003567
John McCall550e0c22009-10-21 00:40:46 +00003568 return Result;
3569}
3570
3571template<typename Derived>
3572QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003573 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003574 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003575 QualType ElementType = getDerived().TransformType(T->getElementType());
3576 if (ElementType.isNull())
3577 return QualType();
3578
3579 QualType Result = TL.getType();
3580 if (getDerived().AlwaysRebuild() ||
3581 ElementType != T->getElementType()) {
3582 Result = getDerived().RebuildExtVectorType(ElementType,
3583 T->getNumElements(),
3584 /*FIXME*/ SourceLocation());
3585 if (Result.isNull())
3586 return QualType();
3587 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003588
John McCall550e0c22009-10-21 00:40:46 +00003589 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3590 NewTL.setNameLoc(TL.getNameLoc());
3591
3592 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003593}
Mike Stump11289f42009-09-09 15:08:12 +00003594
3595template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003596ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003597TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3598 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003599 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003600 TypeSourceInfo *NewDI = 0;
3601
3602 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3603 // If we're substituting into a pack expansion type and we know the
3604 TypeLoc OldTL = OldDI->getTypeLoc();
3605 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3606
3607 TypeLocBuilder TLB;
3608 TypeLoc NewTL = OldDI->getTypeLoc();
3609 TLB.reserve(NewTL.getFullDataSize());
3610
3611 QualType Result = getDerived().TransformType(TLB,
3612 OldExpansionTL.getPatternLoc());
3613 if (Result.isNull())
3614 return 0;
3615
3616 Result = RebuildPackExpansionType(Result,
3617 OldExpansionTL.getPatternLoc().getSourceRange(),
3618 OldExpansionTL.getEllipsisLoc(),
3619 NumExpansions);
3620 if (Result.isNull())
3621 return 0;
3622
3623 PackExpansionTypeLoc NewExpansionTL
3624 = TLB.push<PackExpansionTypeLoc>(Result);
3625 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3626 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3627 } else
3628 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003629 if (!NewDI)
3630 return 0;
3631
3632 if (NewDI == OldDI)
3633 return OldParm;
3634 else
3635 return ParmVarDecl::Create(SemaRef.Context,
3636 OldParm->getDeclContext(),
Abramo Bagnaradff19302011-03-08 08:55:46 +00003637 OldParm->getInnerLocStart(),
John McCall58f10c32010-03-11 09:03:00 +00003638 OldParm->getLocation(),
3639 OldParm->getIdentifier(),
3640 NewDI->getType(),
3641 NewDI,
3642 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003643 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003644 /* DefArg */ NULL);
3645}
3646
3647template<typename Derived>
3648bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003649 TransformFunctionTypeParams(SourceLocation Loc,
3650 ParmVarDecl **Params, unsigned NumParams,
3651 const QualType *ParamTypes,
3652 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3653 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3654 for (unsigned i = 0; i != NumParams; ++i) {
3655 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003656 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003657 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003658 if (OldParm->isParameterPack()) {
3659 // We have a function parameter pack that may need to be expanded.
3660 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003661
Douglas Gregor5499af42011-01-05 23:12:31 +00003662 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003663 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3664 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3665 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3666 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003667 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3668
Douglas Gregor5499af42011-01-05 23:12:31 +00003669 // Determine whether we should expand the parameter packs.
3670 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003671 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003672 llvm::Optional<unsigned> OrigNumExpansions
3673 = ExpansionTL.getTypePtr()->getNumExpansions();
3674 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003675 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3676 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003677 Unexpanded.data(),
3678 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003679 ShouldExpand,
3680 RetainExpansion,
3681 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003682 return true;
3683 }
3684
3685 if (ShouldExpand) {
3686 // Expand the function parameter pack into multiple, separate
3687 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003688 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003689 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003690 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3691 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003692 = getDerived().TransformFunctionTypeParam(OldParm,
3693 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003694 if (!NewParm)
3695 return true;
3696
Douglas Gregordd472162011-01-07 00:20:55 +00003697 OutParamTypes.push_back(NewParm->getType());
3698 if (PVars)
3699 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003700 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003701
3702 // If we're supposed to retain a pack expansion, do so by temporarily
3703 // forgetting the partially-substituted parameter pack.
3704 if (RetainExpansion) {
3705 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3706 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003707 = getDerived().TransformFunctionTypeParam(OldParm,
3708 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003709 if (!NewParm)
3710 return true;
3711
3712 OutParamTypes.push_back(NewParm->getType());
3713 if (PVars)
3714 PVars->push_back(NewParm);
3715 }
3716
Douglas Gregor5499af42011-01-05 23:12:31 +00003717 // We're done with the pack expansion.
3718 continue;
3719 }
3720
3721 // We'll substitute the parameter now without expanding the pack
3722 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003723 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3724 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3725 NumExpansions);
3726 } else {
3727 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3728 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003729 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003730
John McCall58f10c32010-03-11 09:03:00 +00003731 if (!NewParm)
3732 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003733
Douglas Gregordd472162011-01-07 00:20:55 +00003734 OutParamTypes.push_back(NewParm->getType());
3735 if (PVars)
3736 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003737 continue;
3738 }
John McCall58f10c32010-03-11 09:03:00 +00003739
3740 // Deal with the possibility that we don't have a parameter
3741 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003742 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003743 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003744 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003745 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003746 if (const PackExpansionType *Expansion
3747 = dyn_cast<PackExpansionType>(OldType)) {
3748 // We have a function parameter pack that may need to be expanded.
3749 QualType Pattern = Expansion->getPattern();
3750 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3751 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3752
3753 // Determine whether we should expand the parameter packs.
3754 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003755 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003756 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003757 Unexpanded.data(),
3758 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003759 ShouldExpand,
3760 RetainExpansion,
3761 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003762 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003763 }
3764
3765 if (ShouldExpand) {
3766 // Expand the function parameter pack into multiple, separate
3767 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003768 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003769 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3770 QualType NewType = getDerived().TransformType(Pattern);
3771 if (NewType.isNull())
3772 return true;
John McCall58f10c32010-03-11 09:03:00 +00003773
Douglas Gregordd472162011-01-07 00:20:55 +00003774 OutParamTypes.push_back(NewType);
3775 if (PVars)
3776 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003777 }
3778
3779 // We're done with the pack expansion.
3780 continue;
3781 }
3782
Douglas Gregor48d24112011-01-10 20:53:55 +00003783 // If we're supposed to retain a pack expansion, do so by temporarily
3784 // forgetting the partially-substituted parameter pack.
3785 if (RetainExpansion) {
3786 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3787 QualType NewType = getDerived().TransformType(Pattern);
3788 if (NewType.isNull())
3789 return true;
3790
3791 OutParamTypes.push_back(NewType);
3792 if (PVars)
3793 PVars->push_back(0);
3794 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003795
Douglas Gregor5499af42011-01-05 23:12:31 +00003796 // We'll substitute the parameter now without expanding the pack
3797 // expansion.
3798 OldType = Expansion->getPattern();
3799 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003800 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3801 NewType = getDerived().TransformType(OldType);
3802 } else {
3803 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003804 }
3805
Douglas Gregor5499af42011-01-05 23:12:31 +00003806 if (NewType.isNull())
3807 return true;
3808
3809 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003810 NewType = getSema().Context.getPackExpansionType(NewType,
3811 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003812
Douglas Gregordd472162011-01-07 00:20:55 +00003813 OutParamTypes.push_back(NewType);
3814 if (PVars)
3815 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003816 }
3817
3818 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003819 }
John McCall58f10c32010-03-11 09:03:00 +00003820
3821template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003822QualType
John McCall550e0c22009-10-21 00:40:46 +00003823TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003824 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003825 // Transform the parameters and return type.
3826 //
3827 // We instantiate in source order, with the return type first followed by
3828 // the parameters, because users tend to expect this (even if they shouldn't
3829 // rely on it!).
3830 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003831 // When the function has a trailing return type, we instantiate the
3832 // parameters before the return type, since the return type can then refer
3833 // to the parameters themselves (via decltype, sizeof, etc.).
3834 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003835 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003836 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003837 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003838
Douglas Gregor7fb25412010-10-01 18:44:50 +00003839 QualType ResultType;
3840
3841 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003842 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3843 TL.getParmArray(),
3844 TL.getNumArgs(),
3845 TL.getTypePtr()->arg_type_begin(),
3846 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003847 return QualType();
3848
3849 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3850 if (ResultType.isNull())
3851 return QualType();
3852 }
3853 else {
3854 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3855 if (ResultType.isNull())
3856 return QualType();
3857
Douglas Gregordd472162011-01-07 00:20:55 +00003858 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3859 TL.getParmArray(),
3860 TL.getNumArgs(),
3861 TL.getTypePtr()->arg_type_begin(),
3862 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003863 return QualType();
3864 }
3865
John McCall550e0c22009-10-21 00:40:46 +00003866 QualType Result = TL.getType();
3867 if (getDerived().AlwaysRebuild() ||
3868 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003869 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003870 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3871 Result = getDerived().RebuildFunctionProtoType(ResultType,
3872 ParamTypes.data(),
3873 ParamTypes.size(),
3874 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003875 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003876 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003877 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003878 if (Result.isNull())
3879 return QualType();
3880 }
Mike Stump11289f42009-09-09 15:08:12 +00003881
John McCall550e0c22009-10-21 00:40:46 +00003882 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00003883 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
3884 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003885 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003886 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3887 NewTL.setArg(i, ParamDecls[i]);
3888
3889 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003890}
Mike Stump11289f42009-09-09 15:08:12 +00003891
Douglas Gregord6ff3322009-08-04 16:50:30 +00003892template<typename Derived>
3893QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003894 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003895 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003896 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003897 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3898 if (ResultType.isNull())
3899 return QualType();
3900
3901 QualType Result = TL.getType();
3902 if (getDerived().AlwaysRebuild() ||
3903 ResultType != T->getResultType())
3904 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3905
3906 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00003907 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
3908 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003909 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003910
3911 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003912}
Mike Stump11289f42009-09-09 15:08:12 +00003913
John McCallb96ec562009-12-04 22:46:56 +00003914template<typename Derived> QualType
3915TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003916 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003917 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003918 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003919 if (!D)
3920 return QualType();
3921
3922 QualType Result = TL.getType();
3923 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3924 Result = getDerived().RebuildUnresolvedUsingType(D);
3925 if (Result.isNull())
3926 return QualType();
3927 }
3928
3929 // We might get an arbitrary type spec type back. We should at
3930 // least always get a type spec type, though.
3931 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3932 NewTL.setNameLoc(TL.getNameLoc());
3933
3934 return Result;
3935}
3936
Douglas Gregord6ff3322009-08-04 16:50:30 +00003937template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003938QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003939 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003940 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003941 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003942 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3943 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003944 if (!Typedef)
3945 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003946
John McCall550e0c22009-10-21 00:40:46 +00003947 QualType Result = TL.getType();
3948 if (getDerived().AlwaysRebuild() ||
3949 Typedef != T->getDecl()) {
3950 Result = getDerived().RebuildTypedefType(Typedef);
3951 if (Result.isNull())
3952 return QualType();
3953 }
Mike Stump11289f42009-09-09 15:08:12 +00003954
John McCall550e0c22009-10-21 00:40:46 +00003955 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3956 NewTL.setNameLoc(TL.getNameLoc());
3957
3958 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003959}
Mike Stump11289f42009-09-09 15:08:12 +00003960
Douglas Gregord6ff3322009-08-04 16:50:30 +00003961template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003962QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003963 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003964 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003965 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003966
John McCalldadc5752010-08-24 06:29:42 +00003967 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003968 if (E.isInvalid())
3969 return QualType();
3970
John McCall550e0c22009-10-21 00:40:46 +00003971 QualType Result = TL.getType();
3972 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003973 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003974 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003975 if (Result.isNull())
3976 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003977 }
John McCall550e0c22009-10-21 00:40:46 +00003978 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003979
John McCall550e0c22009-10-21 00:40:46 +00003980 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003981 NewTL.setTypeofLoc(TL.getTypeofLoc());
3982 NewTL.setLParenLoc(TL.getLParenLoc());
3983 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003984
3985 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003986}
Mike Stump11289f42009-09-09 15:08:12 +00003987
3988template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003989QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003990 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003991 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3992 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3993 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003994 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003995
John McCall550e0c22009-10-21 00:40:46 +00003996 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003997 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3998 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003999 if (Result.isNull())
4000 return QualType();
4001 }
Mike Stump11289f42009-09-09 15:08:12 +00004002
John McCall550e0c22009-10-21 00:40:46 +00004003 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004004 NewTL.setTypeofLoc(TL.getTypeofLoc());
4005 NewTL.setLParenLoc(TL.getLParenLoc());
4006 NewTL.setRParenLoc(TL.getRParenLoc());
4007 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004008
4009 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004010}
Mike Stump11289f42009-09-09 15:08:12 +00004011
4012template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004013QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004014 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004015 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004016
Douglas Gregore922c772009-08-04 22:27:00 +00004017 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004018 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004019
John McCalldadc5752010-08-24 06:29:42 +00004020 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004021 if (E.isInvalid())
4022 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004023
John McCall550e0c22009-10-21 00:40:46 +00004024 QualType Result = TL.getType();
4025 if (getDerived().AlwaysRebuild() ||
4026 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004027 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004028 if (Result.isNull())
4029 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004030 }
John McCall550e0c22009-10-21 00:40:46 +00004031 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004032
John McCall550e0c22009-10-21 00:40:46 +00004033 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4034 NewTL.setNameLoc(TL.getNameLoc());
4035
4036 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004037}
4038
4039template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004040QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4041 AutoTypeLoc TL) {
4042 const AutoType *T = TL.getTypePtr();
4043 QualType OldDeduced = T->getDeducedType();
4044 QualType NewDeduced;
4045 if (!OldDeduced.isNull()) {
4046 NewDeduced = getDerived().TransformType(OldDeduced);
4047 if (NewDeduced.isNull())
4048 return QualType();
4049 }
4050
4051 QualType Result = TL.getType();
4052 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4053 Result = getDerived().RebuildAutoType(NewDeduced);
4054 if (Result.isNull())
4055 return QualType();
4056 }
4057
4058 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4059 NewTL.setNameLoc(TL.getNameLoc());
4060
4061 return Result;
4062}
4063
4064template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004065QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004066 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004067 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004068 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004069 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4070 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004071 if (!Record)
4072 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004073
John McCall550e0c22009-10-21 00:40:46 +00004074 QualType Result = TL.getType();
4075 if (getDerived().AlwaysRebuild() ||
4076 Record != T->getDecl()) {
4077 Result = getDerived().RebuildRecordType(Record);
4078 if (Result.isNull())
4079 return QualType();
4080 }
Mike Stump11289f42009-09-09 15:08:12 +00004081
John McCall550e0c22009-10-21 00:40:46 +00004082 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4083 NewTL.setNameLoc(TL.getNameLoc());
4084
4085 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004086}
Mike Stump11289f42009-09-09 15:08:12 +00004087
4088template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004089QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004090 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004091 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004092 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004093 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4094 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004095 if (!Enum)
4096 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004097
John McCall550e0c22009-10-21 00:40:46 +00004098 QualType Result = TL.getType();
4099 if (getDerived().AlwaysRebuild() ||
4100 Enum != T->getDecl()) {
4101 Result = getDerived().RebuildEnumType(Enum);
4102 if (Result.isNull())
4103 return QualType();
4104 }
Mike Stump11289f42009-09-09 15:08:12 +00004105
John McCall550e0c22009-10-21 00:40:46 +00004106 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4107 NewTL.setNameLoc(TL.getNameLoc());
4108
4109 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004110}
John McCallfcc33b02009-09-05 00:15:47 +00004111
John McCalle78aac42010-03-10 03:28:59 +00004112template<typename Derived>
4113QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4114 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004115 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004116 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4117 TL.getTypePtr()->getDecl());
4118 if (!D) return QualType();
4119
4120 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4121 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4122 return T;
4123}
4124
Douglas Gregord6ff3322009-08-04 16:50:30 +00004125template<typename Derived>
4126QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004127 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004128 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004129 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004130}
4131
Mike Stump11289f42009-09-09 15:08:12 +00004132template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004133QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004134 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004135 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004136 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4137
4138 // Substitute into the replacement type, which itself might involve something
4139 // that needs to be transformed. This only tends to occur with default
4140 // template arguments of template template parameters.
4141 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4142 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4143 if (Replacement.isNull())
4144 return QualType();
4145
4146 // Always canonicalize the replacement type.
4147 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4148 QualType Result
4149 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4150 Replacement);
4151
4152 // Propagate type-source information.
4153 SubstTemplateTypeParmTypeLoc NewTL
4154 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4155 NewTL.setNameLoc(TL.getNameLoc());
4156 return Result;
4157
John McCallcebee162009-10-18 09:09:24 +00004158}
4159
4160template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004161QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4162 TypeLocBuilder &TLB,
4163 SubstTemplateTypeParmPackTypeLoc TL) {
4164 return TransformTypeSpecType(TLB, TL);
4165}
4166
4167template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004168QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004169 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004170 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004171 const TemplateSpecializationType *T = TL.getTypePtr();
4172
Douglas Gregordf846d12011-03-02 18:46:51 +00004173 // The nested-name-specifier never matters in a TemplateSpecializationType,
4174 // because we can't have a dependent nested-name-specifier anyway.
4175 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004176 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004177 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4178 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004179 if (Template.isNull())
4180 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004181
John McCall31f82722010-11-12 08:19:04 +00004182 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4183}
4184
Douglas Gregorfe921a72010-12-20 23:36:19 +00004185namespace {
4186 /// \brief Simple iterator that traverses the template arguments in a
4187 /// container that provides a \c getArgLoc() member function.
4188 ///
4189 /// This iterator is intended to be used with the iterator form of
4190 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4191 template<typename ArgLocContainer>
4192 class TemplateArgumentLocContainerIterator {
4193 ArgLocContainer *Container;
4194 unsigned Index;
4195
4196 public:
4197 typedef TemplateArgumentLoc value_type;
4198 typedef TemplateArgumentLoc reference;
4199 typedef int difference_type;
4200 typedef std::input_iterator_tag iterator_category;
4201
4202 class pointer {
4203 TemplateArgumentLoc Arg;
4204
4205 public:
4206 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4207
4208 const TemplateArgumentLoc *operator->() const {
4209 return &Arg;
4210 }
4211 };
4212
4213
4214 TemplateArgumentLocContainerIterator() {}
4215
4216 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4217 unsigned Index)
4218 : Container(&Container), Index(Index) { }
4219
4220 TemplateArgumentLocContainerIterator &operator++() {
4221 ++Index;
4222 return *this;
4223 }
4224
4225 TemplateArgumentLocContainerIterator operator++(int) {
4226 TemplateArgumentLocContainerIterator Old(*this);
4227 ++(*this);
4228 return Old;
4229 }
4230
4231 TemplateArgumentLoc operator*() const {
4232 return Container->getArgLoc(Index);
4233 }
4234
4235 pointer operator->() const {
4236 return pointer(Container->getArgLoc(Index));
4237 }
4238
4239 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004240 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004241 return X.Container == Y.Container && X.Index == Y.Index;
4242 }
4243
4244 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004245 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004246 return !(X == Y);
4247 }
4248 };
4249}
4250
4251
John McCall31f82722010-11-12 08:19:04 +00004252template <typename Derived>
4253QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4254 TypeLocBuilder &TLB,
4255 TemplateSpecializationTypeLoc TL,
4256 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004257 TemplateArgumentListInfo NewTemplateArgs;
4258 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4259 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004260 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4261 ArgIterator;
4262 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4263 ArgIterator(TL, TL.getNumArgs()),
4264 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004265 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004266
John McCall0ad16662009-10-29 08:12:44 +00004267 // FIXME: maybe don't rebuild if all the template arguments are the same.
4268
4269 QualType Result =
4270 getDerived().RebuildTemplateSpecializationType(Template,
4271 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004272 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004273
4274 if (!Result.isNull()) {
4275 TemplateSpecializationTypeLoc NewTL
4276 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4277 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4278 NewTL.setLAngleLoc(TL.getLAngleLoc());
4279 NewTL.setRAngleLoc(TL.getRAngleLoc());
4280 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4281 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004282 }
Mike Stump11289f42009-09-09 15:08:12 +00004283
John McCall0ad16662009-10-29 08:12:44 +00004284 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004285}
Mike Stump11289f42009-09-09 15:08:12 +00004286
Douglas Gregor5a064722011-02-28 17:23:35 +00004287template <typename Derived>
4288QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4289 TypeLocBuilder &TLB,
4290 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004291 TemplateName Template,
4292 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004293 TemplateArgumentListInfo NewTemplateArgs;
4294 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4295 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4296 typedef TemplateArgumentLocContainerIterator<
4297 DependentTemplateSpecializationTypeLoc> ArgIterator;
4298 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4299 ArgIterator(TL, TL.getNumArgs()),
4300 NewTemplateArgs))
4301 return QualType();
4302
4303 // FIXME: maybe don't rebuild if all the template arguments are the same.
4304
4305 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4306 QualType Result
4307 = getSema().Context.getDependentTemplateSpecializationType(
4308 TL.getTypePtr()->getKeyword(),
4309 DTN->getQualifier(),
4310 DTN->getIdentifier(),
4311 NewTemplateArgs);
4312
4313 DependentTemplateSpecializationTypeLoc NewTL
4314 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4315 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004316
Douglas Gregora7a795b2011-03-01 20:11:18 +00004317 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004318 NewTL.setNameLoc(TL.getNameLoc());
4319 NewTL.setLAngleLoc(TL.getLAngleLoc());
4320 NewTL.setRAngleLoc(TL.getRAngleLoc());
4321 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4322 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4323 return Result;
4324 }
4325
4326 QualType Result
4327 = getDerived().RebuildTemplateSpecializationType(Template,
4328 TL.getNameLoc(),
4329 NewTemplateArgs);
4330
4331 if (!Result.isNull()) {
4332 /// FIXME: Wrap this in an elaborated-type-specifier?
4333 TemplateSpecializationTypeLoc NewTL
4334 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4335 NewTL.setTemplateNameLoc(TL.getNameLoc());
4336 NewTL.setLAngleLoc(TL.getLAngleLoc());
4337 NewTL.setRAngleLoc(TL.getRAngleLoc());
4338 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4339 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4340 }
4341
4342 return Result;
4343}
4344
Mike Stump11289f42009-09-09 15:08:12 +00004345template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004346QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004347TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004348 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004349 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004350
Douglas Gregor844cb502011-03-01 18:12:44 +00004351 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004352 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004353 if (TL.getQualifierLoc()) {
4354 QualifierLoc
4355 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4356 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004357 return QualType();
4358 }
Mike Stump11289f42009-09-09 15:08:12 +00004359
John McCall31f82722010-11-12 08:19:04 +00004360 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4361 if (NamedT.isNull())
4362 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004363
John McCall550e0c22009-10-21 00:40:46 +00004364 QualType Result = TL.getType();
4365 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004366 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004367 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004368 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004369 T->getKeyword(),
4370 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004371 if (Result.isNull())
4372 return QualType();
4373 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004374
Abramo Bagnara6150c882010-05-11 21:36:43 +00004375 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004376 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004377 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004378 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004379}
Mike Stump11289f42009-09-09 15:08:12 +00004380
4381template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004382QualType TreeTransform<Derived>::TransformAttributedType(
4383 TypeLocBuilder &TLB,
4384 AttributedTypeLoc TL) {
4385 const AttributedType *oldType = TL.getTypePtr();
4386 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4387 if (modifiedType.isNull())
4388 return QualType();
4389
4390 QualType result = TL.getType();
4391
4392 // FIXME: dependent operand expressions?
4393 if (getDerived().AlwaysRebuild() ||
4394 modifiedType != oldType->getModifiedType()) {
4395 // TODO: this is really lame; we should really be rebuilding the
4396 // equivalent type from first principles.
4397 QualType equivalentType
4398 = getDerived().TransformType(oldType->getEquivalentType());
4399 if (equivalentType.isNull())
4400 return QualType();
4401 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4402 modifiedType,
4403 equivalentType);
4404 }
4405
4406 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4407 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4408 if (TL.hasAttrOperand())
4409 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4410 if (TL.hasAttrExprOperand())
4411 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4412 else if (TL.hasAttrEnumOperand())
4413 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4414
4415 return result;
4416}
4417
4418template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004419QualType
4420TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4421 ParenTypeLoc TL) {
4422 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4423 if (Inner.isNull())
4424 return QualType();
4425
4426 QualType Result = TL.getType();
4427 if (getDerived().AlwaysRebuild() ||
4428 Inner != TL.getInnerLoc().getType()) {
4429 Result = getDerived().RebuildParenType(Inner);
4430 if (Result.isNull())
4431 return QualType();
4432 }
4433
4434 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4435 NewTL.setLParenLoc(TL.getLParenLoc());
4436 NewTL.setRParenLoc(TL.getRParenLoc());
4437 return Result;
4438}
4439
4440template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004441QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004442 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004443 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004444
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004445 NestedNameSpecifierLoc QualifierLoc
4446 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4447 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004448 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004449
John McCallc392f372010-06-11 00:33:02 +00004450 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004451 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004452 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004453 QualifierLoc,
4454 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004455 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004456 if (Result.isNull())
4457 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004458
Abramo Bagnarad7548482010-05-19 21:37:53 +00004459 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4460 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004461 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4462
Abramo Bagnarad7548482010-05-19 21:37:53 +00004463 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4464 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004465 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004466 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004467 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4468 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004469 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004470 NewTL.setNameLoc(TL.getNameLoc());
4471 }
John McCall550e0c22009-10-21 00:40:46 +00004472 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004473}
Mike Stump11289f42009-09-09 15:08:12 +00004474
Douglas Gregord6ff3322009-08-04 16:50:30 +00004475template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004476QualType TreeTransform<Derived>::
4477 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004478 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004479 NestedNameSpecifierLoc QualifierLoc;
4480 if (TL.getQualifierLoc()) {
4481 QualifierLoc
4482 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4483 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004484 return QualType();
4485 }
4486
John McCall31f82722010-11-12 08:19:04 +00004487 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004488 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004489}
4490
4491template<typename Derived>
4492QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004493TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4494 DependentTemplateSpecializationTypeLoc TL,
4495 NestedNameSpecifierLoc QualifierLoc) {
4496 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4497
4498 TemplateArgumentListInfo NewTemplateArgs;
4499 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4500 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4501
4502 typedef TemplateArgumentLocContainerIterator<
4503 DependentTemplateSpecializationTypeLoc> ArgIterator;
4504 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4505 ArgIterator(TL, TL.getNumArgs()),
4506 NewTemplateArgs))
4507 return QualType();
4508
4509 QualType Result
4510 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4511 QualifierLoc,
4512 T->getIdentifier(),
4513 TL.getNameLoc(),
4514 NewTemplateArgs);
4515 if (Result.isNull())
4516 return QualType();
4517
4518 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4519 QualType NamedT = ElabT->getNamedType();
4520
4521 // Copy information relevant to the template specialization.
4522 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004523 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Douglas Gregora7a795b2011-03-01 20:11:18 +00004524 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4525 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004526 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004527 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004528
4529 // Copy information relevant to the elaborated type.
4530 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4531 NewTL.setKeywordLoc(TL.getKeywordLoc());
4532 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004533 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4534 DependentTemplateSpecializationTypeLoc SpecTL
4535 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004536 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004537 SpecTL.setQualifierLoc(QualifierLoc);
4538 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4539 SpecTL.setRAngleLoc(TL.getRAngleLoc());
4540 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004541 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004542 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004543 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004544 TemplateSpecializationTypeLoc SpecTL
4545 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4546 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4547 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004548 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004549 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004550 }
4551 return Result;
4552}
4553
4554template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004555QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4556 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004557 QualType Pattern
4558 = getDerived().TransformType(TLB, TL.getPatternLoc());
4559 if (Pattern.isNull())
4560 return QualType();
4561
4562 QualType Result = TL.getType();
4563 if (getDerived().AlwaysRebuild() ||
4564 Pattern != TL.getPatternLoc().getType()) {
4565 Result = getDerived().RebuildPackExpansionType(Pattern,
4566 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004567 TL.getEllipsisLoc(),
4568 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004569 if (Result.isNull())
4570 return QualType();
4571 }
4572
4573 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4574 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4575 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004576}
4577
4578template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004579QualType
4580TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004581 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004582 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004583 TLB.pushFullCopy(TL);
4584 return TL.getType();
4585}
4586
4587template<typename Derived>
4588QualType
4589TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004590 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004591 // ObjCObjectType is never dependent.
4592 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004593 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004594}
Mike Stump11289f42009-09-09 15:08:12 +00004595
4596template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004597QualType
4598TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004599 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004600 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004601 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004602 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004603}
4604
Douglas Gregord6ff3322009-08-04 16:50:30 +00004605//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004606// Statement transformation
4607//===----------------------------------------------------------------------===//
4608template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004609StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004610TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004611 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004612}
4613
4614template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004615StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004616TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4617 return getDerived().TransformCompoundStmt(S, false);
4618}
4619
4620template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004621StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004622TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004623 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004624 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004625 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004626 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004627 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4628 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004629 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004630 if (Result.isInvalid()) {
4631 // Immediately fail if this was a DeclStmt, since it's very
4632 // likely that this will cause problems for future statements.
4633 if (isa<DeclStmt>(*B))
4634 return StmtError();
4635
4636 // Otherwise, just keep processing substatements and fail later.
4637 SubStmtInvalid = true;
4638 continue;
4639 }
Mike Stump11289f42009-09-09 15:08:12 +00004640
Douglas Gregorebe10102009-08-20 07:17:43 +00004641 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4642 Statements.push_back(Result.takeAs<Stmt>());
4643 }
Mike Stump11289f42009-09-09 15:08:12 +00004644
John McCall1ababa62010-08-27 19:56:05 +00004645 if (SubStmtInvalid)
4646 return StmtError();
4647
Douglas Gregorebe10102009-08-20 07:17:43 +00004648 if (!getDerived().AlwaysRebuild() &&
4649 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004650 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004651
4652 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4653 move_arg(Statements),
4654 S->getRBracLoc(),
4655 IsStmtExpr);
4656}
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregorebe10102009-08-20 07:17:43 +00004658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004659StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004660TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004661 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004662 {
4663 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004664 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004665
Eli Friedman06577382009-11-19 03:14:00 +00004666 // Transform the left-hand case value.
4667 LHS = getDerived().TransformExpr(S->getLHS());
4668 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004669 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004670
Eli Friedman06577382009-11-19 03:14:00 +00004671 // Transform the right-hand case value (for the GNU case-range extension).
4672 RHS = getDerived().TransformExpr(S->getRHS());
4673 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004674 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004675 }
Mike Stump11289f42009-09-09 15:08:12 +00004676
Douglas Gregorebe10102009-08-20 07:17:43 +00004677 // Build the case statement.
4678 // Case statements are always rebuilt so that they will attached to their
4679 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004680 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004681 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004682 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004683 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004684 S->getColonLoc());
4685 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004686 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004687
Douglas Gregorebe10102009-08-20 07:17:43 +00004688 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004689 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004690 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004691 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004692
Douglas Gregorebe10102009-08-20 07:17:43 +00004693 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004694 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004695}
4696
4697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004698StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004699TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004700 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004701 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004702 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004703 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004704
Douglas Gregorebe10102009-08-20 07:17:43 +00004705 // Default statements are always rebuilt
4706 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004707 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004708}
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregorebe10102009-08-20 07:17:43 +00004710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004711StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004712TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004713 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004714 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004715 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004716
Chris Lattnercab02a62011-02-17 20:34:02 +00004717 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4718 S->getDecl());
4719 if (!LD)
4720 return StmtError();
4721
4722
Douglas Gregorebe10102009-08-20 07:17:43 +00004723 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004724 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004725 cast<LabelDecl>(LD), SourceLocation(),
4726 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004727}
Mike Stump11289f42009-09-09 15:08:12 +00004728
Douglas Gregorebe10102009-08-20 07:17:43 +00004729template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004730StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004731TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004732 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004733 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004734 VarDecl *ConditionVar = 0;
4735 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004736 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004737 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004738 getDerived().TransformDefinition(
4739 S->getConditionVariable()->getLocation(),
4740 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004741 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004742 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004743 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004744 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004745
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004746 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004747 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004748
4749 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004750 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004751 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4752 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004753 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004754 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004755
John McCallb268a282010-08-23 23:25:46 +00004756 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004757 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004758 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004759
John McCallb268a282010-08-23 23:25:46 +00004760 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4761 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004762 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004763
Douglas Gregorebe10102009-08-20 07:17:43 +00004764 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004765 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004766 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004767 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004768
Douglas Gregorebe10102009-08-20 07:17:43 +00004769 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004770 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004771 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004772 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004773
Douglas Gregorebe10102009-08-20 07:17:43 +00004774 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004775 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004776 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004777 Then.get() == S->getThen() &&
4778 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004779 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004780
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004781 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004782 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004783 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004784}
4785
4786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004787StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004788TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004789 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004790 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004791 VarDecl *ConditionVar = 0;
4792 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004793 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004794 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004795 getDerived().TransformDefinition(
4796 S->getConditionVariable()->getLocation(),
4797 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004798 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004799 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004800 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004801 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004802
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004803 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004804 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004805 }
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregorebe10102009-08-20 07:17:43 +00004807 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004808 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004809 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004810 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004811 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004812 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004813
Douglas Gregorebe10102009-08-20 07:17:43 +00004814 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004815 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004816 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004817 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004818
Douglas Gregorebe10102009-08-20 07:17:43 +00004819 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004820 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4821 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004822}
Mike Stump11289f42009-09-09 15:08:12 +00004823
Douglas Gregorebe10102009-08-20 07:17:43 +00004824template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004825StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004826TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004827 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004828 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004829 VarDecl *ConditionVar = 0;
4830 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004831 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004832 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004833 getDerived().TransformDefinition(
4834 S->getConditionVariable()->getLocation(),
4835 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004836 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004837 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004838 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004839 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004840
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004841 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004842 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004843
4844 if (S->getCond()) {
4845 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004846 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4847 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004848 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004849 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004850 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004851 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004852 }
Mike Stump11289f42009-09-09 15:08:12 +00004853
John McCallb268a282010-08-23 23:25:46 +00004854 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4855 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004856 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004857
Douglas Gregorebe10102009-08-20 07:17:43 +00004858 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004859 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004860 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004861 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004862
Douglas Gregorebe10102009-08-20 07:17:43 +00004863 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004864 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004865 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004866 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004867 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004868
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004869 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004870 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004871}
Mike Stump11289f42009-09-09 15:08:12 +00004872
Douglas Gregorebe10102009-08-20 07:17:43 +00004873template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004874StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004875TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004876 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004877 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004878 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004879 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004880
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004881 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004882 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004883 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004884 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004885
Douglas Gregorebe10102009-08-20 07:17:43 +00004886 if (!getDerived().AlwaysRebuild() &&
4887 Cond.get() == S->getCond() &&
4888 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004889 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004890
John McCallb268a282010-08-23 23:25:46 +00004891 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4892 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004893 S->getRParenLoc());
4894}
Mike Stump11289f42009-09-09 15:08:12 +00004895
Douglas Gregorebe10102009-08-20 07:17:43 +00004896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004897StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004898TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004899 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004900 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004901 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004902 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004903
Douglas Gregorebe10102009-08-20 07:17:43 +00004904 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004905 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004906 VarDecl *ConditionVar = 0;
4907 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004908 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004909 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004910 getDerived().TransformDefinition(
4911 S->getConditionVariable()->getLocation(),
4912 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004913 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004914 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004915 } else {
4916 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004917
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004918 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004919 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004920
4921 if (S->getCond()) {
4922 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004923 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4924 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004925 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004926 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004927
John McCallb268a282010-08-23 23:25:46 +00004928 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004929 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004930 }
Mike Stump11289f42009-09-09 15:08:12 +00004931
John McCallb268a282010-08-23 23:25:46 +00004932 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4933 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004934 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004935
Douglas Gregorebe10102009-08-20 07:17:43 +00004936 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004937 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004938 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004939 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004940
John McCallb268a282010-08-23 23:25:46 +00004941 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4942 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004943 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004944
Douglas Gregorebe10102009-08-20 07:17:43 +00004945 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004946 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004947 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004948 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004949
Douglas Gregorebe10102009-08-20 07:17:43 +00004950 if (!getDerived().AlwaysRebuild() &&
4951 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004952 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004953 Inc.get() == S->getInc() &&
4954 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004955 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004956
Douglas Gregorebe10102009-08-20 07:17:43 +00004957 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004958 Init.get(), FullCond, ConditionVar,
4959 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004960}
4961
4962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004963StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004964TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00004965 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
4966 S->getLabel());
4967 if (!LD)
4968 return StmtError();
4969
Douglas Gregorebe10102009-08-20 07:17:43 +00004970 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004971 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004972 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00004973}
4974
4975template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004976StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004977TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004978 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004979 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004980 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004981
Douglas Gregorebe10102009-08-20 07:17:43 +00004982 if (!getDerived().AlwaysRebuild() &&
4983 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004984 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004985
4986 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004987 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004988}
4989
4990template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004991StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004992TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004993 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004994}
Mike Stump11289f42009-09-09 15:08:12 +00004995
Douglas Gregorebe10102009-08-20 07:17:43 +00004996template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004997StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004998TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004999 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005000}
Mike Stump11289f42009-09-09 15:08:12 +00005001
Douglas Gregorebe10102009-08-20 07:17:43 +00005002template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005003StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005004TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005005 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005006 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005007 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005008
Mike Stump11289f42009-09-09 15:08:12 +00005009 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005010 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005011 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005012}
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregorebe10102009-08-20 07:17:43 +00005014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005015StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005016TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005017 bool DeclChanged = false;
5018 llvm::SmallVector<Decl *, 4> Decls;
5019 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5020 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005021 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5022 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005023 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005024 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005025
Douglas Gregorebe10102009-08-20 07:17:43 +00005026 if (Transformed != *D)
5027 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005028
Douglas Gregorebe10102009-08-20 07:17:43 +00005029 Decls.push_back(Transformed);
5030 }
Mike Stump11289f42009-09-09 15:08:12 +00005031
Douglas Gregorebe10102009-08-20 07:17:43 +00005032 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005033 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005034
5035 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005036 S->getStartLoc(), S->getEndLoc());
5037}
Mike Stump11289f42009-09-09 15:08:12 +00005038
Douglas Gregorebe10102009-08-20 07:17:43 +00005039template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005040StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005041TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005042
John McCall37ad5512010-08-23 06:44:23 +00005043 ASTOwningVector<Expr*> Constraints(getSema());
5044 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005045 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005046
John McCalldadc5752010-08-24 06:29:42 +00005047 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005048 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005049
5050 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005051
Anders Carlssonaaeef072010-01-24 05:50:09 +00005052 // Go through the outputs.
5053 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005054 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005055
Anders Carlssonaaeef072010-01-24 05:50:09 +00005056 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005057 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005058
Anders Carlssonaaeef072010-01-24 05:50:09 +00005059 // Transform the output expr.
5060 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005061 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005062 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005063 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005064
Anders Carlssonaaeef072010-01-24 05:50:09 +00005065 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005066
John McCallb268a282010-08-23 23:25:46 +00005067 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005068 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005069
Anders Carlssonaaeef072010-01-24 05:50:09 +00005070 // Go through the inputs.
5071 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005072 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005073
Anders Carlssonaaeef072010-01-24 05:50:09 +00005074 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005075 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005076
Anders Carlssonaaeef072010-01-24 05:50:09 +00005077 // Transform the input expr.
5078 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005079 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005080 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005081 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005082
Anders Carlssonaaeef072010-01-24 05:50:09 +00005083 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005084
John McCallb268a282010-08-23 23:25:46 +00005085 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005086 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005087
Anders Carlssonaaeef072010-01-24 05:50:09 +00005088 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005089 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005090
5091 // Go through the clobbers.
5092 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005093 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005094
5095 // No need to transform the asm string literal.
5096 AsmString = SemaRef.Owned(S->getAsmString());
5097
5098 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5099 S->isSimple(),
5100 S->isVolatile(),
5101 S->getNumOutputs(),
5102 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005103 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005104 move_arg(Constraints),
5105 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005106 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005107 move_arg(Clobbers),
5108 S->getRParenLoc(),
5109 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005110}
5111
5112
5113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005114StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005115TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005116 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005117 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005118 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005119 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005120
Douglas Gregor96c79492010-04-23 22:50:49 +00005121 // Transform the @catch statements (if present).
5122 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005123 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005124 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005125 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005126 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005127 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005128 if (Catch.get() != S->getCatchStmt(I))
5129 AnyCatchChanged = true;
5130 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005131 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005132
Douglas Gregor306de2f2010-04-22 23:59:56 +00005133 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005134 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005135 if (S->getFinallyStmt()) {
5136 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5137 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005138 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005139 }
5140
5141 // If nothing changed, just retain this statement.
5142 if (!getDerived().AlwaysRebuild() &&
5143 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005144 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005145 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005146 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005147
Douglas Gregor306de2f2010-04-22 23:59:56 +00005148 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005149 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5150 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005151}
Mike Stump11289f42009-09-09 15:08:12 +00005152
Douglas Gregorebe10102009-08-20 07:17:43 +00005153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005154StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005155TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005156 // Transform the @catch parameter, if there is one.
5157 VarDecl *Var = 0;
5158 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5159 TypeSourceInfo *TSInfo = 0;
5160 if (FromVar->getTypeSourceInfo()) {
5161 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5162 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005163 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005164 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005165
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005166 QualType T;
5167 if (TSInfo)
5168 T = TSInfo->getType();
5169 else {
5170 T = getDerived().TransformType(FromVar->getType());
5171 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005172 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005173 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005174
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005175 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5176 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005177 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005178 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005179
John McCalldadc5752010-08-24 06:29:42 +00005180 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005181 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005182 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005183
5184 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005185 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005186 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005187}
Mike Stump11289f42009-09-09 15:08:12 +00005188
Douglas Gregorebe10102009-08-20 07:17:43 +00005189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005190StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005191TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005192 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005193 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005194 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005195 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005196
Douglas Gregor306de2f2010-04-22 23:59:56 +00005197 // If nothing changed, just retain this statement.
5198 if (!getDerived().AlwaysRebuild() &&
5199 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005200 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005201
5202 // Build a new statement.
5203 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005204 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005205}
Mike Stump11289f42009-09-09 15:08:12 +00005206
Douglas Gregorebe10102009-08-20 07:17:43 +00005207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005208StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005209TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005210 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005211 if (S->getThrowExpr()) {
5212 Operand = getDerived().TransformExpr(S->getThrowExpr());
5213 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005214 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005215 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005216
Douglas Gregor2900c162010-04-22 21:44:01 +00005217 if (!getDerived().AlwaysRebuild() &&
5218 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005219 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005220
John McCallb268a282010-08-23 23:25:46 +00005221 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005222}
Mike Stump11289f42009-09-09 15:08:12 +00005223
Douglas Gregorebe10102009-08-20 07:17:43 +00005224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005225StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005226TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005227 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005228 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005229 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005230 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005231 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005232
Douglas Gregor6148de72010-04-22 22:01:21 +00005233 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005234 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005235 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005236 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005237
Douglas Gregor6148de72010-04-22 22:01:21 +00005238 // If nothing change, just retain the current statement.
5239 if (!getDerived().AlwaysRebuild() &&
5240 Object.get() == S->getSynchExpr() &&
5241 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005242 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005243
5244 // Build a new statement.
5245 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005246 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005247}
5248
5249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005250StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005251TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005252 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005253 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005254 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005255 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005256 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005257
Douglas Gregorf68a5082010-04-22 23:10:45 +00005258 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005259 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005260 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005261 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005262
Douglas Gregorf68a5082010-04-22 23:10:45 +00005263 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005264 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005265 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005266 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005267
Douglas Gregorf68a5082010-04-22 23:10:45 +00005268 // If nothing changed, just retain this statement.
5269 if (!getDerived().AlwaysRebuild() &&
5270 Element.get() == S->getElement() &&
5271 Collection.get() == S->getCollection() &&
5272 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005273 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005274
Douglas Gregorf68a5082010-04-22 23:10:45 +00005275 // Build a new statement.
5276 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5277 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005278 Element.get(),
5279 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005280 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005281 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005282}
5283
5284
5285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005286StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005287TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5288 // Transform the exception declaration, if any.
5289 VarDecl *Var = 0;
5290 if (S->getExceptionDecl()) {
5291 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005292 TypeSourceInfo *T = getDerived().TransformType(
5293 ExceptionDecl->getTypeSourceInfo());
5294 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005295 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005296
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005297 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005298 ExceptionDecl->getInnerLocStart(),
5299 ExceptionDecl->getLocation(),
5300 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005301 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005302 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005303 }
Mike Stump11289f42009-09-09 15:08:12 +00005304
Douglas Gregorebe10102009-08-20 07:17:43 +00005305 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005306 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005307 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005308 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005309
Douglas Gregorebe10102009-08-20 07:17:43 +00005310 if (!getDerived().AlwaysRebuild() &&
5311 !Var &&
5312 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005313 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005314
5315 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5316 Var,
John McCallb268a282010-08-23 23:25:46 +00005317 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005318}
Mike Stump11289f42009-09-09 15:08:12 +00005319
Douglas Gregorebe10102009-08-20 07:17:43 +00005320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005321StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005322TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5323 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005324 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005325 = getDerived().TransformCompoundStmt(S->getTryBlock());
5326 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005327 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005328
Douglas Gregorebe10102009-08-20 07:17:43 +00005329 // Transform the handlers.
5330 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005331 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005332 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005333 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005334 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5335 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005336 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005337
Douglas Gregorebe10102009-08-20 07:17:43 +00005338 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5339 Handlers.push_back(Handler.takeAs<Stmt>());
5340 }
Mike Stump11289f42009-09-09 15:08:12 +00005341
Douglas Gregorebe10102009-08-20 07:17:43 +00005342 if (!getDerived().AlwaysRebuild() &&
5343 TryBlock.get() == S->getTryBlock() &&
5344 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005345 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005346
John McCallb268a282010-08-23 23:25:46 +00005347 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005348 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005349}
Mike Stump11289f42009-09-09 15:08:12 +00005350
Douglas Gregorebe10102009-08-20 07:17:43 +00005351//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005352// Expression transformation
5353//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005355ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005356TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005357 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005358}
Mike Stump11289f42009-09-09 15:08:12 +00005359
5360template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005361ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005362TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005363 NestedNameSpecifierLoc QualifierLoc;
5364 if (E->getQualifierLoc()) {
5365 QualifierLoc
5366 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5367 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005368 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005369 }
John McCallce546572009-12-08 09:08:17 +00005370
5371 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005372 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5373 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005374 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005375 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005376
John McCall815039a2010-08-17 21:27:17 +00005377 DeclarationNameInfo NameInfo = E->getNameInfo();
5378 if (NameInfo.getName()) {
5379 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5380 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005381 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005382 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005383
5384 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005385 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005386 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005387 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005388 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005389
5390 // Mark it referenced in the new context regardless.
5391 // FIXME: this is a bit instantiation-specific.
5392 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5393
John McCallc3007a22010-10-26 07:05:15 +00005394 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005395 }
John McCallce546572009-12-08 09:08:17 +00005396
5397 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005398 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005399 TemplateArgs = &TransArgs;
5400 TransArgs.setLAngleLoc(E->getLAngleLoc());
5401 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005402 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5403 E->getNumTemplateArgs(),
5404 TransArgs))
5405 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005406 }
5407
Douglas Gregorea972d32011-02-28 21:54:11 +00005408 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5409 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005410}
Mike Stump11289f42009-09-09 15:08:12 +00005411
Douglas Gregora16548e2009-08-11 05:31:07 +00005412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005413ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005414TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005415 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005416}
Mike Stump11289f42009-09-09 15:08:12 +00005417
Douglas Gregora16548e2009-08-11 05:31:07 +00005418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005420TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005421 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005422}
Mike Stump11289f42009-09-09 15:08:12 +00005423
Douglas Gregora16548e2009-08-11 05:31:07 +00005424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005425ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005426TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005427 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005428}
Mike Stump11289f42009-09-09 15:08:12 +00005429
Douglas Gregora16548e2009-08-11 05:31:07 +00005430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005431ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005432TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005433 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005434}
Mike Stump11289f42009-09-09 15:08:12 +00005435
Douglas Gregora16548e2009-08-11 05:31:07 +00005436template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005437ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005438TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005439 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005440}
5441
5442template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005443ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005444TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005445 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005446 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005447 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005448
Douglas Gregora16548e2009-08-11 05:31:07 +00005449 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005450 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005451
John McCallb268a282010-08-23 23:25:46 +00005452 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005453 E->getRParen());
5454}
5455
Mike Stump11289f42009-09-09 15:08:12 +00005456template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005457ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005458TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005459 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005460 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005461 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005462
Douglas Gregora16548e2009-08-11 05:31:07 +00005463 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005464 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005465
Douglas Gregora16548e2009-08-11 05:31:07 +00005466 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5467 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005468 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005469}
Mike Stump11289f42009-09-09 15:08:12 +00005470
Douglas Gregora16548e2009-08-11 05:31:07 +00005471template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005472ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005473TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5474 // Transform the type.
5475 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5476 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005477 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005478
Douglas Gregor882211c2010-04-28 22:16:22 +00005479 // Transform all of the components into components similar to what the
5480 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005481 // FIXME: It would be slightly more efficient in the non-dependent case to
5482 // just map FieldDecls, rather than requiring the rebuilder to look for
5483 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005484 // template code that we don't care.
5485 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005486 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005487 typedef OffsetOfExpr::OffsetOfNode Node;
5488 llvm::SmallVector<Component, 4> Components;
5489 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5490 const Node &ON = E->getComponent(I);
5491 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005492 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005493 Comp.LocStart = ON.getSourceRange().getBegin();
5494 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005495 switch (ON.getKind()) {
5496 case Node::Array: {
5497 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005498 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005499 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005500 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005501
Douglas Gregor882211c2010-04-28 22:16:22 +00005502 ExprChanged = ExprChanged || Index.get() != FromIndex;
5503 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005504 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005505 break;
5506 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005507
Douglas Gregor882211c2010-04-28 22:16:22 +00005508 case Node::Field:
5509 case Node::Identifier:
5510 Comp.isBrackets = false;
5511 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005512 if (!Comp.U.IdentInfo)
5513 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005514
Douglas Gregor882211c2010-04-28 22:16:22 +00005515 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005516
Douglas Gregord1702062010-04-29 00:18:15 +00005517 case Node::Base:
5518 // Will be recomputed during the rebuild.
5519 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005520 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005521
Douglas Gregor882211c2010-04-28 22:16:22 +00005522 Components.push_back(Comp);
5523 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005524
Douglas Gregor882211c2010-04-28 22:16:22 +00005525 // If nothing changed, retain the existing expression.
5526 if (!getDerived().AlwaysRebuild() &&
5527 Type == E->getTypeSourceInfo() &&
5528 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005529 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005530
Douglas Gregor882211c2010-04-28 22:16:22 +00005531 // Build a new offsetof expression.
5532 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5533 Components.data(), Components.size(),
5534 E->getRParenLoc());
5535}
5536
5537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005538ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005539TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5540 assert(getDerived().AlreadyTransformed(E->getType()) &&
5541 "opaque value expression requires transformation");
5542 return SemaRef.Owned(E);
5543}
5544
5545template<typename Derived>
5546ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005547TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5548 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005549 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005550 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005551
John McCallbcd03502009-12-07 02:54:59 +00005552 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005553 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005554 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005555
John McCall4c98fd82009-11-04 07:28:41 +00005556 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005557 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005558
Peter Collingbournee190dee2011-03-11 19:24:49 +00005559 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5560 E->getKind(),
5561 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005562 }
Mike Stump11289f42009-09-09 15:08:12 +00005563
John McCalldadc5752010-08-24 06:29:42 +00005564 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005565 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005566 // C++0x [expr.sizeof]p1:
5567 // The operand is either an expression, which is an unevaluated operand
5568 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005569 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005570
Douglas Gregora16548e2009-08-11 05:31:07 +00005571 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5572 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005573 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005574
Douglas Gregora16548e2009-08-11 05:31:07 +00005575 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005576 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005577 }
Mike Stump11289f42009-09-09 15:08:12 +00005578
Peter Collingbournee190dee2011-03-11 19:24:49 +00005579 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5580 E->getOperatorLoc(),
5581 E->getKind(),
5582 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005583}
Mike Stump11289f42009-09-09 15:08:12 +00005584
Douglas Gregora16548e2009-08-11 05:31:07 +00005585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005586ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005587TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005588 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005589 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005590 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005591
John McCalldadc5752010-08-24 06:29:42 +00005592 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005593 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005594 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005595
5596
Douglas Gregora16548e2009-08-11 05:31:07 +00005597 if (!getDerived().AlwaysRebuild() &&
5598 LHS.get() == E->getLHS() &&
5599 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005600 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005601
John McCallb268a282010-08-23 23:25:46 +00005602 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005603 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005604 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005605 E->getRBracketLoc());
5606}
Mike Stump11289f42009-09-09 15:08:12 +00005607
5608template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005609ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005610TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005611 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005612 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005613 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005614 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005615
5616 // Transform arguments.
5617 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005618 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005619 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5620 &ArgChanged))
5621 return ExprError();
5622
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 if (!getDerived().AlwaysRebuild() &&
5624 Callee.get() == E->getCallee() &&
5625 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005626 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005627
Douglas Gregora16548e2009-08-11 05:31:07 +00005628 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005629 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005630 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005631 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005633 E->getRParenLoc());
5634}
Mike Stump11289f42009-09-09 15:08:12 +00005635
5636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005637ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005638TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005639 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005640 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005641 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005642
Douglas Gregorea972d32011-02-28 21:54:11 +00005643 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005644 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005645 QualifierLoc
5646 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5647
5648 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005649 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005650 }
Mike Stump11289f42009-09-09 15:08:12 +00005651
Eli Friedman2cfcef62009-12-04 06:40:45 +00005652 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005653 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5654 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005655 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005656 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005657
John McCall16df1e52010-03-30 21:47:33 +00005658 NamedDecl *FoundDecl = E->getFoundDecl();
5659 if (FoundDecl == E->getMemberDecl()) {
5660 FoundDecl = Member;
5661 } else {
5662 FoundDecl = cast_or_null<NamedDecl>(
5663 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5664 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005665 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005666 }
5667
Douglas Gregora16548e2009-08-11 05:31:07 +00005668 if (!getDerived().AlwaysRebuild() &&
5669 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005670 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005671 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005672 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005673 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005674
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005675 // Mark it referenced in the new context regardless.
5676 // FIXME: this is a bit instantiation-specific.
5677 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005678 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005679 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005680
John McCall6b51f282009-11-23 01:53:49 +00005681 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005682 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005683 TransArgs.setLAngleLoc(E->getLAngleLoc());
5684 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005685 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5686 E->getNumTemplateArgs(),
5687 TransArgs))
5688 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005689 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005690
Douglas Gregora16548e2009-08-11 05:31:07 +00005691 // FIXME: Bogus source location for the operator
5692 SourceLocation FakeOperatorLoc
5693 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5694
John McCall38836f02010-01-15 08:34:02 +00005695 // FIXME: to do this check properly, we will need to preserve the
5696 // first-qualifier-in-scope here, just in case we had a dependent
5697 // base (and therefore couldn't do the check) and a
5698 // nested-name-qualifier (and therefore could do the lookup).
5699 NamedDecl *FirstQualifierInScope = 0;
5700
John McCallb268a282010-08-23 23:25:46 +00005701 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005702 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005703 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005704 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005705 Member,
John McCall16df1e52010-03-30 21:47:33 +00005706 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005707 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005708 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005709 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005710}
Mike Stump11289f42009-09-09 15:08:12 +00005711
Douglas Gregora16548e2009-08-11 05:31:07 +00005712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005713ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005714TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005715 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005716 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005717 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005718
John McCalldadc5752010-08-24 06:29:42 +00005719 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005720 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005722
Douglas Gregora16548e2009-08-11 05:31:07 +00005723 if (!getDerived().AlwaysRebuild() &&
5724 LHS.get() == E->getLHS() &&
5725 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005726 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005727
Douglas Gregora16548e2009-08-11 05:31:07 +00005728 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005729 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005730}
5731
Mike Stump11289f42009-09-09 15:08:12 +00005732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005733ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005734TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005735 CompoundAssignOperator *E) {
5736 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005737}
Mike Stump11289f42009-09-09 15:08:12 +00005738
Douglas Gregora16548e2009-08-11 05:31:07 +00005739template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005740ExprResult TreeTransform<Derived>::
5741TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5742 // Just rebuild the common and RHS expressions and see whether we
5743 // get any changes.
5744
5745 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5746 if (commonExpr.isInvalid())
5747 return ExprError();
5748
5749 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5750 if (rhs.isInvalid())
5751 return ExprError();
5752
5753 if (!getDerived().AlwaysRebuild() &&
5754 commonExpr.get() == e->getCommon() &&
5755 rhs.get() == e->getFalseExpr())
5756 return SemaRef.Owned(e);
5757
5758 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5759 e->getQuestionLoc(),
5760 0,
5761 e->getColonLoc(),
5762 rhs.get());
5763}
5764
5765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005766ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005767TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005768 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005769 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005771
John McCalldadc5752010-08-24 06:29:42 +00005772 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005775
John McCalldadc5752010-08-24 06:29:42 +00005776 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005777 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005778 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005779
Douglas Gregora16548e2009-08-11 05:31:07 +00005780 if (!getDerived().AlwaysRebuild() &&
5781 Cond.get() == E->getCond() &&
5782 LHS.get() == E->getLHS() &&
5783 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005784 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005785
John McCallb268a282010-08-23 23:25:46 +00005786 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005787 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005788 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005789 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005790 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005791}
Mike Stump11289f42009-09-09 15:08:12 +00005792
5793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005794ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005795TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005796 // Implicit casts are eliminated during transformation, since they
5797 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005798 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005799}
Mike Stump11289f42009-09-09 15:08:12 +00005800
Douglas Gregora16548e2009-08-11 05:31:07 +00005801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005802ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005803TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005804 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5805 if (!Type)
5806 return ExprError();
5807
John McCalldadc5752010-08-24 06:29:42 +00005808 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005809 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005810 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005811 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005812
Douglas Gregora16548e2009-08-11 05:31:07 +00005813 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005814 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005815 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005816 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005817
John McCall97513962010-01-15 18:39:57 +00005818 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005819 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005821 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005822}
Mike Stump11289f42009-09-09 15:08:12 +00005823
Douglas Gregora16548e2009-08-11 05:31:07 +00005824template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005825ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005826TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005827 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5828 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5829 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005830 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005831
John McCalldadc5752010-08-24 06:29:42 +00005832 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005833 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005834 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005835
Douglas Gregora16548e2009-08-11 05:31:07 +00005836 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005837 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005838 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005839 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005840
John McCall5d7aa7f2010-01-19 22:33:45 +00005841 // Note: the expression type doesn't necessarily match the
5842 // type-as-written, but that's okay, because it should always be
5843 // derivable from the initializer.
5844
John McCalle15bbff2010-01-18 19:35:47 +00005845 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005846 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005847 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005848}
Mike Stump11289f42009-09-09 15:08:12 +00005849
Douglas Gregora16548e2009-08-11 05:31:07 +00005850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005851ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005852TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005853 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005854 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005855 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005856
Douglas Gregora16548e2009-08-11 05:31:07 +00005857 if (!getDerived().AlwaysRebuild() &&
5858 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005859 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005860
Douglas Gregora16548e2009-08-11 05:31:07 +00005861 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005862 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005863 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005864 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005865 E->getAccessorLoc(),
5866 E->getAccessor());
5867}
Mike Stump11289f42009-09-09 15:08:12 +00005868
Douglas Gregora16548e2009-08-11 05:31:07 +00005869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005870ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005871TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005872 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005873
John McCall37ad5512010-08-23 06:44:23 +00005874 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005875 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5876 Inits, &InitChanged))
5877 return ExprError();
5878
Douglas Gregora16548e2009-08-11 05:31:07 +00005879 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005880 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005881
Douglas Gregora16548e2009-08-11 05:31:07 +00005882 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005883 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005884}
Mike Stump11289f42009-09-09 15:08:12 +00005885
Douglas Gregora16548e2009-08-11 05:31:07 +00005886template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005887ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005888TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005890
Douglas Gregorebe10102009-08-20 07:17:43 +00005891 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005892 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005895
Douglas Gregorebe10102009-08-20 07:17:43 +00005896 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005897 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005898 bool ExprChanged = false;
5899 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5900 DEnd = E->designators_end();
5901 D != DEnd; ++D) {
5902 if (D->isFieldDesignator()) {
5903 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5904 D->getDotLoc(),
5905 D->getFieldLoc()));
5906 continue;
5907 }
Mike Stump11289f42009-09-09 15:08:12 +00005908
Douglas Gregora16548e2009-08-11 05:31:07 +00005909 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005910 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005911 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005912 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005913
5914 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005915 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005916
Douglas Gregora16548e2009-08-11 05:31:07 +00005917 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5918 ArrayExprs.push_back(Index.release());
5919 continue;
5920 }
Mike Stump11289f42009-09-09 15:08:12 +00005921
Douglas Gregora16548e2009-08-11 05:31:07 +00005922 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005923 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005924 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5925 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005926 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005927
John McCalldadc5752010-08-24 06:29:42 +00005928 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005929 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005930 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005931
5932 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005933 End.get(),
5934 D->getLBracketLoc(),
5935 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005936
Douglas Gregora16548e2009-08-11 05:31:07 +00005937 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5938 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005939
Douglas Gregora16548e2009-08-11 05:31:07 +00005940 ArrayExprs.push_back(Start.release());
5941 ArrayExprs.push_back(End.release());
5942 }
Mike Stump11289f42009-09-09 15:08:12 +00005943
Douglas Gregora16548e2009-08-11 05:31:07 +00005944 if (!getDerived().AlwaysRebuild() &&
5945 Init.get() == E->getInit() &&
5946 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005947 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005948
Douglas Gregora16548e2009-08-11 05:31:07 +00005949 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5950 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005951 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005952}
Mike Stump11289f42009-09-09 15:08:12 +00005953
Douglas Gregora16548e2009-08-11 05:31:07 +00005954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005955ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005956TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005957 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005958 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005959
Douglas Gregor3da3c062009-10-28 00:29:27 +00005960 // FIXME: Will we ever have proper type location here? Will we actually
5961 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005962 QualType T = getDerived().TransformType(E->getType());
5963 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005964 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005965
Douglas Gregora16548e2009-08-11 05:31:07 +00005966 if (!getDerived().AlwaysRebuild() &&
5967 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005968 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005969
Douglas Gregora16548e2009-08-11 05:31:07 +00005970 return getDerived().RebuildImplicitValueInitExpr(T);
5971}
Mike Stump11289f42009-09-09 15:08:12 +00005972
Douglas Gregora16548e2009-08-11 05:31:07 +00005973template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005974ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005975TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005976 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5977 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005978 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005979
John McCalldadc5752010-08-24 06:29:42 +00005980 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005981 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005982 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005983
Douglas Gregora16548e2009-08-11 05:31:07 +00005984 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005985 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005986 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005987 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005988
John McCallb268a282010-08-23 23:25:46 +00005989 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005990 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005991}
5992
5993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005994ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005995TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005996 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005997 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005998 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5999 &ArgumentChanged))
6000 return ExprError();
6001
Douglas Gregora16548e2009-08-11 05:31:07 +00006002 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6003 move_arg(Inits),
6004 E->getRParenLoc());
6005}
Mike Stump11289f42009-09-09 15:08:12 +00006006
Douglas Gregora16548e2009-08-11 05:31:07 +00006007/// \brief Transform an address-of-label expression.
6008///
6009/// By default, the transformation of an address-of-label expression always
6010/// rebuilds the expression, so that the label identifier can be resolved to
6011/// the corresponding label statement by semantic analysis.
6012template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006013ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006014TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006015 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6016 E->getLabel());
6017 if (!LD)
6018 return ExprError();
6019
Douglas Gregora16548e2009-08-11 05:31:07 +00006020 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006021 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006022}
Mike Stump11289f42009-09-09 15:08:12 +00006023
6024template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006025ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006026TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006027 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006028 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6029 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006031
Douglas Gregora16548e2009-08-11 05:31:07 +00006032 if (!getDerived().AlwaysRebuild() &&
6033 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006034 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006035
6036 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006037 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006038 E->getRParenLoc());
6039}
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregora16548e2009-08-11 05:31:07 +00006041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006042ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006043TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006044 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006045 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006046 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006047
John McCalldadc5752010-08-24 06:29:42 +00006048 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006049 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006050 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006051
John McCalldadc5752010-08-24 06:29:42 +00006052 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006053 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006054 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006055
Douglas Gregora16548e2009-08-11 05:31:07 +00006056 if (!getDerived().AlwaysRebuild() &&
6057 Cond.get() == E->getCond() &&
6058 LHS.get() == E->getLHS() &&
6059 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006060 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006061
Douglas Gregora16548e2009-08-11 05:31:07 +00006062 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006063 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006064 E->getRParenLoc());
6065}
Mike Stump11289f42009-09-09 15:08:12 +00006066
Douglas Gregora16548e2009-08-11 05:31:07 +00006067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006068ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006069TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006070 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006071}
6072
6073template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006074ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006075TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006076 switch (E->getOperator()) {
6077 case OO_New:
6078 case OO_Delete:
6079 case OO_Array_New:
6080 case OO_Array_Delete:
6081 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006082 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006083
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006084 case OO_Call: {
6085 // This is a call to an object's operator().
6086 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6087
6088 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006089 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006090 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006091 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006092
6093 // FIXME: Poor location information
6094 SourceLocation FakeLParenLoc
6095 = SemaRef.PP.getLocForEndOfToken(
6096 static_cast<Expr *>(Object.get())->getLocEnd());
6097
6098 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006099 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006100 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6101 Args))
6102 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006103
John McCallb268a282010-08-23 23:25:46 +00006104 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006105 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006106 E->getLocEnd());
6107 }
6108
6109#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6110 case OO_##Name:
6111#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6112#include "clang/Basic/OperatorKinds.def"
6113 case OO_Subscript:
6114 // Handled below.
6115 break;
6116
6117 case OO_Conditional:
6118 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006119 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006120
6121 case OO_None:
6122 case NUM_OVERLOADED_OPERATORS:
6123 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006124 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006125 }
6126
John McCalldadc5752010-08-24 06:29:42 +00006127 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006128 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006129 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006130
John McCalldadc5752010-08-24 06:29:42 +00006131 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006132 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006133 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006134
John McCalldadc5752010-08-24 06:29:42 +00006135 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006136 if (E->getNumArgs() == 2) {
6137 Second = getDerived().TransformExpr(E->getArg(1));
6138 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006139 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006140 }
Mike Stump11289f42009-09-09 15:08:12 +00006141
Douglas Gregora16548e2009-08-11 05:31:07 +00006142 if (!getDerived().AlwaysRebuild() &&
6143 Callee.get() == E->getCallee() &&
6144 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006145 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006146 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006147
Douglas Gregora16548e2009-08-11 05:31:07 +00006148 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6149 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006150 Callee.get(),
6151 First.get(),
6152 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006153}
Mike Stump11289f42009-09-09 15:08:12 +00006154
Douglas Gregora16548e2009-08-11 05:31:07 +00006155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006156ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006157TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6158 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006159}
Mike Stump11289f42009-09-09 15:08:12 +00006160
Douglas Gregora16548e2009-08-11 05:31:07 +00006161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006162ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006163TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6164 // Transform the callee.
6165 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6166 if (Callee.isInvalid())
6167 return ExprError();
6168
6169 // Transform exec config.
6170 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6171 if (EC.isInvalid())
6172 return ExprError();
6173
6174 // Transform arguments.
6175 bool ArgChanged = false;
6176 ASTOwningVector<Expr*> Args(SemaRef);
6177 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6178 &ArgChanged))
6179 return ExprError();
6180
6181 if (!getDerived().AlwaysRebuild() &&
6182 Callee.get() == E->getCallee() &&
6183 !ArgChanged)
6184 return SemaRef.Owned(E);
6185
6186 // FIXME: Wrong source location information for the '('.
6187 SourceLocation FakeLParenLoc
6188 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6189 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6190 move_arg(Args),
6191 E->getRParenLoc(), EC.get());
6192}
6193
6194template<typename Derived>
6195ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006196TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006197 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6198 if (!Type)
6199 return ExprError();
6200
John McCalldadc5752010-08-24 06:29:42 +00006201 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006202 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006203 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006204 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006205
Douglas Gregora16548e2009-08-11 05:31:07 +00006206 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006207 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006208 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006209 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006210
Douglas Gregora16548e2009-08-11 05:31:07 +00006211 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006212 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006213 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6214 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6215 SourceLocation FakeRParenLoc
6216 = SemaRef.PP.getLocForEndOfToken(
6217 E->getSubExpr()->getSourceRange().getEnd());
6218 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006219 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006220 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006221 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006222 FakeRAngleLoc,
6223 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006224 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006225 FakeRParenLoc);
6226}
Mike Stump11289f42009-09-09 15:08:12 +00006227
Douglas Gregora16548e2009-08-11 05:31:07 +00006228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006229ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006230TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6231 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006232}
Mike Stump11289f42009-09-09 15:08:12 +00006233
6234template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006235ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006236TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6237 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006238}
6239
Douglas Gregora16548e2009-08-11 05:31:07 +00006240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006241ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006242TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006243 CXXReinterpretCastExpr *E) {
6244 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006245}
Mike Stump11289f42009-09-09 15:08:12 +00006246
Douglas Gregora16548e2009-08-11 05:31:07 +00006247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006248ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006249TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6250 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006251}
Mike Stump11289f42009-09-09 15:08:12 +00006252
Douglas Gregora16548e2009-08-11 05:31:07 +00006253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006254ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006255TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006256 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006257 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6258 if (!Type)
6259 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006260
John McCalldadc5752010-08-24 06:29:42 +00006261 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006262 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006263 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006264 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006265
Douglas Gregora16548e2009-08-11 05:31:07 +00006266 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006267 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006268 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006269 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006270
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006271 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006272 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006273 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006274 E->getRParenLoc());
6275}
Mike Stump11289f42009-09-09 15:08:12 +00006276
Douglas Gregora16548e2009-08-11 05:31:07 +00006277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006278ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006279TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006280 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006281 TypeSourceInfo *TInfo
6282 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6283 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006285
Douglas Gregora16548e2009-08-11 05:31:07 +00006286 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006287 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006288 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006289
Douglas Gregor9da64192010-04-26 22:37:10 +00006290 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6291 E->getLocStart(),
6292 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006293 E->getLocEnd());
6294 }
Mike Stump11289f42009-09-09 15:08:12 +00006295
Douglas Gregora16548e2009-08-11 05:31:07 +00006296 // We don't know whether the expression is potentially evaluated until
6297 // after we perform semantic analysis, so the expression is potentially
6298 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006299 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006300 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006301
John McCalldadc5752010-08-24 06:29:42 +00006302 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006303 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006304 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006305
Douglas Gregora16548e2009-08-11 05:31:07 +00006306 if (!getDerived().AlwaysRebuild() &&
6307 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006308 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006309
Douglas Gregor9da64192010-04-26 22:37:10 +00006310 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6311 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006312 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006313 E->getLocEnd());
6314}
6315
6316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006317ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006318TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6319 if (E->isTypeOperand()) {
6320 TypeSourceInfo *TInfo
6321 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6322 if (!TInfo)
6323 return ExprError();
6324
6325 if (!getDerived().AlwaysRebuild() &&
6326 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006327 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006328
Douglas Gregor69735112011-03-06 17:40:41 +00006329 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006330 E->getLocStart(),
6331 TInfo,
6332 E->getLocEnd());
6333 }
6334
6335 // We don't know whether the expression is potentially evaluated until
6336 // after we perform semantic analysis, so the expression is potentially
6337 // potentially evaluated.
6338 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6339
6340 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6341 if (SubExpr.isInvalid())
6342 return ExprError();
6343
6344 if (!getDerived().AlwaysRebuild() &&
6345 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006346 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006347
6348 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6349 E->getLocStart(),
6350 SubExpr.get(),
6351 E->getLocEnd());
6352}
6353
6354template<typename Derived>
6355ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006356TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006357 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006358}
Mike Stump11289f42009-09-09 15:08:12 +00006359
Douglas Gregora16548e2009-08-11 05:31:07 +00006360template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006361ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006362TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006363 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006364 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006365}
Mike Stump11289f42009-09-09 15:08:12 +00006366
Douglas Gregora16548e2009-08-11 05:31:07 +00006367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006369TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006370 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6371 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6372 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006373
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006374 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006375 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006376
Douglas Gregorb15af892010-01-07 23:12:05 +00006377 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006378}
Mike Stump11289f42009-09-09 15:08:12 +00006379
Douglas Gregora16548e2009-08-11 05:31:07 +00006380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006381ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006382TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006383 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006384 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006386
Douglas Gregora16548e2009-08-11 05:31:07 +00006387 if (!getDerived().AlwaysRebuild() &&
6388 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006389 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006390
John McCallb268a282010-08-23 23:25:46 +00006391 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006392}
Mike Stump11289f42009-09-09 15:08:12 +00006393
Douglas Gregora16548e2009-08-11 05:31:07 +00006394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006395ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006396TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006397 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006398 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6399 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006400 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006401 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006402
Chandler Carruth794da4c2010-02-08 06:42:49 +00006403 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006404 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006405 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006406
Douglas Gregor033f6752009-12-23 23:03:06 +00006407 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006408}
Mike Stump11289f42009-09-09 15:08:12 +00006409
Douglas Gregora16548e2009-08-11 05:31:07 +00006410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006411ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006412TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6413 CXXScalarValueInitExpr *E) {
6414 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6415 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006416 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006417
Douglas Gregora16548e2009-08-11 05:31:07 +00006418 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006419 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006420 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006421
Douglas Gregor2b88c112010-09-08 00:15:04 +00006422 return getDerived().RebuildCXXScalarValueInitExpr(T,
6423 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006424 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006425}
Mike Stump11289f42009-09-09 15:08:12 +00006426
Douglas Gregora16548e2009-08-11 05:31:07 +00006427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006428ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006429TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006430 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006431 TypeSourceInfo *AllocTypeInfo
6432 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6433 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006434 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006435
Douglas Gregora16548e2009-08-11 05:31:07 +00006436 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006437 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006439 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006440
Douglas Gregora16548e2009-08-11 05:31:07 +00006441 // Transform the placement arguments (if any).
6442 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006443 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006444 if (getDerived().TransformExprs(E->getPlacementArgs(),
6445 E->getNumPlacementArgs(), true,
6446 PlacementArgs, &ArgumentChanged))
6447 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006448
Douglas Gregorebe10102009-08-20 07:17:43 +00006449 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006450 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006451 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6452 ConstructorArgs, &ArgumentChanged))
6453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006454
Douglas Gregord2d9da02010-02-26 00:38:10 +00006455 // Transform constructor, new operator, and delete operator.
6456 CXXConstructorDecl *Constructor = 0;
6457 if (E->getConstructor()) {
6458 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006459 getDerived().TransformDecl(E->getLocStart(),
6460 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006461 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006462 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006463 }
6464
6465 FunctionDecl *OperatorNew = 0;
6466 if (E->getOperatorNew()) {
6467 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006468 getDerived().TransformDecl(E->getLocStart(),
6469 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006470 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006471 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006472 }
6473
6474 FunctionDecl *OperatorDelete = 0;
6475 if (E->getOperatorDelete()) {
6476 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006477 getDerived().TransformDecl(E->getLocStart(),
6478 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006479 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006480 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006481 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006482
Douglas Gregora16548e2009-08-11 05:31:07 +00006483 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006484 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006485 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006486 Constructor == E->getConstructor() &&
6487 OperatorNew == E->getOperatorNew() &&
6488 OperatorDelete == E->getOperatorDelete() &&
6489 !ArgumentChanged) {
6490 // Mark any declarations we need as referenced.
6491 // FIXME: instantiation-specific.
6492 if (Constructor)
6493 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6494 if (OperatorNew)
6495 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6496 if (OperatorDelete)
6497 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006498 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006499 }
Mike Stump11289f42009-09-09 15:08:12 +00006500
Douglas Gregor0744ef62010-09-07 21:49:58 +00006501 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006502 if (!ArraySize.get()) {
6503 // If no array size was specified, but the new expression was
6504 // instantiated with an array type (e.g., "new T" where T is
6505 // instantiated with "int[4]"), extract the outer bound from the
6506 // array type as our array size. We do this with constant and
6507 // dependently-sized array types.
6508 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6509 if (!ArrayT) {
6510 // Do nothing
6511 } else if (const ConstantArrayType *ConsArrayT
6512 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006513 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006514 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6515 ConsArrayT->getSize(),
6516 SemaRef.Context.getSizeType(),
6517 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006518 AllocType = ConsArrayT->getElementType();
6519 } else if (const DependentSizedArrayType *DepArrayT
6520 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6521 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006522 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006523 AllocType = DepArrayT->getElementType();
6524 }
6525 }
6526 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006527
Douglas Gregora16548e2009-08-11 05:31:07 +00006528 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6529 E->isGlobalNew(),
6530 /*FIXME:*/E->getLocStart(),
6531 move_arg(PlacementArgs),
6532 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006533 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006534 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006535 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006536 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006537 /*FIXME:*/E->getLocStart(),
6538 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006539 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006540}
Mike Stump11289f42009-09-09 15:08:12 +00006541
Douglas Gregora16548e2009-08-11 05:31:07 +00006542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006543ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006544TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006545 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006546 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006547 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006548
Douglas Gregord2d9da02010-02-26 00:38:10 +00006549 // Transform the delete operator, if known.
6550 FunctionDecl *OperatorDelete = 0;
6551 if (E->getOperatorDelete()) {
6552 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006553 getDerived().TransformDecl(E->getLocStart(),
6554 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006555 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006556 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006557 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006558
Douglas Gregora16548e2009-08-11 05:31:07 +00006559 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006560 Operand.get() == E->getArgument() &&
6561 OperatorDelete == E->getOperatorDelete()) {
6562 // Mark any declarations we need as referenced.
6563 // FIXME: instantiation-specific.
6564 if (OperatorDelete)
6565 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006566
6567 if (!E->getArgument()->isTypeDependent()) {
6568 QualType Destroyed = SemaRef.Context.getBaseElementType(
6569 E->getDestroyedType());
6570 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6571 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6572 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6573 SemaRef.LookupDestructor(Record));
6574 }
6575 }
6576
John McCallc3007a22010-10-26 07:05:15 +00006577 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006578 }
Mike Stump11289f42009-09-09 15:08:12 +00006579
Douglas Gregora16548e2009-08-11 05:31:07 +00006580 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6581 E->isGlobalDelete(),
6582 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006583 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006584}
Mike Stump11289f42009-09-09 15:08:12 +00006585
Douglas Gregora16548e2009-08-11 05:31:07 +00006586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006587ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006588TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006589 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006590 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006591 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006592 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006593
John McCallba7bf592010-08-24 05:47:05 +00006594 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006595 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006596 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006597 E->getOperatorLoc(),
6598 E->isArrow()? tok::arrow : tok::period,
6599 ObjectTypePtr,
6600 MayBePseudoDestructor);
6601 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006602 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006603
John McCallba7bf592010-08-24 05:47:05 +00006604 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006605 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6606 if (QualifierLoc) {
6607 QualifierLoc
6608 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6609 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006610 return ExprError();
6611 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006612 CXXScopeSpec SS;
6613 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006614
Douglas Gregor678f90d2010-02-25 01:56:36 +00006615 PseudoDestructorTypeStorage Destroyed;
6616 if (E->getDestroyedTypeInfo()) {
6617 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006618 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006619 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006620 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006621 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006622 Destroyed = DestroyedTypeInfo;
6623 } else if (ObjectType->isDependentType()) {
6624 // We aren't likely to be able to resolve the identifier down to a type
6625 // now anyway, so just retain the identifier.
6626 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6627 E->getDestroyedTypeLoc());
6628 } else {
6629 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006630 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006631 *E->getDestroyedTypeIdentifier(),
6632 E->getDestroyedTypeLoc(),
6633 /*Scope=*/0,
6634 SS, ObjectTypePtr,
6635 false);
6636 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006637 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006638
Douglas Gregor678f90d2010-02-25 01:56:36 +00006639 Destroyed
6640 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6641 E->getDestroyedTypeLoc());
6642 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006643
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006644 TypeSourceInfo *ScopeTypeInfo = 0;
6645 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006646 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006647 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006648 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006649 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006650
John McCallb268a282010-08-23 23:25:46 +00006651 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006652 E->getOperatorLoc(),
6653 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006654 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006655 ScopeTypeInfo,
6656 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006657 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006658 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006659}
Mike Stump11289f42009-09-09 15:08:12 +00006660
Douglas Gregorad8a3362009-09-04 17:36:40 +00006661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006662ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006663TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006664 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006665 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6666 Sema::LookupOrdinaryName);
6667
6668 // Transform all the decls.
6669 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6670 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006671 NamedDecl *InstD = static_cast<NamedDecl*>(
6672 getDerived().TransformDecl(Old->getNameLoc(),
6673 *I));
John McCall84d87672009-12-10 09:41:52 +00006674 if (!InstD) {
6675 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6676 // This can happen because of dependent hiding.
6677 if (isa<UsingShadowDecl>(*I))
6678 continue;
6679 else
John McCallfaf5fb42010-08-26 23:41:50 +00006680 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006681 }
John McCalle66edc12009-11-24 19:00:30 +00006682
6683 // Expand using declarations.
6684 if (isa<UsingDecl>(InstD)) {
6685 UsingDecl *UD = cast<UsingDecl>(InstD);
6686 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6687 E = UD->shadow_end(); I != E; ++I)
6688 R.addDecl(*I);
6689 continue;
6690 }
6691
6692 R.addDecl(InstD);
6693 }
6694
6695 // Resolve a kind, but don't do any further analysis. If it's
6696 // ambiguous, the callee needs to deal with it.
6697 R.resolveKind();
6698
6699 // Rebuild the nested-name qualifier, if present.
6700 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006701 if (Old->getQualifierLoc()) {
6702 NestedNameSpecifierLoc QualifierLoc
6703 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6704 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006705 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006706
Douglas Gregor0da1d432011-02-28 20:01:57 +00006707 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006708 }
6709
Douglas Gregor9262f472010-04-27 18:19:34 +00006710 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006711 CXXRecordDecl *NamingClass
6712 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6713 Old->getNameLoc(),
6714 Old->getNamingClass()));
6715 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006716 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006717
Douglas Gregorda7be082010-04-27 16:10:10 +00006718 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006719 }
6720
6721 // If we have no template arguments, it's a normal declaration name.
6722 if (!Old->hasExplicitTemplateArgs())
6723 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6724
6725 // If we have template arguments, rebuild them, then rebuild the
6726 // templateid expression.
6727 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006728 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6729 Old->getNumTemplateArgs(),
6730 TransArgs))
6731 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006732
6733 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6734 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006735}
Mike Stump11289f42009-09-09 15:08:12 +00006736
Douglas Gregora16548e2009-08-11 05:31:07 +00006737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006738ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006739TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006740 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6741 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006742 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006743
Douglas Gregora16548e2009-08-11 05:31:07 +00006744 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006745 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006746 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006747
Mike Stump11289f42009-09-09 15:08:12 +00006748 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006749 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006750 T,
6751 E->getLocEnd());
6752}
Mike Stump11289f42009-09-09 15:08:12 +00006753
Douglas Gregora16548e2009-08-11 05:31:07 +00006754template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006755ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006756TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6757 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6758 if (!LhsT)
6759 return ExprError();
6760
6761 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6762 if (!RhsT)
6763 return ExprError();
6764
6765 if (!getDerived().AlwaysRebuild() &&
6766 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6767 return SemaRef.Owned(E);
6768
6769 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6770 E->getLocStart(),
6771 LhsT, RhsT,
6772 E->getLocEnd());
6773}
6774
6775template<typename Derived>
6776ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006777TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006778 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006779 NestedNameSpecifierLoc QualifierLoc
6780 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6781 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006782 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006783
John McCall31f82722010-11-12 08:19:04 +00006784 // TODO: If this is a conversion-function-id, verify that the
6785 // destination type name (if present) resolves the same way after
6786 // instantiation as it did in the local scope.
6787
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006788 DeclarationNameInfo NameInfo
6789 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6790 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006791 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006792
John McCalle66edc12009-11-24 19:00:30 +00006793 if (!E->hasExplicitTemplateArgs()) {
6794 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006795 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006796 // Note: it is sufficient to compare the Name component of NameInfo:
6797 // if name has not changed, DNLoc has not changed either.
6798 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006799 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006800
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006801 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006802 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006803 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006804 }
John McCall6b51f282009-11-23 01:53:49 +00006805
6806 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006807 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6808 E->getNumTemplateArgs(),
6809 TransArgs))
6810 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006811
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006812 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006813 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006814 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006815}
6816
6817template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006818ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006819TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006820 // CXXConstructExprs are always implicit, so when we have a
6821 // 1-argument construction we just transform that argument.
6822 if (E->getNumArgs() == 1 ||
6823 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6824 return getDerived().TransformExpr(E->getArg(0));
6825
Douglas Gregora16548e2009-08-11 05:31:07 +00006826 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6827
6828 QualType T = getDerived().TransformType(E->getType());
6829 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006830 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006831
6832 CXXConstructorDecl *Constructor
6833 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006834 getDerived().TransformDecl(E->getLocStart(),
6835 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006836 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006837 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006838
Douglas Gregora16548e2009-08-11 05:31:07 +00006839 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006840 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006841 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6842 &ArgumentChanged))
6843 return ExprError();
6844
Douglas Gregora16548e2009-08-11 05:31:07 +00006845 if (!getDerived().AlwaysRebuild() &&
6846 T == E->getType() &&
6847 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006848 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006849 // Mark the constructor as referenced.
6850 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006851 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006852 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006853 }
Mike Stump11289f42009-09-09 15:08:12 +00006854
Douglas Gregordb121ba2009-12-14 16:27:04 +00006855 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6856 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006857 move_arg(Args),
6858 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006859 E->getConstructionKind(),
6860 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006861}
Mike Stump11289f42009-09-09 15:08:12 +00006862
Douglas Gregora16548e2009-08-11 05:31:07 +00006863/// \brief Transform a C++ temporary-binding expression.
6864///
Douglas Gregor363b1512009-12-24 18:51:59 +00006865/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6866/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006867template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006868ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006869TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006870 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006871}
Mike Stump11289f42009-09-09 15:08:12 +00006872
John McCall5d413782010-12-06 08:20:24 +00006873/// \brief Transform a C++ expression that contains cleanups that should
6874/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006875///
John McCall5d413782010-12-06 08:20:24 +00006876/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006877/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006878template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006879ExprResult
John McCall5d413782010-12-06 08:20:24 +00006880TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006881 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006882}
Mike Stump11289f42009-09-09 15:08:12 +00006883
Douglas Gregora16548e2009-08-11 05:31:07 +00006884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006885ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006886TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006887 CXXTemporaryObjectExpr *E) {
6888 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6889 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006890 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006891
Douglas Gregora16548e2009-08-11 05:31:07 +00006892 CXXConstructorDecl *Constructor
6893 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006894 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006895 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006896 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006897 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006898
Douglas Gregora16548e2009-08-11 05:31:07 +00006899 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006900 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006901 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006902 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6903 &ArgumentChanged))
6904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006905
Douglas Gregora16548e2009-08-11 05:31:07 +00006906 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006907 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006908 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006909 !ArgumentChanged) {
6910 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006911 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006912 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006913 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006914
6915 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6916 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006917 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006918 E->getLocEnd());
6919}
Mike Stump11289f42009-09-09 15:08:12 +00006920
Douglas Gregora16548e2009-08-11 05:31:07 +00006921template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006922ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006923TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006924 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006925 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6926 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006927 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006928
Douglas Gregora16548e2009-08-11 05:31:07 +00006929 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006930 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006931 Args.reserve(E->arg_size());
6932 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6933 &ArgumentChanged))
6934 return ExprError();
6935
Douglas Gregora16548e2009-08-11 05:31:07 +00006936 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006937 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006938 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006939 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006940
Douglas Gregora16548e2009-08-11 05:31:07 +00006941 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006942 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006943 E->getLParenLoc(),
6944 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006945 E->getRParenLoc());
6946}
Mike Stump11289f42009-09-09 15:08:12 +00006947
Douglas Gregora16548e2009-08-11 05:31:07 +00006948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006949ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006950TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006951 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006952 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006953 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006954 Expr *OldBase;
6955 QualType BaseType;
6956 QualType ObjectType;
6957 if (!E->isImplicitAccess()) {
6958 OldBase = E->getBase();
6959 Base = getDerived().TransformExpr(OldBase);
6960 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006961 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006962
John McCall2d74de92009-12-01 22:10:20 +00006963 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006964 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006965 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006966 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006967 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006968 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006969 ObjectTy,
6970 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006971 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006972 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006973
John McCallba7bf592010-08-24 05:47:05 +00006974 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006975 BaseType = ((Expr*) Base.get())->getType();
6976 } else {
6977 OldBase = 0;
6978 BaseType = getDerived().TransformType(E->getBaseType());
6979 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6980 }
Mike Stump11289f42009-09-09 15:08:12 +00006981
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006982 // Transform the first part of the nested-name-specifier that qualifies
6983 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006984 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006985 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00006986 E->getFirstQualifierFoundInScope(),
6987 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00006988
Douglas Gregore16af532011-02-28 18:50:33 +00006989 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006990 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00006991 QualifierLoc
6992 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
6993 ObjectType,
6994 FirstQualifierInScope);
6995 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006996 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006997 }
Mike Stump11289f42009-09-09 15:08:12 +00006998
John McCall31f82722010-11-12 08:19:04 +00006999 // TODO: If this is a conversion-function-id, verify that the
7000 // destination type name (if present) resolves the same way after
7001 // instantiation as it did in the local scope.
7002
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007003 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007004 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007005 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007006 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007007
John McCall2d74de92009-12-01 22:10:20 +00007008 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007009 // This is a reference to a member without an explicitly-specified
7010 // template argument list. Optimize for this common case.
7011 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007012 Base.get() == OldBase &&
7013 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007014 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007015 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007016 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007017 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007018
John McCallb268a282010-08-23 23:25:46 +00007019 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007020 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007021 E->isArrow(),
7022 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007023 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007024 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007025 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007026 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007027 }
7028
John McCall6b51f282009-11-23 01:53:49 +00007029 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007030 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7031 E->getNumTemplateArgs(),
7032 TransArgs))
7033 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007034
John McCallb268a282010-08-23 23:25:46 +00007035 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007036 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007037 E->isArrow(),
7038 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007039 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007040 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007041 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007042 &TransArgs);
7043}
7044
7045template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007046ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007047TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007048 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007049 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007050 QualType BaseType;
7051 if (!Old->isImplicitAccess()) {
7052 Base = getDerived().TransformExpr(Old->getBase());
7053 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007054 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007055 BaseType = ((Expr*) Base.get())->getType();
7056 } else {
7057 BaseType = getDerived().TransformType(Old->getBaseType());
7058 }
John McCall10eae182009-11-30 22:42:35 +00007059
Douglas Gregor0da1d432011-02-28 20:01:57 +00007060 NestedNameSpecifierLoc QualifierLoc;
7061 if (Old->getQualifierLoc()) {
7062 QualifierLoc
7063 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7064 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007065 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007066 }
7067
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007068 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007069 Sema::LookupOrdinaryName);
7070
7071 // Transform all the decls.
7072 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7073 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007074 NamedDecl *InstD = static_cast<NamedDecl*>(
7075 getDerived().TransformDecl(Old->getMemberLoc(),
7076 *I));
John McCall84d87672009-12-10 09:41:52 +00007077 if (!InstD) {
7078 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7079 // This can happen because of dependent hiding.
7080 if (isa<UsingShadowDecl>(*I))
7081 continue;
7082 else
John McCallfaf5fb42010-08-26 23:41:50 +00007083 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007084 }
John McCall10eae182009-11-30 22:42:35 +00007085
7086 // Expand using declarations.
7087 if (isa<UsingDecl>(InstD)) {
7088 UsingDecl *UD = cast<UsingDecl>(InstD);
7089 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7090 E = UD->shadow_end(); I != E; ++I)
7091 R.addDecl(*I);
7092 continue;
7093 }
7094
7095 R.addDecl(InstD);
7096 }
7097
7098 R.resolveKind();
7099
Douglas Gregor9262f472010-04-27 18:19:34 +00007100 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007101 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007102 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007103 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007104 Old->getMemberLoc(),
7105 Old->getNamingClass()));
7106 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007107 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007108
Douglas Gregorda7be082010-04-27 16:10:10 +00007109 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007110 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007111
John McCall10eae182009-11-30 22:42:35 +00007112 TemplateArgumentListInfo TransArgs;
7113 if (Old->hasExplicitTemplateArgs()) {
7114 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7115 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007116 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7117 Old->getNumTemplateArgs(),
7118 TransArgs))
7119 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007120 }
John McCall38836f02010-01-15 08:34:02 +00007121
7122 // FIXME: to do this check properly, we will need to preserve the
7123 // first-qualifier-in-scope here, just in case we had a dependent
7124 // base (and therefore couldn't do the check) and a
7125 // nested-name-qualifier (and therefore could do the lookup).
7126 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007127
John McCallb268a282010-08-23 23:25:46 +00007128 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007129 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007130 Old->getOperatorLoc(),
7131 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007132 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007133 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007134 R,
7135 (Old->hasExplicitTemplateArgs()
7136 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007137}
7138
7139template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007140ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007141TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7142 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7143 if (SubExpr.isInvalid())
7144 return ExprError();
7145
7146 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007147 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007148
7149 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7150}
7151
7152template<typename Derived>
7153ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007154TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007155 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7156 if (Pattern.isInvalid())
7157 return ExprError();
7158
7159 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7160 return SemaRef.Owned(E);
7161
Douglas Gregorb8840002011-01-14 21:20:45 +00007162 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7163 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007164}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007165
7166template<typename Derived>
7167ExprResult
7168TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7169 // If E is not value-dependent, then nothing will change when we transform it.
7170 // Note: This is an instantiation-centric view.
7171 if (!E->isValueDependent())
7172 return SemaRef.Owned(E);
7173
7174 // Note: None of the implementations of TryExpandParameterPacks can ever
7175 // produce a diagnostic when given only a single unexpanded parameter pack,
7176 // so
7177 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7178 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007179 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007180 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007181 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7182 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007183 ShouldExpand, RetainExpansion,
7184 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007185 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007186
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007187 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007188 return SemaRef.Owned(E);
7189
7190 // We now know the length of the parameter pack, so build a new expression
7191 // that stores that length.
7192 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7193 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007194 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007195}
7196
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007197template<typename Derived>
7198ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007199TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7200 SubstNonTypeTemplateParmPackExpr *E) {
7201 // Default behavior is to do nothing with this transformation.
7202 return SemaRef.Owned(E);
7203}
7204
7205template<typename Derived>
7206ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007207TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007208 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007209}
7210
Mike Stump11289f42009-09-09 15:08:12 +00007211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007212ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007213TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007214 TypeSourceInfo *EncodedTypeInfo
7215 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7216 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007217 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007218
Douglas Gregora16548e2009-08-11 05:31:07 +00007219 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007220 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007221 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007222
7223 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007224 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007225 E->getRParenLoc());
7226}
Mike Stump11289f42009-09-09 15:08:12 +00007227
Douglas Gregora16548e2009-08-11 05:31:07 +00007228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007229ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007230TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007231 // Transform arguments.
7232 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007233 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007234 Args.reserve(E->getNumArgs());
7235 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7236 &ArgChanged))
7237 return ExprError();
7238
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007239 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7240 // Class message: transform the receiver type.
7241 TypeSourceInfo *ReceiverTypeInfo
7242 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7243 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007244 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007245
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007246 // If nothing changed, just retain the existing message send.
7247 if (!getDerived().AlwaysRebuild() &&
7248 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007249 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007250
7251 // Build a new class message send.
7252 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7253 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007254 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007255 E->getMethodDecl(),
7256 E->getLeftLoc(),
7257 move_arg(Args),
7258 E->getRightLoc());
7259 }
7260
7261 // Instance message: transform the receiver
7262 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7263 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007264 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007265 = getDerived().TransformExpr(E->getInstanceReceiver());
7266 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007267 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007268
7269 // If nothing changed, just retain the existing message send.
7270 if (!getDerived().AlwaysRebuild() &&
7271 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007272 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007273
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007274 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007275 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007276 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007277 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007278 E->getMethodDecl(),
7279 E->getLeftLoc(),
7280 move_arg(Args),
7281 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007282}
7283
Mike Stump11289f42009-09-09 15:08:12 +00007284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007286TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007287 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007288}
7289
Mike Stump11289f42009-09-09 15:08:12 +00007290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007291ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007292TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007293 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007294}
7295
Mike Stump11289f42009-09-09 15:08:12 +00007296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007297ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007298TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007299 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007300 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007301 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007302 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007303
7304 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007305
Douglas Gregord51d90d2010-04-26 20:11:03 +00007306 // If nothing changed, just retain the existing expression.
7307 if (!getDerived().AlwaysRebuild() &&
7308 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007309 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007310
John McCallb268a282010-08-23 23:25:46 +00007311 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007312 E->getLocation(),
7313 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007314}
7315
Mike Stump11289f42009-09-09 15:08:12 +00007316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007317ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007318TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007319 // 'super' and types never change. Property never changes. Just
7320 // retain the existing expression.
7321 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007322 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007323
Douglas Gregor9faee212010-04-26 20:47:02 +00007324 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007325 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007326 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007327 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007328
Douglas Gregor9faee212010-04-26 20:47:02 +00007329 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007330
Douglas Gregor9faee212010-04-26 20:47:02 +00007331 // If nothing changed, just retain the existing expression.
7332 if (!getDerived().AlwaysRebuild() &&
7333 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007334 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007335
John McCallb7bd14f2010-12-02 01:19:52 +00007336 if (E->isExplicitProperty())
7337 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7338 E->getExplicitProperty(),
7339 E->getLocation());
7340
7341 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7342 E->getType(),
7343 E->getImplicitPropertyGetter(),
7344 E->getImplicitPropertySetter(),
7345 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007346}
7347
Mike Stump11289f42009-09-09 15:08:12 +00007348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007349ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007350TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007351 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007352 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007353 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007354 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007355
Douglas Gregord51d90d2010-04-26 20:11:03 +00007356 // If nothing changed, just retain the existing expression.
7357 if (!getDerived().AlwaysRebuild() &&
7358 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007359 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007360
John McCallb268a282010-08-23 23:25:46 +00007361 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007362 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007363}
7364
Mike Stump11289f42009-09-09 15:08:12 +00007365template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007366ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007367TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007368 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007369 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007370 SubExprs.reserve(E->getNumSubExprs());
7371 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7372 SubExprs, &ArgumentChanged))
7373 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007374
Douglas Gregora16548e2009-08-11 05:31:07 +00007375 if (!getDerived().AlwaysRebuild() &&
7376 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007377 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007378
Douglas Gregora16548e2009-08-11 05:31:07 +00007379 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7380 move_arg(SubExprs),
7381 E->getRParenLoc());
7382}
7383
Mike Stump11289f42009-09-09 15:08:12 +00007384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007385ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007386TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007387 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007388
John McCall490112f2011-02-04 18:33:18 +00007389 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7390 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7391
7392 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7393 llvm::SmallVector<ParmVarDecl*, 4> params;
7394 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007395
7396 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007397 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7398 oldBlock->param_begin(),
7399 oldBlock->param_size(),
7400 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007401 return true;
John McCall490112f2011-02-04 18:33:18 +00007402
7403 const FunctionType *exprFunctionType = E->getFunctionType();
7404 QualType exprResultType = exprFunctionType->getResultType();
7405 if (!exprResultType.isNull()) {
7406 if (!exprResultType->isDependentType())
7407 blockScope->ReturnType = exprResultType;
7408 else if (exprResultType != getSema().Context.DependentTy)
7409 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007410 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007411
7412 // If the return type has not been determined yet, leave it as a dependent
7413 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007414 if (blockScope->ReturnType.isNull())
7415 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007416
7417 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007418 if (blockScope->ReturnType->isObjCObjectType()) {
7419 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007420 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007421 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007422 return ExprError();
7423 }
John McCall3882ace2011-01-05 12:14:39 +00007424
John McCall490112f2011-02-04 18:33:18 +00007425 QualType functionType = getDerived().RebuildFunctionProtoType(
7426 blockScope->ReturnType,
7427 paramTypes.data(),
7428 paramTypes.size(),
7429 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007430 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007431 exprFunctionType->getExtInfo());
7432 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007433
7434 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007435 if (!params.empty())
7436 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007437
7438 // If the return type wasn't explicitly set, it will have been marked as a
7439 // dependent type (DependentTy); clear out the return type setting so
7440 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007441 if (blockScope->ReturnType == getSema().Context.DependentTy)
7442 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007443
John McCall3882ace2011-01-05 12:14:39 +00007444 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007445 StmtResult body = getDerived().TransformStmt(E->getBody());
7446 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007447 return ExprError();
7448
John McCall490112f2011-02-04 18:33:18 +00007449#ifndef NDEBUG
7450 // In builds with assertions, make sure that we captured everything we
7451 // captured before.
7452
7453 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7454
7455 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7456 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007457 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007458
7459 // Ignore parameter packs.
7460 if (isa<ParmVarDecl>(oldCapture) &&
7461 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7462 continue;
7463
7464 VarDecl *newCapture =
7465 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7466 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007467 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007468 }
7469#endif
7470
7471 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7472 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007473}
7474
Mike Stump11289f42009-09-09 15:08:12 +00007475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007476ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007477TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007478 ValueDecl *ND
7479 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7480 E->getDecl()));
7481 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007482 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007483
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007484 if (!getDerived().AlwaysRebuild() &&
7485 ND == E->getDecl()) {
7486 // Mark it referenced in the new context regardless.
7487 // FIXME: this is a bit instantiation-specific.
7488 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7489
John McCallc3007a22010-10-26 07:05:15 +00007490 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007491 }
7492
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007493 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007494 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007495 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007496}
Mike Stump11289f42009-09-09 15:08:12 +00007497
Douglas Gregora16548e2009-08-11 05:31:07 +00007498//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007499// Type reconstruction
7500//===----------------------------------------------------------------------===//
7501
Mike Stump11289f42009-09-09 15:08:12 +00007502template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007503QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7504 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007505 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007506 getDerived().getBaseEntity());
7507}
7508
Mike Stump11289f42009-09-09 15:08:12 +00007509template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007510QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7511 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007512 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007513 getDerived().getBaseEntity());
7514}
7515
Mike Stump11289f42009-09-09 15:08:12 +00007516template<typename Derived>
7517QualType
John McCall70dd5f62009-10-30 00:06:24 +00007518TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7519 bool WrittenAsLValue,
7520 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007521 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007522 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007523}
7524
7525template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007526QualType
John McCall70dd5f62009-10-30 00:06:24 +00007527TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7528 QualType ClassType,
7529 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007530 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007531 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007532}
7533
7534template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007535QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007536TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7537 ArrayType::ArraySizeModifier SizeMod,
7538 const llvm::APInt *Size,
7539 Expr *SizeExpr,
7540 unsigned IndexTypeQuals,
7541 SourceRange BracketsRange) {
7542 if (SizeExpr || !Size)
7543 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7544 IndexTypeQuals, BracketsRange,
7545 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007546
7547 QualType Types[] = {
7548 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7549 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7550 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007551 };
7552 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7553 QualType SizeType;
7554 for (unsigned I = 0; I != NumTypes; ++I)
7555 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7556 SizeType = Types[I];
7557 break;
7558 }
Mike Stump11289f42009-09-09 15:08:12 +00007559
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007560 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7561 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007562 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007563 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007564 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007565}
Mike Stump11289f42009-09-09 15:08:12 +00007566
Douglas Gregord6ff3322009-08-04 16:50:30 +00007567template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007568QualType
7569TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007570 ArrayType::ArraySizeModifier SizeMod,
7571 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007572 unsigned IndexTypeQuals,
7573 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007574 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007575 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007576}
7577
7578template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007579QualType
Mike Stump11289f42009-09-09 15:08:12 +00007580TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007581 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007582 unsigned IndexTypeQuals,
7583 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007584 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007585 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007586}
Mike Stump11289f42009-09-09 15:08:12 +00007587
Douglas Gregord6ff3322009-08-04 16:50:30 +00007588template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007589QualType
7590TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007591 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007592 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007593 unsigned IndexTypeQuals,
7594 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007595 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007596 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007597 IndexTypeQuals, BracketsRange);
7598}
7599
7600template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007601QualType
7602TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007603 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007604 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007605 unsigned IndexTypeQuals,
7606 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007607 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007608 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007609 IndexTypeQuals, BracketsRange);
7610}
7611
7612template<typename Derived>
7613QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007614 unsigned NumElements,
7615 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007616 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007617 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007618}
Mike Stump11289f42009-09-09 15:08:12 +00007619
Douglas Gregord6ff3322009-08-04 16:50:30 +00007620template<typename Derived>
7621QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7622 unsigned NumElements,
7623 SourceLocation AttributeLoc) {
7624 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7625 NumElements, true);
7626 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007627 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7628 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007629 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007630}
Mike Stump11289f42009-09-09 15:08:12 +00007631
Douglas Gregord6ff3322009-08-04 16:50:30 +00007632template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007633QualType
7634TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007635 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007636 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007637 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007638}
Mike Stump11289f42009-09-09 15:08:12 +00007639
Douglas Gregord6ff3322009-08-04 16:50:30 +00007640template<typename Derived>
7641QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007642 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007643 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007644 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007645 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007646 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007647 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007648 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007649 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007650 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007651 getDerived().getBaseEntity(),
7652 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007653}
Mike Stump11289f42009-09-09 15:08:12 +00007654
Douglas Gregord6ff3322009-08-04 16:50:30 +00007655template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007656QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7657 return SemaRef.Context.getFunctionNoProtoType(T);
7658}
7659
7660template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007661QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7662 assert(D && "no decl found");
7663 if (D->isInvalidDecl()) return QualType();
7664
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007665 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007666 TypeDecl *Ty;
7667 if (isa<UsingDecl>(D)) {
7668 UsingDecl *Using = cast<UsingDecl>(D);
7669 assert(Using->isTypeName() &&
7670 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7671
7672 // A valid resolved using typename decl points to exactly one type decl.
7673 assert(++Using->shadow_begin() == Using->shadow_end());
7674 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007675
John McCallb96ec562009-12-04 22:46:56 +00007676 } else {
7677 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7678 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7679 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7680 }
7681
7682 return SemaRef.Context.getTypeDeclType(Ty);
7683}
7684
7685template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007686QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7687 SourceLocation Loc) {
7688 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007689}
7690
7691template<typename Derived>
7692QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7693 return SemaRef.Context.getTypeOfType(Underlying);
7694}
7695
7696template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007697QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7698 SourceLocation Loc) {
7699 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007700}
7701
7702template<typename Derived>
7703QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007704 TemplateName Template,
7705 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00007706 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00007707 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007708}
Mike Stump11289f42009-09-09 15:08:12 +00007709
Douglas Gregor1135c352009-08-06 05:28:30 +00007710template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007711TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007712TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007713 bool TemplateKW,
7714 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007715 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007716 Template);
7717}
7718
7719template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007720TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007721TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
7722 const IdentifierInfo &Name,
7723 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00007724 QualType ObjectType,
7725 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007726 UnqualifiedId TemplateName;
7727 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00007728 Sema::TemplateTy Template;
7729 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007730 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007731 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00007732 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00007733 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007734 /*EnteringContext=*/false,
7735 Template);
John McCall31f82722010-11-12 08:19:04 +00007736 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007737}
Mike Stump11289f42009-09-09 15:08:12 +00007738
Douglas Gregora16548e2009-08-11 05:31:07 +00007739template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007740TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007741TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007742 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00007743 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007744 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00007745 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00007746 // FIXME: Bogus location information.
7747 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
7748 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007749 Sema::TemplateTy Template;
7750 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007751 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007752 SS,
7753 Name,
John McCallba7bf592010-08-24 05:47:05 +00007754 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007755 /*EnteringContext=*/false,
7756 Template);
7757 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007758}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007759
Douglas Gregor71395fa2009-11-04 00:56:37 +00007760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007761ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007762TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7763 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007764 Expr *OrigCallee,
7765 Expr *First,
7766 Expr *Second) {
7767 Expr *Callee = OrigCallee->IgnoreParenCasts();
7768 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007769
Douglas Gregora16548e2009-08-11 05:31:07 +00007770 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007771 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007772 if (!First->getType()->isOverloadableType() &&
7773 !Second->getType()->isOverloadableType())
7774 return getSema().CreateBuiltinArraySubscriptExpr(First,
7775 Callee->getLocStart(),
7776 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007777 } else if (Op == OO_Arrow) {
7778 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007779 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7780 } else if (Second == 0 || isPostIncDec) {
7781 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007782 // The argument is not of overloadable type, so try to create a
7783 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007784 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007785 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007786
John McCallb268a282010-08-23 23:25:46 +00007787 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007788 }
7789 } else {
John McCallb268a282010-08-23 23:25:46 +00007790 if (!First->getType()->isOverloadableType() &&
7791 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007792 // Neither of the arguments is an overloadable type, so try to
7793 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007794 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007795 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007796 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007797 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007798 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007799
Douglas Gregora16548e2009-08-11 05:31:07 +00007800 return move(Result);
7801 }
7802 }
Mike Stump11289f42009-09-09 15:08:12 +00007803
7804 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007805 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007806 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007807
John McCallb268a282010-08-23 23:25:46 +00007808 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007809 assert(ULE->requiresADL());
7810
7811 // FIXME: Do we have to check
7812 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007813 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007814 } else {
John McCallb268a282010-08-23 23:25:46 +00007815 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007816 }
Mike Stump11289f42009-09-09 15:08:12 +00007817
Douglas Gregora16548e2009-08-11 05:31:07 +00007818 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007819 Expr *Args[2] = { First, Second };
7820 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007821
Douglas Gregora16548e2009-08-11 05:31:07 +00007822 // Create the overloaded operator invocation for unary operators.
7823 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007824 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007825 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007826 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007827 }
Mike Stump11289f42009-09-09 15:08:12 +00007828
Sebastian Redladba46e2009-10-29 20:17:01 +00007829 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007830 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007831 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007832 First,
7833 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007834
Douglas Gregora16548e2009-08-11 05:31:07 +00007835 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007836 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007837 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007838 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7839 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007841
Mike Stump11289f42009-09-09 15:08:12 +00007842 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007843}
Mike Stump11289f42009-09-09 15:08:12 +00007844
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007846ExprResult
John McCallb268a282010-08-23 23:25:46 +00007847TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007848 SourceLocation OperatorLoc,
7849 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00007850 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007851 TypeSourceInfo *ScopeType,
7852 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007853 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007854 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00007855 QualType BaseType = Base->getType();
7856 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007857 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007858 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007859 !BaseType->getAs<PointerType>()->getPointeeType()
7860 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007861 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007862 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007863 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007864 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007865 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007866 /*FIXME?*/true);
7867 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007868
Douglas Gregor678f90d2010-02-25 01:56:36 +00007869 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007870 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7871 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7872 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7873 NameInfo.setNamedTypeInfo(DestroyedType);
7874
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007875 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007876
John McCallb268a282010-08-23 23:25:46 +00007877 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007878 OperatorLoc, isArrow,
7879 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007880 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007881 /*TemplateArgs*/ 0);
7882}
7883
Douglas Gregord6ff3322009-08-04 16:50:30 +00007884} // end namespace clang
7885
7886#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H