blob: 21b7c001df68c1a84fed432fe2e22152af9effb5 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000024#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000025#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000027#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000030#include "clang/Sema/Ownership.h"
31#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000032#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000033#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000034#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000035#include <algorithm>
36
37namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000038using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000039
Douglas Gregord6ff3322009-08-04 16:50:30 +000040/// \brief A semantic tree transformation that allows one to transform one
41/// abstract syntax tree into another.
42///
Mike Stump11289f42009-09-09 15:08:12 +000043/// A new tree transformation is defined by creating a new subclass \c X of
44/// \c TreeTransform<X> and then overriding certain operations to provide
45/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000046/// instantiation is implemented as a tree transformation where the
47/// transformation of TemplateTypeParmType nodes involves substituting the
48/// template arguments for their corresponding template parameters; a similar
49/// transformation is performed for non-type template parameters and
50/// template template parameters.
51///
52/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000053/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000054/// override any of the transformation or rebuild operators by providing an
55/// operation with the same signature as the default implementation. The
56/// overridding function should not be virtual.
57///
58/// Semantic tree transformations are split into two stages, either of which
59/// can be replaced by a subclass. The "transform" step transforms an AST node
60/// or the parts of an AST node using the various transformation functions,
61/// then passes the pieces on to the "rebuild" step, which constructs a new AST
62/// node of the appropriate kind from the pieces. The default transformation
63/// routines recursively transform the operands to composite AST nodes (e.g.,
64/// the pointee type of a PointerType node) and, if any of those operand nodes
65/// were changed by the transformation, invokes the rebuild operation to create
66/// a new AST node.
67///
Mike Stump11289f42009-09-09 15:08:12 +000068/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000069/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000071/// TransformTemplateName(), or TransformTemplateArgument() with entirely
72/// new implementations.
73///
74/// For more fine-grained transformations, subclasses can replace any of the
75/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000076/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000078/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// parameters. Additionally, subclasses can override the \c RebuildXXX
80/// functions to control how AST nodes are rebuilt when their operands change.
81/// By default, \c TreeTransform will invoke semantic analysis to rebuild
82/// AST nodes. However, certain other tree transformations (e.g, cloning) may
83/// be able to use more efficient rebuild steps.
84///
85/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000086/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000087/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
88/// operands have not changed (\c AlwaysRebuild()), and customize the
89/// default locations and entity names used for type-checking
90/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000091template<typename Derived>
92class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000093 /// \brief Private RAII object that helps us forget and then re-remember
94 /// the template argument corresponding to a partially-substituted parameter
95 /// pack.
96 class ForgetPartiallySubstitutedPackRAII {
97 Derived &Self;
98 TemplateArgument Old;
99
100 public:
101 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
102 Old = Self.ForgetPartiallySubstitutedPack();
103 }
104
105 ~ForgetPartiallySubstitutedPackRAII() {
106 Self.RememberPartiallySubstitutedPack(Old);
107 }
108 };
109
Douglas Gregord6ff3322009-08-04 16:50:30 +0000110protected:
111 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000112
Mike Stump11289f42009-09-09 15:08:12 +0000113public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000115 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000116
Douglas Gregord6ff3322009-08-04 16:50:30 +0000117 /// \brief Retrieves a reference to the derived class.
118 Derived &getDerived() { return static_cast<Derived&>(*this); }
119
120 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000121 const Derived &getDerived() const {
122 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000123 }
124
John McCalldadc5752010-08-24 06:29:42 +0000125 static inline ExprResult Owned(Expr *E) { return E; }
126 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Retrieves a reference to the semantic analysis object used for
129 /// this tree transform.
130 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000131
Douglas Gregord6ff3322009-08-04 16:50:30 +0000132 /// \brief Whether the transformation should always rebuild AST nodes, even
133 /// if none of the children have changed.
134 ///
135 /// Subclasses may override this function to specify when the transformation
136 /// should rebuild all AST nodes.
137 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Returns the location of the entity being transformed, if that
140 /// information was not available elsewhere in the AST.
141 ///
Mike Stump11289f42009-09-09 15:08:12 +0000142 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000143 /// provide an alternative implementation that provides better location
144 /// information.
145 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000146
Douglas Gregord6ff3322009-08-04 16:50:30 +0000147 /// \brief Returns the name of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
150 /// By default, returns an empty name. Subclasses can provide an alternative
151 /// implementation with a more precise name.
152 DeclarationName getBaseEntity() { return DeclarationName(); }
153
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 /// \brief Sets the "base" location and entity when that
155 /// information is known based on another transformation.
156 ///
157 /// By default, the source location and entity are ignored. Subclasses can
158 /// override this function to provide a customized implementation.
159 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000160
Douglas Gregora16548e2009-08-11 05:31:07 +0000161 /// \brief RAII object that temporarily sets the base location and entity
162 /// used for reporting diagnostics in types.
163 class TemporaryBase {
164 TreeTransform &Self;
165 SourceLocation OldLocation;
166 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000167
Douglas Gregora16548e2009-08-11 05:31:07 +0000168 public:
169 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000170 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000171 OldLocation = Self.getDerived().getBaseLocation();
172 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000173
174 if (Location.isValid())
175 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000176 }
Mike Stump11289f42009-09-09 15:08:12 +0000177
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 ~TemporaryBase() {
179 Self.getDerived().setBase(OldLocation, OldEntity);
180 }
181 };
Mike Stump11289f42009-09-09 15:08:12 +0000182
183 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000184 /// transformed.
185 ///
186 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000187 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000188 /// not change. For example, template instantiation need not traverse
189 /// non-dependent types.
190 bool AlreadyTransformed(QualType T) {
191 return T.isNull();
192 }
193
Douglas Gregord196a582009-12-14 19:27:10 +0000194 /// \brief Determine whether the given call argument should be dropped, e.g.,
195 /// because it is a default argument.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine to
198 /// determine which kinds of call arguments get dropped. By default,
199 /// CXXDefaultArgument nodes are dropped (prior to transformation).
200 bool DropCallArgument(Expr *E) {
201 return E->isDefaultArgument();
202 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000203
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000204 /// \brief Determine whether we should expand a pack expansion with the
205 /// given set of parameter packs into separate arguments by repeatedly
206 /// transforming the pattern.
207 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000208 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000209 /// Subclasses can override this routine to provide different behavior.
210 ///
211 /// \param EllipsisLoc The location of the ellipsis that identifies the
212 /// pack expansion.
213 ///
214 /// \param PatternRange The source range that covers the entire pattern of
215 /// the pack expansion.
216 ///
217 /// \param Unexpanded The set of unexpanded parameter packs within the
218 /// pattern.
219 ///
220 /// \param NumUnexpanded The number of unexpanded parameter packs in
221 /// \p Unexpanded.
222 ///
223 /// \param ShouldExpand Will be set to \c true if the transformer should
224 /// expand the corresponding pack expansions into separate arguments. When
225 /// set, \c NumExpansions must also be set.
226 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000227 /// \param RetainExpansion Whether the caller should add an unexpanded
228 /// pack expansion after all of the expanded arguments. This is used
229 /// when extending explicitly-specified template argument packs per
230 /// C++0x [temp.arg.explicit]p9.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000233 /// the expanded form of the corresponding pack expansion. This is both an
234 /// input and an output parameter, which can be set by the caller if the
235 /// number of expansions is known a priori (e.g., due to a prior substitution)
236 /// and will be set by the callee when the number of expansions is known.
237 /// The callee must set this value when \c ShouldExpand is \c true; it may
238 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000239 ///
240 /// \returns true if an error occurred (e.g., because the parameter packs
241 /// are to be instantiated with arguments of different lengths), false
242 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
243 /// must be set.
244 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
245 SourceRange PatternRange,
246 const UnexpandedParameterPack *Unexpanded,
247 unsigned NumUnexpanded,
248 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000249 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000250 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 ShouldExpand = false;
252 return false;
253 }
254
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000255 /// \brief "Forget" about the partially-substituted pack template argument,
256 /// when performing an instantiation that must preserve the parameter pack
257 /// use.
258 ///
259 /// This routine is meant to be overridden by the template instantiator.
260 TemplateArgument ForgetPartiallySubstitutedPack() {
261 return TemplateArgument();
262 }
263
264 /// \brief "Remember" the partially-substituted pack template argument
265 /// after performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
270
Douglas Gregorf3010112011-01-07 16:43:16 +0000271 /// \brief Note to the derived class when a function parameter pack is
272 /// being expanded.
273 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
274
Douglas Gregord6ff3322009-08-04 16:50:30 +0000275 /// \brief Transforms the given type into another type.
276 ///
John McCall550e0c22009-10-21 00:40:46 +0000277 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000278 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000279 /// function. This is expensive, but we don't mind, because
280 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000281 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 ///
283 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000284 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000285
John McCall550e0c22009-10-21 00:40:46 +0000286 /// \brief Transforms the given type-with-location into a new
287 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000288 ///
John McCall550e0c22009-10-21 00:40:46 +0000289 /// By default, this routine transforms a type by delegating to the
290 /// appropriate TransformXXXType to build a new type. Subclasses
291 /// may override this function (to take over all type
292 /// transformations) or some set of the TransformXXXType functions
293 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000294 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000295
296 /// \brief Transform the given type-with-location into a new
297 /// type, collecting location information in the given builder
298 /// as necessary.
299 ///
John McCall31f82722010-11-12 08:19:04 +0000300 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000301
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000302 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000303 ///
Mike Stump11289f42009-09-09 15:08:12 +0000304 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000305 /// appropriate TransformXXXStmt function to transform a specific kind of
306 /// statement or the TransformExpr() function to transform an expression.
307 /// Subclasses may override this function to transform statements using some
308 /// other mechanism.
309 ///
310 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000311 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000312
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000313 /// \brief Transform the given expression.
314 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000315 /// By default, this routine transforms an expression by delegating to the
316 /// appropriate TransformXXXExpr function to build a new expression.
317 /// Subclasses may override this function to transform expressions using some
318 /// other mechanism.
319 ///
320 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000321 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000322
Douglas Gregora3efea12011-01-03 19:04:46 +0000323 /// \brief Transform the given list of expressions.
324 ///
325 /// This routine transforms a list of expressions by invoking
326 /// \c TransformExpr() for each subexpression. However, it also provides
327 /// support for variadic templates by expanding any pack expansions (if the
328 /// derived class permits such expansion) along the way. When pack expansions
329 /// are present, the number of outputs may not equal the number of inputs.
330 ///
331 /// \param Inputs The set of expressions to be transformed.
332 ///
333 /// \param NumInputs The number of expressions in \c Inputs.
334 ///
335 /// \param IsCall If \c true, then this transform is being performed on
336 /// function-call arguments, and any arguments that should be dropped, will
337 /// be.
338 ///
339 /// \param Outputs The transformed input expressions will be added to this
340 /// vector.
341 ///
342 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
343 /// due to transformation.
344 ///
345 /// \returns true if an error occurred, false otherwise.
346 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
347 llvm::SmallVectorImpl<Expr *> &Outputs,
348 bool *ArgChanged = 0);
349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Transform the given declaration, which is referenced from a type
351 /// or expression.
352 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000353 /// By default, acts as the identity function on declarations. Subclasses
354 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000355 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000356
357 /// \brief Transform the definition of the given declaration.
358 ///
Mike Stump11289f42009-09-09 15:08:12 +0000359 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000360 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000361 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
362 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000363 }
Mike Stump11289f42009-09-09 15:08:12 +0000364
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000365 /// \brief Transform the given declaration, which was the first part of a
366 /// nested-name-specifier in a member access expression.
367 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000368 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000369 /// identifier in a nested-name-specifier of a member access expression, e.g.,
370 /// the \c T in \c x->T::member
371 ///
372 /// By default, invokes TransformDecl() to transform the declaration.
373 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000374 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
375 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000376 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000377
Douglas Gregor14454802011-02-25 02:25:35 +0000378 /// \brief Transform the given nested-name-specifier with source-location
379 /// information.
380 ///
381 /// By default, transforms all of the types and declarations within the
382 /// nested-name-specifier. Subclasses may override this function to provide
383 /// alternate behavior.
384 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
385 NestedNameSpecifierLoc NNS,
386 QualType ObjectType = QualType(),
387 NamedDecl *FirstQualifierInScope = 0);
388
Douglas Gregorf816bd72009-09-03 22:13:48 +0000389 /// \brief Transform the given declaration name.
390 ///
391 /// By default, transforms the types of conversion function, constructor,
392 /// and destructor names and then (if needed) rebuilds the declaration name.
393 /// Identifiers and selectors are returned unmodified. Sublcasses may
394 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000395 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000396 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000399 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000400 /// \param SS The nested-name-specifier that qualifies the template
401 /// name. This nested-name-specifier must already have been transformed.
402 ///
403 /// \param Name The template name to transform.
404 ///
405 /// \param NameLoc The source location of the template name.
406 ///
407 /// \param ObjectType If we're translating a template name within a member
408 /// access expression, this is the type of the object whose member template
409 /// is being referenced.
410 ///
411 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
412 /// also refers to a name within the current (lexical) scope, this is the
413 /// declaration it refers to.
414 ///
415 /// By default, transforms the template name by transforming the declarations
416 /// and nested-name-specifiers that occur within the template name.
417 /// Subclasses may override this function to provide alternate behavior.
418 TemplateName TransformTemplateName(CXXScopeSpec &SS,
419 TemplateName Name,
420 SourceLocation NameLoc,
421 QualType ObjectType = QualType(),
422 NamedDecl *FirstQualifierInScope = 0);
423
Douglas Gregord6ff3322009-08-04 16:50:30 +0000424 /// \brief Transform the given template argument.
425 ///
Mike Stump11289f42009-09-09 15:08:12 +0000426 /// By default, this operation transforms the type, expression, or
427 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000428 /// new template argument from the transformed result. Subclasses may
429 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000430 ///
431 /// Returns true if there was an error.
432 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
433 TemplateArgumentLoc &Output);
434
Douglas Gregor62e06f22010-12-20 17:31:10 +0000435 /// \brief Transform the given set of template arguments.
436 ///
437 /// By default, this operation transforms all of the template arguments
438 /// in the input set using \c TransformTemplateArgument(), and appends
439 /// the transformed arguments to the output list.
440 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000441 /// Note that this overload of \c TransformTemplateArguments() is merely
442 /// a convenience function. Subclasses that wish to override this behavior
443 /// should override the iterator-based member template version.
444 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000445 /// \param Inputs The set of template arguments to be transformed.
446 ///
447 /// \param NumInputs The number of template arguments in \p Inputs.
448 ///
449 /// \param Outputs The set of transformed template arguments output by this
450 /// routine.
451 ///
452 /// Returns true if an error occurred.
453 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
454 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000455 TemplateArgumentListInfo &Outputs) {
456 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
457 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000458
459 /// \brief Transform the given set of template arguments.
460 ///
461 /// By default, this operation transforms all of the template arguments
462 /// in the input set using \c TransformTemplateArgument(), and appends
463 /// the transformed arguments to the output list.
464 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000465 /// \param First An iterator to the first template argument.
466 ///
467 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000468 ///
469 /// \param Outputs The set of transformed template arguments output by this
470 /// routine.
471 ///
472 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000473 template<typename InputIterator>
474 bool TransformTemplateArguments(InputIterator First,
475 InputIterator Last,
476 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000477
John McCall0ad16662009-10-29 08:12:44 +0000478 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
479 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
480 TemplateArgumentLoc &ArgLoc);
481
John McCallbcd03502009-12-07 02:54:59 +0000482 /// \brief Fakes up a TypeSourceInfo for a type.
483 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
484 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000485 getDerived().getBaseLocation());
486 }
Mike Stump11289f42009-09-09 15:08:12 +0000487
John McCall550e0c22009-10-21 00:40:46 +0000488#define ABSTRACT_TYPELOC(CLASS, PARENT)
489#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000490 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000491#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000492
John McCall31f82722010-11-12 08:19:04 +0000493 QualType
494 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
495 TemplateSpecializationTypeLoc TL,
496 TemplateName Template);
497
498 QualType
499 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
500 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor5a064722011-02-28 17:23:35 +0000501 TemplateName Template);
502
503 QualType
504 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
505 DependentTemplateSpecializationTypeLoc TL,
John McCall31f82722010-11-12 08:19:04 +0000506 NestedNameSpecifier *Prefix);
507
Douglas Gregora7a795b2011-03-01 20:11:18 +0000508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall58f10c32010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000523 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000524 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000528 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
529 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000530
John McCall31f82722010-11-12 08:19:04 +0000531 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000532
John McCalldadc5752010-08-24 06:29:42 +0000533 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
534 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000535
Douglas Gregorebe10102009-08-20 07:17:43 +0000536#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000537 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000538#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000539 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000540#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000541#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000542
Douglas Gregord6ff3322009-08-04 16:50:30 +0000543 /// \brief Build a new pointer type given its pointee type.
544 ///
545 /// By default, performs semantic analysis when building the pointer type.
546 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000547 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000548
549 /// \brief Build a new block pointer type given its pointee type.
550 ///
Mike Stump11289f42009-09-09 15:08:12 +0000551 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000553 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000554
John McCall70dd5f62009-10-30 00:06:24 +0000555 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556 ///
John McCall70dd5f62009-10-30 00:06:24 +0000557 /// By default, performs semantic analysis when building the
558 /// reference type. Subclasses may override this routine to provide
559 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 ///
John McCall70dd5f62009-10-30 00:06:24 +0000561 /// \param LValue whether the type was written with an lvalue sigil
562 /// or an rvalue sigil.
563 QualType RebuildReferenceType(QualType ReferentType,
564 bool LValue,
565 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000566
Douglas Gregord6ff3322009-08-04 16:50:30 +0000567 /// \brief Build a new member pointer type given the pointee type and the
568 /// class type it refers into.
569 ///
570 /// By default, performs semantic analysis when building the member pointer
571 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000572 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
573 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000574
Douglas Gregord6ff3322009-08-04 16:50:30 +0000575 /// \brief Build a new array type given the element type, size
576 /// modifier, size of the array (if known), size expression, and index type
577 /// qualifiers.
578 ///
579 /// By default, performs semantic analysis when building the array type.
580 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000581 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000582 QualType RebuildArrayType(QualType ElementType,
583 ArrayType::ArraySizeModifier SizeMod,
584 const llvm::APInt *Size,
585 Expr *SizeExpr,
586 unsigned IndexTypeQuals,
587 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000588
Douglas Gregord6ff3322009-08-04 16:50:30 +0000589 /// \brief Build a new constant array type given the element type, size
590 /// modifier, (known) size of the array, and index type qualifiers.
591 ///
592 /// By default, performs semantic analysis when building the array type.
593 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000594 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000595 ArrayType::ArraySizeModifier SizeMod,
596 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000597 unsigned IndexTypeQuals,
598 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599
Douglas Gregord6ff3322009-08-04 16:50:30 +0000600 /// \brief Build a new incomplete array type given the element type, size
601 /// modifier, and index type qualifiers.
602 ///
603 /// By default, performs semantic analysis when building the array type.
604 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000605 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000606 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000607 unsigned IndexTypeQuals,
608 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000609
Mike Stump11289f42009-09-09 15:08:12 +0000610 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000611 /// size modifier, size expression, and index type qualifiers.
612 ///
613 /// By default, performs semantic analysis when building the array type.
614 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000615 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000616 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000617 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000618 unsigned IndexTypeQuals,
619 SourceRange BracketsRange);
620
Mike Stump11289f42009-09-09 15:08:12 +0000621 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000622 /// size modifier, size expression, and index type qualifiers.
623 ///
624 /// By default, performs semantic analysis when building the array type.
625 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000626 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000627 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000628 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000629 unsigned IndexTypeQuals,
630 SourceRange BracketsRange);
631
632 /// \brief Build a new vector type given the element type and
633 /// number of elements.
634 ///
635 /// By default, performs semantic analysis when building the vector type.
636 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000637 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000638 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000639
Douglas Gregord6ff3322009-08-04 16:50:30 +0000640 /// \brief Build a new extended vector type given the element type and
641 /// number of elements.
642 ///
643 /// By default, performs semantic analysis when building the vector type.
644 /// Subclasses may override this routine to provide different behavior.
645 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
646 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000647
648 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000649 /// given the element type and number of elements.
650 ///
651 /// By default, performs semantic analysis when building the vector type.
652 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000653 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000654 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000655 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000656
Douglas Gregord6ff3322009-08-04 16:50:30 +0000657 /// \brief Build a new function type.
658 ///
659 /// By default, performs semantic analysis when building the function type.
660 /// Subclasses may override this routine to provide different behavior.
661 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000662 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000663 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000664 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000665 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000666 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000667
John McCall550e0c22009-10-21 00:40:46 +0000668 /// \brief Build a new unprototyped function type.
669 QualType RebuildFunctionNoProtoType(QualType ResultType);
670
John McCallb96ec562009-12-04 22:46:56 +0000671 /// \brief Rebuild an unresolved typename type, given the decl that
672 /// the UnresolvedUsingTypenameDecl was transformed to.
673 QualType RebuildUnresolvedUsingType(Decl *D);
674
Douglas Gregord6ff3322009-08-04 16:50:30 +0000675 /// \brief Build a new typedef type.
676 QualType RebuildTypedefType(TypedefDecl *Typedef) {
677 return SemaRef.Context.getTypeDeclType(Typedef);
678 }
679
680 /// \brief Build a new class/struct/union type.
681 QualType RebuildRecordType(RecordDecl *Record) {
682 return SemaRef.Context.getTypeDeclType(Record);
683 }
684
685 /// \brief Build a new Enum type.
686 QualType RebuildEnumType(EnumDecl *Enum) {
687 return SemaRef.Context.getTypeDeclType(Enum);
688 }
John McCallfcc33b02009-09-05 00:15:47 +0000689
Mike Stump11289f42009-09-09 15:08:12 +0000690 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691 ///
692 /// By default, performs semantic analysis when building the typeof type.
693 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000694 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695
Mike Stump11289f42009-09-09 15:08:12 +0000696 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697 ///
698 /// By default, builds a new TypeOfType with the given underlying type.
699 QualType RebuildTypeOfType(QualType Underlying);
700
Mike Stump11289f42009-09-09 15:08:12 +0000701 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 ///
703 /// By default, performs semantic analysis when building the decltype type.
704 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000705 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000706
Richard Smith30482bc2011-02-20 03:19:35 +0000707 /// \brief Build a new C++0x auto type.
708 ///
709 /// By default, builds a new AutoType with the given deduced type.
710 QualType RebuildAutoType(QualType Deduced) {
711 return SemaRef.Context.getAutoType(Deduced);
712 }
713
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 /// \brief Build a new template specialization type.
715 ///
716 /// By default, performs semantic analysis when building the template
717 /// specialization type. Subclasses may override this routine to provide
718 /// different behavior.
719 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000720 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000721 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000722
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000723 /// \brief Build a new parenthesized type.
724 ///
725 /// By default, builds a new ParenType type from the inner type.
726 /// Subclasses may override this routine to provide different behavior.
727 QualType RebuildParenType(QualType InnerType) {
728 return SemaRef.Context.getParenType(InnerType);
729 }
730
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 /// \brief Build a new qualified name type.
732 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000733 /// By default, builds a new ElaboratedType type from the keyword,
734 /// the nested-name-specifier and the named type.
735 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000736 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
737 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000738 NestedNameSpecifierLoc QualifierLoc,
739 QualType Named) {
740 return SemaRef.Context.getElaboratedType(Keyword,
741 QualifierLoc.getNestedNameSpecifier(),
742 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000743 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000744
745 /// \brief Build a new typename type that refers to a template-id.
746 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000747 /// By default, builds a new DependentNameType type from the
748 /// nested-name-specifier and the given type. Subclasses may override
749 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000750 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000751 ElaboratedTypeKeyword Keyword,
752 NestedNameSpecifierLoc QualifierLoc,
753 const IdentifierInfo *Name,
754 SourceLocation NameLoc,
755 const TemplateArgumentListInfo &Args) {
756 // Rebuild the template name.
757 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000758 CXXScopeSpec SS;
759 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000760 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000761 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000762
763 if (InstName.isNull())
764 return QualType();
765
766 // If it's still dependent, make a dependent specialization.
767 if (InstName.getAsDependentTemplateName())
768 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
769 QualifierLoc.getNestedNameSpecifier(),
770 Name,
771 Args);
772
773 // Otherwise, make an elaborated type wrapping a non-dependent
774 // specialization.
775 QualType T =
776 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
777 if (T.isNull()) return QualType();
778
779 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
780 return T;
781
782 return SemaRef.Context.getElaboratedType(Keyword,
783 QualifierLoc.getNestedNameSpecifier(),
784 T);
785 }
786
Douglas Gregord6ff3322009-08-04 16:50:30 +0000787 /// \brief Build a new typename type that refers to an identifier.
788 ///
789 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000790 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000791 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000792 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000793 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000794 NestedNameSpecifierLoc QualifierLoc,
795 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000796 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000797 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000798 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000799
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000800 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000801 // If the name is still dependent, just build a new dependent name type.
802 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000803 return SemaRef.Context.getDependentNameType(Keyword,
804 QualifierLoc.getNestedNameSpecifier(),
805 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000806 }
807
Abramo Bagnara6150c882010-05-11 21:36:43 +0000808 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000809 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000810 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000811
812 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
813
Abramo Bagnarad7548482010-05-19 21:37:53 +0000814 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000815 // into a non-dependent elaborated-type-specifier. Find the tag we're
816 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000817 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000818 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
819 if (!DC)
820 return QualType();
821
John McCallbf8c5192010-05-27 06:40:31 +0000822 if (SemaRef.RequireCompleteDeclContext(SS, DC))
823 return QualType();
824
Douglas Gregore677daf2010-03-31 22:19:08 +0000825 TagDecl *Tag = 0;
826 SemaRef.LookupQualifiedName(Result, DC);
827 switch (Result.getResultKind()) {
828 case LookupResult::NotFound:
829 case LookupResult::NotFoundInCurrentInstantiation:
830 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000831
Douglas Gregore677daf2010-03-31 22:19:08 +0000832 case LookupResult::Found:
833 Tag = Result.getAsSingle<TagDecl>();
834 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000835
Douglas Gregore677daf2010-03-31 22:19:08 +0000836 case LookupResult::FoundOverloaded:
837 case LookupResult::FoundUnresolvedValue:
838 llvm_unreachable("Tag lookup cannot find non-tags");
839 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000840
Douglas Gregore677daf2010-03-31 22:19:08 +0000841 case LookupResult::Ambiguous:
842 // Let the LookupResult structure handle ambiguities.
843 return QualType();
844 }
845
846 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000847 // Check where the name exists but isn't a tag type and use that to emit
848 // better diagnostics.
849 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
850 SemaRef.LookupQualifiedName(Result, DC);
851 switch (Result.getResultKind()) {
852 case LookupResult::Found:
853 case LookupResult::FoundOverloaded:
854 case LookupResult::FoundUnresolvedValue: {
855 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
856 unsigned Kind = 0;
857 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
858 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
859 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
860 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
861 break;
862 }
863 default:
864 // FIXME: Would be nice to highlight just the source range.
865 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
866 << Kind << Id << DC;
867 break;
868 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000869 return QualType();
870 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000871
Abramo Bagnarad7548482010-05-19 21:37:53 +0000872 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
873 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000874 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
875 return QualType();
876 }
877
878 // Build the elaborated-type-specifier type.
879 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000880 return SemaRef.Context.getElaboratedType(Keyword,
881 QualifierLoc.getNestedNameSpecifier(),
882 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000883 }
Mike Stump11289f42009-09-09 15:08:12 +0000884
Douglas Gregor822d0302011-01-12 17:07:58 +0000885 /// \brief Build a new pack expansion type.
886 ///
887 /// By default, builds a new PackExpansionType type from the given pattern.
888 /// Subclasses may override this routine to provide different behavior.
889 QualType RebuildPackExpansionType(QualType Pattern,
890 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000891 SourceLocation EllipsisLoc,
892 llvm::Optional<unsigned> NumExpansions) {
893 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
894 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000895 }
896
Douglas Gregor1135c352009-08-06 05:28:30 +0000897 /// \brief Build a new nested-name-specifier given the prefix and an
898 /// identifier that names the next step in the nested-name-specifier.
899 ///
900 /// By default, performs semantic analysis when building the new
901 /// nested-name-specifier. Subclasses may override this routine to provide
902 /// different behavior.
903 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
904 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000905 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000906 QualType ObjectType,
907 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000908
909 /// \brief Build a new nested-name-specifier given the prefix and the
910 /// namespace named in the next step in the nested-name-specifier.
911 ///
912 /// By default, performs semantic analysis when building the new
913 /// nested-name-specifier. Subclasses may override this routine to provide
914 /// different behavior.
915 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
916 SourceRange Range,
917 NamespaceDecl *NS);
918
919 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor7b26ff92011-02-24 02:36:08 +0000920 /// namespace alias named in the next step in the nested-name-specifier.
921 ///
922 /// By default, performs semantic analysis when building the new
923 /// nested-name-specifier. Subclasses may override this routine to provide
924 /// different behavior.
925 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
926 SourceRange Range,
927 NamespaceAliasDecl *Alias);
928
929 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor1135c352009-08-06 05:28:30 +0000930 /// type named in the next step in the nested-name-specifier.
931 ///
932 /// By default, performs semantic analysis when building the new
933 /// nested-name-specifier. Subclasses may override this routine to provide
934 /// different behavior.
935 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
936 SourceRange Range,
937 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000938 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000939
940 /// \brief Build a new template name given a nested name specifier, a flag
941 /// indicating whether the "template" keyword was provided, and the template
942 /// that the template name refers to.
943 ///
944 /// By default, builds the new template name directly. Subclasses may override
945 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000946 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000947 bool TemplateKW,
948 TemplateDecl *Template);
949
Douglas Gregor71dc5092009-08-06 06:41:21 +0000950 /// \brief Build a new template name given a nested name specifier and the
951 /// name that is referred to as a template.
952 ///
953 /// By default, performs semantic analysis to determine whether the name can
954 /// be resolved to a specific template, then builds the appropriate kind of
955 /// template name. Subclasses may override this routine to provide different
956 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000957 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
958 const IdentifierInfo &Name,
959 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000960 QualType ObjectType,
961 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000962
Douglas Gregor71395fa2009-11-04 00:56:37 +0000963 /// \brief Build a new template name given a nested name specifier and the
964 /// overloaded operator name that is referred to as a template.
965 ///
966 /// By default, performs semantic analysis to determine whether the name can
967 /// be resolved to a specific template, then builds the appropriate kind of
968 /// template name. Subclasses may override this routine to provide different
969 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000970 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000971 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000972 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000973 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000974
975 /// \brief Build a new template name given a template template parameter pack
976 /// and the
977 ///
978 /// By default, performs semantic analysis to determine whether the name can
979 /// be resolved to a specific template, then builds the appropriate kind of
980 /// template name. Subclasses may override this routine to provide different
981 /// behavior.
982 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
983 const TemplateArgument &ArgPack) {
984 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
985 }
986
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 /// \brief Build a new compound statement.
988 ///
989 /// By default, performs semantic analysis to build the new statement.
990 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000991 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000992 MultiStmtArg Statements,
993 SourceLocation RBraceLoc,
994 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000995 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000996 IsStmtExpr);
997 }
998
999 /// \brief Build a new case statement.
1000 ///
1001 /// By default, performs semantic analysis to build the new statement.
1002 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001003 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001004 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001005 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001006 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001007 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001008 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001009 ColonLoc);
1010 }
Mike Stump11289f42009-09-09 15:08:12 +00001011
Douglas Gregorebe10102009-08-20 07:17:43 +00001012 /// \brief Attach the body to a new case statement.
1013 ///
1014 /// By default, performs semantic analysis to build the new statement.
1015 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001016 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001017 getSema().ActOnCaseStmtBody(S, Body);
1018 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001019 }
Mike Stump11289f42009-09-09 15:08:12 +00001020
Douglas Gregorebe10102009-08-20 07:17:43 +00001021 /// \brief Build a new default statement.
1022 ///
1023 /// By default, performs semantic analysis to build the new statement.
1024 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001025 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001026 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001027 Stmt *SubStmt) {
1028 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001029 /*CurScope=*/0);
1030 }
Mike Stump11289f42009-09-09 15:08:12 +00001031
Douglas Gregorebe10102009-08-20 07:17:43 +00001032 /// \brief Build a new label statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001036 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1037 SourceLocation ColonLoc, Stmt *SubStmt) {
1038 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001039 }
Mike Stump11289f42009-09-09 15:08:12 +00001040
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 /// \brief Build a new "if" statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001046 VarDecl *CondVar, Stmt *Then,
1047 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001048 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001049 }
Mike Stump11289f42009-09-09 15:08:12 +00001050
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 /// \brief Start building a new switch statement.
1052 ///
1053 /// By default, performs semantic analysis to build the new statement.
1054 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001055 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001056 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001057 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001058 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 }
Mike Stump11289f42009-09-09 15:08:12 +00001060
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 /// \brief Attach the body to the switch statement.
1062 ///
1063 /// By default, performs semantic analysis to build the new statement.
1064 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001065 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001066 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001067 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 }
1069
1070 /// \brief Build a new while statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001074 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1075 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001076 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001077 }
Mike Stump11289f42009-09-09 15:08:12 +00001078
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 /// \brief Build a new do-while statement.
1080 ///
1081 /// By default, performs semantic analysis to build the new statement.
1082 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001083 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001084 SourceLocation WhileLoc, SourceLocation LParenLoc,
1085 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001086 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1087 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001088 }
1089
1090 /// \brief Build a new for statement.
1091 ///
1092 /// By default, performs semantic analysis to build the new statement.
1093 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001094 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1095 Stmt *Init, Sema::FullExprArg Cond,
1096 VarDecl *CondVar, Sema::FullExprArg Inc,
1097 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001098 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001099 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 }
Mike Stump11289f42009-09-09 15:08:12 +00001101
Douglas Gregorebe10102009-08-20 07:17:43 +00001102 /// \brief Build a new goto statement.
1103 ///
1104 /// By default, performs semantic analysis to build the new statement.
1105 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001106 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1107 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001108 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 }
1110
1111 /// \brief Build a new indirect goto statement.
1112 ///
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001115 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001116 SourceLocation StarLoc,
1117 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001118 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 /// \brief Build a new return statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001125 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001126 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001127 }
Mike Stump11289f42009-09-09 15:08:12 +00001128
Douglas Gregorebe10102009-08-20 07:17:43 +00001129 /// \brief Build a new declaration statement.
1130 ///
1131 /// By default, performs semantic analysis to build the new statement.
1132 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001133 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001134 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001135 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001136 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1137 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001138 }
Mike Stump11289f42009-09-09 15:08:12 +00001139
Anders Carlssonaaeef072010-01-24 05:50:09 +00001140 /// \brief Build a new inline asm statement.
1141 ///
1142 /// By default, performs semantic analysis to build the new statement.
1143 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001144 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001145 bool IsSimple,
1146 bool IsVolatile,
1147 unsigned NumOutputs,
1148 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001149 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001150 MultiExprArg Constraints,
1151 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001152 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001153 MultiExprArg Clobbers,
1154 SourceLocation RParenLoc,
1155 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001156 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001157 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001158 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001159 RParenLoc, MSAsm);
1160 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001161
1162 /// \brief Build a new Objective-C @try statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001166 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001167 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001168 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001169 Stmt *Finally) {
1170 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1171 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001172 }
1173
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001174 /// \brief Rebuild an Objective-C exception declaration.
1175 ///
1176 /// By default, performs semantic analysis to build the new declaration.
1177 /// Subclasses may override this routine to provide different behavior.
1178 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1179 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001180 return getSema().BuildObjCExceptionDecl(TInfo, T,
1181 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001182 ExceptionDecl->getLocation());
1183 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001184
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001185 /// \brief Build a new Objective-C @catch statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001189 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001190 SourceLocation RParenLoc,
1191 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001192 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001193 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001194 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001195 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001196
Douglas Gregor306de2f2010-04-22 23:59:56 +00001197 /// \brief Build a new Objective-C @finally statement.
1198 ///
1199 /// By default, performs semantic analysis to build the new statement.
1200 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001201 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001202 Stmt *Body) {
1203 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001204 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001205
Douglas Gregor6148de72010-04-22 22:01:21 +00001206 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001207 ///
1208 /// By default, performs semantic analysis to build the new statement.
1209 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001210 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001211 Expr *Operand) {
1212 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001213 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001214
Douglas Gregor6148de72010-04-22 22:01:21 +00001215 /// \brief Build a new Objective-C @synchronized statement.
1216 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001217 /// By default, performs semantic analysis to build the new statement.
1218 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001219 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001220 Expr *Object,
1221 Stmt *Body) {
1222 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1223 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001224 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001225
1226 /// \brief Build a new Objective-C fast enumeration statement.
1227 ///
1228 /// By default, performs semantic analysis to build the new statement.
1229 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001230 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001231 SourceLocation LParenLoc,
1232 Stmt *Element,
1233 Expr *Collection,
1234 SourceLocation RParenLoc,
1235 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001236 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001237 Element,
1238 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001239 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001240 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001241 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001242
Douglas Gregorebe10102009-08-20 07:17:43 +00001243 /// \brief Build a new C++ exception declaration.
1244 ///
1245 /// By default, performs semantic analysis to build the new decaration.
1246 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001247 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001248 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001249 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001250 SourceLocation Loc) {
1251 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001252 }
1253
1254 /// \brief Build a new C++ catch statement.
1255 ///
1256 /// By default, performs semantic analysis to build the new statement.
1257 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001258 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001259 VarDecl *ExceptionDecl,
1260 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001261 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1262 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001263 }
Mike Stump11289f42009-09-09 15:08:12 +00001264
Douglas Gregorebe10102009-08-20 07:17:43 +00001265 /// \brief Build a new C++ try statement.
1266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001269 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001270 Stmt *TryBlock,
1271 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001272 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001273 }
Mike Stump11289f42009-09-09 15:08:12 +00001274
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 /// \brief Build a new expression that references a declaration.
1276 ///
1277 /// By default, performs semantic analysis to build the new expression.
1278 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001279 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001280 LookupResult &R,
1281 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001282 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1283 }
1284
1285
1286 /// \brief Build a new expression that references a declaration.
1287 ///
1288 /// By default, performs semantic analysis to build the new expression.
1289 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001290 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001291 ValueDecl *VD,
1292 const DeclarationNameInfo &NameInfo,
1293 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001294 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001295 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001296
1297 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001298
1299 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 }
Mike Stump11289f42009-09-09 15:08:12 +00001301
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001303 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 /// By default, performs semantic analysis to build the new expression.
1305 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001306 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001308 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 }
1310
Douglas Gregorad8a3362009-09-04 17:36:40 +00001311 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001312 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001315 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001316 SourceLocation OperatorLoc,
1317 bool isArrow,
1318 CXXScopeSpec &SS,
1319 TypeSourceInfo *ScopeType,
1320 SourceLocation CCLoc,
1321 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001322 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001323
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001325 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 /// By default, performs semantic analysis to build the new expression.
1327 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001328 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001329 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001330 Expr *SubExpr) {
1331 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 }
Mike Stump11289f42009-09-09 15:08:12 +00001333
Douglas Gregor882211c2010-04-28 22:16:22 +00001334 /// \brief Build a new builtin offsetof expression.
1335 ///
1336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001338 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001339 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001340 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001341 unsigned NumComponents,
1342 SourceLocation RParenLoc) {
1343 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1344 NumComponents, RParenLoc);
1345 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001346
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001348 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 /// By default, performs semantic analysis to build the new expression.
1350 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001351 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001352 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001354 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 }
1356
Mike Stump11289f42009-09-09 15:08:12 +00001357 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001359 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 /// By default, performs semantic analysis to build the new expression.
1361 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001362 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001364 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001365 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001367 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001368
Douglas Gregora16548e2009-08-11 05:31:07 +00001369 return move(Result);
1370 }
Mike Stump11289f42009-09-09 15:08:12 +00001371
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001373 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 /// By default, performs semantic analysis to build the new expression.
1375 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001376 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001378 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001379 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001380 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1381 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 RBracketLoc);
1383 }
1384
1385 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001386 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 /// By default, performs semantic analysis to build the new expression.
1388 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001389 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001391 SourceLocation RParenLoc,
1392 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001393 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001394 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 }
1396
1397 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001398 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 /// By default, performs semantic analysis to build the new expression.
1400 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001401 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001402 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001403 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001404 const DeclarationNameInfo &MemberNameInfo,
1405 ValueDecl *Member,
1406 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001407 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001408 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001409 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001410 // We have a reference to an unnamed field. This is always the
1411 // base of an anonymous struct/union member access, i.e. the
1412 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001413 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001414 assert(Member->getType()->isRecordType() &&
1415 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001416
Douglas Gregorea972d32011-02-28 21:54:11 +00001417 if (getSema().PerformObjectMemberConversion(Base,
1418 QualifierLoc.getNestedNameSpecifier(),
John McCall16df1e52010-03-30 21:47:33 +00001419 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001420 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001421
John McCall7decc9e2010-11-18 06:31:45 +00001422 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001423 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001424 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001425 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001426 cast<FieldDecl>(Member)->getType(),
1427 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001428 return getSema().Owned(ME);
1429 }
Mike Stump11289f42009-09-09 15:08:12 +00001430
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001431 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001432 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001433
John McCallb268a282010-08-23 23:25:46 +00001434 getSema().DefaultFunctionArrayConversion(Base);
1435 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001436
John McCall16df1e52010-03-30 21:47:33 +00001437 // FIXME: this involves duplicating earlier analysis in a lot of
1438 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001439 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001440 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001441 R.resolveKind();
1442
John McCallb268a282010-08-23 23:25:46 +00001443 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001444 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001445 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 }
Mike Stump11289f42009-09-09 15:08:12 +00001447
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001449 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001452 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001453 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001454 Expr *LHS, Expr *RHS) {
1455 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 }
1457
1458 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001459 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001462 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001463 SourceLocation QuestionLoc,
1464 Expr *LHS,
1465 SourceLocation ColonLoc,
1466 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001467 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1468 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 }
1470
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001472 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 /// By default, performs semantic analysis to build the new expression.
1474 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001475 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001476 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001478 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001479 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001480 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 }
Mike Stump11289f42009-09-09 15:08:12 +00001482
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001484 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 /// By default, performs semantic analysis to build the new expression.
1486 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001487 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001488 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001490 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001491 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001492 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 }
Mike Stump11289f42009-09-09 15:08:12 +00001494
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001496 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001499 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 SourceLocation OpLoc,
1501 SourceLocation AccessorLoc,
1502 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001503
John McCall10eae182009-11-30 22:42:35 +00001504 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001505 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001506 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001507 OpLoc, /*IsArrow*/ false,
1508 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001509 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001510 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 }
Mike Stump11289f42009-09-09 15:08:12 +00001512
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001514 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001517 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001519 SourceLocation RBraceLoc,
1520 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001521 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001522 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1523 if (Result.isInvalid() || ResultTy->isDependentType())
1524 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001525
Douglas Gregord3d93062009-11-09 17:16:50 +00001526 // Patch in the result type we were given, which may have been computed
1527 // when the initial InitListExpr was built.
1528 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1529 ILE->setType(ResultTy);
1530 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 }
Mike Stump11289f42009-09-09 15:08:12 +00001532
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001534 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 /// By default, performs semantic analysis to build the new expression.
1536 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001537 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 MultiExprArg ArrayExprs,
1539 SourceLocation EqualOrColonLoc,
1540 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001541 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001542 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001544 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001546 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001547
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 ArrayExprs.release();
1549 return move(Result);
1550 }
Mike Stump11289f42009-09-09 15:08:12 +00001551
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001553 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 /// By default, builds the implicit value initialization without performing
1555 /// any semantic analysis. Subclasses may override this routine to provide
1556 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001557 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1559 }
Mike Stump11289f42009-09-09 15:08:12 +00001560
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001562 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001565 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001566 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001567 SourceLocation RParenLoc) {
1568 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001569 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001570 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 }
1572
1573 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001574 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 /// By default, performs semantic analysis to build the new expression.
1576 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001577 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 MultiExprArg SubExprs,
1579 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001580 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001581 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 }
Mike Stump11289f42009-09-09 15:08:12 +00001583
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001585 ///
1586 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 /// rather than attempting to map the label statement itself.
1588 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001589 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001590 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001591 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 }
Mike Stump11289f42009-09-09 15:08:12 +00001593
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001595 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001598 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001599 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001601 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 }
Mike Stump11289f42009-09-09 15:08:12 +00001603
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 /// \brief Build a new __builtin_choose_expr expression.
1605 ///
1606 /// By default, performs semantic analysis to build the new expression.
1607 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001608 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001609 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 SourceLocation RParenLoc) {
1611 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001612 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001613 RParenLoc);
1614 }
Mike Stump11289f42009-09-09 15:08:12 +00001615
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 /// \brief Build a new overloaded operator call expression.
1617 ///
1618 /// By default, performs semantic analysis to build the new expression.
1619 /// The semantic analysis provides the behavior of template instantiation,
1620 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001621 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 /// argument-dependent lookup, etc. Subclasses may override this routine to
1623 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001624 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001626 Expr *Callee,
1627 Expr *First,
1628 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001629
1630 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 /// reinterpret_cast.
1632 ///
1633 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001634 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001636 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 Stmt::StmtClass Class,
1638 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) {
1644 switch (Class) {
1645 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001646 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001647 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001648 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001649
1650 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001651 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001652 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001653 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001654
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001656 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001657 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001658 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001660
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001662 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001663 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001664 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001665
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 default:
1667 assert(false && "Invalid C++ named cast");
1668 break;
1669 }
Mike Stump11289f42009-09-09 15:08:12 +00001670
John McCallfaf5fb42010-08-26 23:41:50 +00001671 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 }
Mike Stump11289f42009-09-09 15:08:12 +00001673
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 /// \brief Build a new C++ static_cast expression.
1675 ///
1676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001678 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001680 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 SourceLocation RAngleLoc,
1682 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001683 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001684 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001685 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001686 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001687 SourceRange(LAngleLoc, RAngleLoc),
1688 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 }
1690
1691 /// \brief Build a new C++ dynamic_cast expression.
1692 ///
1693 /// By default, performs semantic analysis to build the new expression.
1694 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001695 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001697 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 SourceLocation RAngleLoc,
1699 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001700 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001702 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001703 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001704 SourceRange(LAngleLoc, RAngleLoc),
1705 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 }
1707
1708 /// \brief Build a new C++ reinterpret_cast expression.
1709 ///
1710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001712 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001714 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 SourceLocation RAngleLoc,
1716 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001717 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001719 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001720 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001721 SourceRange(LAngleLoc, RAngleLoc),
1722 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 }
1724
1725 /// \brief Build a new C++ const_cast expression.
1726 ///
1727 /// By default, performs semantic analysis to build the new expression.
1728 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001729 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001731 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 SourceLocation RAngleLoc,
1733 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001734 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001736 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001737 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001738 SourceRange(LAngleLoc, RAngleLoc),
1739 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 }
Mike Stump11289f42009-09-09 15:08:12 +00001741
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 /// \brief Build a new C++ functional-style cast expression.
1743 ///
1744 /// By default, performs semantic analysis to build the new expression.
1745 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001746 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1747 SourceLocation LParenLoc,
1748 Expr *Sub,
1749 SourceLocation RParenLoc) {
1750 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001751 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001752 RParenLoc);
1753 }
Mike Stump11289f42009-09-09 15:08:12 +00001754
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 /// \brief Build a new C++ typeid(type) expression.
1756 ///
1757 /// By default, performs semantic analysis to build the new expression.
1758 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001759 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001760 SourceLocation TypeidLoc,
1761 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001763 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001764 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 }
Mike Stump11289f42009-09-09 15:08:12 +00001766
Francois Pichet9f4f2072010-09-08 12:20:18 +00001767
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 /// \brief Build a new C++ typeid(expr) expression.
1769 ///
1770 /// By default, performs semantic analysis to build the new expression.
1771 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001772 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001773 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001774 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001776 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001777 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001778 }
1779
Francois Pichet9f4f2072010-09-08 12:20:18 +00001780 /// \brief Build a new C++ __uuidof(type) expression.
1781 ///
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
1784 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1785 SourceLocation TypeidLoc,
1786 TypeSourceInfo *Operand,
1787 SourceLocation RParenLoc) {
1788 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1789 RParenLoc);
1790 }
1791
1792 /// \brief Build a new C++ __uuidof(expr) expression.
1793 ///
1794 /// By default, performs semantic analysis to build the new expression.
1795 /// Subclasses may override this routine to provide different behavior.
1796 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1797 SourceLocation TypeidLoc,
1798 Expr *Operand,
1799 SourceLocation RParenLoc) {
1800 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1801 RParenLoc);
1802 }
1803
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 /// \brief Build a new C++ "this" expression.
1805 ///
1806 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001807 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001809 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001810 QualType ThisType,
1811 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001813 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1814 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001815 }
1816
1817 /// \brief Build a new C++ throw expression.
1818 ///
1819 /// By default, performs semantic analysis to build the new expression.
1820 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001821 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001822 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 }
1824
1825 /// \brief Build a new C++ default-argument expression.
1826 ///
1827 /// By default, builds a new default-argument expression, which does not
1828 /// require any semantic analysis. Subclasses may override this routine to
1829 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001830 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001831 ParmVarDecl *Param) {
1832 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1833 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 }
1835
1836 /// \brief Build a new C++ zero-initialization expression.
1837 ///
1838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001840 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1841 SourceLocation LParenLoc,
1842 SourceLocation RParenLoc) {
1843 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001844 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001845 RParenLoc);
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 C++ "new" 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 RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001853 bool UseGlobal,
1854 SourceLocation PlacementLParen,
1855 MultiExprArg PlacementArgs,
1856 SourceLocation PlacementRParen,
1857 SourceRange TypeIdParens,
1858 QualType AllocatedType,
1859 TypeSourceInfo *AllocatedTypeInfo,
1860 Expr *ArraySize,
1861 SourceLocation ConstructorLParen,
1862 MultiExprArg ConstructorArgs,
1863 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001864 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 PlacementLParen,
1866 move(PlacementArgs),
1867 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001868 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001869 AllocatedType,
1870 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001871 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001872 ConstructorLParen,
1873 move(ConstructorArgs),
1874 ConstructorRParen);
1875 }
Mike Stump11289f42009-09-09 15:08:12 +00001876
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 /// \brief Build a new C++ "delete" expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
1880 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001881 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001882 bool IsGlobalDelete,
1883 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001884 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001886 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001887 }
Mike Stump11289f42009-09-09 15:08:12 +00001888
Douglas Gregora16548e2009-08-11 05:31:07 +00001889 /// \brief Build a new unary type trait expression.
1890 ///
1891 /// By default, performs semantic analysis to build the new expression.
1892 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001893 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001894 SourceLocation StartLoc,
1895 TypeSourceInfo *T,
1896 SourceLocation RParenLoc) {
1897 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001898 }
1899
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001900 /// \brief Build a new binary type trait expression.
1901 ///
1902 /// By default, performs semantic analysis to build the new expression.
1903 /// Subclasses may override this routine to provide different behavior.
1904 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1905 SourceLocation StartLoc,
1906 TypeSourceInfo *LhsT,
1907 TypeSourceInfo *RhsT,
1908 SourceLocation RParenLoc) {
1909 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1910 }
1911
Mike Stump11289f42009-09-09 15:08:12 +00001912 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 /// expression.
1914 ///
1915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001917 ExprResult RebuildDependentScopeDeclRefExpr(
1918 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001919 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001920 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001922 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001923
1924 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001925 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001926 *TemplateArgs);
1927
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001928 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 }
1930
1931 /// \brief Build a new template-id expression.
1932 ///
1933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001935 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001936 LookupResult &R,
1937 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001938 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001939 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 }
1941
1942 /// \brief Build a new object-construction expression.
1943 ///
1944 /// By default, performs semantic analysis to build the new expression.
1945 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001946 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001947 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 CXXConstructorDecl *Constructor,
1949 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001950 MultiExprArg Args,
1951 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001952 CXXConstructExpr::ConstructionKind ConstructKind,
1953 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001954 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001955 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001956 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001957 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001958
Douglas Gregordb121ba2009-12-14 16:27:04 +00001959 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001960 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001961 RequiresZeroInit, ConstructKind,
1962 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 }
1964
1965 /// \brief Build a new object-construction expression.
1966 ///
1967 /// By default, performs semantic analysis to build the new expression.
1968 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001969 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1970 SourceLocation LParenLoc,
1971 MultiExprArg Args,
1972 SourceLocation RParenLoc) {
1973 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 LParenLoc,
1975 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 RParenLoc);
1977 }
1978
1979 /// \brief Build a new object-construction expression.
1980 ///
1981 /// By default, performs semantic analysis to build the new expression.
1982 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001983 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1984 SourceLocation LParenLoc,
1985 MultiExprArg Args,
1986 SourceLocation RParenLoc) {
1987 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 LParenLoc,
1989 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 RParenLoc);
1991 }
Mike Stump11289f42009-09-09 15:08:12 +00001992
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 /// \brief Build a new member reference expression.
1994 ///
1995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001997 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00001998 QualType BaseType,
1999 bool IsArrow,
2000 SourceLocation OperatorLoc,
2001 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002002 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002003 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002004 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002006 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002007
John McCallb268a282010-08-23 23:25:46 +00002008 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002009 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002010 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002011 MemberNameInfo,
2012 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002013 }
2014
John McCall10eae182009-11-30 22:42:35 +00002015 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002016 ///
2017 /// By default, performs semantic analysis to build the new expression.
2018 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002019 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002020 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002021 SourceLocation OperatorLoc,
2022 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002023 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002024 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002025 LookupResult &R,
2026 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002027 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002028 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002029
John McCallb268a282010-08-23 23:25:46 +00002030 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002031 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002032 SS, FirstQualifierInScope,
2033 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002034 }
Mike Stump11289f42009-09-09 15:08:12 +00002035
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002036 /// \brief Build a new noexcept expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
2040 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2041 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2042 }
2043
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002044 /// \brief Build a new expression to compute the length of a parameter pack.
2045 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2046 SourceLocation PackLoc,
2047 SourceLocation RParenLoc,
2048 unsigned Length) {
2049 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2050 OperatorLoc, Pack, PackLoc,
2051 RParenLoc, Length);
2052 }
2053
Douglas Gregora16548e2009-08-11 05:31:07 +00002054 /// \brief Build a new Objective-C @encode 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 RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002059 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002060 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002061 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002062 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002063 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002064
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002065 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002066 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002067 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002068 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002069 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002070 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002071 MultiExprArg Args,
2072 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002073 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2074 ReceiverTypeInfo->getType(),
2075 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002076 Sel, Method, LBracLoc, SelectorLoc,
2077 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002078 }
2079
2080 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002081 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002082 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002083 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002084 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002085 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002086 MultiExprArg Args,
2087 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002088 return SemaRef.BuildInstanceMessage(Receiver,
2089 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002090 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002091 Sel, Method, LBracLoc, SelectorLoc,
2092 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002093 }
2094
Douglas Gregord51d90d2010-04-26 20:11:03 +00002095 /// \brief Build a new Objective-C ivar reference expression.
2096 ///
2097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002099 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002100 SourceLocation IvarLoc,
2101 bool IsArrow, bool IsFreeIvar) {
2102 // FIXME: We lose track of the IsFreeIvar bit.
2103 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002104 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002105 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2106 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002107 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002108 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002109 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002110 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002111 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002112 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002113
Douglas Gregord51d90d2010-04-26 20:11:03 +00002114 if (Result.get())
2115 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002116
John McCallb268a282010-08-23 23:25:46 +00002117 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002118 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002119 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002120 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002121 /*TemplateArgs=*/0);
2122 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002123
2124 /// \brief Build a new Objective-C property reference expression.
2125 ///
2126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002128 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002129 ObjCPropertyDecl *Property,
2130 SourceLocation PropertyLoc) {
2131 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002132 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002133 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2134 Sema::LookupMemberName);
2135 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002136 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002137 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002138 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002139 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002140 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002141
Douglas Gregor9faee212010-04-26 20:47:02 +00002142 if (Result.get())
2143 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002144
John McCallb268a282010-08-23 23:25:46 +00002145 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002146 /*FIXME:*/PropertyLoc, IsArrow,
2147 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002148 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002149 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002150 /*TemplateArgs=*/0);
2151 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002152
John McCallb7bd14f2010-12-02 01:19:52 +00002153 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002154 ///
2155 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002156 /// Subclasses may override this routine to provide different behavior.
2157 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2158 ObjCMethodDecl *Getter,
2159 ObjCMethodDecl *Setter,
2160 SourceLocation PropertyLoc) {
2161 // Since these expressions can only be value-dependent, we do not
2162 // need to perform semantic analysis again.
2163 return Owned(
2164 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2165 VK_LValue, OK_ObjCProperty,
2166 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002167 }
2168
Douglas Gregord51d90d2010-04-26 20:11:03 +00002169 /// \brief Build a new Objective-C "isa" expression.
2170 ///
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002173 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002174 bool IsArrow) {
2175 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002176 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002177 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2178 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002179 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002180 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002181 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002182 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002183 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002184
Douglas Gregord51d90d2010-04-26 20:11:03 +00002185 if (Result.get())
2186 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002187
John McCallb268a282010-08-23 23:25:46 +00002188 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002189 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002190 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002191 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002192 /*TemplateArgs=*/0);
2193 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002194
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 /// \brief Build a new shuffle vector expression.
2196 ///
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002199 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002200 MultiExprArg SubExprs,
2201 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002203 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2205 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2206 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2207 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002208
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 // Build a reference to the __builtin_shufflevector builtin
2210 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002211 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002213 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002215
2216 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002217 unsigned NumSubExprs = SubExprs.size();
2218 Expr **Subs = (Expr **)SubExprs.release();
2219 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2220 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002221 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002222 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002224 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002225
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002229 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002230
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002232 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 }
John McCall31f82722010-11-12 08:19:04 +00002234
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002235 /// \brief Build a new template argument pack expansion.
2236 ///
2237 /// By default, performs semantic analysis to build a new pack expansion
2238 /// for a template argument. Subclasses may override this routine to provide
2239 /// different behavior.
2240 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002241 SourceLocation EllipsisLoc,
2242 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002243 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002244 case TemplateArgument::Expression: {
2245 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002246 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2247 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002248 if (Result.isInvalid())
2249 return TemplateArgumentLoc();
2250
2251 return TemplateArgumentLoc(Result.get(), Result.get());
2252 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002253
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002254 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002255 return TemplateArgumentLoc(TemplateArgument(
2256 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002257 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002258 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002259 Pattern.getTemplateNameLoc(),
2260 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002261
2262 case TemplateArgument::Null:
2263 case TemplateArgument::Integral:
2264 case TemplateArgument::Declaration:
2265 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002266 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002267 llvm_unreachable("Pack expansion pattern has no parameter packs");
2268
2269 case TemplateArgument::Type:
2270 if (TypeSourceInfo *Expansion
2271 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002272 EllipsisLoc,
2273 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002274 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2275 Expansion);
2276 break;
2277 }
2278
2279 return TemplateArgumentLoc();
2280 }
2281
Douglas Gregor968f23a2011-01-03 19:31:53 +00002282 /// \brief Build a new expression pack expansion.
2283 ///
2284 /// By default, performs semantic analysis to build a new pack expansion
2285 /// for an expression. Subclasses may override this routine to provide
2286 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002287 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2288 llvm::Optional<unsigned> NumExpansions) {
2289 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002290 }
2291
John McCall31f82722010-11-12 08:19:04 +00002292private:
Douglas Gregor14454802011-02-25 02:25:35 +00002293 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2294 QualType ObjectType,
2295 NamedDecl *FirstQualifierInScope,
2296 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002297
2298 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2299 QualType ObjectType,
2300 NamedDecl *FirstQualifierInScope,
2301 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002302};
Douglas Gregora16548e2009-08-11 05:31:07 +00002303
Douglas Gregorebe10102009-08-20 07:17:43 +00002304template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002305StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002306 if (!S)
2307 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002308
Douglas Gregorebe10102009-08-20 07:17:43 +00002309 switch (S->getStmtClass()) {
2310 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002311
Douglas Gregorebe10102009-08-20 07:17:43 +00002312 // Transform individual statement nodes
2313#define STMT(Node, Parent) \
2314 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002315#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002316#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002317#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002318
Douglas Gregorebe10102009-08-20 07:17:43 +00002319 // Transform expressions by calling TransformExpr.
2320#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002321#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002322#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002323#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002324 {
John McCalldadc5752010-08-24 06:29:42 +00002325 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002326 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002327 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002328
John McCallb268a282010-08-23 23:25:46 +00002329 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002330 }
Mike Stump11289f42009-09-09 15:08:12 +00002331 }
2332
John McCallc3007a22010-10-26 07:05:15 +00002333 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002334}
Mike Stump11289f42009-09-09 15:08:12 +00002335
2336
Douglas Gregore922c772009-08-04 22:27:00 +00002337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002338ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002339 if (!E)
2340 return SemaRef.Owned(E);
2341
2342 switch (E->getStmtClass()) {
2343 case Stmt::NoStmtClass: break;
2344#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002345#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002346#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002347 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002348#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002349 }
2350
John McCallc3007a22010-10-26 07:05:15 +00002351 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002352}
2353
2354template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002355bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2356 unsigned NumInputs,
2357 bool IsCall,
2358 llvm::SmallVectorImpl<Expr *> &Outputs,
2359 bool *ArgChanged) {
2360 for (unsigned I = 0; I != NumInputs; ++I) {
2361 // If requested, drop call arguments that need to be dropped.
2362 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2363 if (ArgChanged)
2364 *ArgChanged = true;
2365
2366 break;
2367 }
2368
Douglas Gregor968f23a2011-01-03 19:31:53 +00002369 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2370 Expr *Pattern = Expansion->getPattern();
2371
2372 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2373 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2374 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2375
2376 // Determine whether the set of unexpanded parameter packs can and should
2377 // be expanded.
2378 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002379 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002380 llvm::Optional<unsigned> OrigNumExpansions
2381 = Expansion->getNumExpansions();
2382 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002383 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2384 Pattern->getSourceRange(),
2385 Unexpanded.data(),
2386 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002387 Expand, RetainExpansion,
2388 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002389 return true;
2390
2391 if (!Expand) {
2392 // The transform has determined that we should perform a simple
2393 // transformation on the pack expansion, producing another pack
2394 // expansion.
2395 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2396 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2397 if (OutPattern.isInvalid())
2398 return true;
2399
2400 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002401 Expansion->getEllipsisLoc(),
2402 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002403 if (Out.isInvalid())
2404 return true;
2405
2406 if (ArgChanged)
2407 *ArgChanged = true;
2408 Outputs.push_back(Out.get());
2409 continue;
2410 }
2411
2412 // The transform has determined that we should perform an elementwise
2413 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002414 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002415 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2416 ExprResult Out = getDerived().TransformExpr(Pattern);
2417 if (Out.isInvalid())
2418 return true;
2419
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002420 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002421 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2422 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002423 if (Out.isInvalid())
2424 return true;
2425 }
2426
Douglas Gregor968f23a2011-01-03 19:31:53 +00002427 if (ArgChanged)
2428 *ArgChanged = true;
2429 Outputs.push_back(Out.get());
2430 }
2431
2432 continue;
2433 }
2434
Douglas Gregora3efea12011-01-03 19:04:46 +00002435 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2436 if (Result.isInvalid())
2437 return true;
2438
2439 if (Result.get() != Inputs[I] && ArgChanged)
2440 *ArgChanged = true;
2441
2442 Outputs.push_back(Result.get());
2443 }
2444
2445 return false;
2446}
2447
2448template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002449NestedNameSpecifierLoc
2450TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2451 NestedNameSpecifierLoc NNS,
2452 QualType ObjectType,
2453 NamedDecl *FirstQualifierInScope) {
2454 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2455 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2456 Qualifier = Qualifier.getPrefix())
2457 Qualifiers.push_back(Qualifier);
2458
2459 CXXScopeSpec SS;
2460 while (!Qualifiers.empty()) {
2461 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2462 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2463
2464 switch (QNNS->getKind()) {
2465 case NestedNameSpecifier::Identifier:
2466 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2467 *QNNS->getAsIdentifier(),
2468 Q.getLocalBeginLoc(),
2469 Q.getLocalEndLoc(),
2470 ObjectType, false, SS,
2471 FirstQualifierInScope, false))
2472 return NestedNameSpecifierLoc();
2473
2474 break;
2475
2476 case NestedNameSpecifier::Namespace: {
2477 NamespaceDecl *NS
2478 = cast_or_null<NamespaceDecl>(
2479 getDerived().TransformDecl(
2480 Q.getLocalBeginLoc(),
2481 QNNS->getAsNamespace()));
2482 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2483 break;
2484 }
2485
2486 case NestedNameSpecifier::NamespaceAlias: {
2487 NamespaceAliasDecl *Alias
2488 = cast_or_null<NamespaceAliasDecl>(
2489 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2490 QNNS->getAsNamespaceAlias()));
2491 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2492 Q.getLocalEndLoc());
2493 break;
2494 }
2495
2496 case NestedNameSpecifier::Global:
2497 // There is no meaningful transformation that one could perform on the
2498 // global scope.
2499 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2500 break;
2501
2502 case NestedNameSpecifier::TypeSpecWithTemplate:
2503 case NestedNameSpecifier::TypeSpec: {
2504 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2505 FirstQualifierInScope, SS);
2506
2507 if (!TL)
2508 return NestedNameSpecifierLoc();
2509
2510 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2511 (SemaRef.getLangOptions().CPlusPlus0x &&
2512 TL.getType()->isEnumeralType())) {
2513 assert(!TL.getType().hasLocalQualifiers() &&
2514 "Can't get cv-qualifiers here");
2515 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2516 Q.getLocalEndLoc());
2517 break;
2518 }
2519
2520 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2521 << TL.getType() << SS.getRange();
2522 return NestedNameSpecifierLoc();
2523 }
Douglas Gregore16af532011-02-28 18:50:33 +00002524 }
Douglas Gregor14454802011-02-25 02:25:35 +00002525
Douglas Gregore16af532011-02-28 18:50:33 +00002526 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002527 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002528 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002529 }
2530
2531 // Don't rebuild the nested-name-specifier if we don't have to.
2532 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2533 !getDerived().AlwaysRebuild())
2534 return NNS;
2535
2536 // If we can re-use the source-location data from the original
2537 // nested-name-specifier, do so.
2538 if (SS.location_size() == NNS.getDataLength() &&
2539 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2540 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2541
2542 // Allocate new nested-name-specifier location information.
2543 return SS.getWithLocInContext(SemaRef.Context);
2544}
2545
2546template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002547DeclarationNameInfo
2548TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002549::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002550 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002551 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002552 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002553
2554 switch (Name.getNameKind()) {
2555 case DeclarationName::Identifier:
2556 case DeclarationName::ObjCZeroArgSelector:
2557 case DeclarationName::ObjCOneArgSelector:
2558 case DeclarationName::ObjCMultiArgSelector:
2559 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002560 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002561 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002562 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002563
Douglas Gregorf816bd72009-09-03 22:13:48 +00002564 case DeclarationName::CXXConstructorName:
2565 case DeclarationName::CXXDestructorName:
2566 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002567 TypeSourceInfo *NewTInfo;
2568 CanQualType NewCanTy;
2569 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002570 NewTInfo = getDerived().TransformType(OldTInfo);
2571 if (!NewTInfo)
2572 return DeclarationNameInfo();
2573 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002574 }
2575 else {
2576 NewTInfo = 0;
2577 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002578 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002579 if (NewT.isNull())
2580 return DeclarationNameInfo();
2581 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2582 }
Mike Stump11289f42009-09-09 15:08:12 +00002583
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002584 DeclarationName NewName
2585 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2586 NewCanTy);
2587 DeclarationNameInfo NewNameInfo(NameInfo);
2588 NewNameInfo.setName(NewName);
2589 NewNameInfo.setNamedTypeInfo(NewTInfo);
2590 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002591 }
Mike Stump11289f42009-09-09 15:08:12 +00002592 }
2593
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002594 assert(0 && "Unknown name kind.");
2595 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002596}
2597
2598template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002599TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002600TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2601 TemplateName Name,
2602 SourceLocation NameLoc,
2603 QualType ObjectType,
2604 NamedDecl *FirstQualifierInScope) {
2605 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2606 TemplateDecl *Template = QTN->getTemplateDecl();
2607 assert(Template && "qualified template name must refer to a template");
2608
2609 TemplateDecl *TransTemplate
2610 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2611 Template));
2612 if (!TransTemplate)
2613 return TemplateName();
2614
2615 if (!getDerived().AlwaysRebuild() &&
2616 SS.getScopeRep() == QTN->getQualifier() &&
2617 TransTemplate == Template)
2618 return Name;
2619
2620 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2621 TransTemplate);
2622 }
2623
2624 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2625 if (SS.getScopeRep()) {
2626 // These apply to the scope specifier, not the template.
2627 ObjectType = QualType();
2628 FirstQualifierInScope = 0;
2629 }
2630
2631 if (!getDerived().AlwaysRebuild() &&
2632 SS.getScopeRep() == DTN->getQualifier() &&
2633 ObjectType.isNull())
2634 return Name;
2635
2636 if (DTN->isIdentifier()) {
2637 return getDerived().RebuildTemplateName(SS,
2638 *DTN->getIdentifier(),
2639 NameLoc,
2640 ObjectType,
2641 FirstQualifierInScope);
2642 }
2643
2644 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2645 ObjectType);
2646 }
2647
2648 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2649 TemplateDecl *TransTemplate
2650 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2651 Template));
2652 if (!TransTemplate)
2653 return TemplateName();
2654
2655 if (!getDerived().AlwaysRebuild() &&
2656 TransTemplate == Template)
2657 return Name;
2658
2659 return TemplateName(TransTemplate);
2660 }
2661
2662 if (SubstTemplateTemplateParmPackStorage *SubstPack
2663 = Name.getAsSubstTemplateTemplateParmPack()) {
2664 TemplateTemplateParmDecl *TransParam
2665 = cast_or_null<TemplateTemplateParmDecl>(
2666 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2667 if (!TransParam)
2668 return TemplateName();
2669
2670 if (!getDerived().AlwaysRebuild() &&
2671 TransParam == SubstPack->getParameterPack())
2672 return Name;
2673
2674 return getDerived().RebuildTemplateName(TransParam,
2675 SubstPack->getArgumentPack());
2676 }
2677
2678 // These should be getting filtered out before they reach the AST.
2679 llvm_unreachable("overloaded function decl survived to here");
2680 return TemplateName();
2681}
2682
2683template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002684void TreeTransform<Derived>::InventTemplateArgumentLoc(
2685 const TemplateArgument &Arg,
2686 TemplateArgumentLoc &Output) {
2687 SourceLocation Loc = getDerived().getBaseLocation();
2688 switch (Arg.getKind()) {
2689 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002690 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002691 break;
2692
2693 case TemplateArgument::Type:
2694 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002695 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002696
John McCall0ad16662009-10-29 08:12:44 +00002697 break;
2698
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002699 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002700 case TemplateArgument::TemplateExpansion: {
2701 NestedNameSpecifierLocBuilder Builder;
2702 TemplateName Template = Arg.getAsTemplate();
2703 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2704 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2705 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2706 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2707
2708 if (Arg.getKind() == TemplateArgument::Template)
2709 Output = TemplateArgumentLoc(Arg,
2710 Builder.getWithLocInContext(SemaRef.Context),
2711 Loc);
2712 else
2713 Output = TemplateArgumentLoc(Arg,
2714 Builder.getWithLocInContext(SemaRef.Context),
2715 Loc, Loc);
2716
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002717 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002718 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002719
John McCall0ad16662009-10-29 08:12:44 +00002720 case TemplateArgument::Expression:
2721 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2722 break;
2723
2724 case TemplateArgument::Declaration:
2725 case TemplateArgument::Integral:
2726 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002727 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002728 break;
2729 }
2730}
2731
2732template<typename Derived>
2733bool TreeTransform<Derived>::TransformTemplateArgument(
2734 const TemplateArgumentLoc &Input,
2735 TemplateArgumentLoc &Output) {
2736 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002737 switch (Arg.getKind()) {
2738 case TemplateArgument::Null:
2739 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002740 Output = Input;
2741 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002742
Douglas Gregore922c772009-08-04 22:27:00 +00002743 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002744 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002745 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002746 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002747
2748 DI = getDerived().TransformType(DI);
2749 if (!DI) return true;
2750
2751 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2752 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002753 }
Mike Stump11289f42009-09-09 15:08:12 +00002754
Douglas Gregore922c772009-08-04 22:27:00 +00002755 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002756 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002757 DeclarationName Name;
2758 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2759 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002760 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002761 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002762 if (!D) return true;
2763
John McCall0d07eb32009-10-29 18:45:58 +00002764 Expr *SourceExpr = Input.getSourceDeclExpression();
2765 if (SourceExpr) {
2766 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002767 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002768 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002769 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002770 }
2771
2772 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002773 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002774 }
Mike Stump11289f42009-09-09 15:08:12 +00002775
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002776 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002777 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2778 if (QualifierLoc) {
2779 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2780 if (!QualifierLoc)
2781 return true;
2782 }
2783
Douglas Gregordf846d12011-03-02 18:46:51 +00002784 CXXScopeSpec SS;
2785 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002786 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002787 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2788 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002789 if (Template.isNull())
2790 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002791
Douglas Gregor9d802122011-03-02 17:09:35 +00002792 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002793 Input.getTemplateNameLoc());
2794 return false;
2795 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002796
2797 case TemplateArgument::TemplateExpansion:
2798 llvm_unreachable("Caller should expand pack expansions");
2799
Douglas Gregore922c772009-08-04 22:27:00 +00002800 case TemplateArgument::Expression: {
2801 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002802 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002803 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002804
John McCall0ad16662009-10-29 08:12:44 +00002805 Expr *InputExpr = Input.getSourceExpression();
2806 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2807
John McCalldadc5752010-08-24 06:29:42 +00002808 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002809 = getDerived().TransformExpr(InputExpr);
2810 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002811 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002812 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002813 }
Mike Stump11289f42009-09-09 15:08:12 +00002814
Douglas Gregore922c772009-08-04 22:27:00 +00002815 case TemplateArgument::Pack: {
2816 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2817 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002818 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002819 AEnd = Arg.pack_end();
2820 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002821
John McCall0ad16662009-10-29 08:12:44 +00002822 // FIXME: preserve source information here when we start
2823 // caring about parameter packs.
2824
John McCall0d07eb32009-10-29 18:45:58 +00002825 TemplateArgumentLoc InputArg;
2826 TemplateArgumentLoc OutputArg;
2827 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2828 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002829 return true;
2830
John McCall0d07eb32009-10-29 18:45:58 +00002831 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002832 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002833
2834 TemplateArgument *TransformedArgsPtr
2835 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2836 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2837 TransformedArgsPtr);
2838 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2839 TransformedArgs.size()),
2840 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002841 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002842 }
2843 }
Mike Stump11289f42009-09-09 15:08:12 +00002844
Douglas Gregore922c772009-08-04 22:27:00 +00002845 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002846 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002847}
2848
Douglas Gregorfe921a72010-12-20 23:36:19 +00002849/// \brief Iterator adaptor that invents template argument location information
2850/// for each of the template arguments in its underlying iterator.
2851template<typename Derived, typename InputIterator>
2852class TemplateArgumentLocInventIterator {
2853 TreeTransform<Derived> &Self;
2854 InputIterator Iter;
2855
2856public:
2857 typedef TemplateArgumentLoc value_type;
2858 typedef TemplateArgumentLoc reference;
2859 typedef typename std::iterator_traits<InputIterator>::difference_type
2860 difference_type;
2861 typedef std::input_iterator_tag iterator_category;
2862
2863 class pointer {
2864 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002865
Douglas Gregorfe921a72010-12-20 23:36:19 +00002866 public:
2867 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2868
2869 const TemplateArgumentLoc *operator->() const { return &Arg; }
2870 };
2871
2872 TemplateArgumentLocInventIterator() { }
2873
2874 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2875 InputIterator Iter)
2876 : Self(Self), Iter(Iter) { }
2877
2878 TemplateArgumentLocInventIterator &operator++() {
2879 ++Iter;
2880 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002881 }
2882
Douglas Gregorfe921a72010-12-20 23:36:19 +00002883 TemplateArgumentLocInventIterator operator++(int) {
2884 TemplateArgumentLocInventIterator Old(*this);
2885 ++(*this);
2886 return Old;
2887 }
2888
2889 reference operator*() const {
2890 TemplateArgumentLoc Result;
2891 Self.InventTemplateArgumentLoc(*Iter, Result);
2892 return Result;
2893 }
2894
2895 pointer operator->() const { return pointer(**this); }
2896
2897 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2898 const TemplateArgumentLocInventIterator &Y) {
2899 return X.Iter == Y.Iter;
2900 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002901
Douglas Gregorfe921a72010-12-20 23:36:19 +00002902 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2903 const TemplateArgumentLocInventIterator &Y) {
2904 return X.Iter != Y.Iter;
2905 }
2906};
2907
Douglas Gregor42cafa82010-12-20 17:42:22 +00002908template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002909template<typename InputIterator>
2910bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2911 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002912 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002913 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002914 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002915 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002916
2917 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2918 // Unpack argument packs, which we translate them into separate
2919 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002920 // FIXME: We could do much better if we could guarantee that the
2921 // TemplateArgumentLocInfo for the pack expansion would be usable for
2922 // all of the template arguments in the argument pack.
2923 typedef TemplateArgumentLocInventIterator<Derived,
2924 TemplateArgument::pack_iterator>
2925 PackLocIterator;
2926 if (TransformTemplateArguments(PackLocIterator(*this,
2927 In.getArgument().pack_begin()),
2928 PackLocIterator(*this,
2929 In.getArgument().pack_end()),
2930 Outputs))
2931 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002932
2933 continue;
2934 }
2935
2936 if (In.getArgument().isPackExpansion()) {
2937 // We have a pack expansion, for which we will be substituting into
2938 // the pattern.
2939 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002940 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002941 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002942 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2943 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002944
2945 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2946 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2947 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2948
2949 // Determine whether the set of unexpanded parameter packs can and should
2950 // be expanded.
2951 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002952 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002953 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002954 if (getDerived().TryExpandParameterPacks(Ellipsis,
2955 Pattern.getSourceRange(),
2956 Unexpanded.data(),
2957 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002958 Expand,
2959 RetainExpansion,
2960 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002961 return true;
2962
2963 if (!Expand) {
2964 // The transform has determined that we should perform a simple
2965 // transformation on the pack expansion, producing another pack
2966 // expansion.
2967 TemplateArgumentLoc OutPattern;
2968 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2969 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2970 return true;
2971
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002972 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2973 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002974 if (Out.getArgument().isNull())
2975 return true;
2976
2977 Outputs.addArgument(Out);
2978 continue;
2979 }
2980
2981 // The transform has determined that we should perform an elementwise
2982 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002983 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002984 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2985
2986 if (getDerived().TransformTemplateArgument(Pattern, Out))
2987 return true;
2988
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002989 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002990 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2991 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002992 if (Out.getArgument().isNull())
2993 return true;
2994 }
2995
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002996 Outputs.addArgument(Out);
2997 }
2998
Douglas Gregor48d24112011-01-10 20:53:55 +00002999 // If we're supposed to retain a pack expansion, do so by temporarily
3000 // forgetting the partially-substituted parameter pack.
3001 if (RetainExpansion) {
3002 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3003
3004 if (getDerived().TransformTemplateArgument(Pattern, Out))
3005 return true;
3006
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003007 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3008 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003009 if (Out.getArgument().isNull())
3010 return true;
3011
3012 Outputs.addArgument(Out);
3013 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003014
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003015 continue;
3016 }
3017
3018 // The simple case:
3019 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003020 return true;
3021
3022 Outputs.addArgument(Out);
3023 }
3024
3025 return false;
3026
3027}
3028
Douglas Gregord6ff3322009-08-04 16:50:30 +00003029//===----------------------------------------------------------------------===//
3030// Type transformation
3031//===----------------------------------------------------------------------===//
3032
3033template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003034QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003035 if (getDerived().AlreadyTransformed(T))
3036 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003037
John McCall550e0c22009-10-21 00:40:46 +00003038 // Temporary workaround. All of these transformations should
3039 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003040 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3041 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003042
John McCall31f82722010-11-12 08:19:04 +00003043 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003044
John McCall550e0c22009-10-21 00:40:46 +00003045 if (!NewDI)
3046 return QualType();
3047
3048 return NewDI->getType();
3049}
3050
3051template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003052TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003053 if (getDerived().AlreadyTransformed(DI->getType()))
3054 return DI;
3055
3056 TypeLocBuilder TLB;
3057
3058 TypeLoc TL = DI->getTypeLoc();
3059 TLB.reserve(TL.getFullDataSize());
3060
John McCall31f82722010-11-12 08:19:04 +00003061 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003062 if (Result.isNull())
3063 return 0;
3064
John McCallbcd03502009-12-07 02:54:59 +00003065 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003066}
3067
3068template<typename Derived>
3069QualType
John McCall31f82722010-11-12 08:19:04 +00003070TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003071 switch (T.getTypeLocClass()) {
3072#define ABSTRACT_TYPELOC(CLASS, PARENT)
3073#define TYPELOC(CLASS, PARENT) \
3074 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003075 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003076#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003077 }
Mike Stump11289f42009-09-09 15:08:12 +00003078
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003079 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003080 return QualType();
3081}
3082
3083/// FIXME: By default, this routine adds type qualifiers only to types
3084/// that can have qualifiers, and silently suppresses those qualifiers
3085/// that are not permitted (e.g., qualifiers on reference or function
3086/// types). This is the right thing for template instantiation, but
3087/// probably not for other clients.
3088template<typename Derived>
3089QualType
3090TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003091 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003092 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003093
John McCall31f82722010-11-12 08:19:04 +00003094 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003095 if (Result.isNull())
3096 return QualType();
3097
3098 // Silently suppress qualifiers if the result type can't be qualified.
3099 // FIXME: this is the right thing for template instantiation, but
3100 // probably not for other clients.
3101 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003102 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003103
John McCallcb0f89a2010-06-05 06:41:15 +00003104 if (!Quals.empty()) {
3105 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3106 TLB.push<QualifiedTypeLoc>(Result);
3107 // No location information to preserve.
3108 }
John McCall550e0c22009-10-21 00:40:46 +00003109
3110 return Result;
3111}
3112
Douglas Gregor14454802011-02-25 02:25:35 +00003113template<typename Derived>
3114TypeLoc
3115TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3116 QualType ObjectType,
3117 NamedDecl *UnqualLookup,
3118 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003119 QualType T = TL.getType();
3120 if (getDerived().AlreadyTransformed(T))
3121 return TL;
3122
3123 TypeLocBuilder TLB;
3124 QualType Result;
3125
3126 if (isa<TemplateSpecializationType>(T)) {
3127 TemplateSpecializationTypeLoc SpecTL
3128 = cast<TemplateSpecializationTypeLoc>(TL);
3129
3130 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003131 getDerived().TransformTemplateName(SS,
3132 SpecTL.getTypePtr()->getTemplateName(),
3133 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003134 ObjectType, UnqualLookup);
3135 if (Template.isNull())
3136 return TypeLoc();
3137
3138 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3139 Template);
3140 } else if (isa<DependentTemplateSpecializationType>(T)) {
3141 DependentTemplateSpecializationTypeLoc SpecTL
3142 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3143
Douglas Gregor5a064722011-02-28 17:23:35 +00003144 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003145 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003146 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003147 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003148 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003149 if (Template.isNull())
3150 return TypeLoc();
3151
Douglas Gregor14454802011-02-25 02:25:35 +00003152 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003153 SpecTL,
3154 Template);
Douglas Gregor14454802011-02-25 02:25:35 +00003155 } else {
3156 // Nothing special needs to be done for these.
3157 Result = getDerived().TransformType(TLB, TL);
3158 }
3159
3160 if (Result.isNull())
3161 return TypeLoc();
3162
3163 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3164}
3165
Douglas Gregor579c15f2011-03-02 18:32:08 +00003166template<typename Derived>
3167TypeSourceInfo *
3168TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3169 QualType ObjectType,
3170 NamedDecl *UnqualLookup,
3171 CXXScopeSpec &SS) {
3172 // FIXME: Painfully copy-paste from the above!
3173
3174 QualType T = TSInfo->getType();
3175 if (getDerived().AlreadyTransformed(T))
3176 return TSInfo;
3177
3178 TypeLocBuilder TLB;
3179 QualType Result;
3180
3181 TypeLoc TL = TSInfo->getTypeLoc();
3182 if (isa<TemplateSpecializationType>(T)) {
3183 TemplateSpecializationTypeLoc SpecTL
3184 = cast<TemplateSpecializationTypeLoc>(TL);
3185
3186 TemplateName Template
3187 = getDerived().TransformTemplateName(SS,
3188 SpecTL.getTypePtr()->getTemplateName(),
3189 SpecTL.getTemplateNameLoc(),
3190 ObjectType, UnqualLookup);
3191 if (Template.isNull())
3192 return 0;
3193
3194 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3195 Template);
3196 } else if (isa<DependentTemplateSpecializationType>(T)) {
3197 DependentTemplateSpecializationTypeLoc SpecTL
3198 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3199
3200 TemplateName Template
3201 = getDerived().RebuildTemplateName(SS,
3202 *SpecTL.getTypePtr()->getIdentifier(),
3203 SpecTL.getNameLoc(),
3204 ObjectType, UnqualLookup);
3205 if (Template.isNull())
3206 return 0;
3207
3208 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3209 SpecTL,
3210 Template);
3211 } else {
3212 // Nothing special needs to be done for these.
3213 Result = getDerived().TransformType(TLB, TL);
3214 }
3215
3216 if (Result.isNull())
3217 return 0;
3218
3219 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3220}
3221
John McCall550e0c22009-10-21 00:40:46 +00003222template <class TyLoc> static inline
3223QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3224 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3225 NewT.setNameLoc(T.getNameLoc());
3226 return T.getType();
3227}
3228
John McCall550e0c22009-10-21 00:40:46 +00003229template<typename Derived>
3230QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003231 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003232 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3233 NewT.setBuiltinLoc(T.getBuiltinLoc());
3234 if (T.needsExtraLocalData())
3235 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3236 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003237}
Mike Stump11289f42009-09-09 15:08:12 +00003238
Douglas Gregord6ff3322009-08-04 16:50:30 +00003239template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003240QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003241 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003242 // FIXME: recurse?
3243 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003244}
Mike Stump11289f42009-09-09 15:08:12 +00003245
Douglas Gregord6ff3322009-08-04 16:50:30 +00003246template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003247QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003248 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003249 QualType PointeeType
3250 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003251 if (PointeeType.isNull())
3252 return QualType();
3253
3254 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003255 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003256 // A dependent pointer type 'T *' has is being transformed such
3257 // that an Objective-C class type is being replaced for 'T'. The
3258 // resulting pointer type is an ObjCObjectPointerType, not a
3259 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003260 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003261
John McCall8b07ec22010-05-15 11:32:37 +00003262 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3263 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003264 return Result;
3265 }
John McCall31f82722010-11-12 08:19:04 +00003266
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003267 if (getDerived().AlwaysRebuild() ||
3268 PointeeType != TL.getPointeeLoc().getType()) {
3269 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3270 if (Result.isNull())
3271 return QualType();
3272 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003273
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003274 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3275 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003276 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003277}
Mike Stump11289f42009-09-09 15:08:12 +00003278
3279template<typename Derived>
3280QualType
John McCall550e0c22009-10-21 00:40:46 +00003281TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003282 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003283 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003284 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3285 if (PointeeType.isNull())
3286 return QualType();
3287
3288 QualType Result = TL.getType();
3289 if (getDerived().AlwaysRebuild() ||
3290 PointeeType != TL.getPointeeLoc().getType()) {
3291 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003292 TL.getSigilLoc());
3293 if (Result.isNull())
3294 return QualType();
3295 }
3296
Douglas Gregor049211a2010-04-22 16:50:51 +00003297 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003298 NewT.setSigilLoc(TL.getSigilLoc());
3299 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003300}
3301
John McCall70dd5f62009-10-30 00:06:24 +00003302/// Transforms a reference type. Note that somewhat paradoxically we
3303/// don't care whether the type itself is an l-value type or an r-value
3304/// type; we only care if the type was *written* as an l-value type
3305/// or an r-value type.
3306template<typename Derived>
3307QualType
3308TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003309 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003310 const ReferenceType *T = TL.getTypePtr();
3311
3312 // Note that this works with the pointee-as-written.
3313 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3314 if (PointeeType.isNull())
3315 return QualType();
3316
3317 QualType Result = TL.getType();
3318 if (getDerived().AlwaysRebuild() ||
3319 PointeeType != T->getPointeeTypeAsWritten()) {
3320 Result = getDerived().RebuildReferenceType(PointeeType,
3321 T->isSpelledAsLValue(),
3322 TL.getSigilLoc());
3323 if (Result.isNull())
3324 return QualType();
3325 }
3326
3327 // r-value references can be rebuilt as l-value references.
3328 ReferenceTypeLoc NewTL;
3329 if (isa<LValueReferenceType>(Result))
3330 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3331 else
3332 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3333 NewTL.setSigilLoc(TL.getSigilLoc());
3334
3335 return Result;
3336}
3337
Mike Stump11289f42009-09-09 15:08:12 +00003338template<typename Derived>
3339QualType
John McCall550e0c22009-10-21 00:40:46 +00003340TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003341 LValueReferenceTypeLoc TL) {
3342 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003343}
3344
Mike Stump11289f42009-09-09 15:08:12 +00003345template<typename Derived>
3346QualType
John McCall550e0c22009-10-21 00:40:46 +00003347TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003348 RValueReferenceTypeLoc TL) {
3349 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003350}
Mike Stump11289f42009-09-09 15:08:12 +00003351
Douglas Gregord6ff3322009-08-04 16:50:30 +00003352template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003353QualType
John McCall550e0c22009-10-21 00:40:46 +00003354TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003355 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003356 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003357
3358 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003359 if (PointeeType.isNull())
3360 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003361
John McCall550e0c22009-10-21 00:40:46 +00003362 // TODO: preserve source information for this.
3363 QualType ClassType
3364 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003365 if (ClassType.isNull())
3366 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003367
John McCall550e0c22009-10-21 00:40:46 +00003368 QualType Result = TL.getType();
3369 if (getDerived().AlwaysRebuild() ||
3370 PointeeType != T->getPointeeType() ||
3371 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003372 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3373 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003374 if (Result.isNull())
3375 return QualType();
3376 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003377
John McCall550e0c22009-10-21 00:40:46 +00003378 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3379 NewTL.setSigilLoc(TL.getSigilLoc());
3380
3381 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003382}
3383
Mike Stump11289f42009-09-09 15:08:12 +00003384template<typename Derived>
3385QualType
John McCall550e0c22009-10-21 00:40:46 +00003386TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003387 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003388 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003389 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003390 if (ElementType.isNull())
3391 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003392
John McCall550e0c22009-10-21 00:40:46 +00003393 QualType Result = TL.getType();
3394 if (getDerived().AlwaysRebuild() ||
3395 ElementType != T->getElementType()) {
3396 Result = getDerived().RebuildConstantArrayType(ElementType,
3397 T->getSizeModifier(),
3398 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003399 T->getIndexTypeCVRQualifiers(),
3400 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003401 if (Result.isNull())
3402 return QualType();
3403 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003404
John McCall550e0c22009-10-21 00:40:46 +00003405 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3406 NewTL.setLBracketLoc(TL.getLBracketLoc());
3407 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003408
John McCall550e0c22009-10-21 00:40:46 +00003409 Expr *Size = TL.getSizeExpr();
3410 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003411 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003412 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3413 }
3414 NewTL.setSizeExpr(Size);
3415
3416 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003417}
Mike Stump11289f42009-09-09 15:08:12 +00003418
Douglas Gregord6ff3322009-08-04 16:50:30 +00003419template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003420QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003421 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003422 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003423 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003424 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003425 if (ElementType.isNull())
3426 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003427
John McCall550e0c22009-10-21 00:40:46 +00003428 QualType Result = TL.getType();
3429 if (getDerived().AlwaysRebuild() ||
3430 ElementType != T->getElementType()) {
3431 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003432 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003433 T->getIndexTypeCVRQualifiers(),
3434 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003435 if (Result.isNull())
3436 return QualType();
3437 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003438
John McCall550e0c22009-10-21 00:40:46 +00003439 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3440 NewTL.setLBracketLoc(TL.getLBracketLoc());
3441 NewTL.setRBracketLoc(TL.getRBracketLoc());
3442 NewTL.setSizeExpr(0);
3443
3444 return Result;
3445}
3446
3447template<typename Derived>
3448QualType
3449TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003450 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003451 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003452 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3453 if (ElementType.isNull())
3454 return QualType();
3455
3456 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003457 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003458
John McCalldadc5752010-08-24 06:29:42 +00003459 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003460 = getDerived().TransformExpr(T->getSizeExpr());
3461 if (SizeResult.isInvalid())
3462 return QualType();
3463
John McCallb268a282010-08-23 23:25:46 +00003464 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003465
3466 QualType Result = TL.getType();
3467 if (getDerived().AlwaysRebuild() ||
3468 ElementType != T->getElementType() ||
3469 Size != T->getSizeExpr()) {
3470 Result = getDerived().RebuildVariableArrayType(ElementType,
3471 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003472 Size,
John McCall550e0c22009-10-21 00:40:46 +00003473 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003474 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003475 if (Result.isNull())
3476 return QualType();
3477 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003478
John McCall550e0c22009-10-21 00:40:46 +00003479 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3480 NewTL.setLBracketLoc(TL.getLBracketLoc());
3481 NewTL.setRBracketLoc(TL.getRBracketLoc());
3482 NewTL.setSizeExpr(Size);
3483
3484 return Result;
3485}
3486
3487template<typename Derived>
3488QualType
3489TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003490 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003491 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003492 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3493 if (ElementType.isNull())
3494 return QualType();
3495
3496 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003497 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003498
John McCall33ddac02011-01-19 10:06:00 +00003499 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3500 Expr *origSize = TL.getSizeExpr();
3501 if (!origSize) origSize = T->getSizeExpr();
3502
3503 ExprResult sizeResult
3504 = getDerived().TransformExpr(origSize);
3505 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003506 return QualType();
3507
John McCall33ddac02011-01-19 10:06:00 +00003508 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003509
3510 QualType Result = TL.getType();
3511 if (getDerived().AlwaysRebuild() ||
3512 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003513 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003514 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3515 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003516 size,
John McCall550e0c22009-10-21 00:40:46 +00003517 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003518 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003519 if (Result.isNull())
3520 return QualType();
3521 }
John McCall550e0c22009-10-21 00:40:46 +00003522
3523 // We might have any sort of array type now, but fortunately they
3524 // all have the same location layout.
3525 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3526 NewTL.setLBracketLoc(TL.getLBracketLoc());
3527 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003528 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003529
3530 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003531}
Mike Stump11289f42009-09-09 15:08:12 +00003532
3533template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003534QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003535 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003536 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003537 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003538
3539 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003540 QualType ElementType = getDerived().TransformType(T->getElementType());
3541 if (ElementType.isNull())
3542 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003543
Douglas Gregore922c772009-08-04 22:27:00 +00003544 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003545 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003546
John McCalldadc5752010-08-24 06:29:42 +00003547 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003548 if (Size.isInvalid())
3549 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003550
John McCall550e0c22009-10-21 00:40:46 +00003551 QualType Result = TL.getType();
3552 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003553 ElementType != T->getElementType() ||
3554 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003555 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003556 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003557 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003558 if (Result.isNull())
3559 return QualType();
3560 }
John McCall550e0c22009-10-21 00:40:46 +00003561
3562 // Result might be dependent or not.
3563 if (isa<DependentSizedExtVectorType>(Result)) {
3564 DependentSizedExtVectorTypeLoc NewTL
3565 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3566 NewTL.setNameLoc(TL.getNameLoc());
3567 } else {
3568 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3569 NewTL.setNameLoc(TL.getNameLoc());
3570 }
3571
3572 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003573}
Mike Stump11289f42009-09-09 15:08:12 +00003574
3575template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003576QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003577 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003578 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003579 QualType ElementType = getDerived().TransformType(T->getElementType());
3580 if (ElementType.isNull())
3581 return QualType();
3582
John McCall550e0c22009-10-21 00:40:46 +00003583 QualType Result = TL.getType();
3584 if (getDerived().AlwaysRebuild() ||
3585 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003586 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003587 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003588 if (Result.isNull())
3589 return QualType();
3590 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003591
John McCall550e0c22009-10-21 00:40:46 +00003592 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3593 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003594
John McCall550e0c22009-10-21 00:40:46 +00003595 return Result;
3596}
3597
3598template<typename Derived>
3599QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003600 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003601 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003602 QualType ElementType = getDerived().TransformType(T->getElementType());
3603 if (ElementType.isNull())
3604 return QualType();
3605
3606 QualType Result = TL.getType();
3607 if (getDerived().AlwaysRebuild() ||
3608 ElementType != T->getElementType()) {
3609 Result = getDerived().RebuildExtVectorType(ElementType,
3610 T->getNumElements(),
3611 /*FIXME*/ SourceLocation());
3612 if (Result.isNull())
3613 return QualType();
3614 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003615
John McCall550e0c22009-10-21 00:40:46 +00003616 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3617 NewTL.setNameLoc(TL.getNameLoc());
3618
3619 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003620}
Mike Stump11289f42009-09-09 15:08:12 +00003621
3622template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003623ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003624TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3625 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003626 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003627 TypeSourceInfo *NewDI = 0;
3628
3629 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3630 // If we're substituting into a pack expansion type and we know the
3631 TypeLoc OldTL = OldDI->getTypeLoc();
3632 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3633
3634 TypeLocBuilder TLB;
3635 TypeLoc NewTL = OldDI->getTypeLoc();
3636 TLB.reserve(NewTL.getFullDataSize());
3637
3638 QualType Result = getDerived().TransformType(TLB,
3639 OldExpansionTL.getPatternLoc());
3640 if (Result.isNull())
3641 return 0;
3642
3643 Result = RebuildPackExpansionType(Result,
3644 OldExpansionTL.getPatternLoc().getSourceRange(),
3645 OldExpansionTL.getEllipsisLoc(),
3646 NumExpansions);
3647 if (Result.isNull())
3648 return 0;
3649
3650 PackExpansionTypeLoc NewExpansionTL
3651 = TLB.push<PackExpansionTypeLoc>(Result);
3652 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3653 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3654 } else
3655 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003656 if (!NewDI)
3657 return 0;
3658
3659 if (NewDI == OldDI)
3660 return OldParm;
3661 else
3662 return ParmVarDecl::Create(SemaRef.Context,
3663 OldParm->getDeclContext(),
3664 OldParm->getLocation(),
3665 OldParm->getIdentifier(),
3666 NewDI->getType(),
3667 NewDI,
3668 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003669 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003670 /* DefArg */ NULL);
3671}
3672
3673template<typename Derived>
3674bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003675 TransformFunctionTypeParams(SourceLocation Loc,
3676 ParmVarDecl **Params, unsigned NumParams,
3677 const QualType *ParamTypes,
3678 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3679 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3680 for (unsigned i = 0; i != NumParams; ++i) {
3681 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003682 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003683 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003684 if (OldParm->isParameterPack()) {
3685 // We have a function parameter pack that may need to be expanded.
3686 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003687
Douglas Gregor5499af42011-01-05 23:12:31 +00003688 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003689 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3690 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3691 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3692 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003693 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3694
Douglas Gregor5499af42011-01-05 23:12:31 +00003695 // Determine whether we should expand the parameter packs.
3696 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003697 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003698 llvm::Optional<unsigned> OrigNumExpansions
3699 = ExpansionTL.getTypePtr()->getNumExpansions();
3700 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003701 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3702 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003703 Unexpanded.data(),
3704 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003705 ShouldExpand,
3706 RetainExpansion,
3707 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003708 return true;
3709 }
3710
3711 if (ShouldExpand) {
3712 // Expand the function parameter pack into multiple, separate
3713 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003714 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003715 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003716 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3717 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003718 = getDerived().TransformFunctionTypeParam(OldParm,
3719 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003720 if (!NewParm)
3721 return true;
3722
Douglas Gregordd472162011-01-07 00:20:55 +00003723 OutParamTypes.push_back(NewParm->getType());
3724 if (PVars)
3725 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003726 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003727
3728 // If we're supposed to retain a pack expansion, do so by temporarily
3729 // forgetting the partially-substituted parameter pack.
3730 if (RetainExpansion) {
3731 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3732 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003733 = getDerived().TransformFunctionTypeParam(OldParm,
3734 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003735 if (!NewParm)
3736 return true;
3737
3738 OutParamTypes.push_back(NewParm->getType());
3739 if (PVars)
3740 PVars->push_back(NewParm);
3741 }
3742
Douglas Gregor5499af42011-01-05 23:12:31 +00003743 // We're done with the pack expansion.
3744 continue;
3745 }
3746
3747 // We'll substitute the parameter now without expanding the pack
3748 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003749 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3750 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3751 NumExpansions);
3752 } else {
3753 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3754 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003755 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003756
John McCall58f10c32010-03-11 09:03:00 +00003757 if (!NewParm)
3758 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003759
Douglas Gregordd472162011-01-07 00:20:55 +00003760 OutParamTypes.push_back(NewParm->getType());
3761 if (PVars)
3762 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003763 continue;
3764 }
John McCall58f10c32010-03-11 09:03:00 +00003765
3766 // Deal with the possibility that we don't have a parameter
3767 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003768 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003769 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003770 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003771 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003772 if (const PackExpansionType *Expansion
3773 = dyn_cast<PackExpansionType>(OldType)) {
3774 // We have a function parameter pack that may need to be expanded.
3775 QualType Pattern = Expansion->getPattern();
3776 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3777 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3778
3779 // Determine whether we should expand the parameter packs.
3780 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003781 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003782 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003783 Unexpanded.data(),
3784 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003785 ShouldExpand,
3786 RetainExpansion,
3787 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003788 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003789 }
3790
3791 if (ShouldExpand) {
3792 // Expand the function parameter pack into multiple, separate
3793 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003794 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003795 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3796 QualType NewType = getDerived().TransformType(Pattern);
3797 if (NewType.isNull())
3798 return true;
John McCall58f10c32010-03-11 09:03:00 +00003799
Douglas Gregordd472162011-01-07 00:20:55 +00003800 OutParamTypes.push_back(NewType);
3801 if (PVars)
3802 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003803 }
3804
3805 // We're done with the pack expansion.
3806 continue;
3807 }
3808
Douglas Gregor48d24112011-01-10 20:53:55 +00003809 // If we're supposed to retain a pack expansion, do so by temporarily
3810 // forgetting the partially-substituted parameter pack.
3811 if (RetainExpansion) {
3812 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3813 QualType NewType = getDerived().TransformType(Pattern);
3814 if (NewType.isNull())
3815 return true;
3816
3817 OutParamTypes.push_back(NewType);
3818 if (PVars)
3819 PVars->push_back(0);
3820 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003821
Douglas Gregor5499af42011-01-05 23:12:31 +00003822 // We'll substitute the parameter now without expanding the pack
3823 // expansion.
3824 OldType = Expansion->getPattern();
3825 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003826 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3827 NewType = getDerived().TransformType(OldType);
3828 } else {
3829 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003830 }
3831
Douglas Gregor5499af42011-01-05 23:12:31 +00003832 if (NewType.isNull())
3833 return true;
3834
3835 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003836 NewType = getSema().Context.getPackExpansionType(NewType,
3837 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003838
Douglas Gregordd472162011-01-07 00:20:55 +00003839 OutParamTypes.push_back(NewType);
3840 if (PVars)
3841 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003842 }
3843
3844 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003845 }
John McCall58f10c32010-03-11 09:03:00 +00003846
3847template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003848QualType
John McCall550e0c22009-10-21 00:40:46 +00003849TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003850 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003851 // Transform the parameters and return type.
3852 //
3853 // We instantiate in source order, with the return type first followed by
3854 // the parameters, because users tend to expect this (even if they shouldn't
3855 // rely on it!).
3856 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003857 // When the function has a trailing return type, we instantiate the
3858 // parameters before the return type, since the return type can then refer
3859 // to the parameters themselves (via decltype, sizeof, etc.).
3860 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003861 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003862 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003863 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003864
Douglas Gregor7fb25412010-10-01 18:44:50 +00003865 QualType ResultType;
3866
3867 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003868 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3869 TL.getParmArray(),
3870 TL.getNumArgs(),
3871 TL.getTypePtr()->arg_type_begin(),
3872 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003873 return QualType();
3874
3875 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3876 if (ResultType.isNull())
3877 return QualType();
3878 }
3879 else {
3880 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3881 if (ResultType.isNull())
3882 return QualType();
3883
Douglas Gregordd472162011-01-07 00:20:55 +00003884 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3885 TL.getParmArray(),
3886 TL.getNumArgs(),
3887 TL.getTypePtr()->arg_type_begin(),
3888 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003889 return QualType();
3890 }
3891
John McCall550e0c22009-10-21 00:40:46 +00003892 QualType Result = TL.getType();
3893 if (getDerived().AlwaysRebuild() ||
3894 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003895 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003896 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3897 Result = getDerived().RebuildFunctionProtoType(ResultType,
3898 ParamTypes.data(),
3899 ParamTypes.size(),
3900 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003901 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003902 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003903 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003904 if (Result.isNull())
3905 return QualType();
3906 }
Mike Stump11289f42009-09-09 15:08:12 +00003907
John McCall550e0c22009-10-21 00:40:46 +00003908 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3909 NewTL.setLParenLoc(TL.getLParenLoc());
3910 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003911 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003912 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3913 NewTL.setArg(i, ParamDecls[i]);
3914
3915 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003916}
Mike Stump11289f42009-09-09 15:08:12 +00003917
Douglas Gregord6ff3322009-08-04 16:50:30 +00003918template<typename Derived>
3919QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003920 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003921 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003922 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003923 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3924 if (ResultType.isNull())
3925 return QualType();
3926
3927 QualType Result = TL.getType();
3928 if (getDerived().AlwaysRebuild() ||
3929 ResultType != T->getResultType())
3930 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3931
3932 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3933 NewTL.setLParenLoc(TL.getLParenLoc());
3934 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003935 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003936
3937 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003938}
Mike Stump11289f42009-09-09 15:08:12 +00003939
John McCallb96ec562009-12-04 22:46:56 +00003940template<typename Derived> QualType
3941TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003942 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003943 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003944 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003945 if (!D)
3946 return QualType();
3947
3948 QualType Result = TL.getType();
3949 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3950 Result = getDerived().RebuildUnresolvedUsingType(D);
3951 if (Result.isNull())
3952 return QualType();
3953 }
3954
3955 // We might get an arbitrary type spec type back. We should at
3956 // least always get a type spec type, though.
3957 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3958 NewTL.setNameLoc(TL.getNameLoc());
3959
3960 return Result;
3961}
3962
Douglas Gregord6ff3322009-08-04 16:50:30 +00003963template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003964QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003965 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003966 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003967 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003968 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3969 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003970 if (!Typedef)
3971 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003972
John McCall550e0c22009-10-21 00:40:46 +00003973 QualType Result = TL.getType();
3974 if (getDerived().AlwaysRebuild() ||
3975 Typedef != T->getDecl()) {
3976 Result = getDerived().RebuildTypedefType(Typedef);
3977 if (Result.isNull())
3978 return QualType();
3979 }
Mike Stump11289f42009-09-09 15:08:12 +00003980
John McCall550e0c22009-10-21 00:40:46 +00003981 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3982 NewTL.setNameLoc(TL.getNameLoc());
3983
3984 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003985}
Mike Stump11289f42009-09-09 15:08:12 +00003986
Douglas Gregord6ff3322009-08-04 16:50:30 +00003987template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003988QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003989 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003990 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003991 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003992
John McCalldadc5752010-08-24 06:29:42 +00003993 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003994 if (E.isInvalid())
3995 return QualType();
3996
John McCall550e0c22009-10-21 00:40:46 +00003997 QualType Result = TL.getType();
3998 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003999 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004000 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004001 if (Result.isNull())
4002 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004003 }
John McCall550e0c22009-10-21 00:40:46 +00004004 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004005
John McCall550e0c22009-10-21 00:40:46 +00004006 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004007 NewTL.setTypeofLoc(TL.getTypeofLoc());
4008 NewTL.setLParenLoc(TL.getLParenLoc());
4009 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004010
4011 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004012}
Mike Stump11289f42009-09-09 15:08:12 +00004013
4014template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004015QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004016 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004017 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4018 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4019 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004020 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004021
John McCall550e0c22009-10-21 00:40:46 +00004022 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004023 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4024 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004025 if (Result.isNull())
4026 return QualType();
4027 }
Mike Stump11289f42009-09-09 15:08:12 +00004028
John McCall550e0c22009-10-21 00:40:46 +00004029 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004030 NewTL.setTypeofLoc(TL.getTypeofLoc());
4031 NewTL.setLParenLoc(TL.getLParenLoc());
4032 NewTL.setRParenLoc(TL.getRParenLoc());
4033 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004034
4035 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004036}
Mike Stump11289f42009-09-09 15:08:12 +00004037
4038template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004039QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004040 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004041 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004042
Douglas Gregore922c772009-08-04 22:27:00 +00004043 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004044 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004045
John McCalldadc5752010-08-24 06:29:42 +00004046 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004047 if (E.isInvalid())
4048 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004049
John McCall550e0c22009-10-21 00:40:46 +00004050 QualType Result = TL.getType();
4051 if (getDerived().AlwaysRebuild() ||
4052 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004053 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004054 if (Result.isNull())
4055 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004056 }
John McCall550e0c22009-10-21 00:40:46 +00004057 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004058
John McCall550e0c22009-10-21 00:40:46 +00004059 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4060 NewTL.setNameLoc(TL.getNameLoc());
4061
4062 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004063}
4064
4065template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004066QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4067 AutoTypeLoc TL) {
4068 const AutoType *T = TL.getTypePtr();
4069 QualType OldDeduced = T->getDeducedType();
4070 QualType NewDeduced;
4071 if (!OldDeduced.isNull()) {
4072 NewDeduced = getDerived().TransformType(OldDeduced);
4073 if (NewDeduced.isNull())
4074 return QualType();
4075 }
4076
4077 QualType Result = TL.getType();
4078 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4079 Result = getDerived().RebuildAutoType(NewDeduced);
4080 if (Result.isNull())
4081 return QualType();
4082 }
4083
4084 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4085 NewTL.setNameLoc(TL.getNameLoc());
4086
4087 return Result;
4088}
4089
4090template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004091QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004092 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004093 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004094 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004095 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4096 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004097 if (!Record)
4098 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004099
John McCall550e0c22009-10-21 00:40:46 +00004100 QualType Result = TL.getType();
4101 if (getDerived().AlwaysRebuild() ||
4102 Record != T->getDecl()) {
4103 Result = getDerived().RebuildRecordType(Record);
4104 if (Result.isNull())
4105 return QualType();
4106 }
Mike Stump11289f42009-09-09 15:08:12 +00004107
John McCall550e0c22009-10-21 00:40:46 +00004108 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4109 NewTL.setNameLoc(TL.getNameLoc());
4110
4111 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004112}
Mike Stump11289f42009-09-09 15:08:12 +00004113
4114template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004115QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004116 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004117 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004118 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004119 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4120 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004121 if (!Enum)
4122 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004123
John McCall550e0c22009-10-21 00:40:46 +00004124 QualType Result = TL.getType();
4125 if (getDerived().AlwaysRebuild() ||
4126 Enum != T->getDecl()) {
4127 Result = getDerived().RebuildEnumType(Enum);
4128 if (Result.isNull())
4129 return QualType();
4130 }
Mike Stump11289f42009-09-09 15:08:12 +00004131
John McCall550e0c22009-10-21 00:40:46 +00004132 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4133 NewTL.setNameLoc(TL.getNameLoc());
4134
4135 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004136}
John McCallfcc33b02009-09-05 00:15:47 +00004137
John McCalle78aac42010-03-10 03:28:59 +00004138template<typename Derived>
4139QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4140 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004141 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004142 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4143 TL.getTypePtr()->getDecl());
4144 if (!D) return QualType();
4145
4146 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4147 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4148 return T;
4149}
4150
Douglas Gregord6ff3322009-08-04 16:50:30 +00004151template<typename Derived>
4152QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004153 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004154 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004155 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004156}
4157
Mike Stump11289f42009-09-09 15:08:12 +00004158template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004159QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004160 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004161 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004162 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004163}
4164
4165template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004166QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4167 TypeLocBuilder &TLB,
4168 SubstTemplateTypeParmPackTypeLoc TL) {
4169 return TransformTypeSpecType(TLB, TL);
4170}
4171
4172template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004173QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004174 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004175 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004176 const TemplateSpecializationType *T = TL.getTypePtr();
4177
Douglas Gregordf846d12011-03-02 18:46:51 +00004178 // The nested-name-specifier never matters in a TemplateSpecializationType,
4179 // because we can't have a dependent nested-name-specifier anyway.
4180 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004181 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004182 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4183 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004184 if (Template.isNull())
4185 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004186
John McCall31f82722010-11-12 08:19:04 +00004187 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4188}
4189
Douglas Gregorfe921a72010-12-20 23:36:19 +00004190namespace {
4191 /// \brief Simple iterator that traverses the template arguments in a
4192 /// container that provides a \c getArgLoc() member function.
4193 ///
4194 /// This iterator is intended to be used with the iterator form of
4195 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4196 template<typename ArgLocContainer>
4197 class TemplateArgumentLocContainerIterator {
4198 ArgLocContainer *Container;
4199 unsigned Index;
4200
4201 public:
4202 typedef TemplateArgumentLoc value_type;
4203 typedef TemplateArgumentLoc reference;
4204 typedef int difference_type;
4205 typedef std::input_iterator_tag iterator_category;
4206
4207 class pointer {
4208 TemplateArgumentLoc Arg;
4209
4210 public:
4211 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4212
4213 const TemplateArgumentLoc *operator->() const {
4214 return &Arg;
4215 }
4216 };
4217
4218
4219 TemplateArgumentLocContainerIterator() {}
4220
4221 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4222 unsigned Index)
4223 : Container(&Container), Index(Index) { }
4224
4225 TemplateArgumentLocContainerIterator &operator++() {
4226 ++Index;
4227 return *this;
4228 }
4229
4230 TemplateArgumentLocContainerIterator operator++(int) {
4231 TemplateArgumentLocContainerIterator Old(*this);
4232 ++(*this);
4233 return Old;
4234 }
4235
4236 TemplateArgumentLoc operator*() const {
4237 return Container->getArgLoc(Index);
4238 }
4239
4240 pointer operator->() const {
4241 return pointer(Container->getArgLoc(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.Container == Y.Container && X.Index == Y.Index;
4247 }
4248
4249 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004250 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004251 return !(X == Y);
4252 }
4253 };
4254}
4255
4256
John McCall31f82722010-11-12 08:19:04 +00004257template <typename Derived>
4258QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4259 TypeLocBuilder &TLB,
4260 TemplateSpecializationTypeLoc TL,
4261 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004262 TemplateArgumentListInfo NewTemplateArgs;
4263 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4264 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004265 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4266 ArgIterator;
4267 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4268 ArgIterator(TL, TL.getNumArgs()),
4269 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004270 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004271
John McCall0ad16662009-10-29 08:12:44 +00004272 // FIXME: maybe don't rebuild if all the template arguments are the same.
4273
4274 QualType Result =
4275 getDerived().RebuildTemplateSpecializationType(Template,
4276 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004277 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004278
4279 if (!Result.isNull()) {
4280 TemplateSpecializationTypeLoc NewTL
4281 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4282 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4283 NewTL.setLAngleLoc(TL.getLAngleLoc());
4284 NewTL.setRAngleLoc(TL.getRAngleLoc());
4285 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4286 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004287 }
Mike Stump11289f42009-09-09 15:08:12 +00004288
John McCall0ad16662009-10-29 08:12:44 +00004289 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004290}
Mike Stump11289f42009-09-09 15:08:12 +00004291
Douglas Gregor5a064722011-02-28 17:23:35 +00004292template <typename Derived>
4293QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4294 TypeLocBuilder &TLB,
4295 DependentTemplateSpecializationTypeLoc TL,
4296 TemplateName Template) {
4297 TemplateArgumentListInfo NewTemplateArgs;
4298 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4299 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4300 typedef TemplateArgumentLocContainerIterator<
4301 DependentTemplateSpecializationTypeLoc> ArgIterator;
4302 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4303 ArgIterator(TL, TL.getNumArgs()),
4304 NewTemplateArgs))
4305 return QualType();
4306
4307 // FIXME: maybe don't rebuild if all the template arguments are the same.
4308
4309 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4310 QualType Result
4311 = getSema().Context.getDependentTemplateSpecializationType(
4312 TL.getTypePtr()->getKeyword(),
4313 DTN->getQualifier(),
4314 DTN->getIdentifier(),
4315 NewTemplateArgs);
4316
4317 DependentTemplateSpecializationTypeLoc NewTL
4318 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4319 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004320
4321 // FIXME: Poor nested-name-specifier source-location information.
4322 CXXScopeSpec SS;
4323 SS.MakeTrivial(SemaRef.Context,
4324 DTN->getQualifier(), TL.getQualifierLoc().getSourceRange());
4325 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004326 NewTL.setNameLoc(TL.getNameLoc());
4327 NewTL.setLAngleLoc(TL.getLAngleLoc());
4328 NewTL.setRAngleLoc(TL.getRAngleLoc());
4329 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4330 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4331 return Result;
4332 }
4333
4334 QualType Result
4335 = getDerived().RebuildTemplateSpecializationType(Template,
4336 TL.getNameLoc(),
4337 NewTemplateArgs);
4338
4339 if (!Result.isNull()) {
4340 /// FIXME: Wrap this in an elaborated-type-specifier?
4341 TemplateSpecializationTypeLoc NewTL
4342 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4343 NewTL.setTemplateNameLoc(TL.getNameLoc());
4344 NewTL.setLAngleLoc(TL.getLAngleLoc());
4345 NewTL.setRAngleLoc(TL.getRAngleLoc());
4346 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4347 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4348 }
4349
4350 return Result;
4351}
4352
Mike Stump11289f42009-09-09 15:08:12 +00004353template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004354QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004355TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004356 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004357 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004358
Douglas Gregor844cb502011-03-01 18:12:44 +00004359 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004360 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004361 if (TL.getQualifierLoc()) {
4362 QualifierLoc
4363 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4364 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004365 return QualType();
4366 }
Mike Stump11289f42009-09-09 15:08:12 +00004367
John McCall31f82722010-11-12 08:19:04 +00004368 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4369 if (NamedT.isNull())
4370 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004371
John McCall550e0c22009-10-21 00:40:46 +00004372 QualType Result = TL.getType();
4373 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004374 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004375 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004376 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004377 T->getKeyword(),
4378 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004379 if (Result.isNull())
4380 return QualType();
4381 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004382
Abramo Bagnara6150c882010-05-11 21:36:43 +00004383 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004384 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004385 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004386 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004387}
Mike Stump11289f42009-09-09 15:08:12 +00004388
4389template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004390QualType TreeTransform<Derived>::TransformAttributedType(
4391 TypeLocBuilder &TLB,
4392 AttributedTypeLoc TL) {
4393 const AttributedType *oldType = TL.getTypePtr();
4394 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4395 if (modifiedType.isNull())
4396 return QualType();
4397
4398 QualType result = TL.getType();
4399
4400 // FIXME: dependent operand expressions?
4401 if (getDerived().AlwaysRebuild() ||
4402 modifiedType != oldType->getModifiedType()) {
4403 // TODO: this is really lame; we should really be rebuilding the
4404 // equivalent type from first principles.
4405 QualType equivalentType
4406 = getDerived().TransformType(oldType->getEquivalentType());
4407 if (equivalentType.isNull())
4408 return QualType();
4409 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4410 modifiedType,
4411 equivalentType);
4412 }
4413
4414 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4415 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4416 if (TL.hasAttrOperand())
4417 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4418 if (TL.hasAttrExprOperand())
4419 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4420 else if (TL.hasAttrEnumOperand())
4421 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4422
4423 return result;
4424}
4425
4426template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004427QualType
4428TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4429 ParenTypeLoc TL) {
4430 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4431 if (Inner.isNull())
4432 return QualType();
4433
4434 QualType Result = TL.getType();
4435 if (getDerived().AlwaysRebuild() ||
4436 Inner != TL.getInnerLoc().getType()) {
4437 Result = getDerived().RebuildParenType(Inner);
4438 if (Result.isNull())
4439 return QualType();
4440 }
4441
4442 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4443 NewTL.setLParenLoc(TL.getLParenLoc());
4444 NewTL.setRParenLoc(TL.getRParenLoc());
4445 return Result;
4446}
4447
4448template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004449QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004450 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004451 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004452
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004453 NestedNameSpecifierLoc QualifierLoc
4454 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4455 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004456 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004457
John McCallc392f372010-06-11 00:33:02 +00004458 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004459 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004460 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004461 QualifierLoc,
4462 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004463 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004464 if (Result.isNull())
4465 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004466
Abramo Bagnarad7548482010-05-19 21:37:53 +00004467 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4468 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004469 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4470
Abramo Bagnarad7548482010-05-19 21:37:53 +00004471 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4472 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004473 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004474 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004475 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4476 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004477 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004478 NewTL.setNameLoc(TL.getNameLoc());
4479 }
John McCall550e0c22009-10-21 00:40:46 +00004480 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004481}
Mike Stump11289f42009-09-09 15:08:12 +00004482
Douglas Gregord6ff3322009-08-04 16:50:30 +00004483template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004484QualType TreeTransform<Derived>::
4485 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004486 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004487 NestedNameSpecifierLoc QualifierLoc;
4488 if (TL.getQualifierLoc()) {
4489 QualifierLoc
4490 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4491 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004492 return QualType();
4493 }
4494
John McCall31f82722010-11-12 08:19:04 +00004495 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004496 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004497}
4498
4499template<typename Derived>
4500QualType TreeTransform<Derived>::
4501 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4502 DependentTemplateSpecializationTypeLoc TL,
4503 NestedNameSpecifier *NNS) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004504 // FIXME: This routine needs to go away.
John McCall424cec92011-01-19 06:33:43 +00004505 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004506
John McCallc392f372010-06-11 00:33:02 +00004507 TemplateArgumentListInfo NewTemplateArgs;
4508 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4509 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor14454802011-02-25 02:25:35 +00004510
4511 // FIXME: Nested-name-specifier source location info!
Douglas Gregorfe921a72010-12-20 23:36:19 +00004512 typedef TemplateArgumentLocContainerIterator<
4513 DependentTemplateSpecializationTypeLoc> ArgIterator;
4514 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4515 ArgIterator(TL, TL.getNumArgs()),
4516 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004517 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004518
Douglas Gregor9db53502011-03-02 18:07:45 +00004519 CXXScopeSpec SS;
4520 SS.MakeTrivial(SemaRef.Context, NNS,
4521 TL.getQualifierLoc().getSourceRange());
Douglas Gregora5614c52010-09-08 23:56:00 +00004522 QualType Result
4523 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
Douglas Gregor9db53502011-03-02 18:07:45 +00004524 SS.getWithLocInContext(SemaRef.Context),
Douglas Gregora5614c52010-09-08 23:56:00 +00004525 T->getIdentifier(),
4526 TL.getNameLoc(),
4527 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004528 if (Result.isNull())
4529 return QualType();
4530
4531 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4532 QualType NamedT = ElabT->getNamedType();
4533
4534 // Copy information relevant to the template specialization.
4535 TemplateSpecializationTypeLoc NamedTL
4536 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4537 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4538 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4539 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4540 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4541
4542 // Copy information relevant to the elaborated type.
4543 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4544 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004545
4546 // FIXME: DependentTemplateSpecializationType needs better source-location
4547 // info.
4548 NestedNameSpecifierLocBuilder Builder;
Douglas Gregora7a795b2011-03-01 20:11:18 +00004549 Builder.MakeTrivial(SemaRef.Context,
4550 NNS, TL.getQualifierLoc().getSourceRange());
Douglas Gregor844cb502011-03-01 18:12:44 +00004551 NewTL.setQualifierLoc(Builder.getWithLocInContext(SemaRef.Context));
John McCallc392f372010-06-11 00:33:02 +00004552 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004553 TypeLoc NewTL(Result, TL.getOpaqueData());
4554 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004555 }
4556 return Result;
4557}
4558
4559template<typename Derived>
Douglas Gregora7a795b2011-03-01 20:11:18 +00004560QualType TreeTransform<Derived>::
4561TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4562 DependentTemplateSpecializationTypeLoc TL,
4563 NestedNameSpecifierLoc QualifierLoc) {
4564 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4565
4566 TemplateArgumentListInfo NewTemplateArgs;
4567 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4568 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4569
4570 typedef TemplateArgumentLocContainerIterator<
4571 DependentTemplateSpecializationTypeLoc> ArgIterator;
4572 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4573 ArgIterator(TL, TL.getNumArgs()),
4574 NewTemplateArgs))
4575 return QualType();
4576
4577 QualType Result
4578 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4579 QualifierLoc,
4580 T->getIdentifier(),
4581 TL.getNameLoc(),
4582 NewTemplateArgs);
4583 if (Result.isNull())
4584 return QualType();
4585
4586 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4587 QualType NamedT = ElabT->getNamedType();
4588
4589 // Copy information relevant to the template specialization.
4590 TemplateSpecializationTypeLoc NamedTL
4591 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4592 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4593 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4594 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4595 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4596
4597 // Copy information relevant to the elaborated type.
4598 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4599 NewTL.setKeywordLoc(TL.getKeywordLoc());
4600 NewTL.setQualifierLoc(QualifierLoc);
4601 } else {
4602 TypeLoc NewTL(Result, TL.getOpaqueData());
4603 TLB.pushFullCopy(NewTL);
4604 }
4605 return Result;
4606}
4607
4608template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004609QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4610 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004611 QualType Pattern
4612 = getDerived().TransformType(TLB, TL.getPatternLoc());
4613 if (Pattern.isNull())
4614 return QualType();
4615
4616 QualType Result = TL.getType();
4617 if (getDerived().AlwaysRebuild() ||
4618 Pattern != TL.getPatternLoc().getType()) {
4619 Result = getDerived().RebuildPackExpansionType(Pattern,
4620 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004621 TL.getEllipsisLoc(),
4622 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004623 if (Result.isNull())
4624 return QualType();
4625 }
4626
4627 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4628 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4629 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004630}
4631
4632template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004633QualType
4634TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004635 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004636 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004637 TLB.pushFullCopy(TL);
4638 return TL.getType();
4639}
4640
4641template<typename Derived>
4642QualType
4643TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004644 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004645 // ObjCObjectType is never dependent.
4646 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004647 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004648}
Mike Stump11289f42009-09-09 15:08:12 +00004649
4650template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004651QualType
4652TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004653 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004654 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004655 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004656 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004657}
4658
Douglas Gregord6ff3322009-08-04 16:50:30 +00004659//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004660// Statement transformation
4661//===----------------------------------------------------------------------===//
4662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004663StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004664TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004665 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004666}
4667
4668template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004669StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004670TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4671 return getDerived().TransformCompoundStmt(S, false);
4672}
4673
4674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004675StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004676TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004677 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004678 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004679 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004680 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004681 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4682 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004683 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004684 if (Result.isInvalid()) {
4685 // Immediately fail if this was a DeclStmt, since it's very
4686 // likely that this will cause problems for future statements.
4687 if (isa<DeclStmt>(*B))
4688 return StmtError();
4689
4690 // Otherwise, just keep processing substatements and fail later.
4691 SubStmtInvalid = true;
4692 continue;
4693 }
Mike Stump11289f42009-09-09 15:08:12 +00004694
Douglas Gregorebe10102009-08-20 07:17:43 +00004695 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4696 Statements.push_back(Result.takeAs<Stmt>());
4697 }
Mike Stump11289f42009-09-09 15:08:12 +00004698
John McCall1ababa62010-08-27 19:56:05 +00004699 if (SubStmtInvalid)
4700 return StmtError();
4701
Douglas Gregorebe10102009-08-20 07:17:43 +00004702 if (!getDerived().AlwaysRebuild() &&
4703 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004704 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004705
4706 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4707 move_arg(Statements),
4708 S->getRBracLoc(),
4709 IsStmtExpr);
4710}
Mike Stump11289f42009-09-09 15:08:12 +00004711
Douglas Gregorebe10102009-08-20 07:17:43 +00004712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004713StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004714TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004715 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004716 {
4717 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004718 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004719
Eli Friedman06577382009-11-19 03:14:00 +00004720 // Transform the left-hand case value.
4721 LHS = getDerived().TransformExpr(S->getLHS());
4722 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004723 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004724
Eli Friedman06577382009-11-19 03:14:00 +00004725 // Transform the right-hand case value (for the GNU case-range extension).
4726 RHS = getDerived().TransformExpr(S->getRHS());
4727 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004728 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004729 }
Mike Stump11289f42009-09-09 15:08:12 +00004730
Douglas Gregorebe10102009-08-20 07:17:43 +00004731 // Build the case statement.
4732 // Case statements are always rebuilt so that they will attached to their
4733 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004734 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004735 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004736 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004737 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004738 S->getColonLoc());
4739 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004740 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregorebe10102009-08-20 07:17:43 +00004742 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004743 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004744 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004745 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004746
Douglas Gregorebe10102009-08-20 07:17:43 +00004747 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004748 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004749}
4750
4751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004752StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004753TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004754 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004755 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004756 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004757 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregorebe10102009-08-20 07:17:43 +00004759 // Default statements are always rebuilt
4760 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004761 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004762}
Mike Stump11289f42009-09-09 15:08:12 +00004763
Douglas Gregorebe10102009-08-20 07:17:43 +00004764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004765StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004766TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004767 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004768 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004769 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004770
Chris Lattnercab02a62011-02-17 20:34:02 +00004771 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4772 S->getDecl());
4773 if (!LD)
4774 return StmtError();
4775
4776
Douglas Gregorebe10102009-08-20 07:17:43 +00004777 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004778 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004779 cast<LabelDecl>(LD), SourceLocation(),
4780 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004781}
Mike Stump11289f42009-09-09 15:08:12 +00004782
Douglas Gregorebe10102009-08-20 07:17:43 +00004783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004784StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004785TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004786 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004787 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004788 VarDecl *ConditionVar = 0;
4789 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004790 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004791 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004792 getDerived().TransformDefinition(
4793 S->getConditionVariable()->getLocation(),
4794 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004795 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004796 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004797 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004798 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004799
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004800 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004801 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004802
4803 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004804 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004805 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4806 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004807 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004808 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004809
John McCallb268a282010-08-23 23:25:46 +00004810 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004811 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004812 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004813
John McCallb268a282010-08-23 23:25:46 +00004814 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4815 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004816 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004817
Douglas Gregorebe10102009-08-20 07:17:43 +00004818 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004819 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004820 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004821 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregorebe10102009-08-20 07:17:43 +00004823 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004824 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004825 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004826 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004827
Douglas Gregorebe10102009-08-20 07:17:43 +00004828 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004829 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004830 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004831 Then.get() == S->getThen() &&
4832 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004833 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004834
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004835 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004836 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004837 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004838}
4839
4840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004841StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004842TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004843 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004844 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004845 VarDecl *ConditionVar = 0;
4846 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004847 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004848 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004849 getDerived().TransformDefinition(
4850 S->getConditionVariable()->getLocation(),
4851 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004852 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004853 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004854 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004855 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004856
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004857 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004858 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004859 }
Mike Stump11289f42009-09-09 15:08:12 +00004860
Douglas Gregorebe10102009-08-20 07:17:43 +00004861 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004862 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004863 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004864 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004865 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004866 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004867
Douglas Gregorebe10102009-08-20 07:17:43 +00004868 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004869 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004870 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004871 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004872
Douglas Gregorebe10102009-08-20 07:17:43 +00004873 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004874 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4875 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004876}
Mike Stump11289f42009-09-09 15:08:12 +00004877
Douglas Gregorebe10102009-08-20 07:17:43 +00004878template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004879StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004880TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004881 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004882 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004883 VarDecl *ConditionVar = 0;
4884 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004885 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004886 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004887 getDerived().TransformDefinition(
4888 S->getConditionVariable()->getLocation(),
4889 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004890 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004891 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004892 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004893 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004894
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004895 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004896 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004897
4898 if (S->getCond()) {
4899 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004900 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4901 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004902 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004903 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004904 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004905 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004906 }
Mike Stump11289f42009-09-09 15:08:12 +00004907
John McCallb268a282010-08-23 23:25:46 +00004908 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4909 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004910 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004911
Douglas Gregorebe10102009-08-20 07:17:43 +00004912 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004913 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004914 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004915 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004916
Douglas Gregorebe10102009-08-20 07:17:43 +00004917 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004918 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004919 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004920 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004921 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004922
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004923 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004924 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004925}
Mike Stump11289f42009-09-09 15:08:12 +00004926
Douglas Gregorebe10102009-08-20 07:17:43 +00004927template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004928StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004929TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004930 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004931 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004932 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004933 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004934
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004935 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004936 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004937 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004938 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004939
Douglas Gregorebe10102009-08-20 07:17:43 +00004940 if (!getDerived().AlwaysRebuild() &&
4941 Cond.get() == S->getCond() &&
4942 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004943 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004944
John McCallb268a282010-08-23 23:25:46 +00004945 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4946 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004947 S->getRParenLoc());
4948}
Mike Stump11289f42009-09-09 15:08:12 +00004949
Douglas Gregorebe10102009-08-20 07:17:43 +00004950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004951StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004952TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004953 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004954 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004955 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004956 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004957
Douglas Gregorebe10102009-08-20 07:17:43 +00004958 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004959 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004960 VarDecl *ConditionVar = 0;
4961 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004962 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004963 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004964 getDerived().TransformDefinition(
4965 S->getConditionVariable()->getLocation(),
4966 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004967 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004968 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004969 } else {
4970 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004971
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004972 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004973 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004974
4975 if (S->getCond()) {
4976 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004977 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4978 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004979 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004980 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004981
John McCallb268a282010-08-23 23:25:46 +00004982 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004983 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004984 }
Mike Stump11289f42009-09-09 15:08:12 +00004985
John McCallb268a282010-08-23 23:25:46 +00004986 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4987 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004988 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004989
Douglas Gregorebe10102009-08-20 07:17:43 +00004990 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004991 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004992 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004993 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004994
John McCallb268a282010-08-23 23:25:46 +00004995 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4996 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004997 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004998
Douglas Gregorebe10102009-08-20 07:17:43 +00004999 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005000 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005001 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005002 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005003
Douglas Gregorebe10102009-08-20 07:17:43 +00005004 if (!getDerived().AlwaysRebuild() &&
5005 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005006 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005007 Inc.get() == S->getInc() &&
5008 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005009 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregorebe10102009-08-20 07:17:43 +00005011 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005012 Init.get(), FullCond, ConditionVar,
5013 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005014}
5015
5016template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005017StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005018TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005019 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5020 S->getLabel());
5021 if (!LD)
5022 return StmtError();
5023
Douglas Gregorebe10102009-08-20 07:17:43 +00005024 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005025 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005026 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005027}
5028
5029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005030StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005031TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005032 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005033 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005034 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005035
Douglas Gregorebe10102009-08-20 07:17:43 +00005036 if (!getDerived().AlwaysRebuild() &&
5037 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005038 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005039
5040 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005041 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005042}
5043
5044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005045StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005046TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005047 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005048}
Mike Stump11289f42009-09-09 15:08:12 +00005049
Douglas Gregorebe10102009-08-20 07:17:43 +00005050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005051StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005052TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005053 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005054}
Mike Stump11289f42009-09-09 15:08:12 +00005055
Douglas Gregorebe10102009-08-20 07:17:43 +00005056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005057StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005058TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005059 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005060 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005061 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005062
Mike Stump11289f42009-09-09 15:08:12 +00005063 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005064 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005065 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005066}
Mike Stump11289f42009-09-09 15:08:12 +00005067
Douglas Gregorebe10102009-08-20 07:17:43 +00005068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005069StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005070TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005071 bool DeclChanged = false;
5072 llvm::SmallVector<Decl *, 4> Decls;
5073 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5074 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005075 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5076 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005077 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005078 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005079
Douglas Gregorebe10102009-08-20 07:17:43 +00005080 if (Transformed != *D)
5081 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005082
Douglas Gregorebe10102009-08-20 07:17:43 +00005083 Decls.push_back(Transformed);
5084 }
Mike Stump11289f42009-09-09 15:08:12 +00005085
Douglas Gregorebe10102009-08-20 07:17:43 +00005086 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005087 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005088
5089 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005090 S->getStartLoc(), S->getEndLoc());
5091}
Mike Stump11289f42009-09-09 15:08:12 +00005092
Douglas Gregorebe10102009-08-20 07:17:43 +00005093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005094StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005095TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005096
John McCall37ad5512010-08-23 06:44:23 +00005097 ASTOwningVector<Expr*> Constraints(getSema());
5098 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005099 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005100
John McCalldadc5752010-08-24 06:29:42 +00005101 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005102 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005103
5104 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005105
Anders Carlssonaaeef072010-01-24 05:50:09 +00005106 // Go through the outputs.
5107 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005108 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005109
Anders Carlssonaaeef072010-01-24 05:50:09 +00005110 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005111 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005112
Anders Carlssonaaeef072010-01-24 05:50:09 +00005113 // Transform the output expr.
5114 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005115 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005116 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005117 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005118
Anders Carlssonaaeef072010-01-24 05:50:09 +00005119 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005120
John McCallb268a282010-08-23 23:25:46 +00005121 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005122 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005123
Anders Carlssonaaeef072010-01-24 05:50:09 +00005124 // Go through the inputs.
5125 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005126 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005127
Anders Carlssonaaeef072010-01-24 05:50:09 +00005128 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005129 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005130
Anders Carlssonaaeef072010-01-24 05:50:09 +00005131 // Transform the input expr.
5132 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005133 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005134 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005135 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005136
Anders Carlssonaaeef072010-01-24 05:50:09 +00005137 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005138
John McCallb268a282010-08-23 23:25:46 +00005139 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005140 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005141
Anders Carlssonaaeef072010-01-24 05:50:09 +00005142 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005143 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005144
5145 // Go through the clobbers.
5146 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005147 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005148
5149 // No need to transform the asm string literal.
5150 AsmString = SemaRef.Owned(S->getAsmString());
5151
5152 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5153 S->isSimple(),
5154 S->isVolatile(),
5155 S->getNumOutputs(),
5156 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005157 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005158 move_arg(Constraints),
5159 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005160 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005161 move_arg(Clobbers),
5162 S->getRParenLoc(),
5163 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005164}
5165
5166
5167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005168StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005169TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005170 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005171 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005172 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005173 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005174
Douglas Gregor96c79492010-04-23 22:50:49 +00005175 // Transform the @catch statements (if present).
5176 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005177 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005178 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005179 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005180 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005181 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005182 if (Catch.get() != S->getCatchStmt(I))
5183 AnyCatchChanged = true;
5184 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005185 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005186
Douglas Gregor306de2f2010-04-22 23:59:56 +00005187 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005188 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005189 if (S->getFinallyStmt()) {
5190 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5191 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005192 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005193 }
5194
5195 // If nothing changed, just retain this statement.
5196 if (!getDerived().AlwaysRebuild() &&
5197 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005198 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005199 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005200 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005201
Douglas Gregor306de2f2010-04-22 23:59:56 +00005202 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005203 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5204 move_arg(CatchStmts), Finally.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>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005210 // Transform the @catch parameter, if there is one.
5211 VarDecl *Var = 0;
5212 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5213 TypeSourceInfo *TSInfo = 0;
5214 if (FromVar->getTypeSourceInfo()) {
5215 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5216 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005217 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005218 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005219
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005220 QualType T;
5221 if (TSInfo)
5222 T = TSInfo->getType();
5223 else {
5224 T = getDerived().TransformType(FromVar->getType());
5225 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005226 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005227 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005228
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005229 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5230 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005231 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005232 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005233
John McCalldadc5752010-08-24 06:29:42 +00005234 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005235 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005236 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005237
5238 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005239 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005240 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005241}
Mike Stump11289f42009-09-09 15:08:12 +00005242
Douglas Gregorebe10102009-08-20 07:17:43 +00005243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005244StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005245TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005246 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005247 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005248 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005249 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005250
Douglas Gregor306de2f2010-04-22 23:59:56 +00005251 // If nothing changed, just retain this statement.
5252 if (!getDerived().AlwaysRebuild() &&
5253 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005254 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005255
5256 // Build a new statement.
5257 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005258 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005259}
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregorebe10102009-08-20 07:17:43 +00005261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005262StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005263TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005264 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005265 if (S->getThrowExpr()) {
5266 Operand = getDerived().TransformExpr(S->getThrowExpr());
5267 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005268 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005269 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005270
Douglas Gregor2900c162010-04-22 21:44:01 +00005271 if (!getDerived().AlwaysRebuild() &&
5272 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005273 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005274
John McCallb268a282010-08-23 23:25:46 +00005275 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005276}
Mike Stump11289f42009-09-09 15:08:12 +00005277
Douglas Gregorebe10102009-08-20 07:17:43 +00005278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005279StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005280TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005281 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005282 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005283 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005284 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005285 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005286
Douglas Gregor6148de72010-04-22 22:01:21 +00005287 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005288 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005289 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005290 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005291
Douglas Gregor6148de72010-04-22 22:01:21 +00005292 // If nothing change, just retain the current statement.
5293 if (!getDerived().AlwaysRebuild() &&
5294 Object.get() == S->getSynchExpr() &&
5295 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005296 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005297
5298 // Build a new statement.
5299 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005300 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005301}
5302
5303template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005304StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005305TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005306 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005307 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005308 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005309 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005310 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005311
Douglas Gregorf68a5082010-04-22 23:10:45 +00005312 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005313 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005314 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005315 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005316
Douglas Gregorf68a5082010-04-22 23:10:45 +00005317 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005318 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005319 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005320 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005321
Douglas Gregorf68a5082010-04-22 23:10:45 +00005322 // If nothing changed, just retain this statement.
5323 if (!getDerived().AlwaysRebuild() &&
5324 Element.get() == S->getElement() &&
5325 Collection.get() == S->getCollection() &&
5326 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005327 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005328
Douglas Gregorf68a5082010-04-22 23:10:45 +00005329 // Build a new statement.
5330 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5331 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005332 Element.get(),
5333 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005334 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005335 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005336}
5337
5338
5339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005340StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005341TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5342 // Transform the exception declaration, if any.
5343 VarDecl *Var = 0;
5344 if (S->getExceptionDecl()) {
5345 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005346 TypeSourceInfo *T = getDerived().TransformType(
5347 ExceptionDecl->getTypeSourceInfo());
5348 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005349 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005350
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005351 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005352 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005353 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005354 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005355 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005356 }
Mike Stump11289f42009-09-09 15:08:12 +00005357
Douglas Gregorebe10102009-08-20 07:17:43 +00005358 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005359 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005360 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005361 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005362
Douglas Gregorebe10102009-08-20 07:17:43 +00005363 if (!getDerived().AlwaysRebuild() &&
5364 !Var &&
5365 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005366 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005367
5368 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5369 Var,
John McCallb268a282010-08-23 23:25:46 +00005370 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005371}
Mike Stump11289f42009-09-09 15:08:12 +00005372
Douglas Gregorebe10102009-08-20 07:17:43 +00005373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005374StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005375TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5376 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005377 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005378 = getDerived().TransformCompoundStmt(S->getTryBlock());
5379 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005380 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005381
Douglas Gregorebe10102009-08-20 07:17:43 +00005382 // Transform the handlers.
5383 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005384 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005385 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005386 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005387 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5388 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005389 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005390
Douglas Gregorebe10102009-08-20 07:17:43 +00005391 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5392 Handlers.push_back(Handler.takeAs<Stmt>());
5393 }
Mike Stump11289f42009-09-09 15:08:12 +00005394
Douglas Gregorebe10102009-08-20 07:17:43 +00005395 if (!getDerived().AlwaysRebuild() &&
5396 TryBlock.get() == S->getTryBlock() &&
5397 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005398 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005399
John McCallb268a282010-08-23 23:25:46 +00005400 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005401 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005402}
Mike Stump11289f42009-09-09 15:08:12 +00005403
Douglas Gregorebe10102009-08-20 07:17:43 +00005404//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005405// Expression transformation
5406//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005408ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005409TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005410 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005411}
Mike Stump11289f42009-09-09 15:08:12 +00005412
5413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005414ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005415TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005416 NestedNameSpecifierLoc QualifierLoc;
5417 if (E->getQualifierLoc()) {
5418 QualifierLoc
5419 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5420 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005421 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005422 }
John McCallce546572009-12-08 09:08:17 +00005423
5424 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005425 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5426 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005427 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005428 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005429
John McCall815039a2010-08-17 21:27:17 +00005430 DeclarationNameInfo NameInfo = E->getNameInfo();
5431 if (NameInfo.getName()) {
5432 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5433 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005434 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005435 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005436
5437 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005438 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005439 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005440 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005441 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005442
5443 // Mark it referenced in the new context regardless.
5444 // FIXME: this is a bit instantiation-specific.
5445 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5446
John McCallc3007a22010-10-26 07:05:15 +00005447 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005448 }
John McCallce546572009-12-08 09:08:17 +00005449
5450 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005451 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005452 TemplateArgs = &TransArgs;
5453 TransArgs.setLAngleLoc(E->getLAngleLoc());
5454 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005455 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5456 E->getNumTemplateArgs(),
5457 TransArgs))
5458 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005459 }
5460
Douglas Gregorea972d32011-02-28 21:54:11 +00005461 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5462 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005463}
Mike Stump11289f42009-09-09 15:08:12 +00005464
Douglas Gregora16548e2009-08-11 05:31:07 +00005465template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005466ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005467TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005468 return SemaRef.Owned(E);
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
John McCall47f29ea2009-12-08 09:21:05 +00005473TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005474 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005475}
Mike Stump11289f42009-09-09 15:08:12 +00005476
Douglas Gregora16548e2009-08-11 05:31:07 +00005477template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005478ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005479TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005480 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005481}
Mike Stump11289f42009-09-09 15:08:12 +00005482
Douglas Gregora16548e2009-08-11 05:31:07 +00005483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005484ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005485TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005486 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005487}
Mike Stump11289f42009-09-09 15:08:12 +00005488
Douglas Gregora16548e2009-08-11 05:31:07 +00005489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005490ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005491TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005492 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005493}
5494
5495template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005496ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005497TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005498 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005499 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005500 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005501
Douglas Gregora16548e2009-08-11 05:31:07 +00005502 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005503 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005504
John McCallb268a282010-08-23 23:25:46 +00005505 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005506 E->getRParen());
5507}
5508
Mike Stump11289f42009-09-09 15:08:12 +00005509template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005510ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005511TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005512 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005513 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005514 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005515
Douglas Gregora16548e2009-08-11 05:31:07 +00005516 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005517 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005518
Douglas Gregora16548e2009-08-11 05:31:07 +00005519 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5520 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005521 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005522}
Mike Stump11289f42009-09-09 15:08:12 +00005523
Douglas Gregora16548e2009-08-11 05:31:07 +00005524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005525ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005526TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5527 // Transform the type.
5528 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5529 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005530 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005531
Douglas Gregor882211c2010-04-28 22:16:22 +00005532 // Transform all of the components into components similar to what the
5533 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005534 // FIXME: It would be slightly more efficient in the non-dependent case to
5535 // just map FieldDecls, rather than requiring the rebuilder to look for
5536 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005537 // template code that we don't care.
5538 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005539 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005540 typedef OffsetOfExpr::OffsetOfNode Node;
5541 llvm::SmallVector<Component, 4> Components;
5542 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5543 const Node &ON = E->getComponent(I);
5544 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005545 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005546 Comp.LocStart = ON.getRange().getBegin();
5547 Comp.LocEnd = ON.getRange().getEnd();
5548 switch (ON.getKind()) {
5549 case Node::Array: {
5550 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005551 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005552 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005553 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005554
Douglas Gregor882211c2010-04-28 22:16:22 +00005555 ExprChanged = ExprChanged || Index.get() != FromIndex;
5556 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005557 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005558 break;
5559 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005560
Douglas Gregor882211c2010-04-28 22:16:22 +00005561 case Node::Field:
5562 case Node::Identifier:
5563 Comp.isBrackets = false;
5564 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005565 if (!Comp.U.IdentInfo)
5566 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005567
Douglas Gregor882211c2010-04-28 22:16:22 +00005568 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005569
Douglas Gregord1702062010-04-29 00:18:15 +00005570 case Node::Base:
5571 // Will be recomputed during the rebuild.
5572 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005573 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005574
Douglas Gregor882211c2010-04-28 22:16:22 +00005575 Components.push_back(Comp);
5576 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005577
Douglas Gregor882211c2010-04-28 22:16:22 +00005578 // If nothing changed, retain the existing expression.
5579 if (!getDerived().AlwaysRebuild() &&
5580 Type == E->getTypeSourceInfo() &&
5581 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005582 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005583
Douglas Gregor882211c2010-04-28 22:16:22 +00005584 // Build a new offsetof expression.
5585 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5586 Components.data(), Components.size(),
5587 E->getRParenLoc());
5588}
5589
5590template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005591ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005592TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5593 assert(getDerived().AlreadyTransformed(E->getType()) &&
5594 "opaque value expression requires transformation");
5595 return SemaRef.Owned(E);
5596}
5597
5598template<typename Derived>
5599ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005600TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005601 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005602 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005603
John McCallbcd03502009-12-07 02:54:59 +00005604 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005605 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005606 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005607
John McCall4c98fd82009-11-04 07:28:41 +00005608 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005609 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005610
John McCall4c98fd82009-11-04 07:28:41 +00005611 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005612 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005613 E->getSourceRange());
5614 }
Mike Stump11289f42009-09-09 15:08:12 +00005615
John McCalldadc5752010-08-24 06:29:42 +00005616 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005617 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005618 // C++0x [expr.sizeof]p1:
5619 // The operand is either an expression, which is an unevaluated operand
5620 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005621 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005622
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5624 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005625 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005626
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005628 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005629 }
Mike Stump11289f42009-09-09 15:08:12 +00005630
John McCallb268a282010-08-23 23:25:46 +00005631 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 E->isSizeOf(),
5633 E->getSourceRange());
5634}
Mike Stump11289f42009-09-09 15:08:12 +00005635
Douglas Gregora16548e2009-08-11 05:31:07 +00005636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005637ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005638TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005639 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005640 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005641 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005642
John McCalldadc5752010-08-24 06:29:42 +00005643 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005644 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005646
5647
Douglas Gregora16548e2009-08-11 05:31:07 +00005648 if (!getDerived().AlwaysRebuild() &&
5649 LHS.get() == E->getLHS() &&
5650 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005651 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005652
John McCallb268a282010-08-23 23:25:46 +00005653 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005654 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005655 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005656 E->getRBracketLoc());
5657}
Mike Stump11289f42009-09-09 15:08:12 +00005658
5659template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005660ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005661TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005662 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005663 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005664 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005665 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005666
5667 // Transform arguments.
5668 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005669 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005670 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5671 &ArgChanged))
5672 return ExprError();
5673
Douglas Gregora16548e2009-08-11 05:31:07 +00005674 if (!getDerived().AlwaysRebuild() &&
5675 Callee.get() == E->getCallee() &&
5676 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005677 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005678
Douglas Gregora16548e2009-08-11 05:31:07 +00005679 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005680 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005681 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005682 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005683 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005684 E->getRParenLoc());
5685}
Mike Stump11289f42009-09-09 15:08:12 +00005686
5687template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005688ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005689TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005690 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005691 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005692 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005693
Douglas Gregorea972d32011-02-28 21:54:11 +00005694 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005695 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005696 QualifierLoc
5697 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5698
5699 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005700 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005701 }
Mike Stump11289f42009-09-09 15:08:12 +00005702
Eli Friedman2cfcef62009-12-04 06:40:45 +00005703 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005704 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5705 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005708
John McCall16df1e52010-03-30 21:47:33 +00005709 NamedDecl *FoundDecl = E->getFoundDecl();
5710 if (FoundDecl == E->getMemberDecl()) {
5711 FoundDecl = Member;
5712 } else {
5713 FoundDecl = cast_or_null<NamedDecl>(
5714 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5715 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005716 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005717 }
5718
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 if (!getDerived().AlwaysRebuild() &&
5720 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005721 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005722 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005723 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005724 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005725
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005726 // Mark it referenced in the new context regardless.
5727 // FIXME: this is a bit instantiation-specific.
5728 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005729 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005730 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005731
John McCall6b51f282009-11-23 01:53:49 +00005732 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005733 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005734 TransArgs.setLAngleLoc(E->getLAngleLoc());
5735 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005736 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5737 E->getNumTemplateArgs(),
5738 TransArgs))
5739 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005740 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005741
Douglas Gregora16548e2009-08-11 05:31:07 +00005742 // FIXME: Bogus source location for the operator
5743 SourceLocation FakeOperatorLoc
5744 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5745
John McCall38836f02010-01-15 08:34:02 +00005746 // FIXME: to do this check properly, we will need to preserve the
5747 // first-qualifier-in-scope here, just in case we had a dependent
5748 // base (and therefore couldn't do the check) and a
5749 // nested-name-qualifier (and therefore could do the lookup).
5750 NamedDecl *FirstQualifierInScope = 0;
5751
John McCallb268a282010-08-23 23:25:46 +00005752 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005753 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005754 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005755 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005756 Member,
John McCall16df1e52010-03-30 21:47:33 +00005757 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005758 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005759 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005760 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005761}
Mike Stump11289f42009-09-09 15:08:12 +00005762
Douglas Gregora16548e2009-08-11 05:31:07 +00005763template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005764ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005765TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005766 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005767 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005768 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005769
John McCalldadc5752010-08-24 06:29:42 +00005770 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005771 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005772 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005773
Douglas Gregora16548e2009-08-11 05:31:07 +00005774 if (!getDerived().AlwaysRebuild() &&
5775 LHS.get() == E->getLHS() &&
5776 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005777 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005778
Douglas Gregora16548e2009-08-11 05:31:07 +00005779 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005780 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005781}
5782
Mike Stump11289f42009-09-09 15:08:12 +00005783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005784ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005785TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005786 CompoundAssignOperator *E) {
5787 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005788}
Mike Stump11289f42009-09-09 15:08:12 +00005789
Douglas Gregora16548e2009-08-11 05:31:07 +00005790template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005791ExprResult TreeTransform<Derived>::
5792TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5793 // Just rebuild the common and RHS expressions and see whether we
5794 // get any changes.
5795
5796 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5797 if (commonExpr.isInvalid())
5798 return ExprError();
5799
5800 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5801 if (rhs.isInvalid())
5802 return ExprError();
5803
5804 if (!getDerived().AlwaysRebuild() &&
5805 commonExpr.get() == e->getCommon() &&
5806 rhs.get() == e->getFalseExpr())
5807 return SemaRef.Owned(e);
5808
5809 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5810 e->getQuestionLoc(),
5811 0,
5812 e->getColonLoc(),
5813 rhs.get());
5814}
5815
5816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005817ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005818TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005819 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005821 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005822
John McCalldadc5752010-08-24 06:29:42 +00005823 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005824 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005825 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005826
John McCalldadc5752010-08-24 06:29:42 +00005827 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005828 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005829 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005830
Douglas Gregora16548e2009-08-11 05:31:07 +00005831 if (!getDerived().AlwaysRebuild() &&
5832 Cond.get() == E->getCond() &&
5833 LHS.get() == E->getLHS() &&
5834 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005835 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005836
John McCallb268a282010-08-23 23:25:46 +00005837 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005838 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005839 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005840 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005841 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005842}
Mike Stump11289f42009-09-09 15:08:12 +00005843
5844template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005845ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005846TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005847 // Implicit casts are eliminated during transformation, since they
5848 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005849 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005850}
Mike Stump11289f42009-09-09 15:08:12 +00005851
Douglas Gregora16548e2009-08-11 05:31:07 +00005852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005854TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005855 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5856 if (!Type)
5857 return ExprError();
5858
John McCalldadc5752010-08-24 06:29:42 +00005859 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005860 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005861 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005863
Douglas Gregora16548e2009-08-11 05:31:07 +00005864 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005865 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005866 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005867 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005868
John McCall97513962010-01-15 18:39:57 +00005869 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005870 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005871 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005872 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005873}
Mike Stump11289f42009-09-09 15:08:12 +00005874
Douglas Gregora16548e2009-08-11 05:31:07 +00005875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005876ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005877TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005878 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5879 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5880 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005882
John McCalldadc5752010-08-24 06:29:42 +00005883 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005886
Douglas Gregora16548e2009-08-11 05:31:07 +00005887 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005888 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005890 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005891
John McCall5d7aa7f2010-01-19 22:33:45 +00005892 // Note: the expression type doesn't necessarily match the
5893 // type-as-written, but that's okay, because it should always be
5894 // derivable from the initializer.
5895
John McCalle15bbff2010-01-18 19:35:47 +00005896 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005898 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005899}
Mike Stump11289f42009-09-09 15:08:12 +00005900
Douglas Gregora16548e2009-08-11 05:31:07 +00005901template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005902ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005903TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005904 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005905 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005906 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005907
Douglas Gregora16548e2009-08-11 05:31:07 +00005908 if (!getDerived().AlwaysRebuild() &&
5909 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005910 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005911
Douglas Gregora16548e2009-08-11 05:31:07 +00005912 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005913 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005914 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005915 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005916 E->getAccessorLoc(),
5917 E->getAccessor());
5918}
Mike Stump11289f42009-09-09 15:08:12 +00005919
Douglas Gregora16548e2009-08-11 05:31:07 +00005920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005922TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005923 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005924
John McCall37ad5512010-08-23 06:44:23 +00005925 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005926 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5927 Inits, &InitChanged))
5928 return ExprError();
5929
Douglas Gregora16548e2009-08-11 05:31:07 +00005930 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005931 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005932
Douglas Gregora16548e2009-08-11 05:31:07 +00005933 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005934 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005935}
Mike Stump11289f42009-09-09 15:08:12 +00005936
Douglas Gregora16548e2009-08-11 05:31:07 +00005937template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005938ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005939TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005940 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005941
Douglas Gregorebe10102009-08-20 07:17:43 +00005942 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005943 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005944 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005945 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005946
Douglas Gregorebe10102009-08-20 07:17:43 +00005947 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005948 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005949 bool ExprChanged = false;
5950 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5951 DEnd = E->designators_end();
5952 D != DEnd; ++D) {
5953 if (D->isFieldDesignator()) {
5954 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5955 D->getDotLoc(),
5956 D->getFieldLoc()));
5957 continue;
5958 }
Mike Stump11289f42009-09-09 15:08:12 +00005959
Douglas Gregora16548e2009-08-11 05:31:07 +00005960 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005961 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005962 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005963 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005964
5965 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005966 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005967
Douglas Gregora16548e2009-08-11 05:31:07 +00005968 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5969 ArrayExprs.push_back(Index.release());
5970 continue;
5971 }
Mike Stump11289f42009-09-09 15:08:12 +00005972
Douglas Gregora16548e2009-08-11 05:31:07 +00005973 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005974 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005975 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5976 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005977 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005978
John McCalldadc5752010-08-24 06:29:42 +00005979 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005980 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005981 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005982
5983 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005984 End.get(),
5985 D->getLBracketLoc(),
5986 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005987
Douglas Gregora16548e2009-08-11 05:31:07 +00005988 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5989 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005990
Douglas Gregora16548e2009-08-11 05:31:07 +00005991 ArrayExprs.push_back(Start.release());
5992 ArrayExprs.push_back(End.release());
5993 }
Mike Stump11289f42009-09-09 15:08:12 +00005994
Douglas Gregora16548e2009-08-11 05:31:07 +00005995 if (!getDerived().AlwaysRebuild() &&
5996 Init.get() == E->getInit() &&
5997 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005998 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005999
Douglas Gregora16548e2009-08-11 05:31:07 +00006000 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6001 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006002 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006003}
Mike Stump11289f42009-09-09 15:08:12 +00006004
Douglas Gregora16548e2009-08-11 05:31:07 +00006005template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006006ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006007TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006008 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006009 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006010
Douglas Gregor3da3c062009-10-28 00:29:27 +00006011 // FIXME: Will we ever have proper type location here? Will we actually
6012 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006013 QualType T = getDerived().TransformType(E->getType());
6014 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006015 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregora16548e2009-08-11 05:31:07 +00006017 if (!getDerived().AlwaysRebuild() &&
6018 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006019 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006020
Douglas Gregora16548e2009-08-11 05:31:07 +00006021 return getDerived().RebuildImplicitValueInitExpr(T);
6022}
Mike Stump11289f42009-09-09 15:08:12 +00006023
Douglas Gregora16548e2009-08-11 05:31:07 +00006024template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006025ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006026TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006027 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6028 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006029 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006030
John McCalldadc5752010-08-24 06:29:42 +00006031 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006032 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006033 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006034
Douglas Gregora16548e2009-08-11 05:31:07 +00006035 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006036 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006037 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006038 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006039
John McCallb268a282010-08-23 23:25:46 +00006040 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006041 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006042}
6043
6044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006046TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006047 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006048 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006049 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6050 &ArgumentChanged))
6051 return ExprError();
6052
Douglas Gregora16548e2009-08-11 05:31:07 +00006053 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6054 move_arg(Inits),
6055 E->getRParenLoc());
6056}
Mike Stump11289f42009-09-09 15:08:12 +00006057
Douglas Gregora16548e2009-08-11 05:31:07 +00006058/// \brief Transform an address-of-label expression.
6059///
6060/// By default, the transformation of an address-of-label expression always
6061/// rebuilds the expression, so that the label identifier can be resolved to
6062/// the corresponding label statement by semantic analysis.
6063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006064ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006065TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006066 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6067 E->getLabel());
6068 if (!LD)
6069 return ExprError();
6070
Douglas Gregora16548e2009-08-11 05:31:07 +00006071 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006072 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006073}
Mike Stump11289f42009-09-09 15:08:12 +00006074
6075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006076ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006077TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006078 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006079 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6080 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006081 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006082
Douglas Gregora16548e2009-08-11 05:31:07 +00006083 if (!getDerived().AlwaysRebuild() &&
6084 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006085 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006086
6087 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006088 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006089 E->getRParenLoc());
6090}
Mike Stump11289f42009-09-09 15:08:12 +00006091
Douglas Gregora16548e2009-08-11 05:31:07 +00006092template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006093ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006094TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006095 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006096 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006097 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006098
John McCalldadc5752010-08-24 06:29:42 +00006099 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006100 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006101 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006102
John McCalldadc5752010-08-24 06:29:42 +00006103 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006104 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006105 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006106
Douglas Gregora16548e2009-08-11 05:31:07 +00006107 if (!getDerived().AlwaysRebuild() &&
6108 Cond.get() == E->getCond() &&
6109 LHS.get() == E->getLHS() &&
6110 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006111 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006112
Douglas Gregora16548e2009-08-11 05:31:07 +00006113 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006114 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006115 E->getRParenLoc());
6116}
Mike Stump11289f42009-09-09 15:08:12 +00006117
Douglas Gregora16548e2009-08-11 05:31:07 +00006118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006119ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006120TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006121 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006122}
6123
6124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006126TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006127 switch (E->getOperator()) {
6128 case OO_New:
6129 case OO_Delete:
6130 case OO_Array_New:
6131 case OO_Array_Delete:
6132 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006133 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006134
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006135 case OO_Call: {
6136 // This is a call to an object's operator().
6137 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6138
6139 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006140 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006141 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006142 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006143
6144 // FIXME: Poor location information
6145 SourceLocation FakeLParenLoc
6146 = SemaRef.PP.getLocForEndOfToken(
6147 static_cast<Expr *>(Object.get())->getLocEnd());
6148
6149 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006150 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006151 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6152 Args))
6153 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006154
John McCallb268a282010-08-23 23:25:46 +00006155 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006156 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006157 E->getLocEnd());
6158 }
6159
6160#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6161 case OO_##Name:
6162#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6163#include "clang/Basic/OperatorKinds.def"
6164 case OO_Subscript:
6165 // Handled below.
6166 break;
6167
6168 case OO_Conditional:
6169 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006170 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006171
6172 case OO_None:
6173 case NUM_OVERLOADED_OPERATORS:
6174 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006175 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006176 }
6177
John McCalldadc5752010-08-24 06:29:42 +00006178 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006179 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006180 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006181
John McCalldadc5752010-08-24 06:29:42 +00006182 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006183 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006184 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006185
John McCalldadc5752010-08-24 06:29:42 +00006186 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006187 if (E->getNumArgs() == 2) {
6188 Second = getDerived().TransformExpr(E->getArg(1));
6189 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006190 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006191 }
Mike Stump11289f42009-09-09 15:08:12 +00006192
Douglas Gregora16548e2009-08-11 05:31:07 +00006193 if (!getDerived().AlwaysRebuild() &&
6194 Callee.get() == E->getCallee() &&
6195 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006196 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006197 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006198
Douglas Gregora16548e2009-08-11 05:31:07 +00006199 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6200 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006201 Callee.get(),
6202 First.get(),
6203 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006204}
Mike Stump11289f42009-09-09 15:08:12 +00006205
Douglas Gregora16548e2009-08-11 05:31:07 +00006206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006207ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006208TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6209 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006210}
Mike Stump11289f42009-09-09 15:08:12 +00006211
Douglas Gregora16548e2009-08-11 05:31:07 +00006212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006213ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006214TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6215 // Transform the callee.
6216 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6217 if (Callee.isInvalid())
6218 return ExprError();
6219
6220 // Transform exec config.
6221 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6222 if (EC.isInvalid())
6223 return ExprError();
6224
6225 // Transform arguments.
6226 bool ArgChanged = false;
6227 ASTOwningVector<Expr*> Args(SemaRef);
6228 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6229 &ArgChanged))
6230 return ExprError();
6231
6232 if (!getDerived().AlwaysRebuild() &&
6233 Callee.get() == E->getCallee() &&
6234 !ArgChanged)
6235 return SemaRef.Owned(E);
6236
6237 // FIXME: Wrong source location information for the '('.
6238 SourceLocation FakeLParenLoc
6239 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6240 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6241 move_arg(Args),
6242 E->getRParenLoc(), EC.get());
6243}
6244
6245template<typename Derived>
6246ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006247TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006248 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6249 if (!Type)
6250 return ExprError();
6251
John McCalldadc5752010-08-24 06:29:42 +00006252 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006253 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006254 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006255 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006256
Douglas Gregora16548e2009-08-11 05:31:07 +00006257 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006258 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006259 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006260 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006261
Douglas Gregora16548e2009-08-11 05:31:07 +00006262 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006263 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006264 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6265 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6266 SourceLocation FakeRParenLoc
6267 = SemaRef.PP.getLocForEndOfToken(
6268 E->getSubExpr()->getSourceRange().getEnd());
6269 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006270 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006271 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006272 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006273 FakeRAngleLoc,
6274 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006275 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006276 FakeRParenLoc);
6277}
Mike Stump11289f42009-09-09 15:08:12 +00006278
Douglas Gregora16548e2009-08-11 05:31:07 +00006279template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006280ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006281TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6282 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006283}
Mike Stump11289f42009-09-09 15:08:12 +00006284
6285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006286ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006287TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6288 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006289}
6290
Douglas Gregora16548e2009-08-11 05:31:07 +00006291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006292ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006293TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006294 CXXReinterpretCastExpr *E) {
6295 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006296}
Mike Stump11289f42009-09-09 15:08:12 +00006297
Douglas Gregora16548e2009-08-11 05:31:07 +00006298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006299ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006300TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6301 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006302}
Mike Stump11289f42009-09-09 15:08:12 +00006303
Douglas Gregora16548e2009-08-11 05:31:07 +00006304template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006305ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006306TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006307 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006308 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6309 if (!Type)
6310 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006311
John McCalldadc5752010-08-24 06:29:42 +00006312 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006313 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006314 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006316
Douglas Gregora16548e2009-08-11 05:31:07 +00006317 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006318 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006319 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006320 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006321
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006322 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006323 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006324 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006325 E->getRParenLoc());
6326}
Mike Stump11289f42009-09-09 15:08:12 +00006327
Douglas Gregora16548e2009-08-11 05:31:07 +00006328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006329ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006330TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006331 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006332 TypeSourceInfo *TInfo
6333 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6334 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006335 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006336
Douglas Gregora16548e2009-08-11 05:31:07 +00006337 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006338 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006339 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006340
Douglas Gregor9da64192010-04-26 22:37:10 +00006341 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6342 E->getLocStart(),
6343 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006344 E->getLocEnd());
6345 }
Mike Stump11289f42009-09-09 15:08:12 +00006346
Douglas Gregora16548e2009-08-11 05:31:07 +00006347 // We don't know whether the expression is potentially evaluated until
6348 // after we perform semantic analysis, so the expression is potentially
6349 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006350 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006351 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006352
John McCalldadc5752010-08-24 06:29:42 +00006353 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006354 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006356
Douglas Gregora16548e2009-08-11 05:31:07 +00006357 if (!getDerived().AlwaysRebuild() &&
6358 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006359 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006360
Douglas Gregor9da64192010-04-26 22:37:10 +00006361 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6362 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006363 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006364 E->getLocEnd());
6365}
6366
6367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006368ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006369TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6370 if (E->isTypeOperand()) {
6371 TypeSourceInfo *TInfo
6372 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6373 if (!TInfo)
6374 return ExprError();
6375
6376 if (!getDerived().AlwaysRebuild() &&
6377 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006378 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006379
6380 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6381 E->getLocStart(),
6382 TInfo,
6383 E->getLocEnd());
6384 }
6385
6386 // We don't know whether the expression is potentially evaluated until
6387 // after we perform semantic analysis, so the expression is potentially
6388 // potentially evaluated.
6389 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6390
6391 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6392 if (SubExpr.isInvalid())
6393 return ExprError();
6394
6395 if (!getDerived().AlwaysRebuild() &&
6396 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006397 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006398
6399 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6400 E->getLocStart(),
6401 SubExpr.get(),
6402 E->getLocEnd());
6403}
6404
6405template<typename Derived>
6406ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006407TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006408 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006409}
Mike Stump11289f42009-09-09 15:08:12 +00006410
Douglas Gregora16548e2009-08-11 05:31:07 +00006411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006412ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006413TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006414 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006415 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006416}
Mike Stump11289f42009-09-09 15:08:12 +00006417
Douglas Gregora16548e2009-08-11 05:31:07 +00006418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006420TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006421 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6422 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6423 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006424
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006425 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006426 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006427
Douglas Gregorb15af892010-01-07 23:12:05 +00006428 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006429}
Mike Stump11289f42009-09-09 15:08:12 +00006430
Douglas Gregora16548e2009-08-11 05:31:07 +00006431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006432ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006433TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006434 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006435 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006436 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006437
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 if (!getDerived().AlwaysRebuild() &&
6439 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006440 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006441
John McCallb268a282010-08-23 23:25:46 +00006442 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006443}
Mike Stump11289f42009-09-09 15:08:12 +00006444
Douglas Gregora16548e2009-08-11 05:31:07 +00006445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006446ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006447TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006448 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006449 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6450 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006451 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006452 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006453
Chandler Carruth794da4c2010-02-08 06:42:49 +00006454 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006455 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006456 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006457
Douglas Gregor033f6752009-12-23 23:03:06 +00006458 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006459}
Mike Stump11289f42009-09-09 15:08:12 +00006460
Douglas Gregora16548e2009-08-11 05:31:07 +00006461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006462ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006463TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6464 CXXScalarValueInitExpr *E) {
6465 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6466 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006467 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006468
Douglas Gregora16548e2009-08-11 05:31:07 +00006469 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006470 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006471 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006472
Douglas Gregor2b88c112010-09-08 00:15:04 +00006473 return getDerived().RebuildCXXScalarValueInitExpr(T,
6474 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006475 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006476}
Mike Stump11289f42009-09-09 15:08:12 +00006477
Douglas Gregora16548e2009-08-11 05:31:07 +00006478template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006479ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006480TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006481 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006482 TypeSourceInfo *AllocTypeInfo
6483 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6484 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006485 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006486
Douglas Gregora16548e2009-08-11 05:31:07 +00006487 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006488 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006489 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006490 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006491
Douglas Gregora16548e2009-08-11 05:31:07 +00006492 // Transform the placement arguments (if any).
6493 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006494 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006495 if (getDerived().TransformExprs(E->getPlacementArgs(),
6496 E->getNumPlacementArgs(), true,
6497 PlacementArgs, &ArgumentChanged))
6498 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006499
Douglas Gregorebe10102009-08-20 07:17:43 +00006500 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006501 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006502 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6503 ConstructorArgs, &ArgumentChanged))
6504 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006505
Douglas Gregord2d9da02010-02-26 00:38:10 +00006506 // Transform constructor, new operator, and delete operator.
6507 CXXConstructorDecl *Constructor = 0;
6508 if (E->getConstructor()) {
6509 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006510 getDerived().TransformDecl(E->getLocStart(),
6511 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006512 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006513 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006514 }
6515
6516 FunctionDecl *OperatorNew = 0;
6517 if (E->getOperatorNew()) {
6518 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006519 getDerived().TransformDecl(E->getLocStart(),
6520 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006521 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006522 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006523 }
6524
6525 FunctionDecl *OperatorDelete = 0;
6526 if (E->getOperatorDelete()) {
6527 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006528 getDerived().TransformDecl(E->getLocStart(),
6529 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006530 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006531 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006532 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006533
Douglas Gregora16548e2009-08-11 05:31:07 +00006534 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006535 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006536 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006537 Constructor == E->getConstructor() &&
6538 OperatorNew == E->getOperatorNew() &&
6539 OperatorDelete == E->getOperatorDelete() &&
6540 !ArgumentChanged) {
6541 // Mark any declarations we need as referenced.
6542 // FIXME: instantiation-specific.
6543 if (Constructor)
6544 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6545 if (OperatorNew)
6546 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6547 if (OperatorDelete)
6548 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006549 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006550 }
Mike Stump11289f42009-09-09 15:08:12 +00006551
Douglas Gregor0744ef62010-09-07 21:49:58 +00006552 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006553 if (!ArraySize.get()) {
6554 // If no array size was specified, but the new expression was
6555 // instantiated with an array type (e.g., "new T" where T is
6556 // instantiated with "int[4]"), extract the outer bound from the
6557 // array type as our array size. We do this with constant and
6558 // dependently-sized array types.
6559 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6560 if (!ArrayT) {
6561 // Do nothing
6562 } else if (const ConstantArrayType *ConsArrayT
6563 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006564 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006565 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6566 ConsArrayT->getSize(),
6567 SemaRef.Context.getSizeType(),
6568 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006569 AllocType = ConsArrayT->getElementType();
6570 } else if (const DependentSizedArrayType *DepArrayT
6571 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6572 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006573 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006574 AllocType = DepArrayT->getElementType();
6575 }
6576 }
6577 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006578
Douglas Gregora16548e2009-08-11 05:31:07 +00006579 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6580 E->isGlobalNew(),
6581 /*FIXME:*/E->getLocStart(),
6582 move_arg(PlacementArgs),
6583 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006584 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006585 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006586 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006587 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006588 /*FIXME:*/E->getLocStart(),
6589 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006590 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006591}
Mike Stump11289f42009-09-09 15:08:12 +00006592
Douglas Gregora16548e2009-08-11 05:31:07 +00006593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006594ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006595TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006596 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006597 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006598 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006599
Douglas Gregord2d9da02010-02-26 00:38:10 +00006600 // Transform the delete operator, if known.
6601 FunctionDecl *OperatorDelete = 0;
6602 if (E->getOperatorDelete()) {
6603 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006604 getDerived().TransformDecl(E->getLocStart(),
6605 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006606 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006607 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006608 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006609
Douglas Gregora16548e2009-08-11 05:31:07 +00006610 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006611 Operand.get() == E->getArgument() &&
6612 OperatorDelete == E->getOperatorDelete()) {
6613 // Mark any declarations we need as referenced.
6614 // FIXME: instantiation-specific.
6615 if (OperatorDelete)
6616 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006617
6618 if (!E->getArgument()->isTypeDependent()) {
6619 QualType Destroyed = SemaRef.Context.getBaseElementType(
6620 E->getDestroyedType());
6621 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6622 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6623 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6624 SemaRef.LookupDestructor(Record));
6625 }
6626 }
6627
John McCallc3007a22010-10-26 07:05:15 +00006628 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006629 }
Mike Stump11289f42009-09-09 15:08:12 +00006630
Douglas Gregora16548e2009-08-11 05:31:07 +00006631 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6632 E->isGlobalDelete(),
6633 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006634 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006635}
Mike Stump11289f42009-09-09 15:08:12 +00006636
Douglas Gregora16548e2009-08-11 05:31:07 +00006637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006638ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006639TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006640 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006641 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006642 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006644
John McCallba7bf592010-08-24 05:47:05 +00006645 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006646 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006647 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006648 E->getOperatorLoc(),
6649 E->isArrow()? tok::arrow : tok::period,
6650 ObjectTypePtr,
6651 MayBePseudoDestructor);
6652 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006653 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006654
John McCallba7bf592010-08-24 05:47:05 +00006655 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006656 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6657 if (QualifierLoc) {
6658 QualifierLoc
6659 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6660 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006661 return ExprError();
6662 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006663 CXXScopeSpec SS;
6664 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006665
Douglas Gregor678f90d2010-02-25 01:56:36 +00006666 PseudoDestructorTypeStorage Destroyed;
6667 if (E->getDestroyedTypeInfo()) {
6668 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006669 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006670 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006671 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006672 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006673 Destroyed = DestroyedTypeInfo;
6674 } else if (ObjectType->isDependentType()) {
6675 // We aren't likely to be able to resolve the identifier down to a type
6676 // now anyway, so just retain the identifier.
6677 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6678 E->getDestroyedTypeLoc());
6679 } else {
6680 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006681 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006682 *E->getDestroyedTypeIdentifier(),
6683 E->getDestroyedTypeLoc(),
6684 /*Scope=*/0,
6685 SS, ObjectTypePtr,
6686 false);
6687 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006688 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006689
Douglas Gregor678f90d2010-02-25 01:56:36 +00006690 Destroyed
6691 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6692 E->getDestroyedTypeLoc());
6693 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006694
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006695 TypeSourceInfo *ScopeTypeInfo = 0;
6696 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006697 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006698 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006699 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006700 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006701
John McCallb268a282010-08-23 23:25:46 +00006702 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006703 E->getOperatorLoc(),
6704 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006705 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006706 ScopeTypeInfo,
6707 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006708 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006709 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006710}
Mike Stump11289f42009-09-09 15:08:12 +00006711
Douglas Gregorad8a3362009-09-04 17:36:40 +00006712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006713ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006714TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006715 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006716 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6717
6718 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6719 Sema::LookupOrdinaryName);
6720
6721 // Transform all the decls.
6722 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6723 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006724 NamedDecl *InstD = static_cast<NamedDecl*>(
6725 getDerived().TransformDecl(Old->getNameLoc(),
6726 *I));
John McCall84d87672009-12-10 09:41:52 +00006727 if (!InstD) {
6728 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6729 // This can happen because of dependent hiding.
6730 if (isa<UsingShadowDecl>(*I))
6731 continue;
6732 else
John McCallfaf5fb42010-08-26 23:41:50 +00006733 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006734 }
John McCalle66edc12009-11-24 19:00:30 +00006735
6736 // Expand using declarations.
6737 if (isa<UsingDecl>(InstD)) {
6738 UsingDecl *UD = cast<UsingDecl>(InstD);
6739 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6740 E = UD->shadow_end(); I != E; ++I)
6741 R.addDecl(*I);
6742 continue;
6743 }
6744
6745 R.addDecl(InstD);
6746 }
6747
6748 // Resolve a kind, but don't do any further analysis. If it's
6749 // ambiguous, the callee needs to deal with it.
6750 R.resolveKind();
6751
6752 // Rebuild the nested-name qualifier, if present.
6753 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006754 if (Old->getQualifierLoc()) {
6755 NestedNameSpecifierLoc QualifierLoc
6756 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6757 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006758 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006759
Douglas Gregor0da1d432011-02-28 20:01:57 +00006760 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006761 }
6762
Douglas Gregor9262f472010-04-27 18:19:34 +00006763 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006764 CXXRecordDecl *NamingClass
6765 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6766 Old->getNameLoc(),
6767 Old->getNamingClass()));
6768 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006769 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006770
Douglas Gregorda7be082010-04-27 16:10:10 +00006771 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006772 }
6773
6774 // If we have no template arguments, it's a normal declaration name.
6775 if (!Old->hasExplicitTemplateArgs())
6776 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6777
6778 // If we have template arguments, rebuild them, then rebuild the
6779 // templateid expression.
6780 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006781 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6782 Old->getNumTemplateArgs(),
6783 TransArgs))
6784 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006785
6786 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6787 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006788}
Mike Stump11289f42009-09-09 15:08:12 +00006789
Douglas Gregora16548e2009-08-11 05:31:07 +00006790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006791ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006792TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006793 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6794 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006795 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006796
Douglas Gregora16548e2009-08-11 05:31:07 +00006797 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006798 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006799 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006800
Mike Stump11289f42009-09-09 15:08:12 +00006801 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006802 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006803 T,
6804 E->getLocEnd());
6805}
Mike Stump11289f42009-09-09 15:08:12 +00006806
Douglas Gregora16548e2009-08-11 05:31:07 +00006807template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006808ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006809TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6810 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6811 if (!LhsT)
6812 return ExprError();
6813
6814 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6815 if (!RhsT)
6816 return ExprError();
6817
6818 if (!getDerived().AlwaysRebuild() &&
6819 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6820 return SemaRef.Owned(E);
6821
6822 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6823 E->getLocStart(),
6824 LhsT, RhsT,
6825 E->getLocEnd());
6826}
6827
6828template<typename Derived>
6829ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006830TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006831 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006832 NestedNameSpecifierLoc QualifierLoc
6833 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6834 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006835 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006836
John McCall31f82722010-11-12 08:19:04 +00006837 // TODO: If this is a conversion-function-id, verify that the
6838 // destination type name (if present) resolves the same way after
6839 // instantiation as it did in the local scope.
6840
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006841 DeclarationNameInfo NameInfo
6842 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6843 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006844 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006845
John McCalle66edc12009-11-24 19:00:30 +00006846 if (!E->hasExplicitTemplateArgs()) {
6847 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006848 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006849 // Note: it is sufficient to compare the Name component of NameInfo:
6850 // if name has not changed, DNLoc has not changed either.
6851 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006852 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006853
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006854 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006855 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006856 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006857 }
John McCall6b51f282009-11-23 01:53:49 +00006858
6859 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006860 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6861 E->getNumTemplateArgs(),
6862 TransArgs))
6863 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006864
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006865 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006866 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006867 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006868}
6869
6870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006871ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006872TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006873 // CXXConstructExprs are always implicit, so when we have a
6874 // 1-argument construction we just transform that argument.
6875 if (E->getNumArgs() == 1 ||
6876 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6877 return getDerived().TransformExpr(E->getArg(0));
6878
Douglas Gregora16548e2009-08-11 05:31:07 +00006879 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6880
6881 QualType T = getDerived().TransformType(E->getType());
6882 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006883 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006884
6885 CXXConstructorDecl *Constructor
6886 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006887 getDerived().TransformDecl(E->getLocStart(),
6888 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006889 if (!Constructor)
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 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006893 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006894 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6895 &ArgumentChanged))
6896 return ExprError();
6897
Douglas Gregora16548e2009-08-11 05:31:07 +00006898 if (!getDerived().AlwaysRebuild() &&
6899 T == E->getType() &&
6900 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006901 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006902 // Mark the constructor as referenced.
6903 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006904 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006905 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006906 }
Mike Stump11289f42009-09-09 15:08:12 +00006907
Douglas Gregordb121ba2009-12-14 16:27:04 +00006908 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6909 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006910 move_arg(Args),
6911 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006912 E->getConstructionKind(),
6913 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006914}
Mike Stump11289f42009-09-09 15:08:12 +00006915
Douglas Gregora16548e2009-08-11 05:31:07 +00006916/// \brief Transform a C++ temporary-binding expression.
6917///
Douglas Gregor363b1512009-12-24 18:51:59 +00006918/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6919/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006922TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006923 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006924}
Mike Stump11289f42009-09-09 15:08:12 +00006925
John McCall5d413782010-12-06 08:20:24 +00006926/// \brief Transform a C++ expression that contains cleanups that should
6927/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006928///
John McCall5d413782010-12-06 08:20:24 +00006929/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006930/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006931template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006932ExprResult
John McCall5d413782010-12-06 08:20:24 +00006933TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006934 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006935}
Mike Stump11289f42009-09-09 15:08:12 +00006936
Douglas Gregora16548e2009-08-11 05:31:07 +00006937template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006938ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006939TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006940 CXXTemporaryObjectExpr *E) {
6941 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6942 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006943 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006944
Douglas Gregora16548e2009-08-11 05:31:07 +00006945 CXXConstructorDecl *Constructor
6946 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006947 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006948 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006949 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006950 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006951
Douglas Gregora16548e2009-08-11 05:31:07 +00006952 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006953 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006954 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006955 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6956 &ArgumentChanged))
6957 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006958
Douglas Gregora16548e2009-08-11 05:31:07 +00006959 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006960 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006961 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006962 !ArgumentChanged) {
6963 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006964 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006965 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006966 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006967
6968 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6969 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006970 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006971 E->getLocEnd());
6972}
Mike Stump11289f42009-09-09 15:08:12 +00006973
Douglas Gregora16548e2009-08-11 05:31:07 +00006974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006975ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006976TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006977 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006978 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6979 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006980 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006981
Douglas Gregora16548e2009-08-11 05:31:07 +00006982 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006983 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006984 Args.reserve(E->arg_size());
6985 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6986 &ArgumentChanged))
6987 return ExprError();
6988
Douglas Gregora16548e2009-08-11 05:31:07 +00006989 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006990 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006991 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006992 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006993
Douglas Gregora16548e2009-08-11 05:31:07 +00006994 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006995 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006996 E->getLParenLoc(),
6997 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006998 E->getRParenLoc());
6999}
Mike Stump11289f42009-09-09 15:08:12 +00007000
Douglas Gregora16548e2009-08-11 05:31:07 +00007001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007002ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007003TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007004 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007005 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007006 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007007 Expr *OldBase;
7008 QualType BaseType;
7009 QualType ObjectType;
7010 if (!E->isImplicitAccess()) {
7011 OldBase = E->getBase();
7012 Base = getDerived().TransformExpr(OldBase);
7013 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007014 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007015
John McCall2d74de92009-12-01 22:10:20 +00007016 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007017 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007018 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007019 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007020 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007021 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007022 ObjectTy,
7023 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007024 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007025 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007026
John McCallba7bf592010-08-24 05:47:05 +00007027 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007028 BaseType = ((Expr*) Base.get())->getType();
7029 } else {
7030 OldBase = 0;
7031 BaseType = getDerived().TransformType(E->getBaseType());
7032 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7033 }
Mike Stump11289f42009-09-09 15:08:12 +00007034
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007035 // Transform the first part of the nested-name-specifier that qualifies
7036 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007037 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007038 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007039 E->getFirstQualifierFoundInScope(),
7040 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007041
Douglas Gregore16af532011-02-28 18:50:33 +00007042 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007043 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007044 QualifierLoc
7045 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7046 ObjectType,
7047 FirstQualifierInScope);
7048 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007049 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007050 }
Mike Stump11289f42009-09-09 15:08:12 +00007051
John McCall31f82722010-11-12 08:19:04 +00007052 // TODO: If this is a conversion-function-id, verify that the
7053 // destination type name (if present) resolves the same way after
7054 // instantiation as it did in the local scope.
7055
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007056 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007057 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007058 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007059 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007060
John McCall2d74de92009-12-01 22:10:20 +00007061 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007062 // This is a reference to a member without an explicitly-specified
7063 // template argument list. Optimize for this common case.
7064 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007065 Base.get() == OldBase &&
7066 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007067 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007068 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007069 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007070 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007071
John McCallb268a282010-08-23 23:25:46 +00007072 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007073 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007074 E->isArrow(),
7075 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007076 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007077 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007078 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007079 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007080 }
7081
John McCall6b51f282009-11-23 01:53:49 +00007082 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007083 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7084 E->getNumTemplateArgs(),
7085 TransArgs))
7086 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007087
John McCallb268a282010-08-23 23:25:46 +00007088 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007089 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007090 E->isArrow(),
7091 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007092 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007093 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007094 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007095 &TransArgs);
7096}
7097
7098template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007099ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007100TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007101 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007102 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007103 QualType BaseType;
7104 if (!Old->isImplicitAccess()) {
7105 Base = getDerived().TransformExpr(Old->getBase());
7106 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007107 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007108 BaseType = ((Expr*) Base.get())->getType();
7109 } else {
7110 BaseType = getDerived().TransformType(Old->getBaseType());
7111 }
John McCall10eae182009-11-30 22:42:35 +00007112
Douglas Gregor0da1d432011-02-28 20:01:57 +00007113 NestedNameSpecifierLoc QualifierLoc;
7114 if (Old->getQualifierLoc()) {
7115 QualifierLoc
7116 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7117 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007118 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007119 }
7120
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007121 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007122 Sema::LookupOrdinaryName);
7123
7124 // Transform all the decls.
7125 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7126 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007127 NamedDecl *InstD = static_cast<NamedDecl*>(
7128 getDerived().TransformDecl(Old->getMemberLoc(),
7129 *I));
John McCall84d87672009-12-10 09:41:52 +00007130 if (!InstD) {
7131 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7132 // This can happen because of dependent hiding.
7133 if (isa<UsingShadowDecl>(*I))
7134 continue;
7135 else
John McCallfaf5fb42010-08-26 23:41:50 +00007136 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007137 }
John McCall10eae182009-11-30 22:42:35 +00007138
7139 // Expand using declarations.
7140 if (isa<UsingDecl>(InstD)) {
7141 UsingDecl *UD = cast<UsingDecl>(InstD);
7142 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7143 E = UD->shadow_end(); I != E; ++I)
7144 R.addDecl(*I);
7145 continue;
7146 }
7147
7148 R.addDecl(InstD);
7149 }
7150
7151 R.resolveKind();
7152
Douglas Gregor9262f472010-04-27 18:19:34 +00007153 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007154 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007155 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007156 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007157 Old->getMemberLoc(),
7158 Old->getNamingClass()));
7159 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007160 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007161
Douglas Gregorda7be082010-04-27 16:10:10 +00007162 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007163 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007164
John McCall10eae182009-11-30 22:42:35 +00007165 TemplateArgumentListInfo TransArgs;
7166 if (Old->hasExplicitTemplateArgs()) {
7167 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7168 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007169 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7170 Old->getNumTemplateArgs(),
7171 TransArgs))
7172 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007173 }
John McCall38836f02010-01-15 08:34:02 +00007174
7175 // FIXME: to do this check properly, we will need to preserve the
7176 // first-qualifier-in-scope here, just in case we had a dependent
7177 // base (and therefore couldn't do the check) and a
7178 // nested-name-qualifier (and therefore could do the lookup).
7179 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007180
John McCallb268a282010-08-23 23:25:46 +00007181 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007182 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007183 Old->getOperatorLoc(),
7184 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007185 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007186 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007187 R,
7188 (Old->hasExplicitTemplateArgs()
7189 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007190}
7191
7192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007193ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007194TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7195 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7196 if (SubExpr.isInvalid())
7197 return ExprError();
7198
7199 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007200 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007201
7202 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7203}
7204
7205template<typename Derived>
7206ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007207TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007208 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7209 if (Pattern.isInvalid())
7210 return ExprError();
7211
7212 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7213 return SemaRef.Owned(E);
7214
Douglas Gregorb8840002011-01-14 21:20:45 +00007215 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7216 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007217}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007218
7219template<typename Derived>
7220ExprResult
7221TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7222 // If E is not value-dependent, then nothing will change when we transform it.
7223 // Note: This is an instantiation-centric view.
7224 if (!E->isValueDependent())
7225 return SemaRef.Owned(E);
7226
7227 // Note: None of the implementations of TryExpandParameterPacks can ever
7228 // produce a diagnostic when given only a single unexpanded parameter pack,
7229 // so
7230 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7231 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007232 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007233 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007234 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7235 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007236 ShouldExpand, RetainExpansion,
7237 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007238 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007239
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007240 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007241 return SemaRef.Owned(E);
7242
7243 // We now know the length of the parameter pack, so build a new expression
7244 // that stores that length.
7245 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7246 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007247 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007248}
7249
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007250template<typename Derived>
7251ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007252TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7253 SubstNonTypeTemplateParmPackExpr *E) {
7254 // Default behavior is to do nothing with this transformation.
7255 return SemaRef.Owned(E);
7256}
7257
7258template<typename Derived>
7259ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007260TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007261 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007262}
7263
Mike Stump11289f42009-09-09 15:08:12 +00007264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007265ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007266TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007267 TypeSourceInfo *EncodedTypeInfo
7268 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7269 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007270 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007271
Douglas Gregora16548e2009-08-11 05:31:07 +00007272 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007273 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007274 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007275
7276 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007277 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007278 E->getRParenLoc());
7279}
Mike Stump11289f42009-09-09 15:08:12 +00007280
Douglas Gregora16548e2009-08-11 05:31:07 +00007281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007282ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007283TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007284 // Transform arguments.
7285 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007286 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007287 Args.reserve(E->getNumArgs());
7288 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7289 &ArgChanged))
7290 return ExprError();
7291
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007292 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7293 // Class message: transform the receiver type.
7294 TypeSourceInfo *ReceiverTypeInfo
7295 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7296 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007297 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007298
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007299 // If nothing changed, just retain the existing message send.
7300 if (!getDerived().AlwaysRebuild() &&
7301 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007302 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007303
7304 // Build a new class message send.
7305 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7306 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007307 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007308 E->getMethodDecl(),
7309 E->getLeftLoc(),
7310 move_arg(Args),
7311 E->getRightLoc());
7312 }
7313
7314 // Instance message: transform the receiver
7315 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7316 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007317 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007318 = getDerived().TransformExpr(E->getInstanceReceiver());
7319 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007320 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007321
7322 // If nothing changed, just retain the existing message send.
7323 if (!getDerived().AlwaysRebuild() &&
7324 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007325 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007326
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007327 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007328 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007329 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007330 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007331 E->getMethodDecl(),
7332 E->getLeftLoc(),
7333 move_arg(Args),
7334 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007335}
7336
Mike Stump11289f42009-09-09 15:08:12 +00007337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007338ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007339TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007340 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007341}
7342
Mike Stump11289f42009-09-09 15:08:12 +00007343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007344ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007345TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007346 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007347}
7348
Mike Stump11289f42009-09-09 15:08:12 +00007349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007351TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007352 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007353 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007354 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007355 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007356
7357 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007358
Douglas Gregord51d90d2010-04-26 20:11:03 +00007359 // If nothing changed, just retain the existing expression.
7360 if (!getDerived().AlwaysRebuild() &&
7361 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007362 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007363
John McCallb268a282010-08-23 23:25:46 +00007364 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007365 E->getLocation(),
7366 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007367}
7368
Mike Stump11289f42009-09-09 15:08:12 +00007369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007370ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007371TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007372 // 'super' and types never change. Property never changes. Just
7373 // retain the existing expression.
7374 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007375 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007376
Douglas Gregor9faee212010-04-26 20:47:02 +00007377 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007378 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007379 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007380 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007381
Douglas Gregor9faee212010-04-26 20:47:02 +00007382 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007383
Douglas Gregor9faee212010-04-26 20:47:02 +00007384 // If nothing changed, just retain the existing expression.
7385 if (!getDerived().AlwaysRebuild() &&
7386 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007387 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007388
John McCallb7bd14f2010-12-02 01:19:52 +00007389 if (E->isExplicitProperty())
7390 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7391 E->getExplicitProperty(),
7392 E->getLocation());
7393
7394 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7395 E->getType(),
7396 E->getImplicitPropertyGetter(),
7397 E->getImplicitPropertySetter(),
7398 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007399}
7400
Mike Stump11289f42009-09-09 15:08:12 +00007401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007402ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007403TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007404 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007405 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007406 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007407 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007408
Douglas Gregord51d90d2010-04-26 20:11:03 +00007409 // If nothing changed, just retain the existing expression.
7410 if (!getDerived().AlwaysRebuild() &&
7411 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007412 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007413
John McCallb268a282010-08-23 23:25:46 +00007414 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007415 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007416}
7417
Mike Stump11289f42009-09-09 15:08:12 +00007418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007420TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007421 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007422 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007423 SubExprs.reserve(E->getNumSubExprs());
7424 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7425 SubExprs, &ArgumentChanged))
7426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007427
Douglas Gregora16548e2009-08-11 05:31:07 +00007428 if (!getDerived().AlwaysRebuild() &&
7429 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007430 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007431
Douglas Gregora16548e2009-08-11 05:31:07 +00007432 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7433 move_arg(SubExprs),
7434 E->getRParenLoc());
7435}
7436
Mike Stump11289f42009-09-09 15:08:12 +00007437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007438ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007439TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007440 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007441
John McCall490112f2011-02-04 18:33:18 +00007442 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7443 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7444
7445 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7446 llvm::SmallVector<ParmVarDecl*, 4> params;
7447 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007448
7449 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007450 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7451 oldBlock->param_begin(),
7452 oldBlock->param_size(),
7453 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007454 return true;
John McCall490112f2011-02-04 18:33:18 +00007455
7456 const FunctionType *exprFunctionType = E->getFunctionType();
7457 QualType exprResultType = exprFunctionType->getResultType();
7458 if (!exprResultType.isNull()) {
7459 if (!exprResultType->isDependentType())
7460 blockScope->ReturnType = exprResultType;
7461 else if (exprResultType != getSema().Context.DependentTy)
7462 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007463 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007464
7465 // If the return type has not been determined yet, leave it as a dependent
7466 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007467 if (blockScope->ReturnType.isNull())
7468 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007469
7470 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007471 if (blockScope->ReturnType->isObjCObjectType()) {
7472 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007473 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007474 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007475 return ExprError();
7476 }
John McCall3882ace2011-01-05 12:14:39 +00007477
John McCall490112f2011-02-04 18:33:18 +00007478 QualType functionType = getDerived().RebuildFunctionProtoType(
7479 blockScope->ReturnType,
7480 paramTypes.data(),
7481 paramTypes.size(),
7482 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007483 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007484 exprFunctionType->getExtInfo());
7485 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007486
7487 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007488 if (!params.empty())
7489 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007490
7491 // If the return type wasn't explicitly set, it will have been marked as a
7492 // dependent type (DependentTy); clear out the return type setting so
7493 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007494 if (blockScope->ReturnType == getSema().Context.DependentTy)
7495 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007496
John McCall3882ace2011-01-05 12:14:39 +00007497 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007498 StmtResult body = getDerived().TransformStmt(E->getBody());
7499 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007500 return ExprError();
7501
John McCall490112f2011-02-04 18:33:18 +00007502#ifndef NDEBUG
7503 // In builds with assertions, make sure that we captured everything we
7504 // captured before.
7505
7506 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7507
7508 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7509 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007510 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007511
7512 // Ignore parameter packs.
7513 if (isa<ParmVarDecl>(oldCapture) &&
7514 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7515 continue;
7516
7517 VarDecl *newCapture =
7518 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7519 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007520 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007521 }
7522#endif
7523
7524 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7525 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007526}
7527
Mike Stump11289f42009-09-09 15:08:12 +00007528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007529ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007530TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007531 ValueDecl *ND
7532 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7533 E->getDecl()));
7534 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007535 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007536
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007537 if (!getDerived().AlwaysRebuild() &&
7538 ND == E->getDecl()) {
7539 // Mark it referenced in the new context regardless.
7540 // FIXME: this is a bit instantiation-specific.
7541 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7542
John McCallc3007a22010-10-26 07:05:15 +00007543 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007544 }
7545
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007546 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007547 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007548 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007549}
Mike Stump11289f42009-09-09 15:08:12 +00007550
Douglas Gregora16548e2009-08-11 05:31:07 +00007551//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007552// Type reconstruction
7553//===----------------------------------------------------------------------===//
7554
Mike Stump11289f42009-09-09 15:08:12 +00007555template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007556QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7557 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007558 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007559 getDerived().getBaseEntity());
7560}
7561
Mike Stump11289f42009-09-09 15:08:12 +00007562template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007563QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7564 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007565 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007566 getDerived().getBaseEntity());
7567}
7568
Mike Stump11289f42009-09-09 15:08:12 +00007569template<typename Derived>
7570QualType
John McCall70dd5f62009-10-30 00:06:24 +00007571TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7572 bool WrittenAsLValue,
7573 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007574 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007575 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007576}
7577
7578template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007579QualType
John McCall70dd5f62009-10-30 00:06:24 +00007580TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7581 QualType ClassType,
7582 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007583 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007584 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007585}
7586
7587template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007588QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007589TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7590 ArrayType::ArraySizeModifier SizeMod,
7591 const llvm::APInt *Size,
7592 Expr *SizeExpr,
7593 unsigned IndexTypeQuals,
7594 SourceRange BracketsRange) {
7595 if (SizeExpr || !Size)
7596 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7597 IndexTypeQuals, BracketsRange,
7598 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007599
7600 QualType Types[] = {
7601 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7602 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7603 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007604 };
7605 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7606 QualType SizeType;
7607 for (unsigned I = 0; I != NumTypes; ++I)
7608 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7609 SizeType = Types[I];
7610 break;
7611 }
Mike Stump11289f42009-09-09 15:08:12 +00007612
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007613 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7614 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007615 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007616 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007617 getDerived().getBaseEntity());
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>
Mike Stump11289f42009-09-09 15:08:12 +00007621QualType
7622TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007623 ArrayType::ArraySizeModifier SizeMod,
7624 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007625 unsigned IndexTypeQuals,
7626 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007627 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007628 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007629}
7630
7631template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007632QualType
Mike Stump11289f42009-09-09 15:08:12 +00007633TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007634 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007635 unsigned IndexTypeQuals,
7636 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007637 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007638 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007639}
Mike Stump11289f42009-09-09 15:08:12 +00007640
Douglas Gregord6ff3322009-08-04 16:50:30 +00007641template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007642QualType
7643TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007644 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007645 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007646 unsigned IndexTypeQuals,
7647 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007648 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007649 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007650 IndexTypeQuals, BracketsRange);
7651}
7652
7653template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007654QualType
7655TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007656 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007657 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007658 unsigned IndexTypeQuals,
7659 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007660 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007661 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007662 IndexTypeQuals, BracketsRange);
7663}
7664
7665template<typename Derived>
7666QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007667 unsigned NumElements,
7668 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007669 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007670 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007671}
Mike Stump11289f42009-09-09 15:08:12 +00007672
Douglas Gregord6ff3322009-08-04 16:50:30 +00007673template<typename Derived>
7674QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7675 unsigned NumElements,
7676 SourceLocation AttributeLoc) {
7677 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7678 NumElements, true);
7679 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007680 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7681 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007682 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007683}
Mike Stump11289f42009-09-09 15:08:12 +00007684
Douglas Gregord6ff3322009-08-04 16:50:30 +00007685template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007686QualType
7687TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007688 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007689 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007690 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007691}
Mike Stump11289f42009-09-09 15:08:12 +00007692
Douglas Gregord6ff3322009-08-04 16:50:30 +00007693template<typename Derived>
7694QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007695 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007696 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007697 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007698 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007699 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007700 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007701 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007702 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007703 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007704 getDerived().getBaseEntity(),
7705 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007706}
Mike Stump11289f42009-09-09 15:08:12 +00007707
Douglas Gregord6ff3322009-08-04 16:50:30 +00007708template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007709QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7710 return SemaRef.Context.getFunctionNoProtoType(T);
7711}
7712
7713template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007714QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7715 assert(D && "no decl found");
7716 if (D->isInvalidDecl()) return QualType();
7717
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007718 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007719 TypeDecl *Ty;
7720 if (isa<UsingDecl>(D)) {
7721 UsingDecl *Using = cast<UsingDecl>(D);
7722 assert(Using->isTypeName() &&
7723 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7724
7725 // A valid resolved using typename decl points to exactly one type decl.
7726 assert(++Using->shadow_begin() == Using->shadow_end());
7727 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007728
John McCallb96ec562009-12-04 22:46:56 +00007729 } else {
7730 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7731 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7732 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7733 }
7734
7735 return SemaRef.Context.getTypeDeclType(Ty);
7736}
7737
7738template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007739QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7740 SourceLocation Loc) {
7741 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007742}
7743
7744template<typename Derived>
7745QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7746 return SemaRef.Context.getTypeOfType(Underlying);
7747}
7748
7749template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007750QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7751 SourceLocation Loc) {
7752 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007753}
7754
7755template<typename Derived>
7756QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007757 TemplateName Template,
7758 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007759 const TemplateArgumentListInfo &TemplateArgs) {
7760 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007761}
Mike Stump11289f42009-09-09 15:08:12 +00007762
Douglas Gregor1135c352009-08-06 05:28:30 +00007763template<typename Derived>
7764NestedNameSpecifier *
7765TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7766 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007767 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007768 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007769 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007770 CXXScopeSpec SS;
7771 // FIXME: The source location information is all wrong.
Douglas Gregor869ad452011-02-24 17:54:50 +00007772 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
Douglas Gregor90c99722011-02-24 00:17:56 +00007773 if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(),
7774 /*FIXME:*/Range.getEnd(),
7775 ObjectType, false,
7776 SS, FirstQualifierInScope,
7777 false))
7778 return 0;
7779
7780 return SS.getScopeRep();
Douglas Gregor1135c352009-08-06 05:28:30 +00007781}
7782
7783template<typename Derived>
7784NestedNameSpecifier *
7785TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7786 SourceRange Range,
7787 NamespaceDecl *NS) {
7788 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7789}
7790
7791template<typename Derived>
7792NestedNameSpecifier *
7793TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7794 SourceRange Range,
Douglas Gregor7b26ff92011-02-24 02:36:08 +00007795 NamespaceAliasDecl *Alias) {
7796 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias);
7797}
7798
7799template<typename Derived>
7800NestedNameSpecifier *
7801TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7802 SourceRange Range,
Douglas Gregor1135c352009-08-06 05:28:30 +00007803 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007804 QualType T) {
7805 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007806 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007807 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007808 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7809 T.getTypePtr());
7810 }
Mike Stump11289f42009-09-09 15:08:12 +00007811
Douglas Gregor1135c352009-08-06 05:28:30 +00007812 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7813 return 0;
7814}
Mike Stump11289f42009-09-09 15:08:12 +00007815
Douglas Gregor71dc5092009-08-06 06:41:21 +00007816template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007817TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007818TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007819 bool TemplateKW,
7820 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007821 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007822 Template);
7823}
7824
7825template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007826TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007827TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
7828 const IdentifierInfo &Name,
7829 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00007830 QualType ObjectType,
7831 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00007832 UnqualifiedId TemplateName;
7833 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00007834 Sema::TemplateTy Template;
7835 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007836 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007837 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00007838 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00007839 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007840 /*EnteringContext=*/false,
7841 Template);
John McCall31f82722010-11-12 08:19:04 +00007842 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007843}
Mike Stump11289f42009-09-09 15:08:12 +00007844
Douglas Gregora16548e2009-08-11 05:31:07 +00007845template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007846TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00007847TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007848 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00007849 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007850 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00007851 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00007852 // FIXME: Bogus location information.
7853 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
7854 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007855 Sema::TemplateTy Template;
7856 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00007857 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007858 SS,
7859 Name,
John McCallba7bf592010-08-24 05:47:05 +00007860 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007861 /*EnteringContext=*/false,
7862 Template);
7863 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007864}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007865
Douglas Gregor71395fa2009-11-04 00:56:37 +00007866template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007867ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007868TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7869 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007870 Expr *OrigCallee,
7871 Expr *First,
7872 Expr *Second) {
7873 Expr *Callee = OrigCallee->IgnoreParenCasts();
7874 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007875
Douglas Gregora16548e2009-08-11 05:31:07 +00007876 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007877 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007878 if (!First->getType()->isOverloadableType() &&
7879 !Second->getType()->isOverloadableType())
7880 return getSema().CreateBuiltinArraySubscriptExpr(First,
7881 Callee->getLocStart(),
7882 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007883 } else if (Op == OO_Arrow) {
7884 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007885 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7886 } else if (Second == 0 || isPostIncDec) {
7887 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007888 // The argument is not of overloadable type, so try to create a
7889 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007890 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007891 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007892
John McCallb268a282010-08-23 23:25:46 +00007893 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007894 }
7895 } else {
John McCallb268a282010-08-23 23:25:46 +00007896 if (!First->getType()->isOverloadableType() &&
7897 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007898 // Neither of the arguments is an overloadable type, so try to
7899 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007900 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007901 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007902 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007903 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007905
Douglas Gregora16548e2009-08-11 05:31:07 +00007906 return move(Result);
7907 }
7908 }
Mike Stump11289f42009-09-09 15:08:12 +00007909
7910 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007911 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007912 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007913
John McCallb268a282010-08-23 23:25:46 +00007914 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007915 assert(ULE->requiresADL());
7916
7917 // FIXME: Do we have to check
7918 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007919 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007920 } else {
John McCallb268a282010-08-23 23:25:46 +00007921 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007922 }
Mike Stump11289f42009-09-09 15:08:12 +00007923
Douglas Gregora16548e2009-08-11 05:31:07 +00007924 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007925 Expr *Args[2] = { First, Second };
7926 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007927
Douglas Gregora16548e2009-08-11 05:31:07 +00007928 // Create the overloaded operator invocation for unary operators.
7929 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007930 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007931 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007932 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007933 }
Mike Stump11289f42009-09-09 15:08:12 +00007934
Sebastian Redladba46e2009-10-29 20:17:01 +00007935 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007936 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007937 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007938 First,
7939 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007940
Douglas Gregora16548e2009-08-11 05:31:07 +00007941 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007942 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007943 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007944 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7945 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007946 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007947
Mike Stump11289f42009-09-09 15:08:12 +00007948 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007949}
Mike Stump11289f42009-09-09 15:08:12 +00007950
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007952ExprResult
John McCallb268a282010-08-23 23:25:46 +00007953TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007954 SourceLocation OperatorLoc,
7955 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00007956 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007957 TypeSourceInfo *ScopeType,
7958 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007959 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007960 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00007961 QualType BaseType = Base->getType();
7962 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007963 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007964 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007965 !BaseType->getAs<PointerType>()->getPointeeType()
7966 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007967 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007968 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007969 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007970 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007971 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007972 /*FIXME?*/true);
7973 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007974
Douglas Gregor678f90d2010-02-25 01:56:36 +00007975 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007976 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7977 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7978 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7979 NameInfo.setNamedTypeInfo(DestroyedType);
7980
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007981 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007982
John McCallb268a282010-08-23 23:25:46 +00007983 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007984 OperatorLoc, isArrow,
7985 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007986 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007987 /*TemplateArgs*/ 0);
7988}
7989
Douglas Gregord6ff3322009-08-04 16:50:30 +00007990} // end namespace clang
7991
7992#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H