blob: 641df425ad174e8fd1cd5e45845e2d031bc7f629 [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 Gregord6ff3322009-08-04 16:50:30 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
71/// 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 Gregord6ff3322009-08-04 16:50:30 +0000378 /// \brief Transform the given nested-name-specifier.
379 ///
Mike Stump11289f42009-09-09 15:08:12 +0000380 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// nested-name-specifier. Subclasses may override this function to provide
382 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000384 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000385 QualType ObjectType = QualType(),
386 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000387
Douglas Gregor14454802011-02-25 02:25:35 +0000388 /// \brief Transform the given nested-name-specifier with source-location
389 /// information.
390 ///
391 /// By default, transforms all of the types and declarations within the
392 /// nested-name-specifier. Subclasses may override this function to provide
393 /// alternate behavior.
394 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
395 NestedNameSpecifierLoc NNS,
396 QualType ObjectType = QualType(),
397 NamedDecl *FirstQualifierInScope = 0);
398
Douglas Gregorf816bd72009-09-03 22:13:48 +0000399 /// \brief Transform the given declaration name.
400 ///
401 /// By default, transforms the types of conversion function, constructor,
402 /// and destructor names and then (if needed) rebuilds the declaration name.
403 /// Identifiers and selectors are returned unmodified. Sublcasses may
404 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000405 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000406 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000407
Douglas Gregord6ff3322009-08-04 16:50:30 +0000408 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000409 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000410 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000412 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000413 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000414 QualType ObjectType = QualType(),
415 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregord6ff3322009-08-04 16:50:30 +0000417 /// \brief Transform the given template argument.
418 ///
Mike Stump11289f42009-09-09 15:08:12 +0000419 /// By default, this operation transforms the type, expression, or
420 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000421 /// new template argument from the transformed result. Subclasses may
422 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000423 ///
424 /// Returns true if there was an error.
425 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
426 TemplateArgumentLoc &Output);
427
Douglas Gregor62e06f22010-12-20 17:31:10 +0000428 /// \brief Transform the given set of template arguments.
429 ///
430 /// By default, this operation transforms all of the template arguments
431 /// in the input set using \c TransformTemplateArgument(), and appends
432 /// the transformed arguments to the output list.
433 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000434 /// Note that this overload of \c TransformTemplateArguments() is merely
435 /// a convenience function. Subclasses that wish to override this behavior
436 /// should override the iterator-based member template version.
437 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000438 /// \param Inputs The set of template arguments to be transformed.
439 ///
440 /// \param NumInputs The number of template arguments in \p Inputs.
441 ///
442 /// \param Outputs The set of transformed template arguments output by this
443 /// routine.
444 ///
445 /// Returns true if an error occurred.
446 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
447 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000448 TemplateArgumentListInfo &Outputs) {
449 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
450 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000451
452 /// \brief Transform the given set of template arguments.
453 ///
454 /// By default, this operation transforms all of the template arguments
455 /// in the input set using \c TransformTemplateArgument(), and appends
456 /// the transformed arguments to the output list.
457 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000458 /// \param First An iterator to the first template argument.
459 ///
460 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000461 ///
462 /// \param Outputs The set of transformed template arguments output by this
463 /// routine.
464 ///
465 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000466 template<typename InputIterator>
467 bool TransformTemplateArguments(InputIterator First,
468 InputIterator Last,
469 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000470
John McCall0ad16662009-10-29 08:12:44 +0000471 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
472 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
473 TemplateArgumentLoc &ArgLoc);
474
John McCallbcd03502009-12-07 02:54:59 +0000475 /// \brief Fakes up a TypeSourceInfo for a type.
476 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
477 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000478 getDerived().getBaseLocation());
479 }
Mike Stump11289f42009-09-09 15:08:12 +0000480
John McCall550e0c22009-10-21 00:40:46 +0000481#define ABSTRACT_TYPELOC(CLASS, PARENT)
482#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000483 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000484#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000485
John McCall31f82722010-11-12 08:19:04 +0000486 QualType
487 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
488 TemplateSpecializationTypeLoc TL,
489 TemplateName Template);
490
491 QualType
492 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
493 DependentTemplateSpecializationTypeLoc TL,
494 NestedNameSpecifier *Prefix);
495
John McCall58f10c32010-03-11 09:03:00 +0000496 /// \brief Transforms the parameters of a function type into the
497 /// given vectors.
498 ///
499 /// The result vectors should be kept in sync; null entries in the
500 /// variables vector are acceptable.
501 ///
502 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000503 bool TransformFunctionTypeParams(SourceLocation Loc,
504 ParmVarDecl **Params, unsigned NumParams,
505 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000506 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000507 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000508
509 /// \brief Transforms a single function-type parameter. Return null
510 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000511 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
512 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000513
John McCall31f82722010-11-12 08:19:04 +0000514 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000515
John McCalldadc5752010-08-24 06:29:42 +0000516 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
517 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000518
Douglas Gregorebe10102009-08-20 07:17:43 +0000519#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000520 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000521#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000522 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000523#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000524#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000525
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 /// \brief Build a new pointer type given its pointee type.
527 ///
528 /// By default, performs semantic analysis when building the pointer type.
529 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000530 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531
532 /// \brief Build a new block pointer type given its pointee type.
533 ///
Mike Stump11289f42009-09-09 15:08:12 +0000534 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000535 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000536 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000537
John McCall70dd5f62009-10-30 00:06:24 +0000538 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000539 ///
John McCall70dd5f62009-10-30 00:06:24 +0000540 /// By default, performs semantic analysis when building the
541 /// reference type. Subclasses may override this routine to provide
542 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000543 ///
John McCall70dd5f62009-10-30 00:06:24 +0000544 /// \param LValue whether the type was written with an lvalue sigil
545 /// or an rvalue sigil.
546 QualType RebuildReferenceType(QualType ReferentType,
547 bool LValue,
548 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000549
Douglas Gregord6ff3322009-08-04 16:50:30 +0000550 /// \brief Build a new member pointer type given the pointee type and the
551 /// class type it refers into.
552 ///
553 /// By default, performs semantic analysis when building the member pointer
554 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000555 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
556 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000557
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558 /// \brief Build a new array type given the element type, size
559 /// modifier, size of the array (if known), size expression, and index type
560 /// qualifiers.
561 ///
562 /// By default, performs semantic analysis when building the array type.
563 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000564 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565 QualType RebuildArrayType(QualType ElementType,
566 ArrayType::ArraySizeModifier SizeMod,
567 const llvm::APInt *Size,
568 Expr *SizeExpr,
569 unsigned IndexTypeQuals,
570 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000571
Douglas Gregord6ff3322009-08-04 16:50:30 +0000572 /// \brief Build a new constant array type given the element type, size
573 /// modifier, (known) size of the array, and index type qualifiers.
574 ///
575 /// By default, performs semantic analysis when building the array type.
576 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000577 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578 ArrayType::ArraySizeModifier SizeMod,
579 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000580 unsigned IndexTypeQuals,
581 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000582
Douglas Gregord6ff3322009-08-04 16:50:30 +0000583 /// \brief Build a new incomplete array type given the element type, size
584 /// modifier, and index type qualifiers.
585 ///
586 /// By default, performs semantic analysis when building the array type.
587 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000588 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000589 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000592
Mike Stump11289f42009-09-09 15:08:12 +0000593 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000594 /// size modifier, size expression, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000598 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000600 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
603
Mike Stump11289f42009-09-09 15:08:12 +0000604 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000605 /// size modifier, size expression, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000609 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000611 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000612 unsigned IndexTypeQuals,
613 SourceRange BracketsRange);
614
615 /// \brief Build a new vector type given the element type and
616 /// number of elements.
617 ///
618 /// By default, performs semantic analysis when building the vector type.
619 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000620 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000621 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000622
Douglas Gregord6ff3322009-08-04 16:50:30 +0000623 /// \brief Build a new extended vector type given the element type and
624 /// number of elements.
625 ///
626 /// By default, performs semantic analysis when building the vector type.
627 /// Subclasses may override this routine to provide different behavior.
628 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
629 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000630
631 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000632 /// given the element type and number of elements.
633 ///
634 /// By default, performs semantic analysis when building the vector type.
635 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000636 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000637 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000638 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000639
Douglas Gregord6ff3322009-08-04 16:50:30 +0000640 /// \brief Build a new function type.
641 ///
642 /// By default, performs semantic analysis when building the function type.
643 /// Subclasses may override this routine to provide different behavior.
644 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000645 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000646 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000647 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000648 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000649 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000650
John McCall550e0c22009-10-21 00:40:46 +0000651 /// \brief Build a new unprototyped function type.
652 QualType RebuildFunctionNoProtoType(QualType ResultType);
653
John McCallb96ec562009-12-04 22:46:56 +0000654 /// \brief Rebuild an unresolved typename type, given the decl that
655 /// the UnresolvedUsingTypenameDecl was transformed to.
656 QualType RebuildUnresolvedUsingType(Decl *D);
657
Douglas Gregord6ff3322009-08-04 16:50:30 +0000658 /// \brief Build a new typedef type.
659 QualType RebuildTypedefType(TypedefDecl *Typedef) {
660 return SemaRef.Context.getTypeDeclType(Typedef);
661 }
662
663 /// \brief Build a new class/struct/union type.
664 QualType RebuildRecordType(RecordDecl *Record) {
665 return SemaRef.Context.getTypeDeclType(Record);
666 }
667
668 /// \brief Build a new Enum type.
669 QualType RebuildEnumType(EnumDecl *Enum) {
670 return SemaRef.Context.getTypeDeclType(Enum);
671 }
John McCallfcc33b02009-09-05 00:15:47 +0000672
Mike Stump11289f42009-09-09 15:08:12 +0000673 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
675 /// By default, performs semantic analysis when building the typeof type.
676 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000677 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678
Mike Stump11289f42009-09-09 15:08:12 +0000679 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 ///
681 /// By default, builds a new TypeOfType with the given underlying type.
682 QualType RebuildTypeOfType(QualType Underlying);
683
Mike Stump11289f42009-09-09 15:08:12 +0000684 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 ///
686 /// By default, performs semantic analysis when building the decltype type.
687 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000688 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000689
Richard Smith30482bc2011-02-20 03:19:35 +0000690 /// \brief Build a new C++0x auto type.
691 ///
692 /// By default, builds a new AutoType with the given deduced type.
693 QualType RebuildAutoType(QualType Deduced) {
694 return SemaRef.Context.getAutoType(Deduced);
695 }
696
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697 /// \brief Build a new template specialization type.
698 ///
699 /// By default, performs semantic analysis when building the template
700 /// specialization type. Subclasses may override this routine to provide
701 /// different behavior.
702 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000703 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000704 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000705
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000706 /// \brief Build a new parenthesized type.
707 ///
708 /// By default, builds a new ParenType type from the inner type.
709 /// Subclasses may override this routine to provide different behavior.
710 QualType RebuildParenType(QualType InnerType) {
711 return SemaRef.Context.getParenType(InnerType);
712 }
713
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 /// \brief Build a new qualified name type.
715 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000716 /// By default, builds a new ElaboratedType type from the keyword,
717 /// the nested-name-specifier and the named type.
718 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000719 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
720 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000721 NestedNameSpecifier *NNS, QualType Named) {
722 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000723 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724
725 /// \brief Build a new typename type that refers to a template-id.
726 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000727 /// By default, builds a new DependentNameType type from the
728 /// nested-name-specifier and the given type. Subclasses may override
729 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000730 QualType RebuildDependentTemplateSpecializationType(
731 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000732 NestedNameSpecifier *Qualifier,
733 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000734 const IdentifierInfo *Name,
735 SourceLocation NameLoc,
736 const TemplateArgumentListInfo &Args) {
737 // Rebuild the template name.
738 // TODO: avoid TemplateName abstraction
739 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000740 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000741 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000742
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000743 if (InstName.isNull())
744 return QualType();
745
John McCallc392f372010-06-11 00:33:02 +0000746 // If it's still dependent, make a dependent specialization.
747 if (InstName.getAsDependentTemplateName())
748 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000749 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000750
751 // Otherwise, make an elaborated type wrapping a non-dependent
752 // specialization.
753 QualType T =
754 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
755 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000756
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000757 // NOTE: NNS is already recorded in template specialization type T.
758 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000759 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000760
761 /// \brief Build a new typename type that refers to an identifier.
762 ///
763 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000764 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000765 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000766 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000767 NestedNameSpecifier *NNS,
768 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000769 SourceLocation KeywordLoc,
770 SourceRange NNSRange,
771 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000772 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +0000773 SS.MakeTrivial(SemaRef.Context, NNS, NNSRange);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000774
Douglas Gregore677daf2010-03-31 22:19:08 +0000775 if (NNS->isDependent()) {
776 // If the name is still dependent, just build a new dependent name type.
777 if (!SemaRef.computeDeclContext(SS))
778 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
779 }
780
Abramo Bagnara6150c882010-05-11 21:36:43 +0000781 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000782 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
783 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000784
785 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
786
Abramo Bagnarad7548482010-05-19 21:37:53 +0000787 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000788 // into a non-dependent elaborated-type-specifier. Find the tag we're
789 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000790 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000791 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
792 if (!DC)
793 return QualType();
794
John McCallbf8c5192010-05-27 06:40:31 +0000795 if (SemaRef.RequireCompleteDeclContext(SS, DC))
796 return QualType();
797
Douglas Gregore677daf2010-03-31 22:19:08 +0000798 TagDecl *Tag = 0;
799 SemaRef.LookupQualifiedName(Result, DC);
800 switch (Result.getResultKind()) {
801 case LookupResult::NotFound:
802 case LookupResult::NotFoundInCurrentInstantiation:
803 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000804
Douglas Gregore677daf2010-03-31 22:19:08 +0000805 case LookupResult::Found:
806 Tag = Result.getAsSingle<TagDecl>();
807 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000808
Douglas Gregore677daf2010-03-31 22:19:08 +0000809 case LookupResult::FoundOverloaded:
810 case LookupResult::FoundUnresolvedValue:
811 llvm_unreachable("Tag lookup cannot find non-tags");
812 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000813
Douglas Gregore677daf2010-03-31 22:19:08 +0000814 case LookupResult::Ambiguous:
815 // Let the LookupResult structure handle ambiguities.
816 return QualType();
817 }
818
819 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000820 // Check where the name exists but isn't a tag type and use that to emit
821 // better diagnostics.
822 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
823 SemaRef.LookupQualifiedName(Result, DC);
824 switch (Result.getResultKind()) {
825 case LookupResult::Found:
826 case LookupResult::FoundOverloaded:
827 case LookupResult::FoundUnresolvedValue: {
828 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
829 unsigned Kind = 0;
830 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
831 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
832 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
833 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
834 break;
835 }
836 default:
837 // FIXME: Would be nice to highlight just the source range.
838 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
839 << Kind << Id << DC;
840 break;
841 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000842 return QualType();
843 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000844
Abramo Bagnarad7548482010-05-19 21:37:53 +0000845 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
846 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000847 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
848 return QualType();
849 }
850
851 // Build the elaborated-type-specifier type.
852 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000853 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000854 }
Mike Stump11289f42009-09-09 15:08:12 +0000855
Douglas Gregor822d0302011-01-12 17:07:58 +0000856 /// \brief Build a new pack expansion type.
857 ///
858 /// By default, builds a new PackExpansionType type from the given pattern.
859 /// Subclasses may override this routine to provide different behavior.
860 QualType RebuildPackExpansionType(QualType Pattern,
861 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000862 SourceLocation EllipsisLoc,
863 llvm::Optional<unsigned> NumExpansions) {
864 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
865 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000866 }
867
Douglas Gregor1135c352009-08-06 05:28:30 +0000868 /// \brief Build a new nested-name-specifier given the prefix and an
869 /// identifier that names the next step in the nested-name-specifier.
870 ///
871 /// By default, performs semantic analysis when building the new
872 /// nested-name-specifier. Subclasses may override this routine to provide
873 /// different behavior.
874 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
875 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000876 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000877 QualType ObjectType,
878 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000879
880 /// \brief Build a new nested-name-specifier given the prefix and the
881 /// namespace named in the next step in the nested-name-specifier.
882 ///
883 /// By default, performs semantic analysis when building the new
884 /// nested-name-specifier. Subclasses may override this routine to provide
885 /// different behavior.
886 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
887 SourceRange Range,
888 NamespaceDecl *NS);
889
890 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor7b26ff92011-02-24 02:36:08 +0000891 /// namespace alias named in the next step in the nested-name-specifier.
892 ///
893 /// By default, performs semantic analysis when building the new
894 /// nested-name-specifier. Subclasses may override this routine to provide
895 /// different behavior.
896 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
897 SourceRange Range,
898 NamespaceAliasDecl *Alias);
899
900 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor1135c352009-08-06 05:28:30 +0000901 /// type named in the next step in the nested-name-specifier.
902 ///
903 /// By default, performs semantic analysis when building the new
904 /// nested-name-specifier. Subclasses may override this routine to provide
905 /// different behavior.
906 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
907 SourceRange Range,
908 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000909 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000910
911 /// \brief Build a new template name given a nested name specifier, a flag
912 /// indicating whether the "template" keyword was provided, and the template
913 /// that the template name refers to.
914 ///
915 /// By default, builds the new template name directly. Subclasses may override
916 /// this routine to provide different behavior.
917 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
918 bool TemplateKW,
919 TemplateDecl *Template);
920
Douglas Gregor71dc5092009-08-06 06:41:21 +0000921 /// \brief Build a new template name given a nested name specifier and the
922 /// name that is referred to as a template.
923 ///
924 /// By default, performs semantic analysis to determine whether the name can
925 /// be resolved to a specific template, then builds the appropriate kind of
926 /// template name. Subclasses may override this routine to provide different
927 /// behavior.
928 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000929 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000930 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000931 QualType ObjectType,
932 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000933
Douglas Gregor71395fa2009-11-04 00:56:37 +0000934 /// \brief Build a new template name given a nested name specifier and the
935 /// overloaded operator name that is referred to as a template.
936 ///
937 /// By default, performs semantic analysis to determine whether the name can
938 /// be resolved to a specific template, then builds the appropriate kind of
939 /// template name. Subclasses may override this routine to provide different
940 /// behavior.
941 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
942 OverloadedOperatorKind Operator,
943 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000944
945 /// \brief Build a new template name given a template template parameter pack
946 /// and the
947 ///
948 /// By default, performs semantic analysis to determine whether the name can
949 /// be resolved to a specific template, then builds the appropriate kind of
950 /// template name. Subclasses may override this routine to provide different
951 /// behavior.
952 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
953 const TemplateArgument &ArgPack) {
954 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
955 }
956
Douglas Gregorebe10102009-08-20 07:17:43 +0000957 /// \brief Build a new compound statement.
958 ///
959 /// By default, performs semantic analysis to build the new statement.
960 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000961 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000962 MultiStmtArg Statements,
963 SourceLocation RBraceLoc,
964 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000965 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000966 IsStmtExpr);
967 }
968
969 /// \brief Build a new case statement.
970 ///
971 /// By default, performs semantic analysis to build the new statement.
972 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000973 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000974 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000975 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000976 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000977 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000978 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000979 ColonLoc);
980 }
Mike Stump11289f42009-09-09 15:08:12 +0000981
Douglas Gregorebe10102009-08-20 07:17:43 +0000982 /// \brief Attach the body to a new case statement.
983 ///
984 /// By default, performs semantic analysis to build the new statement.
985 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000986 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000987 getSema().ActOnCaseStmtBody(S, Body);
988 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 }
Mike Stump11289f42009-09-09 15:08:12 +0000990
Douglas Gregorebe10102009-08-20 07:17:43 +0000991 /// \brief Build a new default statement.
992 ///
993 /// By default, performs semantic analysis to build the new statement.
994 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000995 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000996 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000997 Stmt *SubStmt) {
998 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000999 /*CurScope=*/0);
1000 }
Mike Stump11289f42009-09-09 15:08:12 +00001001
Douglas Gregorebe10102009-08-20 07:17:43 +00001002 /// \brief Build a new label statement.
1003 ///
1004 /// By default, performs semantic analysis to build the new statement.
1005 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001006 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1007 SourceLocation ColonLoc, Stmt *SubStmt) {
1008 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001009 }
Mike Stump11289f42009-09-09 15:08:12 +00001010
Douglas Gregorebe10102009-08-20 07:17:43 +00001011 /// \brief Build a new "if" statement.
1012 ///
1013 /// By default, performs semantic analysis to build the new statement.
1014 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001015 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001016 VarDecl *CondVar, Stmt *Then,
1017 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001018 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
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 Start building a new switch 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 RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001026 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001027 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001028 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001029 }
Mike Stump11289f42009-09-09 15:08:12 +00001030
Douglas Gregorebe10102009-08-20 07:17:43 +00001031 /// \brief Attach the body to the switch statement.
1032 ///
1033 /// By default, performs semantic analysis to build the new statement.
1034 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001035 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001036 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001037 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001038 }
1039
1040 /// \brief Build a new while statement.
1041 ///
1042 /// By default, performs semantic analysis to build the new statement.
1043 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001044 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1045 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001046 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001047 }
Mike Stump11289f42009-09-09 15:08:12 +00001048
Douglas Gregorebe10102009-08-20 07:17:43 +00001049 /// \brief Build a new do-while statement.
1050 ///
1051 /// By default, performs semantic analysis to build the new statement.
1052 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001053 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001054 SourceLocation WhileLoc, SourceLocation LParenLoc,
1055 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001056 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1057 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001058 }
1059
1060 /// \brief Build a new for statement.
1061 ///
1062 /// By default, performs semantic analysis to build the new statement.
1063 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001064 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1065 Stmt *Init, Sema::FullExprArg Cond,
1066 VarDecl *CondVar, Sema::FullExprArg Inc,
1067 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001068 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001069 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregorebe10102009-08-20 07:17:43 +00001072 /// \brief Build a new goto statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001076 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1077 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001078 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 }
1080
1081 /// \brief Build a new indirect goto statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001085 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001086 SourceLocation StarLoc,
1087 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001088 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001089 }
Mike Stump11289f42009-09-09 15:08:12 +00001090
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 /// \brief Build a new return statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001095 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001096 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001097 }
Mike Stump11289f42009-09-09 15:08:12 +00001098
Douglas Gregorebe10102009-08-20 07:17:43 +00001099 /// \brief Build a new declaration statement.
1100 ///
1101 /// By default, performs semantic analysis to build the new statement.
1102 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001103 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001104 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001106 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1107 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001108 }
Mike Stump11289f42009-09-09 15:08:12 +00001109
Anders Carlssonaaeef072010-01-24 05:50:09 +00001110 /// \brief Build a new inline asm statement.
1111 ///
1112 /// By default, performs semantic analysis to build the new statement.
1113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001114 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001115 bool IsSimple,
1116 bool IsVolatile,
1117 unsigned NumOutputs,
1118 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001119 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001120 MultiExprArg Constraints,
1121 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001122 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001123 MultiExprArg Clobbers,
1124 SourceLocation RParenLoc,
1125 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001126 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001127 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001128 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001129 RParenLoc, MSAsm);
1130 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001131
1132 /// \brief Build a new Objective-C @try statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001136 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001137 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001138 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001139 Stmt *Finally) {
1140 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1141 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001142 }
1143
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001144 /// \brief Rebuild an Objective-C exception declaration.
1145 ///
1146 /// By default, performs semantic analysis to build the new declaration.
1147 /// Subclasses may override this routine to provide different behavior.
1148 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1149 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001150 return getSema().BuildObjCExceptionDecl(TInfo, T,
1151 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001152 ExceptionDecl->getLocation());
1153 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001154
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001155 /// \brief Build a new Objective-C @catch statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001159 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001160 SourceLocation RParenLoc,
1161 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001162 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001163 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001164 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001165 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001166
Douglas Gregor306de2f2010-04-22 23:59:56 +00001167 /// \brief Build a new Objective-C @finally statement.
1168 ///
1169 /// By default, performs semantic analysis to build the new statement.
1170 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001171 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001172 Stmt *Body) {
1173 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001174 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001175
Douglas Gregor6148de72010-04-22 22:01:21 +00001176 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001177 ///
1178 /// By default, performs semantic analysis to build the new statement.
1179 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001180 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001181 Expr *Operand) {
1182 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001183 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001184
Douglas Gregor6148de72010-04-22 22:01:21 +00001185 /// \brief Build a new Objective-C @synchronized statement.
1186 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001187 /// 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 RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001190 Expr *Object,
1191 Stmt *Body) {
1192 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1193 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001194 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001195
1196 /// \brief Build a new Objective-C fast enumeration statement.
1197 ///
1198 /// By default, performs semantic analysis to build the new statement.
1199 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001200 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001201 SourceLocation LParenLoc,
1202 Stmt *Element,
1203 Expr *Collection,
1204 SourceLocation RParenLoc,
1205 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001206 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001207 Element,
1208 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001209 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001210 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001211 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001212
Douglas Gregorebe10102009-08-20 07:17:43 +00001213 /// \brief Build a new C++ exception declaration.
1214 ///
1215 /// By default, performs semantic analysis to build the new decaration.
1216 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001217 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001218 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001220 SourceLocation Loc) {
1221 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 }
1223
1224 /// \brief Build a new C++ catch statement.
1225 ///
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001228 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001229 VarDecl *ExceptionDecl,
1230 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001231 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1232 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 }
Mike Stump11289f42009-09-09 15:08:12 +00001234
Douglas Gregorebe10102009-08-20 07:17:43 +00001235 /// \brief Build a new C++ try statement.
1236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001239 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001240 Stmt *TryBlock,
1241 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001242 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001243 }
Mike Stump11289f42009-09-09 15:08:12 +00001244
Douglas Gregora16548e2009-08-11 05:31:07 +00001245 /// \brief Build a new expression that references a declaration.
1246 ///
1247 /// By default, performs semantic analysis to build the new expression.
1248 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001249 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001250 LookupResult &R,
1251 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001252 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1253 }
1254
1255
1256 /// \brief Build a new expression that references a declaration.
1257 ///
1258 /// By default, performs semantic analysis to build the new expression.
1259 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001260 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001261 SourceRange QualifierRange,
1262 ValueDecl *VD,
1263 const DeclarationNameInfo &NameInfo,
1264 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001265 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00001266 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001267
1268 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001269
1270 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001271 }
Mike Stump11289f42009-09-09 15:08:12 +00001272
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001274 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001277 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001279 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 }
1281
Douglas Gregorad8a3362009-09-04 17:36:40 +00001282 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001283 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001284 /// By default, performs semantic analysis to build the new expression.
1285 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001286 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001287 SourceLocation OperatorLoc,
1288 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001289 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001290 SourceRange QualifierRange,
1291 TypeSourceInfo *ScopeType,
1292 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001293 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001294 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001295
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001297 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001300 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001301 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001302 Expr *SubExpr) {
1303 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 }
Mike Stump11289f42009-09-09 15:08:12 +00001305
Douglas Gregor882211c2010-04-28 22:16:22 +00001306 /// \brief Build a new builtin offsetof expression.
1307 ///
1308 /// By default, performs semantic analysis to build the new expression.
1309 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001310 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001311 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001312 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001313 unsigned NumComponents,
1314 SourceLocation RParenLoc) {
1315 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1316 NumComponents, RParenLoc);
1317 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001318
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001323 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001324 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001326 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001327 }
1328
Mike Stump11289f42009-09-09 15:08:12 +00001329 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001334 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001336 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001337 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001340
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 return move(Result);
1342 }
Mike Stump11289f42009-09-09 15:08:12 +00001343
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001345 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 /// By default, performs semantic analysis to build the new expression.
1347 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001348 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001350 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001352 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1353 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 RBracketLoc);
1355 }
1356
1357 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001358 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 /// By default, performs semantic analysis to build the new expression.
1360 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001361 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001363 SourceLocation RParenLoc,
1364 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001365 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001366 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 }
1368
1369 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001370 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001371 /// By default, performs semantic analysis to build the new expression.
1372 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001373 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001374 bool isArrow,
1375 NestedNameSpecifier *Qualifier,
1376 SourceRange QualifierRange,
1377 const DeclarationNameInfo &MemberNameInfo,
1378 ValueDecl *Member,
1379 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001380 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001381 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001382 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001383 // We have a reference to an unnamed field. This is always the
1384 // base of an anonymous struct/union member access, i.e. the
1385 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001386 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001387 assert(Member->getType()->isRecordType() &&
1388 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001389
John McCallb268a282010-08-23 23:25:46 +00001390 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001391 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001392 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001393
John McCall7decc9e2010-11-18 06:31:45 +00001394 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001395 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001396 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001397 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001398 cast<FieldDecl>(Member)->getType(),
1399 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001400 return getSema().Owned(ME);
1401 }
Mike Stump11289f42009-09-09 15:08:12 +00001402
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001403 CXXScopeSpec SS;
1404 if (Qualifier) {
Douglas Gregor869ad452011-02-24 17:54:50 +00001405 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001406 }
1407
John McCallb268a282010-08-23 23:25:46 +00001408 getSema().DefaultFunctionArrayConversion(Base);
1409 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001410
John McCall16df1e52010-03-30 21:47:33 +00001411 // FIXME: this involves duplicating earlier analysis in a lot of
1412 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001413 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001414 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001415 R.resolveKind();
1416
John McCallb268a282010-08-23 23:25:46 +00001417 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001418 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001419 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 }
Mike Stump11289f42009-09-09 15:08:12 +00001421
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001423 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 /// By default, performs semantic analysis to build the new expression.
1425 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001426 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001427 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001428 Expr *LHS, Expr *RHS) {
1429 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 }
1431
1432 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001433 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 /// By default, performs semantic analysis to build the new expression.
1435 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001436 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001437 SourceLocation QuestionLoc,
1438 Expr *LHS,
1439 SourceLocation ColonLoc,
1440 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001441 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1442 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001443 }
1444
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001446 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 /// By default, performs semantic analysis to build the new expression.
1448 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001449 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001450 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001452 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001453 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001454 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001455 }
Mike Stump11289f42009-09-09 15:08:12 +00001456
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001458 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001461 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001462 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001464 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001465 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001466 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 }
Mike Stump11289f42009-09-09 15:08:12 +00001468
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001470 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 /// By default, performs semantic analysis to build the new expression.
1472 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001473 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 SourceLocation OpLoc,
1475 SourceLocation AccessorLoc,
1476 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001477
John McCall10eae182009-11-30 22:42:35 +00001478 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001479 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001480 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001481 OpLoc, /*IsArrow*/ false,
1482 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001483 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001484 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 }
Mike Stump11289f42009-09-09 15:08:12 +00001486
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001488 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 /// By default, performs semantic analysis to build the new expression.
1490 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001491 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001493 SourceLocation RBraceLoc,
1494 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001495 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001496 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1497 if (Result.isInvalid() || ResultTy->isDependentType())
1498 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001499
Douglas Gregord3d93062009-11-09 17:16:50 +00001500 // Patch in the result type we were given, which may have been computed
1501 // when the initial InitListExpr was built.
1502 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1503 ILE->setType(ResultTy);
1504 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 }
Mike Stump11289f42009-09-09 15:08:12 +00001506
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001508 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 /// By default, performs semantic analysis to build the new expression.
1510 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001511 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 MultiExprArg ArrayExprs,
1513 SourceLocation EqualOrColonLoc,
1514 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001515 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001516 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001518 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001520 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001521
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 ArrayExprs.release();
1523 return move(Result);
1524 }
Mike Stump11289f42009-09-09 15:08:12 +00001525
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001527 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 /// By default, builds the implicit value initialization without performing
1529 /// any semantic analysis. Subclasses may override this routine to provide
1530 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001531 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1533 }
Mike Stump11289f42009-09-09 15:08:12 +00001534
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001536 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001539 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001540 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001541 SourceLocation RParenLoc) {
1542 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001543 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001544 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 }
1546
1547 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001548 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 /// By default, performs semantic analysis to build the new expression.
1550 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001551 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 MultiExprArg SubExprs,
1553 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001554 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001555 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 }
Mike Stump11289f42009-09-09 15:08:12 +00001557
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001559 ///
1560 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 /// rather than attempting to map the label statement itself.
1562 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001563 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001564 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001565 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 }
Mike Stump11289f42009-09-09 15:08:12 +00001567
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001569 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001572 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001573 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001575 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 }
Mike Stump11289f42009-09-09 15:08:12 +00001577
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 /// \brief Build a new __builtin_choose_expr expression.
1579 ///
1580 /// By default, performs semantic analysis to build the new expression.
1581 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001582 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001583 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 SourceLocation RParenLoc) {
1585 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001586 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 RParenLoc);
1588 }
Mike Stump11289f42009-09-09 15:08:12 +00001589
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 /// \brief Build a new overloaded operator call expression.
1591 ///
1592 /// By default, performs semantic analysis to build the new expression.
1593 /// The semantic analysis provides the behavior of template instantiation,
1594 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001595 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 /// argument-dependent lookup, etc. Subclasses may override this routine to
1597 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001598 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001600 Expr *Callee,
1601 Expr *First,
1602 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001603
1604 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 /// reinterpret_cast.
1606 ///
1607 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001608 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001610 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 Stmt::StmtClass Class,
1612 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001613 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 SourceLocation RAngleLoc,
1615 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001616 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 SourceLocation RParenLoc) {
1618 switch (Class) {
1619 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001620 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001621 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001622 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001623
1624 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001625 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001626 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001627 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001628
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001630 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001631 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001632 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001634
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001636 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001637 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001638 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001639
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 default:
1641 assert(false && "Invalid C++ named cast");
1642 break;
1643 }
Mike Stump11289f42009-09-09 15:08:12 +00001644
John McCallfaf5fb42010-08-26 23:41:50 +00001645 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 }
Mike Stump11289f42009-09-09 15:08:12 +00001647
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 /// \brief Build a new C++ static_cast expression.
1649 ///
1650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001652 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001654 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 SourceLocation RAngleLoc,
1656 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001657 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001659 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001660 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001661 SourceRange(LAngleLoc, RAngleLoc),
1662 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 }
1664
1665 /// \brief Build a new C++ dynamic_cast expression.
1666 ///
1667 /// By default, performs semantic analysis to build the new expression.
1668 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001669 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001671 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 SourceLocation RAngleLoc,
1673 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001674 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001676 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001677 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001678 SourceRange(LAngleLoc, RAngleLoc),
1679 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 }
1681
1682 /// \brief Build a new C++ reinterpret_cast expression.
1683 ///
1684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001686 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001688 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 SourceLocation RAngleLoc,
1690 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001691 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001693 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001694 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001695 SourceRange(LAngleLoc, RAngleLoc),
1696 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001697 }
1698
1699 /// \brief Build a new C++ const_cast expression.
1700 ///
1701 /// By default, performs semantic analysis to build the new expression.
1702 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001703 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001705 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 SourceLocation RAngleLoc,
1707 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001708 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001710 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001711 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001712 SourceRange(LAngleLoc, RAngleLoc),
1713 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 }
Mike Stump11289f42009-09-09 15:08:12 +00001715
Douglas Gregora16548e2009-08-11 05:31:07 +00001716 /// \brief Build a new C++ functional-style cast expression.
1717 ///
1718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001720 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1721 SourceLocation LParenLoc,
1722 Expr *Sub,
1723 SourceLocation RParenLoc) {
1724 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001725 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 RParenLoc);
1727 }
Mike Stump11289f42009-09-09 15:08:12 +00001728
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 /// \brief Build a new C++ typeid(type) expression.
1730 ///
1731 /// By default, performs semantic analysis to build the new expression.
1732 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001733 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001734 SourceLocation TypeidLoc,
1735 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001737 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001738 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 }
Mike Stump11289f42009-09-09 15:08:12 +00001740
Francois Pichet9f4f2072010-09-08 12:20:18 +00001741
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 /// \brief Build a new C++ typeid(expr) expression.
1743 ///
1744 /// By default, performs semantic analysis to build the new expression.
1745 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001746 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001747 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001748 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001750 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001751 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001752 }
1753
Francois Pichet9f4f2072010-09-08 12:20:18 +00001754 /// \brief Build a new C++ __uuidof(type) expression.
1755 ///
1756 /// By default, performs semantic analysis to build the new expression.
1757 /// Subclasses may override this routine to provide different behavior.
1758 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1759 SourceLocation TypeidLoc,
1760 TypeSourceInfo *Operand,
1761 SourceLocation RParenLoc) {
1762 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1763 RParenLoc);
1764 }
1765
1766 /// \brief Build a new C++ __uuidof(expr) expression.
1767 ///
1768 /// By default, performs semantic analysis to build the new expression.
1769 /// Subclasses may override this routine to provide different behavior.
1770 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1771 SourceLocation TypeidLoc,
1772 Expr *Operand,
1773 SourceLocation RParenLoc) {
1774 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1775 RParenLoc);
1776 }
1777
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 /// \brief Build a new C++ "this" expression.
1779 ///
1780 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001781 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001783 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001784 QualType ThisType,
1785 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001787 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1788 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 }
1790
1791 /// \brief Build a new C++ throw expression.
1792 ///
1793 /// By default, performs semantic analysis to build the new expression.
1794 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001795 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001796 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 }
1798
1799 /// \brief Build a new C++ default-argument expression.
1800 ///
1801 /// By default, builds a new default-argument expression, which does not
1802 /// require any semantic analysis. Subclasses may override this routine to
1803 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001805 ParmVarDecl *Param) {
1806 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1807 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 }
1809
1810 /// \brief Build a new C++ zero-initialization expression.
1811 ///
1812 /// By default, performs semantic analysis to build the new expression.
1813 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001814 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1815 SourceLocation LParenLoc,
1816 SourceLocation RParenLoc) {
1817 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001818 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001819 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 }
Mike Stump11289f42009-09-09 15:08:12 +00001821
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 /// \brief Build a new C++ "new" expression.
1823 ///
1824 /// By default, performs semantic analysis to build the new expression.
1825 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001826 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001827 bool UseGlobal,
1828 SourceLocation PlacementLParen,
1829 MultiExprArg PlacementArgs,
1830 SourceLocation PlacementRParen,
1831 SourceRange TypeIdParens,
1832 QualType AllocatedType,
1833 TypeSourceInfo *AllocatedTypeInfo,
1834 Expr *ArraySize,
1835 SourceLocation ConstructorLParen,
1836 MultiExprArg ConstructorArgs,
1837 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001838 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 PlacementLParen,
1840 move(PlacementArgs),
1841 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001842 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001843 AllocatedType,
1844 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001845 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 ConstructorLParen,
1847 move(ConstructorArgs),
1848 ConstructorRParen);
1849 }
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 /// \brief Build a new C++ "delete" expression.
1852 ///
1853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001856 bool IsGlobalDelete,
1857 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001858 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001859 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001860 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 }
Mike Stump11289f42009-09-09 15:08:12 +00001862
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 /// \brief Build a new unary type trait expression.
1864 ///
1865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001867 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001868 SourceLocation StartLoc,
1869 TypeSourceInfo *T,
1870 SourceLocation RParenLoc) {
1871 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001872 }
1873
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001874 /// \brief Build a new binary type trait expression.
1875 ///
1876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
1878 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1879 SourceLocation StartLoc,
1880 TypeSourceInfo *LhsT,
1881 TypeSourceInfo *RhsT,
1882 SourceLocation RParenLoc) {
1883 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1884 }
1885
Mike Stump11289f42009-09-09 15:08:12 +00001886 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001887 /// expression.
1888 ///
1889 /// By default, performs semantic analysis to build the new expression.
1890 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001891 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001893 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001894 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00001896 SS.MakeTrivial(SemaRef.Context, NNS, QualifierRange);
John McCalle66edc12009-11-24 19:00:30 +00001897
1898 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001899 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001900 *TemplateArgs);
1901
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001902 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 }
1904
1905 /// \brief Build a new template-id expression.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001909 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001910 LookupResult &R,
1911 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001912 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001913 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 }
1915
1916 /// \brief Build a new object-construction expression.
1917 ///
1918 /// By default, performs semantic analysis to build the new expression.
1919 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001920 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001921 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 CXXConstructorDecl *Constructor,
1923 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001924 MultiExprArg Args,
1925 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001926 CXXConstructExpr::ConstructionKind ConstructKind,
1927 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001928 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001929 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001930 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001931 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001932
Douglas Gregordb121ba2009-12-14 16:27:04 +00001933 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001934 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001935 RequiresZeroInit, ConstructKind,
1936 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 }
1938
1939 /// \brief Build a new object-construction expression.
1940 ///
1941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001943 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1944 SourceLocation LParenLoc,
1945 MultiExprArg Args,
1946 SourceLocation RParenLoc) {
1947 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 LParenLoc,
1949 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 RParenLoc);
1951 }
1952
1953 /// \brief Build a new object-construction expression.
1954 ///
1955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001957 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1958 SourceLocation LParenLoc,
1959 MultiExprArg Args,
1960 SourceLocation RParenLoc) {
1961 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 LParenLoc,
1963 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 RParenLoc);
1965 }
Mike Stump11289f42009-09-09 15:08:12 +00001966
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 /// \brief Build a new member reference expression.
1968 ///
1969 /// By default, performs semantic analysis to build the new expression.
1970 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001971 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001972 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 bool IsArrow,
1974 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001975 NestedNameSpecifier *Qualifier,
1976 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001977 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001978 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001979 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00001981 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00001982
John McCallb268a282010-08-23 23:25:46 +00001983 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001984 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001985 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001986 MemberNameInfo,
1987 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 }
1989
John McCall10eae182009-11-30 22:42:35 +00001990 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001991 ///
1992 /// By default, performs semantic analysis to build the new expression.
1993 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001994 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001995 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001996 SourceLocation OperatorLoc,
1997 bool IsArrow,
1998 NestedNameSpecifier *Qualifier,
1999 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00002000 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002001 LookupResult &R,
2002 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002003 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00002004 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00002005
John McCallb268a282010-08-23 23:25:46 +00002006 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002007 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002008 SS, FirstQualifierInScope,
2009 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002010 }
Mike Stump11289f42009-09-09 15:08:12 +00002011
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002012 /// \brief Build a new noexcept expression.
2013 ///
2014 /// By default, performs semantic analysis to build the new expression.
2015 /// Subclasses may override this routine to provide different behavior.
2016 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2017 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2018 }
2019
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002020 /// \brief Build a new expression to compute the length of a parameter pack.
2021 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2022 SourceLocation PackLoc,
2023 SourceLocation RParenLoc,
2024 unsigned Length) {
2025 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2026 OperatorLoc, Pack, PackLoc,
2027 RParenLoc, Length);
2028 }
2029
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 /// \brief Build a new Objective-C @encode expression.
2031 ///
2032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002034 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002035 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002037 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002039 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002040
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002041 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002042 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002043 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002044 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002045 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002046 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002047 MultiExprArg Args,
2048 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002049 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2050 ReceiverTypeInfo->getType(),
2051 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002052 Sel, Method, LBracLoc, SelectorLoc,
2053 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002054 }
2055
2056 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002057 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002058 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002059 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002060 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002061 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002062 MultiExprArg Args,
2063 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002064 return SemaRef.BuildInstanceMessage(Receiver,
2065 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002066 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002067 Sel, Method, LBracLoc, SelectorLoc,
2068 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002069 }
2070
Douglas Gregord51d90d2010-04-26 20:11:03 +00002071 /// \brief Build a new Objective-C ivar reference expression.
2072 ///
2073 /// By default, performs semantic analysis to build the new expression.
2074 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002075 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002076 SourceLocation IvarLoc,
2077 bool IsArrow, bool IsFreeIvar) {
2078 // FIXME: We lose track of the IsFreeIvar bit.
2079 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002080 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002081 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2082 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002083 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002084 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002085 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002086 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002087 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002088 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002089
Douglas Gregord51d90d2010-04-26 20:11:03 +00002090 if (Result.get())
2091 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002092
John McCallb268a282010-08-23 23:25:46 +00002093 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002094 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002095 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002096 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002097 /*TemplateArgs=*/0);
2098 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002099
2100 /// \brief Build a new Objective-C property reference expression.
2101 ///
2102 /// By default, performs semantic analysis to build the new expression.
2103 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002104 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002105 ObjCPropertyDecl *Property,
2106 SourceLocation PropertyLoc) {
2107 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002108 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002109 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2110 Sema::LookupMemberName);
2111 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002112 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002113 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002114 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002115 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002116 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002117
Douglas Gregor9faee212010-04-26 20:47:02 +00002118 if (Result.get())
2119 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002120
John McCallb268a282010-08-23 23:25:46 +00002121 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002122 /*FIXME:*/PropertyLoc, IsArrow,
2123 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002124 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002125 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002126 /*TemplateArgs=*/0);
2127 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002128
John McCallb7bd14f2010-12-02 01:19:52 +00002129 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002130 ///
2131 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002132 /// Subclasses may override this routine to provide different behavior.
2133 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2134 ObjCMethodDecl *Getter,
2135 ObjCMethodDecl *Setter,
2136 SourceLocation PropertyLoc) {
2137 // Since these expressions can only be value-dependent, we do not
2138 // need to perform semantic analysis again.
2139 return Owned(
2140 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2141 VK_LValue, OK_ObjCProperty,
2142 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002143 }
2144
Douglas Gregord51d90d2010-04-26 20:11:03 +00002145 /// \brief Build a new Objective-C "isa" expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002149 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002150 bool IsArrow) {
2151 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002152 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002153 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2154 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002155 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002156 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002157 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002158 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002159 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002160
Douglas Gregord51d90d2010-04-26 20:11:03 +00002161 if (Result.get())
2162 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002163
John McCallb268a282010-08-23 23:25:46 +00002164 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002165 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002166 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002167 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002168 /*TemplateArgs=*/0);
2169 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002170
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 /// \brief Build a new shuffle vector expression.
2172 ///
2173 /// By default, performs semantic analysis to build the new expression.
2174 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002175 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002176 MultiExprArg SubExprs,
2177 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002179 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2181 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2182 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2183 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002184
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 // Build a reference to the __builtin_shufflevector builtin
2186 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002187 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002189 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002191
2192 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 unsigned NumSubExprs = SubExprs.size();
2194 Expr **Subs = (Expr **)SubExprs.release();
2195 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2196 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002197 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002198 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002200 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002201
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002203 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002206
Douglas Gregora16548e2009-08-11 05:31:07 +00002207 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002208 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 }
John McCall31f82722010-11-12 08:19:04 +00002210
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002211 /// \brief Build a new template argument pack expansion.
2212 ///
2213 /// By default, performs semantic analysis to build a new pack expansion
2214 /// for a template argument. Subclasses may override this routine to provide
2215 /// different behavior.
2216 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002217 SourceLocation EllipsisLoc,
2218 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002219 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002220 case TemplateArgument::Expression: {
2221 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002222 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2223 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002224 if (Result.isInvalid())
2225 return TemplateArgumentLoc();
2226
2227 return TemplateArgumentLoc(Result.get(), Result.get());
2228 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002229
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002230 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002231 return TemplateArgumentLoc(TemplateArgument(
2232 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002233 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002234 Pattern.getTemplateQualifierRange(),
2235 Pattern.getTemplateNameLoc(),
2236 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002237
2238 case TemplateArgument::Null:
2239 case TemplateArgument::Integral:
2240 case TemplateArgument::Declaration:
2241 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002242 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002243 llvm_unreachable("Pack expansion pattern has no parameter packs");
2244
2245 case TemplateArgument::Type:
2246 if (TypeSourceInfo *Expansion
2247 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002248 EllipsisLoc,
2249 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002250 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2251 Expansion);
2252 break;
2253 }
2254
2255 return TemplateArgumentLoc();
2256 }
2257
Douglas Gregor968f23a2011-01-03 19:31:53 +00002258 /// \brief Build a new expression pack expansion.
2259 ///
2260 /// By default, performs semantic analysis to build a new pack expansion
2261 /// for an expression. Subclasses may override this routine to provide
2262 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002263 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2264 llvm::Optional<unsigned> NumExpansions) {
2265 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002266 }
2267
John McCall31f82722010-11-12 08:19:04 +00002268private:
2269 QualType TransformTypeInObjectScope(QualType T,
2270 QualType ObjectType,
2271 NamedDecl *FirstQualifierInScope,
2272 NestedNameSpecifier *Prefix);
2273
2274 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2275 QualType ObjectType,
2276 NamedDecl *FirstQualifierInScope,
2277 NestedNameSpecifier *Prefix);
Douglas Gregor14454802011-02-25 02:25:35 +00002278
2279 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2280 QualType ObjectType,
2281 NamedDecl *FirstQualifierInScope,
2282 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002283};
Douglas Gregora16548e2009-08-11 05:31:07 +00002284
Douglas Gregorebe10102009-08-20 07:17:43 +00002285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002286StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002287 if (!S)
2288 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002289
Douglas Gregorebe10102009-08-20 07:17:43 +00002290 switch (S->getStmtClass()) {
2291 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002292
Douglas Gregorebe10102009-08-20 07:17:43 +00002293 // Transform individual statement nodes
2294#define STMT(Node, Parent) \
2295 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002296#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002297#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002298#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002299
Douglas Gregorebe10102009-08-20 07:17:43 +00002300 // Transform expressions by calling TransformExpr.
2301#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002302#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002303#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002304#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002305 {
John McCalldadc5752010-08-24 06:29:42 +00002306 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002307 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002308 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002309
John McCallb268a282010-08-23 23:25:46 +00002310 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002311 }
Mike Stump11289f42009-09-09 15:08:12 +00002312 }
2313
John McCallc3007a22010-10-26 07:05:15 +00002314 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002315}
Mike Stump11289f42009-09-09 15:08:12 +00002316
2317
Douglas Gregore922c772009-08-04 22:27:00 +00002318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002319ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 if (!E)
2321 return SemaRef.Owned(E);
2322
2323 switch (E->getStmtClass()) {
2324 case Stmt::NoStmtClass: break;
2325#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002326#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002327#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002328 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002329#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002330 }
2331
John McCallc3007a22010-10-26 07:05:15 +00002332 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002333}
2334
2335template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002336bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2337 unsigned NumInputs,
2338 bool IsCall,
2339 llvm::SmallVectorImpl<Expr *> &Outputs,
2340 bool *ArgChanged) {
2341 for (unsigned I = 0; I != NumInputs; ++I) {
2342 // If requested, drop call arguments that need to be dropped.
2343 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2344 if (ArgChanged)
2345 *ArgChanged = true;
2346
2347 break;
2348 }
2349
Douglas Gregor968f23a2011-01-03 19:31:53 +00002350 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2351 Expr *Pattern = Expansion->getPattern();
2352
2353 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2354 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2355 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2356
2357 // Determine whether the set of unexpanded parameter packs can and should
2358 // be expanded.
2359 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002360 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002361 llvm::Optional<unsigned> OrigNumExpansions
2362 = Expansion->getNumExpansions();
2363 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002364 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2365 Pattern->getSourceRange(),
2366 Unexpanded.data(),
2367 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002368 Expand, RetainExpansion,
2369 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002370 return true;
2371
2372 if (!Expand) {
2373 // The transform has determined that we should perform a simple
2374 // transformation on the pack expansion, producing another pack
2375 // expansion.
2376 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2377 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2378 if (OutPattern.isInvalid())
2379 return true;
2380
2381 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002382 Expansion->getEllipsisLoc(),
2383 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002384 if (Out.isInvalid())
2385 return true;
2386
2387 if (ArgChanged)
2388 *ArgChanged = true;
2389 Outputs.push_back(Out.get());
2390 continue;
2391 }
2392
2393 // The transform has determined that we should perform an elementwise
2394 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002395 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002396 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2397 ExprResult Out = getDerived().TransformExpr(Pattern);
2398 if (Out.isInvalid())
2399 return true;
2400
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002401 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002402 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2403 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002404 if (Out.isInvalid())
2405 return true;
2406 }
2407
Douglas Gregor968f23a2011-01-03 19:31:53 +00002408 if (ArgChanged)
2409 *ArgChanged = true;
2410 Outputs.push_back(Out.get());
2411 }
2412
2413 continue;
2414 }
2415
Douglas Gregora3efea12011-01-03 19:04:46 +00002416 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2417 if (Result.isInvalid())
2418 return true;
2419
2420 if (Result.get() != Inputs[I] && ArgChanged)
2421 *ArgChanged = true;
2422
2423 Outputs.push_back(Result.get());
2424 }
2425
2426 return false;
2427}
2428
2429template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002430NestedNameSpecifier *
2431TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002432 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002433 QualType ObjectType,
2434 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002435 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002436
Douglas Gregorebe10102009-08-20 07:17:43 +00002437 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002438 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002439 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002440 ObjectType,
2441 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002442 if (!Prefix)
2443 return 0;
2444 }
Mike Stump11289f42009-09-09 15:08:12 +00002445
Douglas Gregor1135c352009-08-06 05:28:30 +00002446 switch (NNS->getKind()) {
2447 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002448 if (Prefix) {
2449 // The object type and qualifier-in-scope really apply to the
2450 // leftmost entity.
2451 ObjectType = QualType();
2452 FirstQualifierInScope = 0;
2453 }
2454
Mike Stump11289f42009-09-09 15:08:12 +00002455 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002456 "Identifier nested-name-specifier with no prefix or object type");
2457 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2458 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002459 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002460
2461 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002462 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002463 ObjectType,
2464 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002465
Douglas Gregor1135c352009-08-06 05:28:30 +00002466 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002467 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002468 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002469 getDerived().TransformDecl(Range.getBegin(),
2470 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002471 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002472 Prefix == NNS->getPrefix() &&
2473 NS == NNS->getAsNamespace())
2474 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002475
Douglas Gregor1135c352009-08-06 05:28:30 +00002476 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2477 }
Mike Stump11289f42009-09-09 15:08:12 +00002478
Douglas Gregor7b26ff92011-02-24 02:36:08 +00002479 case NestedNameSpecifier::NamespaceAlias: {
2480 NamespaceAliasDecl *Alias
2481 = cast_or_null<NamespaceAliasDecl>(
2482 getDerived().TransformDecl(Range.getBegin(),
2483 NNS->getAsNamespaceAlias()));
2484 if (!getDerived().AlwaysRebuild() &&
2485 Prefix == NNS->getPrefix() &&
2486 Alias == NNS->getAsNamespaceAlias())
2487 return NNS;
2488
2489 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias);
2490 }
2491
Douglas Gregor1135c352009-08-06 05:28:30 +00002492 case NestedNameSpecifier::Global:
2493 // There is no meaningful transformation that one could perform on the
2494 // global scope.
2495 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002496
Douglas Gregor1135c352009-08-06 05:28:30 +00002497 case NestedNameSpecifier::TypeSpecWithTemplate:
2498 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002499 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002500 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2501 ObjectType,
2502 FirstQualifierInScope,
2503 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002504 if (T.isNull())
2505 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002506
Douglas Gregor1135c352009-08-06 05:28:30 +00002507 if (!getDerived().AlwaysRebuild() &&
2508 Prefix == NNS->getPrefix() &&
2509 T == QualType(NNS->getAsType(), 0))
2510 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002511
2512 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2513 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002514 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002515 }
2516 }
Mike Stump11289f42009-09-09 15:08:12 +00002517
Douglas Gregor1135c352009-08-06 05:28:30 +00002518 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002519 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002520}
2521
2522template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002523NestedNameSpecifierLoc
2524TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2525 NestedNameSpecifierLoc NNS,
2526 QualType ObjectType,
2527 NamedDecl *FirstQualifierInScope) {
2528 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2529 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2530 Qualifier = Qualifier.getPrefix())
2531 Qualifiers.push_back(Qualifier);
2532
2533 CXXScopeSpec SS;
2534 while (!Qualifiers.empty()) {
2535 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2536 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2537
2538 switch (QNNS->getKind()) {
2539 case NestedNameSpecifier::Identifier:
2540 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2541 *QNNS->getAsIdentifier(),
2542 Q.getLocalBeginLoc(),
2543 Q.getLocalEndLoc(),
2544 ObjectType, false, SS,
2545 FirstQualifierInScope, false))
2546 return NestedNameSpecifierLoc();
2547
2548 break;
2549
2550 case NestedNameSpecifier::Namespace: {
2551 NamespaceDecl *NS
2552 = cast_or_null<NamespaceDecl>(
2553 getDerived().TransformDecl(
2554 Q.getLocalBeginLoc(),
2555 QNNS->getAsNamespace()));
2556 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2557 break;
2558 }
2559
2560 case NestedNameSpecifier::NamespaceAlias: {
2561 NamespaceAliasDecl *Alias
2562 = cast_or_null<NamespaceAliasDecl>(
2563 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2564 QNNS->getAsNamespaceAlias()));
2565 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2566 Q.getLocalEndLoc());
2567 break;
2568 }
2569
2570 case NestedNameSpecifier::Global:
2571 // There is no meaningful transformation that one could perform on the
2572 // global scope.
2573 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2574 break;
2575
2576 case NestedNameSpecifier::TypeSpecWithTemplate:
2577 case NestedNameSpecifier::TypeSpec: {
2578 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2579 FirstQualifierInScope, SS);
2580
2581 if (!TL)
2582 return NestedNameSpecifierLoc();
2583
2584 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2585 (SemaRef.getLangOptions().CPlusPlus0x &&
2586 TL.getType()->isEnumeralType())) {
2587 assert(!TL.getType().hasLocalQualifiers() &&
2588 "Can't get cv-qualifiers here");
2589 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2590 Q.getLocalEndLoc());
2591 break;
2592 }
2593
2594 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2595 << TL.getType() << SS.getRange();
2596 return NestedNameSpecifierLoc();
2597 }
2598 }
2599
2600 // The object type and qualifier-in-scope really apply to the
2601 // leftmost entity.
2602 ObjectType = QualType();
2603 FirstQualifierInScope = 0;
2604 }
2605
2606 // Don't rebuild the nested-name-specifier if we don't have to.
2607 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2608 !getDerived().AlwaysRebuild())
2609 return NNS;
2610
2611 // If we can re-use the source-location data from the original
2612 // nested-name-specifier, do so.
2613 if (SS.location_size() == NNS.getDataLength() &&
2614 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2615 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2616
2617 // Allocate new nested-name-specifier location information.
2618 return SS.getWithLocInContext(SemaRef.Context);
2619}
2620
2621template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002622DeclarationNameInfo
2623TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002624::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002625 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002626 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002627 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002628
2629 switch (Name.getNameKind()) {
2630 case DeclarationName::Identifier:
2631 case DeclarationName::ObjCZeroArgSelector:
2632 case DeclarationName::ObjCOneArgSelector:
2633 case DeclarationName::ObjCMultiArgSelector:
2634 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002635 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002636 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002637 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002638
Douglas Gregorf816bd72009-09-03 22:13:48 +00002639 case DeclarationName::CXXConstructorName:
2640 case DeclarationName::CXXDestructorName:
2641 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002642 TypeSourceInfo *NewTInfo;
2643 CanQualType NewCanTy;
2644 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002645 NewTInfo = getDerived().TransformType(OldTInfo);
2646 if (!NewTInfo)
2647 return DeclarationNameInfo();
2648 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002649 }
2650 else {
2651 NewTInfo = 0;
2652 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002653 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002654 if (NewT.isNull())
2655 return DeclarationNameInfo();
2656 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2657 }
Mike Stump11289f42009-09-09 15:08:12 +00002658
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002659 DeclarationName NewName
2660 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2661 NewCanTy);
2662 DeclarationNameInfo NewNameInfo(NameInfo);
2663 NewNameInfo.setName(NewName);
2664 NewNameInfo.setNamedTypeInfo(NewTInfo);
2665 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002666 }
Mike Stump11289f42009-09-09 15:08:12 +00002667 }
2668
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002669 assert(0 && "Unknown name kind.");
2670 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002671}
2672
2673template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002674TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002675TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002676 QualType ObjectType,
2677 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002678 SourceLocation Loc = getDerived().getBaseLocation();
2679
Douglas Gregor71dc5092009-08-06 06:41:21 +00002680 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002681 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002682 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002683 /*FIXME*/ SourceRange(Loc),
2684 ObjectType,
2685 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002686 if (!NNS)
2687 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002688
Douglas Gregor71dc5092009-08-06 06:41:21 +00002689 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002690 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002691 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002692 if (!TransTemplate)
2693 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002694
Douglas Gregor71dc5092009-08-06 06:41:21 +00002695 if (!getDerived().AlwaysRebuild() &&
2696 NNS == QTN->getQualifier() &&
2697 TransTemplate == Template)
2698 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002699
Douglas Gregor71dc5092009-08-06 06:41:21 +00002700 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2701 TransTemplate);
2702 }
Mike Stump11289f42009-09-09 15:08:12 +00002703
John McCalle66edc12009-11-24 19:00:30 +00002704 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002705 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002706 }
Mike Stump11289f42009-09-09 15:08:12 +00002707
Douglas Gregor71dc5092009-08-06 06:41:21 +00002708 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002709 NestedNameSpecifier *NNS = DTN->getQualifier();
2710 if (NNS) {
2711 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2712 /*FIXME:*/SourceRange(Loc),
2713 ObjectType,
2714 FirstQualifierInScope);
2715 if (!NNS) return TemplateName();
2716
2717 // These apply to the scope specifier, not the template.
2718 ObjectType = QualType();
2719 FirstQualifierInScope = 0;
2720 }
Mike Stump11289f42009-09-09 15:08:12 +00002721
Douglas Gregor71dc5092009-08-06 06:41:21 +00002722 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002723 NNS == DTN->getQualifier() &&
2724 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002725 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002726
Douglas Gregora5614c52010-09-08 23:56:00 +00002727 if (DTN->isIdentifier()) {
2728 // FIXME: Bad range
2729 SourceRange QualifierRange(getDerived().getBaseLocation());
2730 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2731 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002732 ObjectType,
2733 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002734 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002735
2736 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002737 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002738 }
Mike Stump11289f42009-09-09 15:08:12 +00002739
Douglas Gregor71dc5092009-08-06 06:41:21 +00002740 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002741 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002742 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002743 if (!TransTemplate)
2744 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002745
Douglas Gregor71dc5092009-08-06 06:41:21 +00002746 if (!getDerived().AlwaysRebuild() &&
2747 TransTemplate == Template)
2748 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002749
Douglas Gregor71dc5092009-08-06 06:41:21 +00002750 return TemplateName(TransTemplate);
2751 }
Mike Stump11289f42009-09-09 15:08:12 +00002752
Douglas Gregor5590be02011-01-15 06:45:20 +00002753 if (SubstTemplateTemplateParmPackStorage *SubstPack
2754 = Name.getAsSubstTemplateTemplateParmPack()) {
2755 TemplateTemplateParmDecl *TransParam
2756 = cast_or_null<TemplateTemplateParmDecl>(
2757 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2758 if (!TransParam)
2759 return TemplateName();
2760
2761 if (!getDerived().AlwaysRebuild() &&
2762 TransParam == SubstPack->getParameterPack())
2763 return Name;
2764
2765 return getDerived().RebuildTemplateName(TransParam,
2766 SubstPack->getArgumentPack());
2767 }
2768
John McCalle66edc12009-11-24 19:00:30 +00002769 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002770 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002771 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002772}
2773
2774template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002775void TreeTransform<Derived>::InventTemplateArgumentLoc(
2776 const TemplateArgument &Arg,
2777 TemplateArgumentLoc &Output) {
2778 SourceLocation Loc = getDerived().getBaseLocation();
2779 switch (Arg.getKind()) {
2780 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002781 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002782 break;
2783
2784 case TemplateArgument::Type:
2785 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002786 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002787
John McCall0ad16662009-10-29 08:12:44 +00002788 break;
2789
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002790 case TemplateArgument::Template:
2791 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2792 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002793
2794 case TemplateArgument::TemplateExpansion:
2795 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2796 break;
2797
John McCall0ad16662009-10-29 08:12:44 +00002798 case TemplateArgument::Expression:
2799 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2800 break;
2801
2802 case TemplateArgument::Declaration:
2803 case TemplateArgument::Integral:
2804 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002805 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002806 break;
2807 }
2808}
2809
2810template<typename Derived>
2811bool TreeTransform<Derived>::TransformTemplateArgument(
2812 const TemplateArgumentLoc &Input,
2813 TemplateArgumentLoc &Output) {
2814 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002815 switch (Arg.getKind()) {
2816 case TemplateArgument::Null:
2817 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002818 Output = Input;
2819 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002820
Douglas Gregore922c772009-08-04 22:27:00 +00002821 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002822 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002823 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002824 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002825
2826 DI = getDerived().TransformType(DI);
2827 if (!DI) return true;
2828
2829 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2830 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002831 }
Mike Stump11289f42009-09-09 15:08:12 +00002832
Douglas Gregore922c772009-08-04 22:27:00 +00002833 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002834 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002835 DeclarationName Name;
2836 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2837 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002838 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002839 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002840 if (!D) return true;
2841
John McCall0d07eb32009-10-29 18:45:58 +00002842 Expr *SourceExpr = Input.getSourceDeclExpression();
2843 if (SourceExpr) {
2844 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002845 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002846 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002847 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002848 }
2849
2850 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002851 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002852 }
Mike Stump11289f42009-09-09 15:08:12 +00002853
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002854 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002855 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002856 TemplateName Template
2857 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2858 if (Template.isNull())
2859 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002860
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002861 Output = TemplateArgumentLoc(TemplateArgument(Template),
2862 Input.getTemplateQualifierRange(),
2863 Input.getTemplateNameLoc());
2864 return false;
2865 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002866
2867 case TemplateArgument::TemplateExpansion:
2868 llvm_unreachable("Caller should expand pack expansions");
2869
Douglas Gregore922c772009-08-04 22:27:00 +00002870 case TemplateArgument::Expression: {
2871 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002872 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002873 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002874
John McCall0ad16662009-10-29 08:12:44 +00002875 Expr *InputExpr = Input.getSourceExpression();
2876 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2877
John McCalldadc5752010-08-24 06:29:42 +00002878 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002879 = getDerived().TransformExpr(InputExpr);
2880 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002881 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002882 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002883 }
Mike Stump11289f42009-09-09 15:08:12 +00002884
Douglas Gregore922c772009-08-04 22:27:00 +00002885 case TemplateArgument::Pack: {
2886 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2887 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002888 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002889 AEnd = Arg.pack_end();
2890 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002891
John McCall0ad16662009-10-29 08:12:44 +00002892 // FIXME: preserve source information here when we start
2893 // caring about parameter packs.
2894
John McCall0d07eb32009-10-29 18:45:58 +00002895 TemplateArgumentLoc InputArg;
2896 TemplateArgumentLoc OutputArg;
2897 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2898 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002899 return true;
2900
John McCall0d07eb32009-10-29 18:45:58 +00002901 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002902 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002903
2904 TemplateArgument *TransformedArgsPtr
2905 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2906 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2907 TransformedArgsPtr);
2908 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2909 TransformedArgs.size()),
2910 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002911 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002912 }
2913 }
Mike Stump11289f42009-09-09 15:08:12 +00002914
Douglas Gregore922c772009-08-04 22:27:00 +00002915 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002916 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002917}
2918
Douglas Gregorfe921a72010-12-20 23:36:19 +00002919/// \brief Iterator adaptor that invents template argument location information
2920/// for each of the template arguments in its underlying iterator.
2921template<typename Derived, typename InputIterator>
2922class TemplateArgumentLocInventIterator {
2923 TreeTransform<Derived> &Self;
2924 InputIterator Iter;
2925
2926public:
2927 typedef TemplateArgumentLoc value_type;
2928 typedef TemplateArgumentLoc reference;
2929 typedef typename std::iterator_traits<InputIterator>::difference_type
2930 difference_type;
2931 typedef std::input_iterator_tag iterator_category;
2932
2933 class pointer {
2934 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002935
Douglas Gregorfe921a72010-12-20 23:36:19 +00002936 public:
2937 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2938
2939 const TemplateArgumentLoc *operator->() const { return &Arg; }
2940 };
2941
2942 TemplateArgumentLocInventIterator() { }
2943
2944 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2945 InputIterator Iter)
2946 : Self(Self), Iter(Iter) { }
2947
2948 TemplateArgumentLocInventIterator &operator++() {
2949 ++Iter;
2950 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002951 }
2952
Douglas Gregorfe921a72010-12-20 23:36:19 +00002953 TemplateArgumentLocInventIterator operator++(int) {
2954 TemplateArgumentLocInventIterator Old(*this);
2955 ++(*this);
2956 return Old;
2957 }
2958
2959 reference operator*() const {
2960 TemplateArgumentLoc Result;
2961 Self.InventTemplateArgumentLoc(*Iter, Result);
2962 return Result;
2963 }
2964
2965 pointer operator->() const { return pointer(**this); }
2966
2967 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2968 const TemplateArgumentLocInventIterator &Y) {
2969 return X.Iter == Y.Iter;
2970 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002971
Douglas Gregorfe921a72010-12-20 23:36:19 +00002972 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2973 const TemplateArgumentLocInventIterator &Y) {
2974 return X.Iter != Y.Iter;
2975 }
2976};
2977
Douglas Gregor42cafa82010-12-20 17:42:22 +00002978template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002979template<typename InputIterator>
2980bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2981 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002982 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002983 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002984 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002985 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002986
2987 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2988 // Unpack argument packs, which we translate them into separate
2989 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002990 // FIXME: We could do much better if we could guarantee that the
2991 // TemplateArgumentLocInfo for the pack expansion would be usable for
2992 // all of the template arguments in the argument pack.
2993 typedef TemplateArgumentLocInventIterator<Derived,
2994 TemplateArgument::pack_iterator>
2995 PackLocIterator;
2996 if (TransformTemplateArguments(PackLocIterator(*this,
2997 In.getArgument().pack_begin()),
2998 PackLocIterator(*this,
2999 In.getArgument().pack_end()),
3000 Outputs))
3001 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003002
3003 continue;
3004 }
3005
3006 if (In.getArgument().isPackExpansion()) {
3007 // We have a pack expansion, for which we will be substituting into
3008 // the pattern.
3009 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003010 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003011 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003012 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3013 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003014
3015 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3016 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3017 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3018
3019 // Determine whether the set of unexpanded parameter packs can and should
3020 // be expanded.
3021 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003022 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003023 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003024 if (getDerived().TryExpandParameterPacks(Ellipsis,
3025 Pattern.getSourceRange(),
3026 Unexpanded.data(),
3027 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003028 Expand,
3029 RetainExpansion,
3030 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003031 return true;
3032
3033 if (!Expand) {
3034 // The transform has determined that we should perform a simple
3035 // transformation on the pack expansion, producing another pack
3036 // expansion.
3037 TemplateArgumentLoc OutPattern;
3038 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3039 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3040 return true;
3041
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003042 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3043 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003044 if (Out.getArgument().isNull())
3045 return true;
3046
3047 Outputs.addArgument(Out);
3048 continue;
3049 }
3050
3051 // The transform has determined that we should perform an elementwise
3052 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003053 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003054 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3055
3056 if (getDerived().TransformTemplateArgument(Pattern, Out))
3057 return true;
3058
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003059 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003060 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3061 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003062 if (Out.getArgument().isNull())
3063 return true;
3064 }
3065
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003066 Outputs.addArgument(Out);
3067 }
3068
Douglas Gregor48d24112011-01-10 20:53:55 +00003069 // If we're supposed to retain a pack expansion, do so by temporarily
3070 // forgetting the partially-substituted parameter pack.
3071 if (RetainExpansion) {
3072 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3073
3074 if (getDerived().TransformTemplateArgument(Pattern, Out))
3075 return true;
3076
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003077 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3078 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003079 if (Out.getArgument().isNull())
3080 return true;
3081
3082 Outputs.addArgument(Out);
3083 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003084
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003085 continue;
3086 }
3087
3088 // The simple case:
3089 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003090 return true;
3091
3092 Outputs.addArgument(Out);
3093 }
3094
3095 return false;
3096
3097}
3098
Douglas Gregord6ff3322009-08-04 16:50:30 +00003099//===----------------------------------------------------------------------===//
3100// Type transformation
3101//===----------------------------------------------------------------------===//
3102
3103template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003104QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003105 if (getDerived().AlreadyTransformed(T))
3106 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003107
John McCall550e0c22009-10-21 00:40:46 +00003108 // Temporary workaround. All of these transformations should
3109 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003110 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3111 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003112
John McCall31f82722010-11-12 08:19:04 +00003113 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003114
John McCall550e0c22009-10-21 00:40:46 +00003115 if (!NewDI)
3116 return QualType();
3117
3118 return NewDI->getType();
3119}
3120
3121template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003122TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003123 if (getDerived().AlreadyTransformed(DI->getType()))
3124 return DI;
3125
3126 TypeLocBuilder TLB;
3127
3128 TypeLoc TL = DI->getTypeLoc();
3129 TLB.reserve(TL.getFullDataSize());
3130
John McCall31f82722010-11-12 08:19:04 +00003131 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003132 if (Result.isNull())
3133 return 0;
3134
John McCallbcd03502009-12-07 02:54:59 +00003135 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003136}
3137
3138template<typename Derived>
3139QualType
John McCall31f82722010-11-12 08:19:04 +00003140TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003141 switch (T.getTypeLocClass()) {
3142#define ABSTRACT_TYPELOC(CLASS, PARENT)
3143#define TYPELOC(CLASS, PARENT) \
3144 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003145 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003146#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003147 }
Mike Stump11289f42009-09-09 15:08:12 +00003148
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003149 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003150 return QualType();
3151}
3152
3153/// FIXME: By default, this routine adds type qualifiers only to types
3154/// that can have qualifiers, and silently suppresses those qualifiers
3155/// that are not permitted (e.g., qualifiers on reference or function
3156/// types). This is the right thing for template instantiation, but
3157/// probably not for other clients.
3158template<typename Derived>
3159QualType
3160TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003161 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003162 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003163
John McCall31f82722010-11-12 08:19:04 +00003164 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003165 if (Result.isNull())
3166 return QualType();
3167
3168 // Silently suppress qualifiers if the result type can't be qualified.
3169 // FIXME: this is the right thing for template instantiation, but
3170 // probably not for other clients.
3171 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003172 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003173
John McCallcb0f89a2010-06-05 06:41:15 +00003174 if (!Quals.empty()) {
3175 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3176 TLB.push<QualifiedTypeLoc>(Result);
3177 // No location information to preserve.
3178 }
John McCall550e0c22009-10-21 00:40:46 +00003179
3180 return Result;
3181}
3182
John McCall31f82722010-11-12 08:19:04 +00003183/// \brief Transforms a type that was written in a scope specifier,
3184/// given an object type, the results of unqualified lookup, and
3185/// an already-instantiated prefix.
3186///
3187/// The object type is provided iff the scope specifier qualifies the
3188/// member of a dependent member-access expression. The prefix is
3189/// provided iff the the scope specifier in which this appears has a
3190/// prefix.
3191///
3192/// This is private to TreeTransform.
3193template<typename Derived>
3194QualType
3195TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3196 QualType ObjectType,
3197 NamedDecl *UnqualLookup,
3198 NestedNameSpecifier *Prefix) {
3199 if (getDerived().AlreadyTransformed(T))
3200 return T;
3201
3202 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003203 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003204
3205 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3206 UnqualLookup, Prefix);
3207 if (!TSI) return QualType();
3208 return TSI->getType();
3209}
3210
3211template<typename Derived>
3212TypeSourceInfo *
3213TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3214 QualType ObjectType,
3215 NamedDecl *UnqualLookup,
3216 NestedNameSpecifier *Prefix) {
Douglas Gregor14454802011-02-25 02:25:35 +00003217 // TODO: in some cases, we might have some verification to do here.
John McCall31f82722010-11-12 08:19:04 +00003218 if (ObjectType.isNull())
3219 return getDerived().TransformType(TSI);
3220
3221 QualType T = TSI->getType();
3222 if (getDerived().AlreadyTransformed(T))
3223 return TSI;
3224
3225 TypeLocBuilder TLB;
3226 QualType Result;
3227
3228 if (isa<TemplateSpecializationType>(T)) {
3229 TemplateSpecializationTypeLoc TL
3230 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3231
3232 TemplateName Template =
3233 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3234 ObjectType, UnqualLookup);
3235 if (Template.isNull()) return 0;
3236
3237 Result = getDerived()
3238 .TransformTemplateSpecializationType(TLB, TL, Template);
3239 } else if (isa<DependentTemplateSpecializationType>(T)) {
3240 DependentTemplateSpecializationTypeLoc TL
3241 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3242
3243 Result = getDerived()
3244 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3245 } else {
3246 // Nothing special needs to be done for these.
3247 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3248 }
3249
3250 if (Result.isNull()) return 0;
3251 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3252}
3253
Douglas Gregor14454802011-02-25 02:25:35 +00003254template<typename Derived>
3255TypeLoc
3256TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3257 QualType ObjectType,
3258 NamedDecl *UnqualLookup,
3259 CXXScopeSpec &SS) {
3260 // FIXME: Painfully copy-paste from the above!
3261
3262 // TODO: in some cases, we might have some verification to do here.
3263 if (ObjectType.isNull()) {
3264 TypeLocBuilder TLB;
3265 TLB.reserve(TL.getFullDataSize());
3266 QualType Result = getDerived().TransformType(TLB, TL);
3267 if (Result.isNull())
3268 return TypeLoc();
3269
3270 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3271 }
3272
3273 QualType T = TL.getType();
3274 if (getDerived().AlreadyTransformed(T))
3275 return TL;
3276
3277 TypeLocBuilder TLB;
3278 QualType Result;
3279
3280 if (isa<TemplateSpecializationType>(T)) {
3281 TemplateSpecializationTypeLoc SpecTL
3282 = cast<TemplateSpecializationTypeLoc>(TL);
3283
3284 TemplateName Template =
3285 getDerived().TransformTemplateName(SpecTL.getTypePtr()->getTemplateName(),
3286 ObjectType, UnqualLookup);
3287 if (Template.isNull())
3288 return TypeLoc();
3289
3290 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3291 Template);
3292 } else if (isa<DependentTemplateSpecializationType>(T)) {
3293 DependentTemplateSpecializationTypeLoc SpecTL
3294 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3295
3296 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3297 SpecTL,
3298 SS.getScopeRep());
3299 } else {
3300 // Nothing special needs to be done for these.
3301 Result = getDerived().TransformType(TLB, TL);
3302 }
3303
3304 if (Result.isNull())
3305 return TypeLoc();
3306
3307 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3308}
3309
John McCall550e0c22009-10-21 00:40:46 +00003310template <class TyLoc> static inline
3311QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3312 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3313 NewT.setNameLoc(T.getNameLoc());
3314 return T.getType();
3315}
3316
John McCall550e0c22009-10-21 00:40:46 +00003317template<typename Derived>
3318QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003319 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003320 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3321 NewT.setBuiltinLoc(T.getBuiltinLoc());
3322 if (T.needsExtraLocalData())
3323 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3324 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003325}
Mike Stump11289f42009-09-09 15:08:12 +00003326
Douglas Gregord6ff3322009-08-04 16:50:30 +00003327template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003328QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003329 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003330 // FIXME: recurse?
3331 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003332}
Mike Stump11289f42009-09-09 15:08:12 +00003333
Douglas Gregord6ff3322009-08-04 16:50:30 +00003334template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003335QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003336 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003337 QualType PointeeType
3338 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003339 if (PointeeType.isNull())
3340 return QualType();
3341
3342 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003343 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003344 // A dependent pointer type 'T *' has is being transformed such
3345 // that an Objective-C class type is being replaced for 'T'. The
3346 // resulting pointer type is an ObjCObjectPointerType, not a
3347 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003348 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003349
John McCall8b07ec22010-05-15 11:32:37 +00003350 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3351 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003352 return Result;
3353 }
John McCall31f82722010-11-12 08:19:04 +00003354
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003355 if (getDerived().AlwaysRebuild() ||
3356 PointeeType != TL.getPointeeLoc().getType()) {
3357 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3358 if (Result.isNull())
3359 return QualType();
3360 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003361
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003362 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3363 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003364 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003365}
Mike Stump11289f42009-09-09 15:08:12 +00003366
3367template<typename Derived>
3368QualType
John McCall550e0c22009-10-21 00:40:46 +00003369TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003370 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003371 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003372 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3373 if (PointeeType.isNull())
3374 return QualType();
3375
3376 QualType Result = TL.getType();
3377 if (getDerived().AlwaysRebuild() ||
3378 PointeeType != TL.getPointeeLoc().getType()) {
3379 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003380 TL.getSigilLoc());
3381 if (Result.isNull())
3382 return QualType();
3383 }
3384
Douglas Gregor049211a2010-04-22 16:50:51 +00003385 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003386 NewT.setSigilLoc(TL.getSigilLoc());
3387 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003388}
3389
John McCall70dd5f62009-10-30 00:06:24 +00003390/// Transforms a reference type. Note that somewhat paradoxically we
3391/// don't care whether the type itself is an l-value type or an r-value
3392/// type; we only care if the type was *written* as an l-value type
3393/// or an r-value type.
3394template<typename Derived>
3395QualType
3396TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003397 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003398 const ReferenceType *T = TL.getTypePtr();
3399
3400 // Note that this works with the pointee-as-written.
3401 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3402 if (PointeeType.isNull())
3403 return QualType();
3404
3405 QualType Result = TL.getType();
3406 if (getDerived().AlwaysRebuild() ||
3407 PointeeType != T->getPointeeTypeAsWritten()) {
3408 Result = getDerived().RebuildReferenceType(PointeeType,
3409 T->isSpelledAsLValue(),
3410 TL.getSigilLoc());
3411 if (Result.isNull())
3412 return QualType();
3413 }
3414
3415 // r-value references can be rebuilt as l-value references.
3416 ReferenceTypeLoc NewTL;
3417 if (isa<LValueReferenceType>(Result))
3418 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3419 else
3420 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3421 NewTL.setSigilLoc(TL.getSigilLoc());
3422
3423 return Result;
3424}
3425
Mike Stump11289f42009-09-09 15:08:12 +00003426template<typename Derived>
3427QualType
John McCall550e0c22009-10-21 00:40:46 +00003428TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003429 LValueReferenceTypeLoc TL) {
3430 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003431}
3432
Mike Stump11289f42009-09-09 15:08:12 +00003433template<typename Derived>
3434QualType
John McCall550e0c22009-10-21 00:40:46 +00003435TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003436 RValueReferenceTypeLoc TL) {
3437 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003438}
Mike Stump11289f42009-09-09 15:08:12 +00003439
Douglas Gregord6ff3322009-08-04 16:50:30 +00003440template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003441QualType
John McCall550e0c22009-10-21 00:40:46 +00003442TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003443 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003444 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003445
3446 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003447 if (PointeeType.isNull())
3448 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003449
John McCall550e0c22009-10-21 00:40:46 +00003450 // TODO: preserve source information for this.
3451 QualType ClassType
3452 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003453 if (ClassType.isNull())
3454 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003455
John McCall550e0c22009-10-21 00:40:46 +00003456 QualType Result = TL.getType();
3457 if (getDerived().AlwaysRebuild() ||
3458 PointeeType != T->getPointeeType() ||
3459 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003460 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3461 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003462 if (Result.isNull())
3463 return QualType();
3464 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003465
John McCall550e0c22009-10-21 00:40:46 +00003466 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3467 NewTL.setSigilLoc(TL.getSigilLoc());
3468
3469 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003470}
3471
Mike Stump11289f42009-09-09 15:08:12 +00003472template<typename Derived>
3473QualType
John McCall550e0c22009-10-21 00:40:46 +00003474TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003475 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003476 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003477 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003478 if (ElementType.isNull())
3479 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003480
John McCall550e0c22009-10-21 00:40:46 +00003481 QualType Result = TL.getType();
3482 if (getDerived().AlwaysRebuild() ||
3483 ElementType != T->getElementType()) {
3484 Result = getDerived().RebuildConstantArrayType(ElementType,
3485 T->getSizeModifier(),
3486 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003487 T->getIndexTypeCVRQualifiers(),
3488 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003489 if (Result.isNull())
3490 return QualType();
3491 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003492
John McCall550e0c22009-10-21 00:40:46 +00003493 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3494 NewTL.setLBracketLoc(TL.getLBracketLoc());
3495 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003496
John McCall550e0c22009-10-21 00:40:46 +00003497 Expr *Size = TL.getSizeExpr();
3498 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003499 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003500 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3501 }
3502 NewTL.setSizeExpr(Size);
3503
3504 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003505}
Mike Stump11289f42009-09-09 15:08:12 +00003506
Douglas Gregord6ff3322009-08-04 16:50:30 +00003507template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003508QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003509 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003510 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003511 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003512 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003513 if (ElementType.isNull())
3514 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003515
John McCall550e0c22009-10-21 00:40:46 +00003516 QualType Result = TL.getType();
3517 if (getDerived().AlwaysRebuild() ||
3518 ElementType != T->getElementType()) {
3519 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003520 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003521 T->getIndexTypeCVRQualifiers(),
3522 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003523 if (Result.isNull())
3524 return QualType();
3525 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003526
John McCall550e0c22009-10-21 00:40:46 +00003527 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3528 NewTL.setLBracketLoc(TL.getLBracketLoc());
3529 NewTL.setRBracketLoc(TL.getRBracketLoc());
3530 NewTL.setSizeExpr(0);
3531
3532 return Result;
3533}
3534
3535template<typename Derived>
3536QualType
3537TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003538 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003539 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003540 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3541 if (ElementType.isNull())
3542 return QualType();
3543
3544 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003545 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003546
John McCalldadc5752010-08-24 06:29:42 +00003547 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003548 = getDerived().TransformExpr(T->getSizeExpr());
3549 if (SizeResult.isInvalid())
3550 return QualType();
3551
John McCallb268a282010-08-23 23:25:46 +00003552 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003553
3554 QualType Result = TL.getType();
3555 if (getDerived().AlwaysRebuild() ||
3556 ElementType != T->getElementType() ||
3557 Size != T->getSizeExpr()) {
3558 Result = getDerived().RebuildVariableArrayType(ElementType,
3559 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003560 Size,
John McCall550e0c22009-10-21 00:40:46 +00003561 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003562 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003563 if (Result.isNull())
3564 return QualType();
3565 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003566
John McCall550e0c22009-10-21 00:40:46 +00003567 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3568 NewTL.setLBracketLoc(TL.getLBracketLoc());
3569 NewTL.setRBracketLoc(TL.getRBracketLoc());
3570 NewTL.setSizeExpr(Size);
3571
3572 return Result;
3573}
3574
3575template<typename Derived>
3576QualType
3577TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003578 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003579 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003580 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3581 if (ElementType.isNull())
3582 return QualType();
3583
3584 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003585 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003586
John McCall33ddac02011-01-19 10:06:00 +00003587 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3588 Expr *origSize = TL.getSizeExpr();
3589 if (!origSize) origSize = T->getSizeExpr();
3590
3591 ExprResult sizeResult
3592 = getDerived().TransformExpr(origSize);
3593 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003594 return QualType();
3595
John McCall33ddac02011-01-19 10:06:00 +00003596 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003597
3598 QualType Result = TL.getType();
3599 if (getDerived().AlwaysRebuild() ||
3600 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003601 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003602 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3603 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003604 size,
John McCall550e0c22009-10-21 00:40:46 +00003605 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003606 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003607 if (Result.isNull())
3608 return QualType();
3609 }
John McCall550e0c22009-10-21 00:40:46 +00003610
3611 // We might have any sort of array type now, but fortunately they
3612 // all have the same location layout.
3613 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3614 NewTL.setLBracketLoc(TL.getLBracketLoc());
3615 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003616 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003617
3618 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003619}
Mike Stump11289f42009-09-09 15:08:12 +00003620
3621template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003622QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003623 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003624 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003625 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003626
3627 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003628 QualType ElementType = getDerived().TransformType(T->getElementType());
3629 if (ElementType.isNull())
3630 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003631
Douglas Gregore922c772009-08-04 22:27:00 +00003632 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003633 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003634
John McCalldadc5752010-08-24 06:29:42 +00003635 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003636 if (Size.isInvalid())
3637 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003638
John McCall550e0c22009-10-21 00:40:46 +00003639 QualType Result = TL.getType();
3640 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003641 ElementType != T->getElementType() ||
3642 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003643 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003644 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003645 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003646 if (Result.isNull())
3647 return QualType();
3648 }
John McCall550e0c22009-10-21 00:40:46 +00003649
3650 // Result might be dependent or not.
3651 if (isa<DependentSizedExtVectorType>(Result)) {
3652 DependentSizedExtVectorTypeLoc NewTL
3653 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3654 NewTL.setNameLoc(TL.getNameLoc());
3655 } else {
3656 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3657 NewTL.setNameLoc(TL.getNameLoc());
3658 }
3659
3660 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003661}
Mike Stump11289f42009-09-09 15:08:12 +00003662
3663template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003664QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003665 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003666 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003667 QualType ElementType = getDerived().TransformType(T->getElementType());
3668 if (ElementType.isNull())
3669 return QualType();
3670
John McCall550e0c22009-10-21 00:40:46 +00003671 QualType Result = TL.getType();
3672 if (getDerived().AlwaysRebuild() ||
3673 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003674 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003675 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003676 if (Result.isNull())
3677 return QualType();
3678 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003679
John McCall550e0c22009-10-21 00:40:46 +00003680 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3681 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003682
John McCall550e0c22009-10-21 00:40:46 +00003683 return Result;
3684}
3685
3686template<typename Derived>
3687QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003688 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003689 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003690 QualType ElementType = getDerived().TransformType(T->getElementType());
3691 if (ElementType.isNull())
3692 return QualType();
3693
3694 QualType Result = TL.getType();
3695 if (getDerived().AlwaysRebuild() ||
3696 ElementType != T->getElementType()) {
3697 Result = getDerived().RebuildExtVectorType(ElementType,
3698 T->getNumElements(),
3699 /*FIXME*/ SourceLocation());
3700 if (Result.isNull())
3701 return QualType();
3702 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003703
John McCall550e0c22009-10-21 00:40:46 +00003704 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3705 NewTL.setNameLoc(TL.getNameLoc());
3706
3707 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003708}
Mike Stump11289f42009-09-09 15:08:12 +00003709
3710template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003711ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003712TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3713 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003714 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003715 TypeSourceInfo *NewDI = 0;
3716
3717 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3718 // If we're substituting into a pack expansion type and we know the
3719 TypeLoc OldTL = OldDI->getTypeLoc();
3720 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3721
3722 TypeLocBuilder TLB;
3723 TypeLoc NewTL = OldDI->getTypeLoc();
3724 TLB.reserve(NewTL.getFullDataSize());
3725
3726 QualType Result = getDerived().TransformType(TLB,
3727 OldExpansionTL.getPatternLoc());
3728 if (Result.isNull())
3729 return 0;
3730
3731 Result = RebuildPackExpansionType(Result,
3732 OldExpansionTL.getPatternLoc().getSourceRange(),
3733 OldExpansionTL.getEllipsisLoc(),
3734 NumExpansions);
3735 if (Result.isNull())
3736 return 0;
3737
3738 PackExpansionTypeLoc NewExpansionTL
3739 = TLB.push<PackExpansionTypeLoc>(Result);
3740 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3741 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3742 } else
3743 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003744 if (!NewDI)
3745 return 0;
3746
3747 if (NewDI == OldDI)
3748 return OldParm;
3749 else
3750 return ParmVarDecl::Create(SemaRef.Context,
3751 OldParm->getDeclContext(),
3752 OldParm->getLocation(),
3753 OldParm->getIdentifier(),
3754 NewDI->getType(),
3755 NewDI,
3756 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003757 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003758 /* DefArg */ NULL);
3759}
3760
3761template<typename Derived>
3762bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003763 TransformFunctionTypeParams(SourceLocation Loc,
3764 ParmVarDecl **Params, unsigned NumParams,
3765 const QualType *ParamTypes,
3766 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3767 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3768 for (unsigned i = 0; i != NumParams; ++i) {
3769 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003770 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003771 if (OldParm->isParameterPack()) {
3772 // We have a function parameter pack that may need to be expanded.
3773 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003774
Douglas Gregor5499af42011-01-05 23:12:31 +00003775 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003776 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3777 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3778 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3779 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003780
3781 // Determine whether we should expand the parameter packs.
3782 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003783 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003784 llvm::Optional<unsigned> OrigNumExpansions
3785 = ExpansionTL.getTypePtr()->getNumExpansions();
3786 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003787 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3788 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003789 Unexpanded.data(),
3790 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003791 ShouldExpand,
3792 RetainExpansion,
3793 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003794 return true;
3795 }
3796
3797 if (ShouldExpand) {
3798 // Expand the function parameter pack into multiple, separate
3799 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003800 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003801 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003802 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3803 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003804 = getDerived().TransformFunctionTypeParam(OldParm,
3805 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003806 if (!NewParm)
3807 return true;
3808
Douglas Gregordd472162011-01-07 00:20:55 +00003809 OutParamTypes.push_back(NewParm->getType());
3810 if (PVars)
3811 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003812 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003813
3814 // If we're supposed to retain a pack expansion, do so by temporarily
3815 // forgetting the partially-substituted parameter pack.
3816 if (RetainExpansion) {
3817 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3818 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003819 = getDerived().TransformFunctionTypeParam(OldParm,
3820 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003821 if (!NewParm)
3822 return true;
3823
3824 OutParamTypes.push_back(NewParm->getType());
3825 if (PVars)
3826 PVars->push_back(NewParm);
3827 }
3828
Douglas Gregor5499af42011-01-05 23:12:31 +00003829 // We're done with the pack expansion.
3830 continue;
3831 }
3832
3833 // We'll substitute the parameter now without expanding the pack
3834 // expansion.
3835 }
3836
3837 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003838 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3839 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003840 if (!NewParm)
3841 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003842
Douglas Gregordd472162011-01-07 00:20:55 +00003843 OutParamTypes.push_back(NewParm->getType());
3844 if (PVars)
3845 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003846 continue;
3847 }
John McCall58f10c32010-03-11 09:03:00 +00003848
3849 // Deal with the possibility that we don't have a parameter
3850 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003851 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003852 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003853 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003854 if (const PackExpansionType *Expansion
3855 = dyn_cast<PackExpansionType>(OldType)) {
3856 // We have a function parameter pack that may need to be expanded.
3857 QualType Pattern = Expansion->getPattern();
3858 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3859 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3860
3861 // Determine whether we should expand the parameter packs.
3862 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003863 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003864 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003865 Unexpanded.data(),
3866 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003867 ShouldExpand,
3868 RetainExpansion,
3869 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003870 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003871 }
3872
3873 if (ShouldExpand) {
3874 // Expand the function parameter pack into multiple, separate
3875 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003876 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003877 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3878 QualType NewType = getDerived().TransformType(Pattern);
3879 if (NewType.isNull())
3880 return true;
John McCall58f10c32010-03-11 09:03:00 +00003881
Douglas Gregordd472162011-01-07 00:20:55 +00003882 OutParamTypes.push_back(NewType);
3883 if (PVars)
3884 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003885 }
3886
3887 // We're done with the pack expansion.
3888 continue;
3889 }
3890
Douglas Gregor48d24112011-01-10 20:53:55 +00003891 // If we're supposed to retain a pack expansion, do so by temporarily
3892 // forgetting the partially-substituted parameter pack.
3893 if (RetainExpansion) {
3894 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3895 QualType NewType = getDerived().TransformType(Pattern);
3896 if (NewType.isNull())
3897 return true;
3898
3899 OutParamTypes.push_back(NewType);
3900 if (PVars)
3901 PVars->push_back(0);
3902 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003903
Douglas Gregor5499af42011-01-05 23:12:31 +00003904 // We'll substitute the parameter now without expanding the pack
3905 // expansion.
3906 OldType = Expansion->getPattern();
3907 IsPackExpansion = true;
3908 }
3909
3910 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3911 QualType NewType = getDerived().TransformType(OldType);
3912 if (NewType.isNull())
3913 return true;
3914
3915 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003916 NewType = getSema().Context.getPackExpansionType(NewType,
3917 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003918
Douglas Gregordd472162011-01-07 00:20:55 +00003919 OutParamTypes.push_back(NewType);
3920 if (PVars)
3921 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003922 }
3923
3924 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003925 }
John McCall58f10c32010-03-11 09:03:00 +00003926
3927template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003928QualType
John McCall550e0c22009-10-21 00:40:46 +00003929TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003930 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003931 // Transform the parameters and return type.
3932 //
3933 // We instantiate in source order, with the return type first followed by
3934 // the parameters, because users tend to expect this (even if they shouldn't
3935 // rely on it!).
3936 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003937 // When the function has a trailing return type, we instantiate the
3938 // parameters before the return type, since the return type can then refer
3939 // to the parameters themselves (via decltype, sizeof, etc.).
3940 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003941 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003942 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003943 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003944
Douglas Gregor7fb25412010-10-01 18:44:50 +00003945 QualType ResultType;
3946
3947 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003948 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3949 TL.getParmArray(),
3950 TL.getNumArgs(),
3951 TL.getTypePtr()->arg_type_begin(),
3952 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003953 return QualType();
3954
3955 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3956 if (ResultType.isNull())
3957 return QualType();
3958 }
3959 else {
3960 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3961 if (ResultType.isNull())
3962 return QualType();
3963
Douglas Gregordd472162011-01-07 00:20:55 +00003964 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3965 TL.getParmArray(),
3966 TL.getNumArgs(),
3967 TL.getTypePtr()->arg_type_begin(),
3968 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003969 return QualType();
3970 }
3971
John McCall550e0c22009-10-21 00:40:46 +00003972 QualType Result = TL.getType();
3973 if (getDerived().AlwaysRebuild() ||
3974 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003975 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003976 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3977 Result = getDerived().RebuildFunctionProtoType(ResultType,
3978 ParamTypes.data(),
3979 ParamTypes.size(),
3980 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003981 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003982 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003983 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003984 if (Result.isNull())
3985 return QualType();
3986 }
Mike Stump11289f42009-09-09 15:08:12 +00003987
John McCall550e0c22009-10-21 00:40:46 +00003988 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3989 NewTL.setLParenLoc(TL.getLParenLoc());
3990 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003991 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003992 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3993 NewTL.setArg(i, ParamDecls[i]);
3994
3995 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003996}
Mike Stump11289f42009-09-09 15:08:12 +00003997
Douglas Gregord6ff3322009-08-04 16:50:30 +00003998template<typename Derived>
3999QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004000 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004001 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004002 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004003 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4004 if (ResultType.isNull())
4005 return QualType();
4006
4007 QualType Result = TL.getType();
4008 if (getDerived().AlwaysRebuild() ||
4009 ResultType != T->getResultType())
4010 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4011
4012 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4013 NewTL.setLParenLoc(TL.getLParenLoc());
4014 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004015 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004016
4017 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004018}
Mike Stump11289f42009-09-09 15:08:12 +00004019
John McCallb96ec562009-12-04 22:46:56 +00004020template<typename Derived> QualType
4021TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004022 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004023 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004024 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004025 if (!D)
4026 return QualType();
4027
4028 QualType Result = TL.getType();
4029 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4030 Result = getDerived().RebuildUnresolvedUsingType(D);
4031 if (Result.isNull())
4032 return QualType();
4033 }
4034
4035 // We might get an arbitrary type spec type back. We should at
4036 // least always get a type spec type, though.
4037 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4038 NewTL.setNameLoc(TL.getNameLoc());
4039
4040 return Result;
4041}
4042
Douglas Gregord6ff3322009-08-04 16:50:30 +00004043template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004044QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004045 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004046 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004047 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004048 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4049 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004050 if (!Typedef)
4051 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004052
John McCall550e0c22009-10-21 00:40:46 +00004053 QualType Result = TL.getType();
4054 if (getDerived().AlwaysRebuild() ||
4055 Typedef != T->getDecl()) {
4056 Result = getDerived().RebuildTypedefType(Typedef);
4057 if (Result.isNull())
4058 return QualType();
4059 }
Mike Stump11289f42009-09-09 15:08:12 +00004060
John McCall550e0c22009-10-21 00:40:46 +00004061 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4062 NewTL.setNameLoc(TL.getNameLoc());
4063
4064 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004065}
Mike Stump11289f42009-09-09 15:08:12 +00004066
Douglas Gregord6ff3322009-08-04 16:50:30 +00004067template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004068QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004069 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004070 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004071 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004072
John McCalldadc5752010-08-24 06:29:42 +00004073 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004074 if (E.isInvalid())
4075 return QualType();
4076
John McCall550e0c22009-10-21 00:40:46 +00004077 QualType Result = TL.getType();
4078 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004079 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004080 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004081 if (Result.isNull())
4082 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004083 }
John McCall550e0c22009-10-21 00:40:46 +00004084 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004085
John McCall550e0c22009-10-21 00:40:46 +00004086 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004087 NewTL.setTypeofLoc(TL.getTypeofLoc());
4088 NewTL.setLParenLoc(TL.getLParenLoc());
4089 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004090
4091 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004092}
Mike Stump11289f42009-09-09 15:08:12 +00004093
4094template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004095QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004096 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004097 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4098 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4099 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004100 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004101
John McCall550e0c22009-10-21 00:40:46 +00004102 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004103 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4104 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004105 if (Result.isNull())
4106 return QualType();
4107 }
Mike Stump11289f42009-09-09 15:08:12 +00004108
John McCall550e0c22009-10-21 00:40:46 +00004109 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004110 NewTL.setTypeofLoc(TL.getTypeofLoc());
4111 NewTL.setLParenLoc(TL.getLParenLoc());
4112 NewTL.setRParenLoc(TL.getRParenLoc());
4113 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004114
4115 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004116}
Mike Stump11289f42009-09-09 15:08:12 +00004117
4118template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004119QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004120 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004121 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004122
Douglas Gregore922c772009-08-04 22:27:00 +00004123 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004124 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004125
John McCalldadc5752010-08-24 06:29:42 +00004126 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004127 if (E.isInvalid())
4128 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004129
John McCall550e0c22009-10-21 00:40:46 +00004130 QualType Result = TL.getType();
4131 if (getDerived().AlwaysRebuild() ||
4132 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004133 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004134 if (Result.isNull())
4135 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004136 }
John McCall550e0c22009-10-21 00:40:46 +00004137 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004138
John McCall550e0c22009-10-21 00:40:46 +00004139 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4140 NewTL.setNameLoc(TL.getNameLoc());
4141
4142 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004143}
4144
4145template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004146QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4147 AutoTypeLoc TL) {
4148 const AutoType *T = TL.getTypePtr();
4149 QualType OldDeduced = T->getDeducedType();
4150 QualType NewDeduced;
4151 if (!OldDeduced.isNull()) {
4152 NewDeduced = getDerived().TransformType(OldDeduced);
4153 if (NewDeduced.isNull())
4154 return QualType();
4155 }
4156
4157 QualType Result = TL.getType();
4158 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4159 Result = getDerived().RebuildAutoType(NewDeduced);
4160 if (Result.isNull())
4161 return QualType();
4162 }
4163
4164 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4165 NewTL.setNameLoc(TL.getNameLoc());
4166
4167 return Result;
4168}
4169
4170template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004171QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004172 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004173 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004174 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004175 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4176 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004177 if (!Record)
4178 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004179
John McCall550e0c22009-10-21 00:40:46 +00004180 QualType Result = TL.getType();
4181 if (getDerived().AlwaysRebuild() ||
4182 Record != T->getDecl()) {
4183 Result = getDerived().RebuildRecordType(Record);
4184 if (Result.isNull())
4185 return QualType();
4186 }
Mike Stump11289f42009-09-09 15:08:12 +00004187
John McCall550e0c22009-10-21 00:40:46 +00004188 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4189 NewTL.setNameLoc(TL.getNameLoc());
4190
4191 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004192}
Mike Stump11289f42009-09-09 15:08:12 +00004193
4194template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004195QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004196 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004197 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004198 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004199 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4200 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004201 if (!Enum)
4202 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004203
John McCall550e0c22009-10-21 00:40:46 +00004204 QualType Result = TL.getType();
4205 if (getDerived().AlwaysRebuild() ||
4206 Enum != T->getDecl()) {
4207 Result = getDerived().RebuildEnumType(Enum);
4208 if (Result.isNull())
4209 return QualType();
4210 }
Mike Stump11289f42009-09-09 15:08:12 +00004211
John McCall550e0c22009-10-21 00:40:46 +00004212 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4213 NewTL.setNameLoc(TL.getNameLoc());
4214
4215 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004216}
John McCallfcc33b02009-09-05 00:15:47 +00004217
John McCalle78aac42010-03-10 03:28:59 +00004218template<typename Derived>
4219QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4220 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004221 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004222 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4223 TL.getTypePtr()->getDecl());
4224 if (!D) return QualType();
4225
4226 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4227 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4228 return T;
4229}
4230
Douglas Gregord6ff3322009-08-04 16:50:30 +00004231template<typename Derived>
4232QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004233 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004234 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004235 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004236}
4237
Mike Stump11289f42009-09-09 15:08:12 +00004238template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004239QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004240 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004241 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004242 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004243}
4244
4245template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004246QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4247 TypeLocBuilder &TLB,
4248 SubstTemplateTypeParmPackTypeLoc TL) {
4249 return TransformTypeSpecType(TLB, TL);
4250}
4251
4252template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004253QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004254 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004255 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004256 const TemplateSpecializationType *T = TL.getTypePtr();
4257
Mike Stump11289f42009-09-09 15:08:12 +00004258 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004259 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004260 if (Template.isNull())
4261 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004262
John McCall31f82722010-11-12 08:19:04 +00004263 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4264}
4265
Douglas Gregorfe921a72010-12-20 23:36:19 +00004266namespace {
4267 /// \brief Simple iterator that traverses the template arguments in a
4268 /// container that provides a \c getArgLoc() member function.
4269 ///
4270 /// This iterator is intended to be used with the iterator form of
4271 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4272 template<typename ArgLocContainer>
4273 class TemplateArgumentLocContainerIterator {
4274 ArgLocContainer *Container;
4275 unsigned Index;
4276
4277 public:
4278 typedef TemplateArgumentLoc value_type;
4279 typedef TemplateArgumentLoc reference;
4280 typedef int difference_type;
4281 typedef std::input_iterator_tag iterator_category;
4282
4283 class pointer {
4284 TemplateArgumentLoc Arg;
4285
4286 public:
4287 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4288
4289 const TemplateArgumentLoc *operator->() const {
4290 return &Arg;
4291 }
4292 };
4293
4294
4295 TemplateArgumentLocContainerIterator() {}
4296
4297 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4298 unsigned Index)
4299 : Container(&Container), Index(Index) { }
4300
4301 TemplateArgumentLocContainerIterator &operator++() {
4302 ++Index;
4303 return *this;
4304 }
4305
4306 TemplateArgumentLocContainerIterator operator++(int) {
4307 TemplateArgumentLocContainerIterator Old(*this);
4308 ++(*this);
4309 return Old;
4310 }
4311
4312 TemplateArgumentLoc operator*() const {
4313 return Container->getArgLoc(Index);
4314 }
4315
4316 pointer operator->() const {
4317 return pointer(Container->getArgLoc(Index));
4318 }
4319
4320 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004321 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004322 return X.Container == Y.Container && X.Index == Y.Index;
4323 }
4324
4325 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004326 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004327 return !(X == Y);
4328 }
4329 };
4330}
4331
4332
John McCall31f82722010-11-12 08:19:04 +00004333template <typename Derived>
4334QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4335 TypeLocBuilder &TLB,
4336 TemplateSpecializationTypeLoc TL,
4337 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004338 TemplateArgumentListInfo NewTemplateArgs;
4339 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4340 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004341 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4342 ArgIterator;
4343 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4344 ArgIterator(TL, TL.getNumArgs()),
4345 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004346 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004347
John McCall0ad16662009-10-29 08:12:44 +00004348 // FIXME: maybe don't rebuild if all the template arguments are the same.
4349
4350 QualType Result =
4351 getDerived().RebuildTemplateSpecializationType(Template,
4352 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004353 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004354
4355 if (!Result.isNull()) {
4356 TemplateSpecializationTypeLoc NewTL
4357 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4358 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4359 NewTL.setLAngleLoc(TL.getLAngleLoc());
4360 NewTL.setRAngleLoc(TL.getRAngleLoc());
4361 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4362 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004363 }
Mike Stump11289f42009-09-09 15:08:12 +00004364
John McCall0ad16662009-10-29 08:12:44 +00004365 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004366}
Mike Stump11289f42009-09-09 15:08:12 +00004367
4368template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004369QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004370TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004371 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004372 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004373
4374 NestedNameSpecifier *NNS = 0;
4375 // NOTE: the qualifier in an ElaboratedType is optional.
4376 if (T->getQualifier() != 0) {
4377 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004378 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004379 if (!NNS)
4380 return QualType();
4381 }
Mike Stump11289f42009-09-09 15:08:12 +00004382
John McCall31f82722010-11-12 08:19:04 +00004383 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4384 if (NamedT.isNull())
4385 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004386
John McCall550e0c22009-10-21 00:40:46 +00004387 QualType Result = TL.getType();
4388 if (getDerived().AlwaysRebuild() ||
4389 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004390 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004391 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4392 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004393 if (Result.isNull())
4394 return QualType();
4395 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004396
Abramo Bagnara6150c882010-05-11 21:36:43 +00004397 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004398 NewTL.setKeywordLoc(TL.getKeywordLoc());
4399 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004400
4401 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004402}
Mike Stump11289f42009-09-09 15:08:12 +00004403
4404template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004405QualType TreeTransform<Derived>::TransformAttributedType(
4406 TypeLocBuilder &TLB,
4407 AttributedTypeLoc TL) {
4408 const AttributedType *oldType = TL.getTypePtr();
4409 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4410 if (modifiedType.isNull())
4411 return QualType();
4412
4413 QualType result = TL.getType();
4414
4415 // FIXME: dependent operand expressions?
4416 if (getDerived().AlwaysRebuild() ||
4417 modifiedType != oldType->getModifiedType()) {
4418 // TODO: this is really lame; we should really be rebuilding the
4419 // equivalent type from first principles.
4420 QualType equivalentType
4421 = getDerived().TransformType(oldType->getEquivalentType());
4422 if (equivalentType.isNull())
4423 return QualType();
4424 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4425 modifiedType,
4426 equivalentType);
4427 }
4428
4429 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4430 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4431 if (TL.hasAttrOperand())
4432 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4433 if (TL.hasAttrExprOperand())
4434 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4435 else if (TL.hasAttrEnumOperand())
4436 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4437
4438 return result;
4439}
4440
4441template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004442QualType
4443TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4444 ParenTypeLoc TL) {
4445 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4446 if (Inner.isNull())
4447 return QualType();
4448
4449 QualType Result = TL.getType();
4450 if (getDerived().AlwaysRebuild() ||
4451 Inner != TL.getInnerLoc().getType()) {
4452 Result = getDerived().RebuildParenType(Inner);
4453 if (Result.isNull())
4454 return QualType();
4455 }
4456
4457 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4458 NewTL.setLParenLoc(TL.getLParenLoc());
4459 NewTL.setRParenLoc(TL.getRParenLoc());
4460 return Result;
4461}
4462
4463template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004464QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004465 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004466 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004467
Douglas Gregord6ff3322009-08-04 16:50:30 +00004468 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004469 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004470 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004471 if (!NNS)
4472 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004473
John McCallc392f372010-06-11 00:33:02 +00004474 QualType Result
4475 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4476 T->getIdentifier(),
4477 TL.getKeywordLoc(),
4478 TL.getQualifierRange(),
4479 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004480 if (Result.isNull())
4481 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004482
Abramo Bagnarad7548482010-05-19 21:37:53 +00004483 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4484 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004485 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4486
Abramo Bagnarad7548482010-05-19 21:37:53 +00004487 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4488 NewTL.setKeywordLoc(TL.getKeywordLoc());
4489 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004490 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004491 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4492 NewTL.setKeywordLoc(TL.getKeywordLoc());
4493 NewTL.setQualifierRange(TL.getQualifierRange());
4494 NewTL.setNameLoc(TL.getNameLoc());
4495 }
John McCall550e0c22009-10-21 00:40:46 +00004496 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004497}
Mike Stump11289f42009-09-09 15:08:12 +00004498
Douglas Gregord6ff3322009-08-04 16:50:30 +00004499template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004500QualType TreeTransform<Derived>::
4501 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004502 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004503 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004504
4505 NestedNameSpecifier *NNS
4506 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004507 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004508 if (!NNS)
4509 return QualType();
4510
John McCall31f82722010-11-12 08:19:04 +00004511 return getDerived()
4512 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4513}
4514
4515template<typename Derived>
4516QualType TreeTransform<Derived>::
4517 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4518 DependentTemplateSpecializationTypeLoc TL,
4519 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004520 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004521
John McCallc392f372010-06-11 00:33:02 +00004522 TemplateArgumentListInfo NewTemplateArgs;
4523 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4524 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor14454802011-02-25 02:25:35 +00004525
4526 // FIXME: Nested-name-specifier source location info!
Douglas Gregorfe921a72010-12-20 23:36:19 +00004527 typedef TemplateArgumentLocContainerIterator<
4528 DependentTemplateSpecializationTypeLoc> ArgIterator;
4529 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4530 ArgIterator(TL, TL.getNumArgs()),
4531 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004532 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004533
Douglas Gregora5614c52010-09-08 23:56:00 +00004534 QualType Result
4535 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4536 NNS,
4537 TL.getQualifierRange(),
4538 T->getIdentifier(),
4539 TL.getNameLoc(),
4540 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004541 if (Result.isNull())
4542 return QualType();
4543
4544 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4545 QualType NamedT = ElabT->getNamedType();
4546
4547 // Copy information relevant to the template specialization.
4548 TemplateSpecializationTypeLoc NamedTL
4549 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4550 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4551 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4552 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4553 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4554
4555 // Copy information relevant to the elaborated type.
4556 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4557 NewTL.setKeywordLoc(TL.getKeywordLoc());
4558 NewTL.setQualifierRange(TL.getQualifierRange());
4559 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004560 TypeLoc NewTL(Result, TL.getOpaqueData());
4561 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004562 }
4563 return Result;
4564}
4565
4566template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004567QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4568 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004569 QualType Pattern
4570 = getDerived().TransformType(TLB, TL.getPatternLoc());
4571 if (Pattern.isNull())
4572 return QualType();
4573
4574 QualType Result = TL.getType();
4575 if (getDerived().AlwaysRebuild() ||
4576 Pattern != TL.getPatternLoc().getType()) {
4577 Result = getDerived().RebuildPackExpansionType(Pattern,
4578 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004579 TL.getEllipsisLoc(),
4580 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004581 if (Result.isNull())
4582 return QualType();
4583 }
4584
4585 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4586 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4587 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004588}
4589
4590template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004591QualType
4592TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004593 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004594 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004595 TLB.pushFullCopy(TL);
4596 return TL.getType();
4597}
4598
4599template<typename Derived>
4600QualType
4601TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004602 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004603 // ObjCObjectType is never dependent.
4604 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004605 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004606}
Mike Stump11289f42009-09-09 15:08:12 +00004607
4608template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004609QualType
4610TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004611 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004612 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004613 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004614 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004615}
4616
Douglas Gregord6ff3322009-08-04 16:50:30 +00004617//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004618// Statement transformation
4619//===----------------------------------------------------------------------===//
4620template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004621StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004622TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004623 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004624}
4625
4626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004627StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004628TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4629 return getDerived().TransformCompoundStmt(S, false);
4630}
4631
4632template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004633StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004634TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004635 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004636 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004637 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004638 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004639 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4640 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004641 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004642 if (Result.isInvalid()) {
4643 // Immediately fail if this was a DeclStmt, since it's very
4644 // likely that this will cause problems for future statements.
4645 if (isa<DeclStmt>(*B))
4646 return StmtError();
4647
4648 // Otherwise, just keep processing substatements and fail later.
4649 SubStmtInvalid = true;
4650 continue;
4651 }
Mike Stump11289f42009-09-09 15:08:12 +00004652
Douglas Gregorebe10102009-08-20 07:17:43 +00004653 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4654 Statements.push_back(Result.takeAs<Stmt>());
4655 }
Mike Stump11289f42009-09-09 15:08:12 +00004656
John McCall1ababa62010-08-27 19:56:05 +00004657 if (SubStmtInvalid)
4658 return StmtError();
4659
Douglas Gregorebe10102009-08-20 07:17:43 +00004660 if (!getDerived().AlwaysRebuild() &&
4661 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004662 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004663
4664 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4665 move_arg(Statements),
4666 S->getRBracLoc(),
4667 IsStmtExpr);
4668}
Mike Stump11289f42009-09-09 15:08:12 +00004669
Douglas Gregorebe10102009-08-20 07:17:43 +00004670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004671StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004672TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004673 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004674 {
4675 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004676 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004677
Eli Friedman06577382009-11-19 03:14:00 +00004678 // Transform the left-hand case value.
4679 LHS = getDerived().TransformExpr(S->getLHS());
4680 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004681 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004682
Eli Friedman06577382009-11-19 03:14:00 +00004683 // Transform the right-hand case value (for the GNU case-range extension).
4684 RHS = getDerived().TransformExpr(S->getRHS());
4685 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004686 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004687 }
Mike Stump11289f42009-09-09 15:08:12 +00004688
Douglas Gregorebe10102009-08-20 07:17:43 +00004689 // Build the case statement.
4690 // Case statements are always rebuilt so that they will attached to their
4691 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004692 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004693 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004694 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004695 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004696 S->getColonLoc());
4697 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004698 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004699
Douglas Gregorebe10102009-08-20 07:17:43 +00004700 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004701 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004702 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004703 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004704
Douglas Gregorebe10102009-08-20 07:17:43 +00004705 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004706 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004707}
4708
4709template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004710StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004711TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004712 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004713 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004714 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004715 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004716
Douglas Gregorebe10102009-08-20 07:17:43 +00004717 // Default statements are always rebuilt
4718 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004719 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004720}
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregorebe10102009-08-20 07:17:43 +00004722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004723StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004724TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004725 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004726 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004727 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004728
Chris Lattnercab02a62011-02-17 20:34:02 +00004729 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4730 S->getDecl());
4731 if (!LD)
4732 return StmtError();
4733
4734
Douglas Gregorebe10102009-08-20 07:17:43 +00004735 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004736 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004737 cast<LabelDecl>(LD), SourceLocation(),
4738 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004739}
Mike Stump11289f42009-09-09 15:08:12 +00004740
Douglas Gregorebe10102009-08-20 07:17:43 +00004741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004742StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004743TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004744 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004745 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004746 VarDecl *ConditionVar = 0;
4747 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004748 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004749 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004750 getDerived().TransformDefinition(
4751 S->getConditionVariable()->getLocation(),
4752 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004753 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004754 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004755 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004756 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004757
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004758 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004759 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004760
4761 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004762 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004763 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4764 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004765 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004766 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004767
John McCallb268a282010-08-23 23:25:46 +00004768 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004769 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004770 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004771
John McCallb268a282010-08-23 23:25:46 +00004772 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4773 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004774 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004775
Douglas Gregorebe10102009-08-20 07:17:43 +00004776 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004777 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004778 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004779 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004780
Douglas Gregorebe10102009-08-20 07:17:43 +00004781 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004782 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004783 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004784 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004785
Douglas Gregorebe10102009-08-20 07:17:43 +00004786 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004787 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004788 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004789 Then.get() == S->getThen() &&
4790 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004791 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004792
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004793 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004794 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004795 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004796}
4797
4798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004799StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004800TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004801 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004802 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004803 VarDecl *ConditionVar = 0;
4804 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004805 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004806 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004807 getDerived().TransformDefinition(
4808 S->getConditionVariable()->getLocation(),
4809 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004810 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004811 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004812 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004813 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004814
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004815 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004816 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004817 }
Mike Stump11289f42009-09-09 15:08:12 +00004818
Douglas Gregorebe10102009-08-20 07:17:43 +00004819 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004820 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004821 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004822 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004823 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004824 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004825
Douglas Gregorebe10102009-08-20 07:17:43 +00004826 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004827 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004828 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004829 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004830
Douglas Gregorebe10102009-08-20 07:17:43 +00004831 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004832 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4833 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004834}
Mike Stump11289f42009-09-09 15:08:12 +00004835
Douglas Gregorebe10102009-08-20 07:17:43 +00004836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004837StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004838TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004839 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004840 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004841 VarDecl *ConditionVar = 0;
4842 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004843 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004844 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004845 getDerived().TransformDefinition(
4846 S->getConditionVariable()->getLocation(),
4847 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004848 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004849 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004850 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004851 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004852
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004853 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004854 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004855
4856 if (S->getCond()) {
4857 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004858 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4859 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004860 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004861 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004862 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004863 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004864 }
Mike Stump11289f42009-09-09 15:08:12 +00004865
John McCallb268a282010-08-23 23:25:46 +00004866 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4867 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004868 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004869
Douglas Gregorebe10102009-08-20 07:17:43 +00004870 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004871 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004872 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004873 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004874
Douglas Gregorebe10102009-08-20 07:17:43 +00004875 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004876 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004877 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004878 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004879 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004880
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004881 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004882 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004883}
Mike Stump11289f42009-09-09 15:08:12 +00004884
Douglas Gregorebe10102009-08-20 07:17:43 +00004885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004886StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004887TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004888 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004889 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004890 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004891 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004892
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004893 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004894 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004895 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004896 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004897
Douglas Gregorebe10102009-08-20 07:17:43 +00004898 if (!getDerived().AlwaysRebuild() &&
4899 Cond.get() == S->getCond() &&
4900 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004901 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004902
John McCallb268a282010-08-23 23:25:46 +00004903 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4904 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004905 S->getRParenLoc());
4906}
Mike Stump11289f42009-09-09 15:08:12 +00004907
Douglas Gregorebe10102009-08-20 07:17:43 +00004908template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004909StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004910TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004911 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004912 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004913 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004914 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004915
Douglas Gregorebe10102009-08-20 07:17:43 +00004916 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004917 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004918 VarDecl *ConditionVar = 0;
4919 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004920 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004921 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004922 getDerived().TransformDefinition(
4923 S->getConditionVariable()->getLocation(),
4924 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004925 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004926 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004927 } else {
4928 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004929
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004930 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004931 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004932
4933 if (S->getCond()) {
4934 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004935 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4936 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004937 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004938 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004939
John McCallb268a282010-08-23 23:25:46 +00004940 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004941 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004942 }
Mike Stump11289f42009-09-09 15:08:12 +00004943
John McCallb268a282010-08-23 23:25:46 +00004944 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4945 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004946 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004947
Douglas Gregorebe10102009-08-20 07:17:43 +00004948 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004949 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004950 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004951 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004952
John McCallb268a282010-08-23 23:25:46 +00004953 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4954 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004955 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004956
Douglas Gregorebe10102009-08-20 07:17:43 +00004957 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004958 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004959 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004960 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004961
Douglas Gregorebe10102009-08-20 07:17:43 +00004962 if (!getDerived().AlwaysRebuild() &&
4963 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004964 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004965 Inc.get() == S->getInc() &&
4966 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004967 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004968
Douglas Gregorebe10102009-08-20 07:17:43 +00004969 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004970 Init.get(), FullCond, ConditionVar,
4971 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004972}
4973
4974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004975StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004976TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00004977 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
4978 S->getLabel());
4979 if (!LD)
4980 return StmtError();
4981
Douglas Gregorebe10102009-08-20 07:17:43 +00004982 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004983 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004984 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00004985}
4986
4987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004988StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004989TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004990 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004991 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004992 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004993
Douglas Gregorebe10102009-08-20 07:17:43 +00004994 if (!getDerived().AlwaysRebuild() &&
4995 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004996 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004997
4998 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004999 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005000}
5001
5002template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005003StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005004TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005005 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005006}
Mike Stump11289f42009-09-09 15:08:12 +00005007
Douglas Gregorebe10102009-08-20 07:17:43 +00005008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005009StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005010TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005011 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005012}
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregorebe10102009-08-20 07:17:43 +00005014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005015StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005016TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005017 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005018 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005019 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005020
Mike Stump11289f42009-09-09 15:08:12 +00005021 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005022 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005023 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005024}
Mike Stump11289f42009-09-09 15:08:12 +00005025
Douglas Gregorebe10102009-08-20 07:17:43 +00005026template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005027StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005028TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005029 bool DeclChanged = false;
5030 llvm::SmallVector<Decl *, 4> Decls;
5031 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5032 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005033 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5034 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005035 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005036 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005037
Douglas Gregorebe10102009-08-20 07:17:43 +00005038 if (Transformed != *D)
5039 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005040
Douglas Gregorebe10102009-08-20 07:17:43 +00005041 Decls.push_back(Transformed);
5042 }
Mike Stump11289f42009-09-09 15:08:12 +00005043
Douglas Gregorebe10102009-08-20 07:17:43 +00005044 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005045 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005046
5047 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005048 S->getStartLoc(), S->getEndLoc());
5049}
Mike Stump11289f42009-09-09 15:08:12 +00005050
Douglas Gregorebe10102009-08-20 07:17:43 +00005051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005052StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005053TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005054
John McCall37ad5512010-08-23 06:44:23 +00005055 ASTOwningVector<Expr*> Constraints(getSema());
5056 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005057 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005058
John McCalldadc5752010-08-24 06:29:42 +00005059 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005060 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005061
5062 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005063
Anders Carlssonaaeef072010-01-24 05:50:09 +00005064 // Go through the outputs.
5065 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005066 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005067
Anders Carlssonaaeef072010-01-24 05:50:09 +00005068 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005069 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005070
Anders Carlssonaaeef072010-01-24 05:50:09 +00005071 // Transform the output expr.
5072 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005073 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005074 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005075 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005076
Anders Carlssonaaeef072010-01-24 05:50:09 +00005077 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005078
John McCallb268a282010-08-23 23:25:46 +00005079 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005080 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005081
Anders Carlssonaaeef072010-01-24 05:50:09 +00005082 // Go through the inputs.
5083 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005084 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005085
Anders Carlssonaaeef072010-01-24 05:50:09 +00005086 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005087 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005088
Anders Carlssonaaeef072010-01-24 05:50:09 +00005089 // Transform the input expr.
5090 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005091 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005092 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005093 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005094
Anders Carlssonaaeef072010-01-24 05:50:09 +00005095 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005096
John McCallb268a282010-08-23 23:25:46 +00005097 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005098 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005099
Anders Carlssonaaeef072010-01-24 05:50:09 +00005100 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005101 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005102
5103 // Go through the clobbers.
5104 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005105 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005106
5107 // No need to transform the asm string literal.
5108 AsmString = SemaRef.Owned(S->getAsmString());
5109
5110 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5111 S->isSimple(),
5112 S->isVolatile(),
5113 S->getNumOutputs(),
5114 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005115 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005116 move_arg(Constraints),
5117 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005118 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005119 move_arg(Clobbers),
5120 S->getRParenLoc(),
5121 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005122}
5123
5124
5125template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005126StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005127TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005128 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005129 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005130 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005131 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005132
Douglas Gregor96c79492010-04-23 22:50:49 +00005133 // Transform the @catch statements (if present).
5134 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005135 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005136 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005137 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005138 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005139 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005140 if (Catch.get() != S->getCatchStmt(I))
5141 AnyCatchChanged = true;
5142 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005143 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005144
Douglas Gregor306de2f2010-04-22 23:59:56 +00005145 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005146 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005147 if (S->getFinallyStmt()) {
5148 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5149 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005150 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005151 }
5152
5153 // If nothing changed, just retain this statement.
5154 if (!getDerived().AlwaysRebuild() &&
5155 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005156 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005157 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005158 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005159
Douglas Gregor306de2f2010-04-22 23:59:56 +00005160 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005161 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5162 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005163}
Mike Stump11289f42009-09-09 15:08:12 +00005164
Douglas Gregorebe10102009-08-20 07:17:43 +00005165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005166StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005167TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005168 // Transform the @catch parameter, if there is one.
5169 VarDecl *Var = 0;
5170 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5171 TypeSourceInfo *TSInfo = 0;
5172 if (FromVar->getTypeSourceInfo()) {
5173 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5174 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005175 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005176 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005177
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005178 QualType T;
5179 if (TSInfo)
5180 T = TSInfo->getType();
5181 else {
5182 T = getDerived().TransformType(FromVar->getType());
5183 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005184 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005185 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005186
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005187 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5188 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005189 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005190 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005191
John McCalldadc5752010-08-24 06:29:42 +00005192 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005193 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005194 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005195
5196 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005197 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005198 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005199}
Mike Stump11289f42009-09-09 15:08:12 +00005200
Douglas Gregorebe10102009-08-20 07:17:43 +00005201template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005202StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005203TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005204 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005205 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005206 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005207 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005208
Douglas Gregor306de2f2010-04-22 23:59:56 +00005209 // If nothing changed, just retain this statement.
5210 if (!getDerived().AlwaysRebuild() &&
5211 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005212 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005213
5214 // Build a new statement.
5215 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005216 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005217}
Mike Stump11289f42009-09-09 15:08:12 +00005218
Douglas Gregorebe10102009-08-20 07:17:43 +00005219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005220StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005221TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005222 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005223 if (S->getThrowExpr()) {
5224 Operand = getDerived().TransformExpr(S->getThrowExpr());
5225 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005226 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005227 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005228
Douglas Gregor2900c162010-04-22 21:44:01 +00005229 if (!getDerived().AlwaysRebuild() &&
5230 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005231 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005232
John McCallb268a282010-08-23 23:25:46 +00005233 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005234}
Mike Stump11289f42009-09-09 15:08:12 +00005235
Douglas Gregorebe10102009-08-20 07:17:43 +00005236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005237StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005238TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005239 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005240 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005241 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005242 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005243 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005244
Douglas Gregor6148de72010-04-22 22:01:21 +00005245 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005246 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005247 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005248 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005249
Douglas Gregor6148de72010-04-22 22:01:21 +00005250 // If nothing change, just retain the current statement.
5251 if (!getDerived().AlwaysRebuild() &&
5252 Object.get() == S->getSynchExpr() &&
5253 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005254 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005255
5256 // Build a new statement.
5257 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005258 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005259}
5260
5261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005262StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005263TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005264 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005265 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005266 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005267 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005268 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005269
Douglas Gregorf68a5082010-04-22 23:10:45 +00005270 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005271 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005272 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005273 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005274
Douglas Gregorf68a5082010-04-22 23:10:45 +00005275 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005276 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005277 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005278 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005279
Douglas Gregorf68a5082010-04-22 23:10:45 +00005280 // If nothing changed, just retain this statement.
5281 if (!getDerived().AlwaysRebuild() &&
5282 Element.get() == S->getElement() &&
5283 Collection.get() == S->getCollection() &&
5284 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005285 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005286
Douglas Gregorf68a5082010-04-22 23:10:45 +00005287 // Build a new statement.
5288 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5289 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005290 Element.get(),
5291 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005292 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005293 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005294}
5295
5296
5297template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005298StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005299TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5300 // Transform the exception declaration, if any.
5301 VarDecl *Var = 0;
5302 if (S->getExceptionDecl()) {
5303 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005304 TypeSourceInfo *T = getDerived().TransformType(
5305 ExceptionDecl->getTypeSourceInfo());
5306 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005307 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005308
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005309 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005310 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005311 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005312 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005313 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005314 }
Mike Stump11289f42009-09-09 15:08:12 +00005315
Douglas Gregorebe10102009-08-20 07:17:43 +00005316 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005317 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005318 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005319 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005320
Douglas Gregorebe10102009-08-20 07:17:43 +00005321 if (!getDerived().AlwaysRebuild() &&
5322 !Var &&
5323 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005324 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005325
5326 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5327 Var,
John McCallb268a282010-08-23 23:25:46 +00005328 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005329}
Mike Stump11289f42009-09-09 15:08:12 +00005330
Douglas Gregorebe10102009-08-20 07:17:43 +00005331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005332StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005333TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5334 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005335 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005336 = getDerived().TransformCompoundStmt(S->getTryBlock());
5337 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005338 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005339
Douglas Gregorebe10102009-08-20 07:17:43 +00005340 // Transform the handlers.
5341 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005342 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005343 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005344 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005345 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5346 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005347 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005348
Douglas Gregorebe10102009-08-20 07:17:43 +00005349 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5350 Handlers.push_back(Handler.takeAs<Stmt>());
5351 }
Mike Stump11289f42009-09-09 15:08:12 +00005352
Douglas Gregorebe10102009-08-20 07:17:43 +00005353 if (!getDerived().AlwaysRebuild() &&
5354 TryBlock.get() == S->getTryBlock() &&
5355 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005356 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005357
John McCallb268a282010-08-23 23:25:46 +00005358 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005359 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005360}
Mike Stump11289f42009-09-09 15:08:12 +00005361
Douglas Gregorebe10102009-08-20 07:17:43 +00005362//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005363// Expression transformation
5364//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005365template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005366ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005367TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005368 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005369}
Mike Stump11289f42009-09-09 15:08:12 +00005370
5371template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005372ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005373TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005374 NestedNameSpecifier *Qualifier = 0;
5375 if (E->getQualifier()) {
5376 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005377 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005378 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005379 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005380 }
John McCallce546572009-12-08 09:08:17 +00005381
5382 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005383 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5384 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005385 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005386 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005387
John McCall815039a2010-08-17 21:27:17 +00005388 DeclarationNameInfo NameInfo = E->getNameInfo();
5389 if (NameInfo.getName()) {
5390 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5391 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005392 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005393 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005394
5395 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005396 Qualifier == E->getQualifier() &&
5397 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005398 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005399 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005400
5401 // Mark it referenced in the new context regardless.
5402 // FIXME: this is a bit instantiation-specific.
5403 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5404
John McCallc3007a22010-10-26 07:05:15 +00005405 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005406 }
John McCallce546572009-12-08 09:08:17 +00005407
5408 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005409 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005410 TemplateArgs = &TransArgs;
5411 TransArgs.setLAngleLoc(E->getLAngleLoc());
5412 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005413 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5414 E->getNumTemplateArgs(),
5415 TransArgs))
5416 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005417 }
5418
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005419 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005420 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005421}
Mike Stump11289f42009-09-09 15:08:12 +00005422
Douglas Gregora16548e2009-08-11 05:31:07 +00005423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005424ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005425TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005426 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005427}
Mike Stump11289f42009-09-09 15:08:12 +00005428
Douglas Gregora16548e2009-08-11 05:31:07 +00005429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005430ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005431TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005432 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005433}
Mike Stump11289f42009-09-09 15:08:12 +00005434
Douglas Gregora16548e2009-08-11 05:31:07 +00005435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005436ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005437TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005438 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005439}
Mike Stump11289f42009-09-09 15:08:12 +00005440
Douglas Gregora16548e2009-08-11 05:31:07 +00005441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005442ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005443TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005444 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005445}
Mike Stump11289f42009-09-09 15:08:12 +00005446
Douglas Gregora16548e2009-08-11 05:31:07 +00005447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005448ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005449TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005450 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005451}
5452
5453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005454ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005455TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005456 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005457 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005458 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005459
Douglas Gregora16548e2009-08-11 05:31:07 +00005460 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005461 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005462
John McCallb268a282010-08-23 23:25:46 +00005463 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005464 E->getRParen());
5465}
5466
Mike Stump11289f42009-09-09 15:08:12 +00005467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005468ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005469TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005470 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005471 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005472 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005473
Douglas Gregora16548e2009-08-11 05:31:07 +00005474 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005475 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005476
Douglas Gregora16548e2009-08-11 05:31:07 +00005477 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5478 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005479 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005480}
Mike Stump11289f42009-09-09 15:08:12 +00005481
Douglas Gregora16548e2009-08-11 05:31:07 +00005482template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005483ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005484TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5485 // Transform the type.
5486 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5487 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005488 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005489
Douglas Gregor882211c2010-04-28 22:16:22 +00005490 // Transform all of the components into components similar to what the
5491 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005492 // FIXME: It would be slightly more efficient in the non-dependent case to
5493 // just map FieldDecls, rather than requiring the rebuilder to look for
5494 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005495 // template code that we don't care.
5496 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005497 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005498 typedef OffsetOfExpr::OffsetOfNode Node;
5499 llvm::SmallVector<Component, 4> Components;
5500 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5501 const Node &ON = E->getComponent(I);
5502 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005503 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005504 Comp.LocStart = ON.getRange().getBegin();
5505 Comp.LocEnd = ON.getRange().getEnd();
5506 switch (ON.getKind()) {
5507 case Node::Array: {
5508 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005509 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005510 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005511 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005512
Douglas Gregor882211c2010-04-28 22:16:22 +00005513 ExprChanged = ExprChanged || Index.get() != FromIndex;
5514 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005515 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005516 break;
5517 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005518
Douglas Gregor882211c2010-04-28 22:16:22 +00005519 case Node::Field:
5520 case Node::Identifier:
5521 Comp.isBrackets = false;
5522 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005523 if (!Comp.U.IdentInfo)
5524 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005525
Douglas Gregor882211c2010-04-28 22:16:22 +00005526 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005527
Douglas Gregord1702062010-04-29 00:18:15 +00005528 case Node::Base:
5529 // Will be recomputed during the rebuild.
5530 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005531 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005532
Douglas Gregor882211c2010-04-28 22:16:22 +00005533 Components.push_back(Comp);
5534 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005535
Douglas Gregor882211c2010-04-28 22:16:22 +00005536 // If nothing changed, retain the existing expression.
5537 if (!getDerived().AlwaysRebuild() &&
5538 Type == E->getTypeSourceInfo() &&
5539 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005540 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005541
Douglas Gregor882211c2010-04-28 22:16:22 +00005542 // Build a new offsetof expression.
5543 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5544 Components.data(), Components.size(),
5545 E->getRParenLoc());
5546}
5547
5548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005549ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005550TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5551 assert(getDerived().AlreadyTransformed(E->getType()) &&
5552 "opaque value expression requires transformation");
5553 return SemaRef.Owned(E);
5554}
5555
5556template<typename Derived>
5557ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005558TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005559 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005560 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005561
John McCallbcd03502009-12-07 02:54:59 +00005562 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005563 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005565
John McCall4c98fd82009-11-04 07:28:41 +00005566 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005567 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005568
John McCall4c98fd82009-11-04 07:28:41 +00005569 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005570 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005571 E->getSourceRange());
5572 }
Mike Stump11289f42009-09-09 15:08:12 +00005573
John McCalldadc5752010-08-24 06:29:42 +00005574 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005575 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005576 // C++0x [expr.sizeof]p1:
5577 // The operand is either an expression, which is an unevaluated operand
5578 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005579 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005580
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5582 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005583 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005584
Douglas Gregora16548e2009-08-11 05:31:07 +00005585 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005586 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005587 }
Mike Stump11289f42009-09-09 15:08:12 +00005588
John McCallb268a282010-08-23 23:25:46 +00005589 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005590 E->isSizeOf(),
5591 E->getSourceRange());
5592}
Mike Stump11289f42009-09-09 15:08:12 +00005593
Douglas Gregora16548e2009-08-11 05:31:07 +00005594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005595ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005596TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005597 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005598 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005599 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005600
John McCalldadc5752010-08-24 06:29:42 +00005601 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005602 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005603 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005604
5605
Douglas Gregora16548e2009-08-11 05:31:07 +00005606 if (!getDerived().AlwaysRebuild() &&
5607 LHS.get() == E->getLHS() &&
5608 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005609 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005610
John McCallb268a282010-08-23 23:25:46 +00005611 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005612 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005613 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005614 E->getRBracketLoc());
5615}
Mike Stump11289f42009-09-09 15:08:12 +00005616
5617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005618ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005619TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005620 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005621 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005622 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005623 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005624
5625 // Transform arguments.
5626 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005627 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005628 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5629 &ArgChanged))
5630 return ExprError();
5631
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 if (!getDerived().AlwaysRebuild() &&
5633 Callee.get() == E->getCallee() &&
5634 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005635 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005636
Douglas Gregora16548e2009-08-11 05:31:07 +00005637 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005638 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005640 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005641 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005642 E->getRParenLoc());
5643}
Mike Stump11289f42009-09-09 15:08:12 +00005644
5645template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005646ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005647TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005648 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005649 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005652 NestedNameSpecifier *Qualifier = 0;
5653 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005654 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005655 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005656 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005657 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005658 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005659 }
Mike Stump11289f42009-09-09 15:08:12 +00005660
Eli Friedman2cfcef62009-12-04 06:40:45 +00005661 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005662 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5663 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005664 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005665 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005666
John McCall16df1e52010-03-30 21:47:33 +00005667 NamedDecl *FoundDecl = E->getFoundDecl();
5668 if (FoundDecl == E->getMemberDecl()) {
5669 FoundDecl = Member;
5670 } else {
5671 FoundDecl = cast_or_null<NamedDecl>(
5672 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5673 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005674 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005675 }
5676
Douglas Gregora16548e2009-08-11 05:31:07 +00005677 if (!getDerived().AlwaysRebuild() &&
5678 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005679 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005680 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005681 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005682 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005683
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005684 // Mark it referenced in the new context regardless.
5685 // FIXME: this is a bit instantiation-specific.
5686 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005687 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005688 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005689
John McCall6b51f282009-11-23 01:53:49 +00005690 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005691 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005692 TransArgs.setLAngleLoc(E->getLAngleLoc());
5693 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005694 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5695 E->getNumTemplateArgs(),
5696 TransArgs))
5697 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005698 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005699
Douglas Gregora16548e2009-08-11 05:31:07 +00005700 // FIXME: Bogus source location for the operator
5701 SourceLocation FakeOperatorLoc
5702 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5703
John McCall38836f02010-01-15 08:34:02 +00005704 // FIXME: to do this check properly, we will need to preserve the
5705 // first-qualifier-in-scope here, just in case we had a dependent
5706 // base (and therefore couldn't do the check) and a
5707 // nested-name-qualifier (and therefore could do the lookup).
5708 NamedDecl *FirstQualifierInScope = 0;
5709
John McCallb268a282010-08-23 23:25:46 +00005710 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005711 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005712 Qualifier,
5713 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005714 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005715 Member,
John McCall16df1e52010-03-30 21:47:33 +00005716 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005717 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005718 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005719 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005720}
Mike Stump11289f42009-09-09 15:08:12 +00005721
Douglas Gregora16548e2009-08-11 05:31:07 +00005722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005723ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005724TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005725 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005726 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005727 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005728
John McCalldadc5752010-08-24 06:29:42 +00005729 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005731 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005732
Douglas Gregora16548e2009-08-11 05:31:07 +00005733 if (!getDerived().AlwaysRebuild() &&
5734 LHS.get() == E->getLHS() &&
5735 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005736 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005737
Douglas Gregora16548e2009-08-11 05:31:07 +00005738 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005739 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005740}
5741
Mike Stump11289f42009-09-09 15:08:12 +00005742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005743ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005744TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005745 CompoundAssignOperator *E) {
5746 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005747}
Mike Stump11289f42009-09-09 15:08:12 +00005748
Douglas Gregora16548e2009-08-11 05:31:07 +00005749template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005750ExprResult TreeTransform<Derived>::
5751TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5752 // Just rebuild the common and RHS expressions and see whether we
5753 // get any changes.
5754
5755 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5756 if (commonExpr.isInvalid())
5757 return ExprError();
5758
5759 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5760 if (rhs.isInvalid())
5761 return ExprError();
5762
5763 if (!getDerived().AlwaysRebuild() &&
5764 commonExpr.get() == e->getCommon() &&
5765 rhs.get() == e->getFalseExpr())
5766 return SemaRef.Owned(e);
5767
5768 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5769 e->getQuestionLoc(),
5770 0,
5771 e->getColonLoc(),
5772 rhs.get());
5773}
5774
5775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005776ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005777TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005778 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005779 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005780 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005781
John McCalldadc5752010-08-24 06:29:42 +00005782 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005783 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005784 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005785
John McCalldadc5752010-08-24 06:29:42 +00005786 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005787 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005789
Douglas Gregora16548e2009-08-11 05:31:07 +00005790 if (!getDerived().AlwaysRebuild() &&
5791 Cond.get() == E->getCond() &&
5792 LHS.get() == E->getLHS() &&
5793 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005794 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005795
John McCallb268a282010-08-23 23:25:46 +00005796 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005797 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005798 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005799 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005800 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005801}
Mike Stump11289f42009-09-09 15:08:12 +00005802
5803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005805TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005806 // Implicit casts are eliminated during transformation, since they
5807 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005808 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005809}
Mike Stump11289f42009-09-09 15:08:12 +00005810
Douglas Gregora16548e2009-08-11 05:31:07 +00005811template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005812ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005813TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005814 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5815 if (!Type)
5816 return ExprError();
5817
John McCalldadc5752010-08-24 06:29:42 +00005818 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005819 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005821 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005822
Douglas Gregora16548e2009-08-11 05:31:07 +00005823 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005824 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005825 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005826 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005827
John McCall97513962010-01-15 18:39:57 +00005828 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005829 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005830 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005831 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005832}
Mike Stump11289f42009-09-09 15:08:12 +00005833
Douglas Gregora16548e2009-08-11 05:31:07 +00005834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005835ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005836TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005837 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5838 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5839 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005841
John McCalldadc5752010-08-24 06:29:42 +00005842 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005843 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005844 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005845
Douglas Gregora16548e2009-08-11 05:31:07 +00005846 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005847 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005848 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005849 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005850
John McCall5d7aa7f2010-01-19 22:33:45 +00005851 // Note: the expression type doesn't necessarily match the
5852 // type-as-written, but that's okay, because it should always be
5853 // derivable from the initializer.
5854
John McCalle15bbff2010-01-18 19:35:47 +00005855 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005856 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005857 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005858}
Mike Stump11289f42009-09-09 15:08:12 +00005859
Douglas Gregora16548e2009-08-11 05:31:07 +00005860template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005861ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005862TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005863 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005864 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005865 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005866
Douglas Gregora16548e2009-08-11 05:31:07 +00005867 if (!getDerived().AlwaysRebuild() &&
5868 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005869 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005870
Douglas Gregora16548e2009-08-11 05:31:07 +00005871 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005872 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005873 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005874 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005875 E->getAccessorLoc(),
5876 E->getAccessor());
5877}
Mike Stump11289f42009-09-09 15:08:12 +00005878
Douglas Gregora16548e2009-08-11 05:31:07 +00005879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005880ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005881TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005882 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005883
John McCall37ad5512010-08-23 06:44:23 +00005884 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005885 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5886 Inits, &InitChanged))
5887 return ExprError();
5888
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005890 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005891
Douglas Gregora16548e2009-08-11 05:31:07 +00005892 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005893 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005894}
Mike Stump11289f42009-09-09 15:08:12 +00005895
Douglas Gregora16548e2009-08-11 05:31:07 +00005896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005897ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005898TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005899 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005900
Douglas Gregorebe10102009-08-20 07:17:43 +00005901 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005902 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005903 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005905
Douglas Gregorebe10102009-08-20 07:17:43 +00005906 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005907 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005908 bool ExprChanged = false;
5909 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5910 DEnd = E->designators_end();
5911 D != DEnd; ++D) {
5912 if (D->isFieldDesignator()) {
5913 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5914 D->getDotLoc(),
5915 D->getFieldLoc()));
5916 continue;
5917 }
Mike Stump11289f42009-09-09 15:08:12 +00005918
Douglas Gregora16548e2009-08-11 05:31:07 +00005919 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005920 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005921 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005922 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005923
5924 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005925 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005926
Douglas Gregora16548e2009-08-11 05:31:07 +00005927 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5928 ArrayExprs.push_back(Index.release());
5929 continue;
5930 }
Mike Stump11289f42009-09-09 15:08:12 +00005931
Douglas Gregora16548e2009-08-11 05:31:07 +00005932 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005933 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005934 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5935 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005936 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005937
John McCalldadc5752010-08-24 06:29:42 +00005938 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005939 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005940 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005941
5942 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005943 End.get(),
5944 D->getLBracketLoc(),
5945 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005946
Douglas Gregora16548e2009-08-11 05:31:07 +00005947 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5948 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005949
Douglas Gregora16548e2009-08-11 05:31:07 +00005950 ArrayExprs.push_back(Start.release());
5951 ArrayExprs.push_back(End.release());
5952 }
Mike Stump11289f42009-09-09 15:08:12 +00005953
Douglas Gregora16548e2009-08-11 05:31:07 +00005954 if (!getDerived().AlwaysRebuild() &&
5955 Init.get() == E->getInit() &&
5956 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005957 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005958
Douglas Gregora16548e2009-08-11 05:31:07 +00005959 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5960 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005961 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005962}
Mike Stump11289f42009-09-09 15:08:12 +00005963
Douglas Gregora16548e2009-08-11 05:31:07 +00005964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005965ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005966TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005967 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005968 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005969
Douglas Gregor3da3c062009-10-28 00:29:27 +00005970 // FIXME: Will we ever have proper type location here? Will we actually
5971 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005972 QualType T = getDerived().TransformType(E->getType());
5973 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005974 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005975
Douglas Gregora16548e2009-08-11 05:31:07 +00005976 if (!getDerived().AlwaysRebuild() &&
5977 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005978 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005979
Douglas Gregora16548e2009-08-11 05:31:07 +00005980 return getDerived().RebuildImplicitValueInitExpr(T);
5981}
Mike Stump11289f42009-09-09 15:08:12 +00005982
Douglas Gregora16548e2009-08-11 05:31:07 +00005983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005984ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005985TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005986 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5987 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005988 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005989
John McCalldadc5752010-08-24 06:29:42 +00005990 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005991 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005992 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005993
Douglas Gregora16548e2009-08-11 05:31:07 +00005994 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005995 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005996 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005997 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005998
John McCallb268a282010-08-23 23:25:46 +00005999 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006000 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006001}
6002
6003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006004ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006005TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006006 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006007 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006008 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6009 &ArgumentChanged))
6010 return ExprError();
6011
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6013 move_arg(Inits),
6014 E->getRParenLoc());
6015}
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregora16548e2009-08-11 05:31:07 +00006017/// \brief Transform an address-of-label expression.
6018///
6019/// By default, the transformation of an address-of-label expression always
6020/// rebuilds the expression, so that the label identifier can be resolved to
6021/// the corresponding label statement by semantic analysis.
6022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006023ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006024TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006025 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6026 E->getLabel());
6027 if (!LD)
6028 return ExprError();
6029
Douglas Gregora16548e2009-08-11 05:31:07 +00006030 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006031 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006032}
Mike Stump11289f42009-09-09 15:08:12 +00006033
6034template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006035ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006036TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006037 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006038 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6039 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006040 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006041
Douglas Gregora16548e2009-08-11 05:31:07 +00006042 if (!getDerived().AlwaysRebuild() &&
6043 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006044 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006045
6046 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006047 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006048 E->getRParenLoc());
6049}
Mike Stump11289f42009-09-09 15:08:12 +00006050
Douglas Gregora16548e2009-08-11 05:31:07 +00006051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006052ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006053TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006054 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006055 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006057
John McCalldadc5752010-08-24 06:29:42 +00006058 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006059 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006060 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006061
John McCalldadc5752010-08-24 06:29:42 +00006062 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006063 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006064 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006065
Douglas Gregora16548e2009-08-11 05:31:07 +00006066 if (!getDerived().AlwaysRebuild() &&
6067 Cond.get() == E->getCond() &&
6068 LHS.get() == E->getLHS() &&
6069 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006070 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006071
Douglas Gregora16548e2009-08-11 05:31:07 +00006072 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006073 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006074 E->getRParenLoc());
6075}
Mike Stump11289f42009-09-09 15:08:12 +00006076
Douglas Gregora16548e2009-08-11 05:31:07 +00006077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006079TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006080 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006081}
6082
6083template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006084ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006085TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006086 switch (E->getOperator()) {
6087 case OO_New:
6088 case OO_Delete:
6089 case OO_Array_New:
6090 case OO_Array_Delete:
6091 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006092 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006093
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006094 case OO_Call: {
6095 // This is a call to an object's operator().
6096 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6097
6098 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006099 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006100 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006101 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006102
6103 // FIXME: Poor location information
6104 SourceLocation FakeLParenLoc
6105 = SemaRef.PP.getLocForEndOfToken(
6106 static_cast<Expr *>(Object.get())->getLocEnd());
6107
6108 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006109 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006110 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6111 Args))
6112 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006113
John McCallb268a282010-08-23 23:25:46 +00006114 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006115 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006116 E->getLocEnd());
6117 }
6118
6119#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6120 case OO_##Name:
6121#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6122#include "clang/Basic/OperatorKinds.def"
6123 case OO_Subscript:
6124 // Handled below.
6125 break;
6126
6127 case OO_Conditional:
6128 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006129 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006130
6131 case OO_None:
6132 case NUM_OVERLOADED_OPERATORS:
6133 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006134 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006135 }
6136
John McCalldadc5752010-08-24 06:29:42 +00006137 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006138 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006139 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006140
John McCalldadc5752010-08-24 06:29:42 +00006141 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006142 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006143 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006144
John McCalldadc5752010-08-24 06:29:42 +00006145 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006146 if (E->getNumArgs() == 2) {
6147 Second = getDerived().TransformExpr(E->getArg(1));
6148 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006149 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006150 }
Mike Stump11289f42009-09-09 15:08:12 +00006151
Douglas Gregora16548e2009-08-11 05:31:07 +00006152 if (!getDerived().AlwaysRebuild() &&
6153 Callee.get() == E->getCallee() &&
6154 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006155 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006156 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006157
Douglas Gregora16548e2009-08-11 05:31:07 +00006158 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6159 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006160 Callee.get(),
6161 First.get(),
6162 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006163}
Mike Stump11289f42009-09-09 15:08:12 +00006164
Douglas Gregora16548e2009-08-11 05:31:07 +00006165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006167TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6168 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006169}
Mike Stump11289f42009-09-09 15:08:12 +00006170
Douglas Gregora16548e2009-08-11 05:31:07 +00006171template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006172ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006173TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6174 // Transform the callee.
6175 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6176 if (Callee.isInvalid())
6177 return ExprError();
6178
6179 // Transform exec config.
6180 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6181 if (EC.isInvalid())
6182 return ExprError();
6183
6184 // Transform arguments.
6185 bool ArgChanged = false;
6186 ASTOwningVector<Expr*> Args(SemaRef);
6187 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6188 &ArgChanged))
6189 return ExprError();
6190
6191 if (!getDerived().AlwaysRebuild() &&
6192 Callee.get() == E->getCallee() &&
6193 !ArgChanged)
6194 return SemaRef.Owned(E);
6195
6196 // FIXME: Wrong source location information for the '('.
6197 SourceLocation FakeLParenLoc
6198 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6199 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6200 move_arg(Args),
6201 E->getRParenLoc(), EC.get());
6202}
6203
6204template<typename Derived>
6205ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006206TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006207 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6208 if (!Type)
6209 return ExprError();
6210
John McCalldadc5752010-08-24 06:29:42 +00006211 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006212 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006213 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006214 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006215
Douglas Gregora16548e2009-08-11 05:31:07 +00006216 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006217 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006218 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006219 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006220
Douglas Gregora16548e2009-08-11 05:31:07 +00006221 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006222 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006223 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6224 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6225 SourceLocation FakeRParenLoc
6226 = SemaRef.PP.getLocForEndOfToken(
6227 E->getSubExpr()->getSourceRange().getEnd());
6228 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006229 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006230 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006231 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006232 FakeRAngleLoc,
6233 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006234 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006235 FakeRParenLoc);
6236}
Mike Stump11289f42009-09-09 15:08:12 +00006237
Douglas Gregora16548e2009-08-11 05:31:07 +00006238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006239ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006240TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6241 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006242}
Mike Stump11289f42009-09-09 15:08:12 +00006243
6244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006245ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006246TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6247 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006248}
6249
Douglas Gregora16548e2009-08-11 05:31:07 +00006250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006251ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006252TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006253 CXXReinterpretCastExpr *E) {
6254 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006255}
Mike Stump11289f42009-09-09 15:08:12 +00006256
Douglas Gregora16548e2009-08-11 05:31:07 +00006257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006258ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006259TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6260 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006261}
Mike Stump11289f42009-09-09 15:08:12 +00006262
Douglas Gregora16548e2009-08-11 05:31:07 +00006263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006264ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006265TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006266 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006267 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6268 if (!Type)
6269 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006270
John McCalldadc5752010-08-24 06:29:42 +00006271 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006272 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006273 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006274 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006275
Douglas Gregora16548e2009-08-11 05:31:07 +00006276 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006277 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006278 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006279 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006280
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006281 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006282 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006283 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006284 E->getRParenLoc());
6285}
Mike Stump11289f42009-09-09 15:08:12 +00006286
Douglas Gregora16548e2009-08-11 05:31:07 +00006287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006288ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006289TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006290 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006291 TypeSourceInfo *TInfo
6292 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6293 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006294 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006295
Douglas Gregora16548e2009-08-11 05:31:07 +00006296 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006297 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006298 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006299
Douglas Gregor9da64192010-04-26 22:37:10 +00006300 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6301 E->getLocStart(),
6302 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006303 E->getLocEnd());
6304 }
Mike Stump11289f42009-09-09 15:08:12 +00006305
Douglas Gregora16548e2009-08-11 05:31:07 +00006306 // We don't know whether the expression is potentially evaluated until
6307 // after we perform semantic analysis, so the expression is potentially
6308 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006309 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006310 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006311
John McCalldadc5752010-08-24 06:29:42 +00006312 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006313 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006314 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006315
Douglas Gregora16548e2009-08-11 05:31:07 +00006316 if (!getDerived().AlwaysRebuild() &&
6317 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006318 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006319
Douglas Gregor9da64192010-04-26 22:37:10 +00006320 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6321 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006322 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006323 E->getLocEnd());
6324}
6325
6326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006327ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006328TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6329 if (E->isTypeOperand()) {
6330 TypeSourceInfo *TInfo
6331 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6332 if (!TInfo)
6333 return ExprError();
6334
6335 if (!getDerived().AlwaysRebuild() &&
6336 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006337 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006338
6339 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6340 E->getLocStart(),
6341 TInfo,
6342 E->getLocEnd());
6343 }
6344
6345 // We don't know whether the expression is potentially evaluated until
6346 // after we perform semantic analysis, so the expression is potentially
6347 // potentially evaluated.
6348 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6349
6350 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6351 if (SubExpr.isInvalid())
6352 return ExprError();
6353
6354 if (!getDerived().AlwaysRebuild() &&
6355 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006356 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006357
6358 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6359 E->getLocStart(),
6360 SubExpr.get(),
6361 E->getLocEnd());
6362}
6363
6364template<typename Derived>
6365ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006366TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006367 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006368}
Mike Stump11289f42009-09-09 15:08:12 +00006369
Douglas Gregora16548e2009-08-11 05:31:07 +00006370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006371ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006372TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006373 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006374 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006375}
Mike Stump11289f42009-09-09 15:08:12 +00006376
Douglas Gregora16548e2009-08-11 05:31:07 +00006377template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006378ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006379TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006380 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6381 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6382 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006384 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006385 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006386
Douglas Gregorb15af892010-01-07 23:12:05 +00006387 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006388}
Mike Stump11289f42009-09-09 15:08:12 +00006389
Douglas Gregora16548e2009-08-11 05:31:07 +00006390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006391ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006392TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006393 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006394 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006395 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006396
Douglas Gregora16548e2009-08-11 05:31:07 +00006397 if (!getDerived().AlwaysRebuild() &&
6398 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006399 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006400
John McCallb268a282010-08-23 23:25:46 +00006401 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006402}
Mike Stump11289f42009-09-09 15:08:12 +00006403
Douglas Gregora16548e2009-08-11 05:31:07 +00006404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006405ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006406TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006407 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006408 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6409 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006410 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006411 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006412
Chandler Carruth794da4c2010-02-08 06:42:49 +00006413 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006414 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006415 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006416
Douglas Gregor033f6752009-12-23 23:03:06 +00006417 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006418}
Mike Stump11289f42009-09-09 15:08:12 +00006419
Douglas Gregora16548e2009-08-11 05:31:07 +00006420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006421ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006422TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6423 CXXScalarValueInitExpr *E) {
6424 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6425 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006426 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006427
Douglas Gregora16548e2009-08-11 05:31:07 +00006428 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006429 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006430 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006431
Douglas Gregor2b88c112010-09-08 00:15:04 +00006432 return getDerived().RebuildCXXScalarValueInitExpr(T,
6433 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006434 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006435}
Mike Stump11289f42009-09-09 15:08:12 +00006436
Douglas Gregora16548e2009-08-11 05:31:07 +00006437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006438ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006439TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006440 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006441 TypeSourceInfo *AllocTypeInfo
6442 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6443 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006444 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006445
Douglas Gregora16548e2009-08-11 05:31:07 +00006446 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006447 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006448 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006449 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006450
Douglas Gregora16548e2009-08-11 05:31:07 +00006451 // Transform the placement arguments (if any).
6452 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006453 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006454 if (getDerived().TransformExprs(E->getPlacementArgs(),
6455 E->getNumPlacementArgs(), true,
6456 PlacementArgs, &ArgumentChanged))
6457 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006458
Douglas Gregorebe10102009-08-20 07:17:43 +00006459 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006460 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006461 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6462 ConstructorArgs, &ArgumentChanged))
6463 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006464
Douglas Gregord2d9da02010-02-26 00:38:10 +00006465 // Transform constructor, new operator, and delete operator.
6466 CXXConstructorDecl *Constructor = 0;
6467 if (E->getConstructor()) {
6468 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006469 getDerived().TransformDecl(E->getLocStart(),
6470 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006471 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006472 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006473 }
6474
6475 FunctionDecl *OperatorNew = 0;
6476 if (E->getOperatorNew()) {
6477 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006478 getDerived().TransformDecl(E->getLocStart(),
6479 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006480 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006481 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006482 }
6483
6484 FunctionDecl *OperatorDelete = 0;
6485 if (E->getOperatorDelete()) {
6486 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006487 getDerived().TransformDecl(E->getLocStart(),
6488 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006489 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006490 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006491 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006492
Douglas Gregora16548e2009-08-11 05:31:07 +00006493 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006494 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006495 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006496 Constructor == E->getConstructor() &&
6497 OperatorNew == E->getOperatorNew() &&
6498 OperatorDelete == E->getOperatorDelete() &&
6499 !ArgumentChanged) {
6500 // Mark any declarations we need as referenced.
6501 // FIXME: instantiation-specific.
6502 if (Constructor)
6503 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6504 if (OperatorNew)
6505 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6506 if (OperatorDelete)
6507 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006508 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006509 }
Mike Stump11289f42009-09-09 15:08:12 +00006510
Douglas Gregor0744ef62010-09-07 21:49:58 +00006511 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006512 if (!ArraySize.get()) {
6513 // If no array size was specified, but the new expression was
6514 // instantiated with an array type (e.g., "new T" where T is
6515 // instantiated with "int[4]"), extract the outer bound from the
6516 // array type as our array size. We do this with constant and
6517 // dependently-sized array types.
6518 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6519 if (!ArrayT) {
6520 // Do nothing
6521 } else if (const ConstantArrayType *ConsArrayT
6522 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006523 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006524 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6525 ConsArrayT->getSize(),
6526 SemaRef.Context.getSizeType(),
6527 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006528 AllocType = ConsArrayT->getElementType();
6529 } else if (const DependentSizedArrayType *DepArrayT
6530 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6531 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006532 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006533 AllocType = DepArrayT->getElementType();
6534 }
6535 }
6536 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006537
Douglas Gregora16548e2009-08-11 05:31:07 +00006538 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6539 E->isGlobalNew(),
6540 /*FIXME:*/E->getLocStart(),
6541 move_arg(PlacementArgs),
6542 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006543 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006544 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006545 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006546 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006547 /*FIXME:*/E->getLocStart(),
6548 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006549 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006550}
Mike Stump11289f42009-09-09 15:08:12 +00006551
Douglas Gregora16548e2009-08-11 05:31:07 +00006552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006553ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006554TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006555 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006556 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006557 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006558
Douglas Gregord2d9da02010-02-26 00:38:10 +00006559 // Transform the delete operator, if known.
6560 FunctionDecl *OperatorDelete = 0;
6561 if (E->getOperatorDelete()) {
6562 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006563 getDerived().TransformDecl(E->getLocStart(),
6564 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006565 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006566 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006567 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006568
Douglas Gregora16548e2009-08-11 05:31:07 +00006569 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006570 Operand.get() == E->getArgument() &&
6571 OperatorDelete == E->getOperatorDelete()) {
6572 // Mark any declarations we need as referenced.
6573 // FIXME: instantiation-specific.
6574 if (OperatorDelete)
6575 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006576
6577 if (!E->getArgument()->isTypeDependent()) {
6578 QualType Destroyed = SemaRef.Context.getBaseElementType(
6579 E->getDestroyedType());
6580 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6581 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6582 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6583 SemaRef.LookupDestructor(Record));
6584 }
6585 }
6586
John McCallc3007a22010-10-26 07:05:15 +00006587 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006588 }
Mike Stump11289f42009-09-09 15:08:12 +00006589
Douglas Gregora16548e2009-08-11 05:31:07 +00006590 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6591 E->isGlobalDelete(),
6592 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006593 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006594}
Mike Stump11289f42009-09-09 15:08:12 +00006595
Douglas Gregora16548e2009-08-11 05:31:07 +00006596template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006597ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006598TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006599 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006600 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006601 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006602 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006603
John McCallba7bf592010-08-24 05:47:05 +00006604 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006605 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006606 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006607 E->getOperatorLoc(),
6608 E->isArrow()? tok::arrow : tok::period,
6609 ObjectTypePtr,
6610 MayBePseudoDestructor);
6611 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006612 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006613
John McCallba7bf592010-08-24 05:47:05 +00006614 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00006615 NestedNameSpecifier *Qualifier = E->getQualifier();
6616 if (Qualifier) {
6617 Qualifier
6618 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6619 E->getQualifierRange(),
6620 ObjectType);
6621 if (!Qualifier)
6622 return ExprError();
6623 }
Mike Stump11289f42009-09-09 15:08:12 +00006624
Douglas Gregor678f90d2010-02-25 01:56:36 +00006625 PseudoDestructorTypeStorage Destroyed;
6626 if (E->getDestroyedTypeInfo()) {
6627 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006628 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6629 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006630 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006631 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006632 Destroyed = DestroyedTypeInfo;
6633 } else if (ObjectType->isDependentType()) {
6634 // We aren't likely to be able to resolve the identifier down to a type
6635 // now anyway, so just retain the identifier.
6636 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6637 E->getDestroyedTypeLoc());
6638 } else {
6639 // Look for a destructor known with the given name.
6640 CXXScopeSpec SS;
Douglas Gregor2ab3fee2011-02-24 00:49:34 +00006641 if (Qualifier)
Douglas Gregor869ad452011-02-24 17:54:50 +00006642 SS.MakeTrivial(SemaRef.Context, Qualifier, E->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006643
John McCallba7bf592010-08-24 05:47:05 +00006644 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006645 *E->getDestroyedTypeIdentifier(),
6646 E->getDestroyedTypeLoc(),
6647 /*Scope=*/0,
6648 SS, ObjectTypePtr,
6649 false);
6650 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006651 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006652
Douglas Gregor678f90d2010-02-25 01:56:36 +00006653 Destroyed
6654 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6655 E->getDestroyedTypeLoc());
6656 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006657
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006658 TypeSourceInfo *ScopeTypeInfo = 0;
6659 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006660 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006661 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006662 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006663 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006664
John McCallb268a282010-08-23 23:25:46 +00006665 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006666 E->getOperatorLoc(),
6667 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006668 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006669 E->getQualifierRange(),
6670 ScopeTypeInfo,
6671 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006672 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006673 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006674}
Mike Stump11289f42009-09-09 15:08:12 +00006675
Douglas Gregorad8a3362009-09-04 17:36:40 +00006676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006677ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006678TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006679 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006680 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6681
6682 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6683 Sema::LookupOrdinaryName);
6684
6685 // Transform all the decls.
6686 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6687 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006688 NamedDecl *InstD = static_cast<NamedDecl*>(
6689 getDerived().TransformDecl(Old->getNameLoc(),
6690 *I));
John McCall84d87672009-12-10 09:41:52 +00006691 if (!InstD) {
6692 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6693 // This can happen because of dependent hiding.
6694 if (isa<UsingShadowDecl>(*I))
6695 continue;
6696 else
John McCallfaf5fb42010-08-26 23:41:50 +00006697 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006698 }
John McCalle66edc12009-11-24 19:00:30 +00006699
6700 // Expand using declarations.
6701 if (isa<UsingDecl>(InstD)) {
6702 UsingDecl *UD = cast<UsingDecl>(InstD);
6703 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6704 E = UD->shadow_end(); I != E; ++I)
6705 R.addDecl(*I);
6706 continue;
6707 }
6708
6709 R.addDecl(InstD);
6710 }
6711
6712 // Resolve a kind, but don't do any further analysis. If it's
6713 // ambiguous, the callee needs to deal with it.
6714 R.resolveKind();
6715
6716 // Rebuild the nested-name qualifier, if present.
6717 CXXScopeSpec SS;
6718 NestedNameSpecifier *Qualifier = 0;
6719 if (Old->getQualifier()) {
6720 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006721 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006722 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006723 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006724
Douglas Gregor869ad452011-02-24 17:54:50 +00006725 SS.MakeTrivial(SemaRef.Context, Qualifier, Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006726 }
6727
Douglas Gregor9262f472010-04-27 18:19:34 +00006728 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006729 CXXRecordDecl *NamingClass
6730 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6731 Old->getNameLoc(),
6732 Old->getNamingClass()));
6733 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006734 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006735
Douglas Gregorda7be082010-04-27 16:10:10 +00006736 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006737 }
6738
6739 // If we have no template arguments, it's a normal declaration name.
6740 if (!Old->hasExplicitTemplateArgs())
6741 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6742
6743 // If we have template arguments, rebuild them, then rebuild the
6744 // templateid expression.
6745 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006746 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6747 Old->getNumTemplateArgs(),
6748 TransArgs))
6749 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006750
6751 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6752 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006753}
Mike Stump11289f42009-09-09 15:08:12 +00006754
Douglas Gregora16548e2009-08-11 05:31:07 +00006755template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006756ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006757TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006758 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6759 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006760 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006761
Douglas Gregora16548e2009-08-11 05:31:07 +00006762 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006763 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006764 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006765
Mike Stump11289f42009-09-09 15:08:12 +00006766 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006767 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006768 T,
6769 E->getLocEnd());
6770}
Mike Stump11289f42009-09-09 15:08:12 +00006771
Douglas Gregora16548e2009-08-11 05:31:07 +00006772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006773ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006774TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6775 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6776 if (!LhsT)
6777 return ExprError();
6778
6779 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6780 if (!RhsT)
6781 return ExprError();
6782
6783 if (!getDerived().AlwaysRebuild() &&
6784 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6785 return SemaRef.Owned(E);
6786
6787 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6788 E->getLocStart(),
6789 LhsT, RhsT,
6790 E->getLocEnd());
6791}
6792
6793template<typename Derived>
6794ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006795TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006796 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006797 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006798 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006799 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006800 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006801 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006802
John McCall31f82722010-11-12 08:19:04 +00006803 // TODO: If this is a conversion-function-id, verify that the
6804 // destination type name (if present) resolves the same way after
6805 // instantiation as it did in the local scope.
6806
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006807 DeclarationNameInfo NameInfo
6808 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6809 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006811
John McCalle66edc12009-11-24 19:00:30 +00006812 if (!E->hasExplicitTemplateArgs()) {
6813 if (!getDerived().AlwaysRebuild() &&
6814 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006815 // Note: it is sufficient to compare the Name component of NameInfo:
6816 // if name has not changed, DNLoc has not changed either.
6817 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006818 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006819
John McCalle66edc12009-11-24 19:00:30 +00006820 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6821 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006822 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006823 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006824 }
John McCall6b51f282009-11-23 01:53:49 +00006825
6826 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006827 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6828 E->getNumTemplateArgs(),
6829 TransArgs))
6830 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006831
John McCalle66edc12009-11-24 19:00:30 +00006832 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6833 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006834 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006835 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006836}
6837
6838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006839ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006840TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006841 // CXXConstructExprs are always implicit, so when we have a
6842 // 1-argument construction we just transform that argument.
6843 if (E->getNumArgs() == 1 ||
6844 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6845 return getDerived().TransformExpr(E->getArg(0));
6846
Douglas Gregora16548e2009-08-11 05:31:07 +00006847 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6848
6849 QualType T = getDerived().TransformType(E->getType());
6850 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006851 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006852
6853 CXXConstructorDecl *Constructor
6854 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006855 getDerived().TransformDecl(E->getLocStart(),
6856 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006857 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006858 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006859
Douglas Gregora16548e2009-08-11 05:31:07 +00006860 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006861 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006862 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6863 &ArgumentChanged))
6864 return ExprError();
6865
Douglas Gregora16548e2009-08-11 05:31:07 +00006866 if (!getDerived().AlwaysRebuild() &&
6867 T == E->getType() &&
6868 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006869 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006870 // Mark the constructor as referenced.
6871 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006872 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006873 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006874 }
Mike Stump11289f42009-09-09 15:08:12 +00006875
Douglas Gregordb121ba2009-12-14 16:27:04 +00006876 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6877 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006878 move_arg(Args),
6879 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006880 E->getConstructionKind(),
6881 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006882}
Mike Stump11289f42009-09-09 15:08:12 +00006883
Douglas Gregora16548e2009-08-11 05:31:07 +00006884/// \brief Transform a C++ temporary-binding expression.
6885///
Douglas Gregor363b1512009-12-24 18:51:59 +00006886/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6887/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006888template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006889ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006890TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006891 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006892}
Mike Stump11289f42009-09-09 15:08:12 +00006893
John McCall5d413782010-12-06 08:20:24 +00006894/// \brief Transform a C++ expression that contains cleanups that should
6895/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006896///
John McCall5d413782010-12-06 08:20:24 +00006897/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006898/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006900ExprResult
John McCall5d413782010-12-06 08:20:24 +00006901TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006902 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006903}
Mike Stump11289f42009-09-09 15:08:12 +00006904
Douglas Gregora16548e2009-08-11 05:31:07 +00006905template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006906ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006907TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006908 CXXTemporaryObjectExpr *E) {
6909 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6910 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006911 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006912
Douglas Gregora16548e2009-08-11 05:31:07 +00006913 CXXConstructorDecl *Constructor
6914 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006915 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006916 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006917 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006918 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006919
Douglas Gregora16548e2009-08-11 05:31:07 +00006920 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006921 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006922 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006923 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6924 &ArgumentChanged))
6925 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006926
Douglas Gregora16548e2009-08-11 05:31:07 +00006927 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006928 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006929 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006930 !ArgumentChanged) {
6931 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006932 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006933 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006934 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006935
6936 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6937 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006938 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006939 E->getLocEnd());
6940}
Mike Stump11289f42009-09-09 15:08:12 +00006941
Douglas Gregora16548e2009-08-11 05:31:07 +00006942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006943ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006944TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006945 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006946 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6947 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006948 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006949
Douglas Gregora16548e2009-08-11 05:31:07 +00006950 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006951 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006952 Args.reserve(E->arg_size());
6953 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6954 &ArgumentChanged))
6955 return ExprError();
6956
Douglas Gregora16548e2009-08-11 05:31:07 +00006957 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006958 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006959 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006960 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006961
Douglas Gregora16548e2009-08-11 05:31:07 +00006962 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006963 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006964 E->getLParenLoc(),
6965 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006966 E->getRParenLoc());
6967}
Mike Stump11289f42009-09-09 15:08:12 +00006968
Douglas Gregora16548e2009-08-11 05:31:07 +00006969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006970ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006971TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006972 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006973 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006974 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006975 Expr *OldBase;
6976 QualType BaseType;
6977 QualType ObjectType;
6978 if (!E->isImplicitAccess()) {
6979 OldBase = E->getBase();
6980 Base = getDerived().TransformExpr(OldBase);
6981 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006982 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006983
John McCall2d74de92009-12-01 22:10:20 +00006984 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006985 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006986 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006987 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006988 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006989 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006990 ObjectTy,
6991 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006992 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006993 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006994
John McCallba7bf592010-08-24 05:47:05 +00006995 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006996 BaseType = ((Expr*) Base.get())->getType();
6997 } else {
6998 OldBase = 0;
6999 BaseType = getDerived().TransformType(E->getBaseType());
7000 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7001 }
Mike Stump11289f42009-09-09 15:08:12 +00007002
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007003 // Transform the first part of the nested-name-specifier that qualifies
7004 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007005 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007006 = getDerived().TransformFirstQualifierInScope(
7007 E->getFirstQualifierFoundInScope(),
7008 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007009
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007010 NestedNameSpecifier *Qualifier = 0;
7011 if (E->getQualifier()) {
7012 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
7013 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00007014 ObjectType,
7015 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007016 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00007017 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007018 }
Mike Stump11289f42009-09-09 15:08:12 +00007019
John McCall31f82722010-11-12 08:19:04 +00007020 // TODO: If this is a conversion-function-id, verify that the
7021 // destination type name (if present) resolves the same way after
7022 // instantiation as it did in the local scope.
7023
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007024 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007025 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007026 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007027 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007028
John McCall2d74de92009-12-01 22:10:20 +00007029 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007030 // This is a reference to a member without an explicitly-specified
7031 // template argument list. Optimize for this common case.
7032 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007033 Base.get() == OldBase &&
7034 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007035 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007036 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007037 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007038 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007039
John McCallb268a282010-08-23 23:25:46 +00007040 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007041 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007042 E->isArrow(),
7043 E->getOperatorLoc(),
7044 Qualifier,
7045 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00007046 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007047 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007048 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007049 }
7050
John McCall6b51f282009-11-23 01:53:49 +00007051 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007052 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7053 E->getNumTemplateArgs(),
7054 TransArgs))
7055 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007056
John McCallb268a282010-08-23 23:25:46 +00007057 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007058 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007059 E->isArrow(),
7060 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007061 Qualifier,
7062 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00007063 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007064 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007065 &TransArgs);
7066}
7067
7068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007069ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007070TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007071 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007072 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007073 QualType BaseType;
7074 if (!Old->isImplicitAccess()) {
7075 Base = getDerived().TransformExpr(Old->getBase());
7076 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007077 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007078 BaseType = ((Expr*) Base.get())->getType();
7079 } else {
7080 BaseType = getDerived().TransformType(Old->getBaseType());
7081 }
John McCall10eae182009-11-30 22:42:35 +00007082
7083 NestedNameSpecifier *Qualifier = 0;
7084 if (Old->getQualifier()) {
7085 Qualifier
7086 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007087 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00007088 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00007089 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007090 }
7091
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007092 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007093 Sema::LookupOrdinaryName);
7094
7095 // Transform all the decls.
7096 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7097 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007098 NamedDecl *InstD = static_cast<NamedDecl*>(
7099 getDerived().TransformDecl(Old->getMemberLoc(),
7100 *I));
John McCall84d87672009-12-10 09:41:52 +00007101 if (!InstD) {
7102 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7103 // This can happen because of dependent hiding.
7104 if (isa<UsingShadowDecl>(*I))
7105 continue;
7106 else
John McCallfaf5fb42010-08-26 23:41:50 +00007107 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007108 }
John McCall10eae182009-11-30 22:42:35 +00007109
7110 // Expand using declarations.
7111 if (isa<UsingDecl>(InstD)) {
7112 UsingDecl *UD = cast<UsingDecl>(InstD);
7113 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7114 E = UD->shadow_end(); I != E; ++I)
7115 R.addDecl(*I);
7116 continue;
7117 }
7118
7119 R.addDecl(InstD);
7120 }
7121
7122 R.resolveKind();
7123
Douglas Gregor9262f472010-04-27 18:19:34 +00007124 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007125 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007126 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007127 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007128 Old->getMemberLoc(),
7129 Old->getNamingClass()));
7130 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007131 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007132
Douglas Gregorda7be082010-04-27 16:10:10 +00007133 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007134 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007135
John McCall10eae182009-11-30 22:42:35 +00007136 TemplateArgumentListInfo TransArgs;
7137 if (Old->hasExplicitTemplateArgs()) {
7138 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7139 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007140 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7141 Old->getNumTemplateArgs(),
7142 TransArgs))
7143 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007144 }
John McCall38836f02010-01-15 08:34:02 +00007145
7146 // FIXME: to do this check properly, we will need to preserve the
7147 // first-qualifier-in-scope here, just in case we had a dependent
7148 // base (and therefore couldn't do the check) and a
7149 // nested-name-qualifier (and therefore could do the lookup).
7150 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007151
John McCallb268a282010-08-23 23:25:46 +00007152 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007153 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007154 Old->getOperatorLoc(),
7155 Old->isArrow(),
7156 Qualifier,
7157 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00007158 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007159 R,
7160 (Old->hasExplicitTemplateArgs()
7161 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007162}
7163
7164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007165ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007166TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7167 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7168 if (SubExpr.isInvalid())
7169 return ExprError();
7170
7171 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007172 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007173
7174 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7175}
7176
7177template<typename Derived>
7178ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007179TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007180 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7181 if (Pattern.isInvalid())
7182 return ExprError();
7183
7184 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7185 return SemaRef.Owned(E);
7186
Douglas Gregorb8840002011-01-14 21:20:45 +00007187 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7188 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007189}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007190
7191template<typename Derived>
7192ExprResult
7193TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7194 // If E is not value-dependent, then nothing will change when we transform it.
7195 // Note: This is an instantiation-centric view.
7196 if (!E->isValueDependent())
7197 return SemaRef.Owned(E);
7198
7199 // Note: None of the implementations of TryExpandParameterPacks can ever
7200 // produce a diagnostic when given only a single unexpanded parameter pack,
7201 // so
7202 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7203 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007204 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007205 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007206 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7207 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007208 ShouldExpand, RetainExpansion,
7209 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007210 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007211
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007212 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007213 return SemaRef.Owned(E);
7214
7215 // We now know the length of the parameter pack, so build a new expression
7216 // that stores that length.
7217 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7218 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007219 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007220}
7221
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007222template<typename Derived>
7223ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007224TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7225 SubstNonTypeTemplateParmPackExpr *E) {
7226 // Default behavior is to do nothing with this transformation.
7227 return SemaRef.Owned(E);
7228}
7229
7230template<typename Derived>
7231ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007232TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007233 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007234}
7235
Mike Stump11289f42009-09-09 15:08:12 +00007236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007237ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007238TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007239 TypeSourceInfo *EncodedTypeInfo
7240 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7241 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007242 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007243
Douglas Gregora16548e2009-08-11 05:31:07 +00007244 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007245 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007246 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007247
7248 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007249 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007250 E->getRParenLoc());
7251}
Mike Stump11289f42009-09-09 15:08:12 +00007252
Douglas Gregora16548e2009-08-11 05:31:07 +00007253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007254ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007255TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007256 // Transform arguments.
7257 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007258 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007259 Args.reserve(E->getNumArgs());
7260 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7261 &ArgChanged))
7262 return ExprError();
7263
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007264 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7265 // Class message: transform the receiver type.
7266 TypeSourceInfo *ReceiverTypeInfo
7267 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7268 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007269 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007270
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007271 // If nothing changed, just retain the existing message send.
7272 if (!getDerived().AlwaysRebuild() &&
7273 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007274 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007275
7276 // Build a new class message send.
7277 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7278 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007279 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007280 E->getMethodDecl(),
7281 E->getLeftLoc(),
7282 move_arg(Args),
7283 E->getRightLoc());
7284 }
7285
7286 // Instance message: transform the receiver
7287 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7288 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007289 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007290 = getDerived().TransformExpr(E->getInstanceReceiver());
7291 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007292 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007293
7294 // If nothing changed, just retain the existing message send.
7295 if (!getDerived().AlwaysRebuild() &&
7296 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007297 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007298
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007299 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007300 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007301 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007302 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007303 E->getMethodDecl(),
7304 E->getLeftLoc(),
7305 move_arg(Args),
7306 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007307}
7308
Mike Stump11289f42009-09-09 15:08:12 +00007309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007310ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007311TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007312 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007313}
7314
Mike Stump11289f42009-09-09 15:08:12 +00007315template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007316ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007317TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007318 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007319}
7320
Mike Stump11289f42009-09-09 15:08:12 +00007321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007322ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007323TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007324 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007325 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007326 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007327 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007328
7329 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007330
Douglas Gregord51d90d2010-04-26 20:11:03 +00007331 // If nothing changed, just retain the existing expression.
7332 if (!getDerived().AlwaysRebuild() &&
7333 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007334 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007335
John McCallb268a282010-08-23 23:25:46 +00007336 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007337 E->getLocation(),
7338 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007339}
7340
Mike Stump11289f42009-09-09 15:08:12 +00007341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007342ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007343TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007344 // 'super' and types never change. Property never changes. Just
7345 // retain the existing expression.
7346 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007347 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007348
Douglas Gregor9faee212010-04-26 20:47:02 +00007349 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007350 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007351 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007352 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007353
Douglas Gregor9faee212010-04-26 20:47:02 +00007354 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007355
Douglas Gregor9faee212010-04-26 20:47:02 +00007356 // If nothing changed, just retain the existing expression.
7357 if (!getDerived().AlwaysRebuild() &&
7358 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007359 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007360
John McCallb7bd14f2010-12-02 01:19:52 +00007361 if (E->isExplicitProperty())
7362 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7363 E->getExplicitProperty(),
7364 E->getLocation());
7365
7366 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7367 E->getType(),
7368 E->getImplicitPropertyGetter(),
7369 E->getImplicitPropertySetter(),
7370 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007371}
7372
Mike Stump11289f42009-09-09 15:08:12 +00007373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007374ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007375TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007376 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007377 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007378 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007379 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007380
Douglas Gregord51d90d2010-04-26 20:11:03 +00007381 // If nothing changed, just retain the existing expression.
7382 if (!getDerived().AlwaysRebuild() &&
7383 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007384 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007385
John McCallb268a282010-08-23 23:25:46 +00007386 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007387 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007388}
7389
Mike Stump11289f42009-09-09 15:08:12 +00007390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007391ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007392TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007393 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007394 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007395 SubExprs.reserve(E->getNumSubExprs());
7396 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7397 SubExprs, &ArgumentChanged))
7398 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007399
Douglas Gregora16548e2009-08-11 05:31:07 +00007400 if (!getDerived().AlwaysRebuild() &&
7401 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007402 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007403
Douglas Gregora16548e2009-08-11 05:31:07 +00007404 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7405 move_arg(SubExprs),
7406 E->getRParenLoc());
7407}
7408
Mike Stump11289f42009-09-09 15:08:12 +00007409template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007410ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007411TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007412 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007413
John McCall490112f2011-02-04 18:33:18 +00007414 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7415 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7416
7417 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7418 llvm::SmallVector<ParmVarDecl*, 4> params;
7419 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007420
7421 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007422 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7423 oldBlock->param_begin(),
7424 oldBlock->param_size(),
7425 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007426 return true;
John McCall490112f2011-02-04 18:33:18 +00007427
7428 const FunctionType *exprFunctionType = E->getFunctionType();
7429 QualType exprResultType = exprFunctionType->getResultType();
7430 if (!exprResultType.isNull()) {
7431 if (!exprResultType->isDependentType())
7432 blockScope->ReturnType = exprResultType;
7433 else if (exprResultType != getSema().Context.DependentTy)
7434 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007435 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007436
7437 // If the return type has not been determined yet, leave it as a dependent
7438 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007439 if (blockScope->ReturnType.isNull())
7440 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007441
7442 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007443 if (blockScope->ReturnType->isObjCObjectType()) {
7444 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007445 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007446 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007447 return ExprError();
7448 }
John McCall3882ace2011-01-05 12:14:39 +00007449
John McCall490112f2011-02-04 18:33:18 +00007450 QualType functionType = getDerived().RebuildFunctionProtoType(
7451 blockScope->ReturnType,
7452 paramTypes.data(),
7453 paramTypes.size(),
7454 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007455 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007456 exprFunctionType->getExtInfo());
7457 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007458
7459 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007460 if (!params.empty())
7461 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007462
7463 // If the return type wasn't explicitly set, it will have been marked as a
7464 // dependent type (DependentTy); clear out the return type setting so
7465 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007466 if (blockScope->ReturnType == getSema().Context.DependentTy)
7467 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007468
John McCall3882ace2011-01-05 12:14:39 +00007469 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007470 StmtResult body = getDerived().TransformStmt(E->getBody());
7471 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007472 return ExprError();
7473
John McCall490112f2011-02-04 18:33:18 +00007474#ifndef NDEBUG
7475 // In builds with assertions, make sure that we captured everything we
7476 // captured before.
7477
7478 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7479
7480 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7481 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007482 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007483
7484 // Ignore parameter packs.
7485 if (isa<ParmVarDecl>(oldCapture) &&
7486 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7487 continue;
7488
7489 VarDecl *newCapture =
7490 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7491 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007492 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007493 }
7494#endif
7495
7496 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7497 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007498}
7499
Mike Stump11289f42009-09-09 15:08:12 +00007500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007501ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007502TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007503 NestedNameSpecifier *Qualifier = 0;
7504
7505 ValueDecl *ND
7506 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7507 E->getDecl()));
7508 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007509 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007510
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007511 if (!getDerived().AlwaysRebuild() &&
7512 ND == E->getDecl()) {
7513 // Mark it referenced in the new context regardless.
7514 // FIXME: this is a bit instantiation-specific.
7515 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7516
John McCallc3007a22010-10-26 07:05:15 +00007517 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007518 }
7519
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007520 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007521 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007522 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007523}
Mike Stump11289f42009-09-09 15:08:12 +00007524
Douglas Gregora16548e2009-08-11 05:31:07 +00007525//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007526// Type reconstruction
7527//===----------------------------------------------------------------------===//
7528
Mike Stump11289f42009-09-09 15:08:12 +00007529template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007530QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7531 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007532 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007533 getDerived().getBaseEntity());
7534}
7535
Mike Stump11289f42009-09-09 15:08:12 +00007536template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007537QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7538 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007539 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007540 getDerived().getBaseEntity());
7541}
7542
Mike Stump11289f42009-09-09 15:08:12 +00007543template<typename Derived>
7544QualType
John McCall70dd5f62009-10-30 00:06:24 +00007545TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7546 bool WrittenAsLValue,
7547 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007548 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007549 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007550}
7551
7552template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007553QualType
John McCall70dd5f62009-10-30 00:06:24 +00007554TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7555 QualType ClassType,
7556 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007557 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007558 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007559}
7560
7561template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007562QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007563TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7564 ArrayType::ArraySizeModifier SizeMod,
7565 const llvm::APInt *Size,
7566 Expr *SizeExpr,
7567 unsigned IndexTypeQuals,
7568 SourceRange BracketsRange) {
7569 if (SizeExpr || !Size)
7570 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7571 IndexTypeQuals, BracketsRange,
7572 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007573
7574 QualType Types[] = {
7575 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7576 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7577 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007578 };
7579 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7580 QualType SizeType;
7581 for (unsigned I = 0; I != NumTypes; ++I)
7582 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7583 SizeType = Types[I];
7584 break;
7585 }
Mike Stump11289f42009-09-09 15:08:12 +00007586
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007587 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7588 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007589 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007590 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007591 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007592}
Mike Stump11289f42009-09-09 15:08:12 +00007593
Douglas Gregord6ff3322009-08-04 16:50:30 +00007594template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007595QualType
7596TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007597 ArrayType::ArraySizeModifier SizeMod,
7598 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007599 unsigned IndexTypeQuals,
7600 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007601 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007602 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007603}
7604
7605template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007606QualType
Mike Stump11289f42009-09-09 15:08:12 +00007607TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007608 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007609 unsigned IndexTypeQuals,
7610 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007611 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007612 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007613}
Mike Stump11289f42009-09-09 15:08:12 +00007614
Douglas Gregord6ff3322009-08-04 16:50:30 +00007615template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007616QualType
7617TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007618 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007619 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007620 unsigned IndexTypeQuals,
7621 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007622 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007623 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007624 IndexTypeQuals, BracketsRange);
7625}
7626
7627template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007628QualType
7629TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007630 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007631 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007632 unsigned IndexTypeQuals,
7633 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007634 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007635 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007636 IndexTypeQuals, BracketsRange);
7637}
7638
7639template<typename Derived>
7640QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007641 unsigned NumElements,
7642 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007643 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007644 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007645}
Mike Stump11289f42009-09-09 15:08:12 +00007646
Douglas Gregord6ff3322009-08-04 16:50:30 +00007647template<typename Derived>
7648QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7649 unsigned NumElements,
7650 SourceLocation AttributeLoc) {
7651 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7652 NumElements, true);
7653 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007654 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7655 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007656 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007657}
Mike Stump11289f42009-09-09 15:08:12 +00007658
Douglas Gregord6ff3322009-08-04 16:50:30 +00007659template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007660QualType
7661TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007662 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007663 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007664 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007665}
Mike Stump11289f42009-09-09 15:08:12 +00007666
Douglas Gregord6ff3322009-08-04 16:50:30 +00007667template<typename Derived>
7668QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007669 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007670 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007671 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007672 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007673 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007674 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007675 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007676 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007677 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007678 getDerived().getBaseEntity(),
7679 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007680}
Mike Stump11289f42009-09-09 15:08:12 +00007681
Douglas Gregord6ff3322009-08-04 16:50:30 +00007682template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007683QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7684 return SemaRef.Context.getFunctionNoProtoType(T);
7685}
7686
7687template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007688QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7689 assert(D && "no decl found");
7690 if (D->isInvalidDecl()) return QualType();
7691
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007692 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007693 TypeDecl *Ty;
7694 if (isa<UsingDecl>(D)) {
7695 UsingDecl *Using = cast<UsingDecl>(D);
7696 assert(Using->isTypeName() &&
7697 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7698
7699 // A valid resolved using typename decl points to exactly one type decl.
7700 assert(++Using->shadow_begin() == Using->shadow_end());
7701 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007702
John McCallb96ec562009-12-04 22:46:56 +00007703 } else {
7704 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7705 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7706 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7707 }
7708
7709 return SemaRef.Context.getTypeDeclType(Ty);
7710}
7711
7712template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007713QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7714 SourceLocation Loc) {
7715 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007716}
7717
7718template<typename Derived>
7719QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7720 return SemaRef.Context.getTypeOfType(Underlying);
7721}
7722
7723template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007724QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7725 SourceLocation Loc) {
7726 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007727}
7728
7729template<typename Derived>
7730QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007731 TemplateName Template,
7732 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007733 const TemplateArgumentListInfo &TemplateArgs) {
7734 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007735}
Mike Stump11289f42009-09-09 15:08:12 +00007736
Douglas Gregor1135c352009-08-06 05:28:30 +00007737template<typename Derived>
7738NestedNameSpecifier *
7739TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7740 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007741 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007742 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007743 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007744 CXXScopeSpec SS;
7745 // FIXME: The source location information is all wrong.
Douglas Gregor869ad452011-02-24 17:54:50 +00007746 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
Douglas Gregor90c99722011-02-24 00:17:56 +00007747 if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(),
7748 /*FIXME:*/Range.getEnd(),
7749 ObjectType, false,
7750 SS, FirstQualifierInScope,
7751 false))
7752 return 0;
7753
7754 return SS.getScopeRep();
Douglas Gregor1135c352009-08-06 05:28:30 +00007755}
7756
7757template<typename Derived>
7758NestedNameSpecifier *
7759TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7760 SourceRange Range,
7761 NamespaceDecl *NS) {
7762 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7763}
7764
7765template<typename Derived>
7766NestedNameSpecifier *
7767TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7768 SourceRange Range,
Douglas Gregor7b26ff92011-02-24 02:36:08 +00007769 NamespaceAliasDecl *Alias) {
7770 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias);
7771}
7772
7773template<typename Derived>
7774NestedNameSpecifier *
7775TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7776 SourceRange Range,
Douglas Gregor1135c352009-08-06 05:28:30 +00007777 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007778 QualType T) {
7779 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007780 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007781 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007782 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7783 T.getTypePtr());
7784 }
Mike Stump11289f42009-09-09 15:08:12 +00007785
Douglas Gregor1135c352009-08-06 05:28:30 +00007786 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7787 return 0;
7788}
Mike Stump11289f42009-09-09 15:08:12 +00007789
Douglas Gregor71dc5092009-08-06 06:41:21 +00007790template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007791TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007792TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7793 bool TemplateKW,
7794 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007795 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007796 Template);
7797}
7798
7799template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007800TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007801TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007802 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007803 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007804 QualType ObjectType,
7805 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007806 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007807 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007808 UnqualifiedId Name;
7809 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007810 Sema::TemplateTy Template;
7811 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7812 /*FIXME:*/getDerived().getBaseLocation(),
7813 SS,
7814 Name,
John McCallba7bf592010-08-24 05:47:05 +00007815 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007816 /*EnteringContext=*/false,
7817 Template);
John McCall31f82722010-11-12 08:19:04 +00007818 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007819}
Mike Stump11289f42009-09-09 15:08:12 +00007820
Douglas Gregora16548e2009-08-11 05:31:07 +00007821template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007822TemplateName
7823TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7824 OverloadedOperatorKind Operator,
7825 QualType ObjectType) {
7826 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007827 SS.MakeTrivial(SemaRef.Context, Qualifier, SourceRange(getDerived().getBaseLocation()));
Douglas Gregor71395fa2009-11-04 00:56:37 +00007828 UnqualifiedId Name;
7829 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7830 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7831 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007832 Sema::TemplateTy Template;
7833 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007834 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007835 SS,
7836 Name,
John McCallba7bf592010-08-24 05:47:05 +00007837 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007838 /*EnteringContext=*/false,
7839 Template);
7840 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007841}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007842
Douglas Gregor71395fa2009-11-04 00:56:37 +00007843template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007844ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007845TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7846 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007847 Expr *OrigCallee,
7848 Expr *First,
7849 Expr *Second) {
7850 Expr *Callee = OrigCallee->IgnoreParenCasts();
7851 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007852
Douglas Gregora16548e2009-08-11 05:31:07 +00007853 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007854 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007855 if (!First->getType()->isOverloadableType() &&
7856 !Second->getType()->isOverloadableType())
7857 return getSema().CreateBuiltinArraySubscriptExpr(First,
7858 Callee->getLocStart(),
7859 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007860 } else if (Op == OO_Arrow) {
7861 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007862 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7863 } else if (Second == 0 || isPostIncDec) {
7864 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007865 // The argument is not of overloadable type, so try to create a
7866 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007867 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007868 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007869
John McCallb268a282010-08-23 23:25:46 +00007870 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007871 }
7872 } else {
John McCallb268a282010-08-23 23:25:46 +00007873 if (!First->getType()->isOverloadableType() &&
7874 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007875 // Neither of the arguments is an overloadable type, so try to
7876 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007877 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007878 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007879 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007880 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007882
Douglas Gregora16548e2009-08-11 05:31:07 +00007883 return move(Result);
7884 }
7885 }
Mike Stump11289f42009-09-09 15:08:12 +00007886
7887 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007888 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007889 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007890
John McCallb268a282010-08-23 23:25:46 +00007891 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007892 assert(ULE->requiresADL());
7893
7894 // FIXME: Do we have to check
7895 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007896 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007897 } else {
John McCallb268a282010-08-23 23:25:46 +00007898 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007899 }
Mike Stump11289f42009-09-09 15:08:12 +00007900
Douglas Gregora16548e2009-08-11 05:31:07 +00007901 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007902 Expr *Args[2] = { First, Second };
7903 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007904
Douglas Gregora16548e2009-08-11 05:31:07 +00007905 // Create the overloaded operator invocation for unary operators.
7906 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007907 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007908 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007909 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007910 }
Mike Stump11289f42009-09-09 15:08:12 +00007911
Sebastian Redladba46e2009-10-29 20:17:01 +00007912 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007913 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007914 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007915 First,
7916 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007917
Douglas Gregora16548e2009-08-11 05:31:07 +00007918 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007919 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007920 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007921 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7922 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007923 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007924
Mike Stump11289f42009-09-09 15:08:12 +00007925 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007926}
Mike Stump11289f42009-09-09 15:08:12 +00007927
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007929ExprResult
John McCallb268a282010-08-23 23:25:46 +00007930TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007931 SourceLocation OperatorLoc,
7932 bool isArrow,
7933 NestedNameSpecifier *Qualifier,
7934 SourceRange QualifierRange,
7935 TypeSourceInfo *ScopeType,
7936 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007937 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007938 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007939 CXXScopeSpec SS;
Douglas Gregor2ab3fee2011-02-24 00:49:34 +00007940 if (Qualifier)
Douglas Gregor869ad452011-02-24 17:54:50 +00007941 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007942
John McCallb268a282010-08-23 23:25:46 +00007943 QualType BaseType = Base->getType();
7944 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007945 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007946 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007947 !BaseType->getAs<PointerType>()->getPointeeType()
7948 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007949 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007950 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007951 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007952 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007953 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007954 /*FIXME?*/true);
7955 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007956
Douglas Gregor678f90d2010-02-25 01:56:36 +00007957 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007958 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7959 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7960 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7961 NameInfo.setNamedTypeInfo(DestroyedType);
7962
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007963 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007964
John McCallb268a282010-08-23 23:25:46 +00007965 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007966 OperatorLoc, isArrow,
7967 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007968 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007969 /*TemplateArgs*/ 0);
7970}
7971
Douglas Gregord6ff3322009-08-04 16:50:30 +00007972} // end namespace clang
7973
7974#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H