blob: 373339a2cb8b84eca9eae99e4bffee6be91f965c [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000034#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000035#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000036#include <algorithm>
37
38namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000039using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000040
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// \brief A semantic tree transformation that allows one to transform one
42/// abstract syntax tree into another.
43///
Mike Stump11289f42009-09-09 15:08:12 +000044/// A new tree transformation is defined by creating a new subclass \c X of
45/// \c TreeTransform<X> and then overriding certain operations to provide
46/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000047/// instantiation is implemented as a tree transformation where the
48/// transformation of TemplateTypeParmType nodes involves substituting the
49/// template arguments for their corresponding template parameters; a similar
50/// transformation is performed for non-type template parameters and
51/// template template parameters.
52///
53/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000054/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000055/// override any of the transformation or rebuild operators by providing an
56/// operation with the same signature as the default implementation. The
57/// overridding function should not be virtual.
58///
59/// Semantic tree transformations are split into two stages, either of which
60/// can be replaced by a subclass. The "transform" step transforms an AST node
61/// or the parts of an AST node using the various transformation functions,
62/// then passes the pieces on to the "rebuild" step, which constructs a new AST
63/// node of the appropriate kind from the pieces. The default transformation
64/// routines recursively transform the operands to composite AST nodes (e.g.,
65/// the pointee type of a PointerType node) and, if any of those operand nodes
66/// were changed by the transformation, invokes the rebuild operation to create
67/// a new AST node.
68///
Mike Stump11289f42009-09-09 15:08:12 +000069/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000070/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000071/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// TransformTemplateName(), or TransformTemplateArgument() with entirely
73/// new implementations.
74///
75/// For more fine-grained transformations, subclasses can replace any of the
76/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000077/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000078/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000079/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// parameters. Additionally, subclasses can override the \c RebuildXXX
81/// functions to control how AST nodes are rebuilt when their operands change.
82/// By default, \c TreeTransform will invoke semantic analysis to rebuild
83/// AST nodes. However, certain other tree transformations (e.g, cloning) may
84/// be able to use more efficient rebuild steps.
85///
86/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000087/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000088/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
89/// operands have not changed (\c AlwaysRebuild()), and customize the
90/// default locations and entity names used for type-checking
91/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000092template<typename Derived>
93class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000094 /// \brief Private RAII object that helps us forget and then re-remember
95 /// the template argument corresponding to a partially-substituted parameter
96 /// pack.
97 class ForgetPartiallySubstitutedPackRAII {
98 Derived &Self;
99 TemplateArgument Old;
100
101 public:
102 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
103 Old = Self.ForgetPartiallySubstitutedPack();
104 }
105
106 ~ForgetPartiallySubstitutedPackRAII() {
107 Self.RememberPartiallySubstitutedPack(Old);
108 }
109 };
110
Douglas Gregord6ff3322009-08-04 16:50:30 +0000111protected:
112 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000113
Mike Stump11289f42009-09-09 15:08:12 +0000114public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000116 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000117
Douglas Gregord6ff3322009-08-04 16:50:30 +0000118 /// \brief Retrieves a reference to the derived class.
119 Derived &getDerived() { return static_cast<Derived&>(*this); }
120
121 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000122 const Derived &getDerived() const {
123 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 }
125
John McCalldadc5752010-08-24 06:29:42 +0000126 static inline ExprResult Owned(Expr *E) { return E; }
127 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000128
Douglas Gregord6ff3322009-08-04 16:50:30 +0000129 /// \brief Retrieves a reference to the semantic analysis object used for
130 /// this tree transform.
131 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000132
Douglas Gregord6ff3322009-08-04 16:50:30 +0000133 /// \brief Whether the transformation should always rebuild AST nodes, even
134 /// if none of the children have changed.
135 ///
136 /// Subclasses may override this function to specify when the transformation
137 /// should rebuild all AST nodes.
138 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Returns the location of the entity being transformed, if that
141 /// information was not available elsewhere in the AST.
142 ///
Mike Stump11289f42009-09-09 15:08:12 +0000143 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000144 /// provide an alternative implementation that provides better location
145 /// information.
146 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000147
Douglas Gregord6ff3322009-08-04 16:50:30 +0000148 /// \brief Returns the name of the entity being transformed, if that
149 /// information was not available elsewhere in the AST.
150 ///
151 /// By default, returns an empty name. Subclasses can provide an alternative
152 /// implementation with a more precise name.
153 DeclarationName getBaseEntity() { return DeclarationName(); }
154
Douglas Gregora16548e2009-08-11 05:31:07 +0000155 /// \brief Sets the "base" location and entity when that
156 /// information is known based on another transformation.
157 ///
158 /// By default, the source location and entity are ignored. Subclasses can
159 /// override this function to provide a customized implementation.
160 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000161
Douglas Gregora16548e2009-08-11 05:31:07 +0000162 /// \brief RAII object that temporarily sets the base location and entity
163 /// used for reporting diagnostics in types.
164 class TemporaryBase {
165 TreeTransform &Self;
166 SourceLocation OldLocation;
167 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000168
Douglas Gregora16548e2009-08-11 05:31:07 +0000169 public:
170 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000171 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 OldLocation = Self.getDerived().getBaseLocation();
173 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000174
175 if (Location.isValid())
176 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000177 }
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 ~TemporaryBase() {
180 Self.getDerived().setBase(OldLocation, OldEntity);
181 }
182 };
Mike Stump11289f42009-09-09 15:08:12 +0000183
184 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// transformed.
186 ///
187 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000188 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000189 /// not change. For example, template instantiation need not traverse
190 /// non-dependent types.
191 bool AlreadyTransformed(QualType T) {
192 return T.isNull();
193 }
194
Douglas Gregord196a582009-12-14 19:27:10 +0000195 /// \brief Determine whether the given call argument should be dropped, e.g.,
196 /// because it is a default argument.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine to
199 /// determine which kinds of call arguments get dropped. By default,
200 /// CXXDefaultArgument nodes are dropped (prior to transformation).
201 bool DropCallArgument(Expr *E) {
202 return E->isDefaultArgument();
203 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000204
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000205 /// \brief Determine whether we should expand a pack expansion with the
206 /// given set of parameter packs into separate arguments by repeatedly
207 /// transforming the pattern.
208 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000209 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000210 /// Subclasses can override this routine to provide different behavior.
211 ///
212 /// \param EllipsisLoc The location of the ellipsis that identifies the
213 /// pack expansion.
214 ///
215 /// \param PatternRange The source range that covers the entire pattern of
216 /// the pack expansion.
217 ///
218 /// \param Unexpanded The set of unexpanded parameter packs within the
219 /// pattern.
220 ///
221 /// \param NumUnexpanded The number of unexpanded parameter packs in
222 /// \p Unexpanded.
223 ///
224 /// \param ShouldExpand Will be set to \c true if the transformer should
225 /// expand the corresponding pack expansions into separate arguments. When
226 /// set, \c NumExpansions must also be set.
227 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000228 /// \param RetainExpansion Whether the caller should add an unexpanded
229 /// pack expansion after all of the expanded arguments. This is used
230 /// when extending explicitly-specified template argument packs per
231 /// C++0x [temp.arg.explicit]p9.
232 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000233 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000234 /// the expanded form of the corresponding pack expansion. This is both an
235 /// input and an output parameter, which can be set by the caller if the
236 /// number of expansions is known a priori (e.g., due to a prior substitution)
237 /// and will be set by the callee when the number of expansions is known.
238 /// The callee must set this value when \c ShouldExpand is \c true; it may
239 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 ///
241 /// \returns true if an error occurred (e.g., because the parameter packs
242 /// are to be instantiated with arguments of different lengths), false
243 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
244 /// must be set.
245 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
246 SourceRange PatternRange,
247 const UnexpandedParameterPack *Unexpanded,
248 unsigned NumUnexpanded,
249 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 /// \brief "Forget" about the partially-substituted pack template argument,
257 /// when performing an instantiation that must preserve the parameter pack
258 /// use.
259 ///
260 /// This routine is meant to be overridden by the template instantiator.
261 TemplateArgument ForgetPartiallySubstitutedPack() {
262 return TemplateArgument();
263 }
264
265 /// \brief "Remember" the partially-substituted pack template argument
266 /// after performing an instantiation that must preserve the parameter pack
267 /// use.
268 ///
269 /// This routine is meant to be overridden by the template instantiator.
270 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271
Douglas Gregorf3010112011-01-07 16:43:16 +0000272 /// \brief Note to the derived class when a function parameter pack is
273 /// being expanded.
274 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
275
Douglas Gregord6ff3322009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCall550e0c22009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000280 /// function. This is expensive, but we don't mind, because
281 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000286
John McCall550e0c22009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
John McCall550e0c22009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by delegating to the
291 /// appropriate TransformXXXType to build a new type. Subclasses
292 /// may override this function (to take over all type
293 /// transformations) or some set of the TransformXXXType functions
294 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000296
297 /// \brief Transform the given type-with-location into a new
298 /// type, collecting location information in the given builder
299 /// as necessary.
300 ///
John McCall31f82722010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000302
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000304 ///
Mike Stump11289f42009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000306 /// appropriate TransformXXXStmt function to transform a specific kind of
307 /// statement or the TransformExpr() function to transform an expression.
308 /// Subclasses may override this function to transform statements using some
309 /// other mechanism.
310 ///
311 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000313
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000316 /// By default, this routine transforms an expression by delegating to the
317 /// appropriate TransformXXXExpr function to build a new expression.
318 /// Subclasses may override this function to transform expressions using some
319 /// other mechanism.
320 ///
321 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000323
Douglas Gregora3efea12011-01-03 19:04:46 +0000324 /// \brief Transform the given list of expressions.
325 ///
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
331 ///
332 /// \param Inputs The set of expressions to be transformed.
333 ///
334 /// \param NumInputs The number of expressions in \c Inputs.
335 ///
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
338 /// be.
339 ///
340 /// \param Outputs The transformed input expressions will be added to this
341 /// vector.
342 ///
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
345 ///
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000348 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 bool *ArgChanged = 0);
350
Douglas Gregord6ff3322009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000354 /// By default, acts as the identity function on declarations. Subclasses
355 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump11289f42009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000364 }
Mike Stump11289f42009-09-09 15:08:12 +0000365
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000366 /// \brief Transform the given declaration, which was the first part of a
367 /// nested-name-specifier in a member access expression.
368 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000370 /// identifier in a nested-name-specifier of a member access expression, e.g.,
371 /// the \c T in \c x->T::member
372 ///
373 /// By default, invokes TransformDecl() to transform the declaration.
374 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000377 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000378
Douglas Gregor14454802011-02-25 02:25:35 +0000379 /// \brief Transform the given nested-name-specifier with source-location
380 /// information.
381 ///
382 /// By default, transforms all of the types and declarations within the
383 /// nested-name-specifier. Subclasses may override this function to provide
384 /// alternate behavior.
385 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386 NestedNameSpecifierLoc NNS,
387 QualType ObjectType = QualType(),
388 NamedDecl *FirstQualifierInScope = 0);
389
Douglas Gregorf816bd72009-09-03 22:13:48 +0000390 /// \brief Transform the given declaration name.
391 ///
392 /// By default, transforms the types of conversion function, constructor,
393 /// and destructor names and then (if needed) rebuilds the declaration name.
394 /// Identifiers and selectors are returned unmodified. Sublcasses may
395 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000398
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000400 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000401 /// \param SS The nested-name-specifier that qualifies the template
402 /// name. This nested-name-specifier must already have been transformed.
403 ///
404 /// \param Name The template name to transform.
405 ///
406 /// \param NameLoc The source location of the template name.
407 ///
408 /// \param ObjectType If we're translating a template name within a member
409 /// access expression, this is the type of the object whose member template
410 /// is being referenced.
411 ///
412 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413 /// also refers to a name within the current (lexical) scope, this is the
414 /// declaration it refers to.
415 ///
416 /// By default, transforms the template name by transforming the declarations
417 /// and nested-name-specifiers that occur within the template name.
418 /// Subclasses may override this function to provide alternate behavior.
419 TemplateName TransformTemplateName(CXXScopeSpec &SS,
420 TemplateName Name,
421 SourceLocation NameLoc,
422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
424
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump11289f42009-09-09 15:08:12 +0000427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000431 ///
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
435
Douglas Gregor62e06f22010-12-20 17:31:10 +0000436 /// \brief Transform the given set of template arguments.
437 ///
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
441 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
445 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000446 /// \param Inputs The set of template arguments to be transformed.
447 ///
448 /// \param NumInputs The number of template arguments in \p Inputs.
449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000459
460 /// \brief Transform the given set of template arguments.
461 ///
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
465 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000466 /// \param First An iterator to the first template argument.
467 ///
468 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000469 ///
470 /// \param Outputs The set of transformed template arguments output by this
471 /// routine.
472 ///
473 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000478
John McCall0ad16662009-10-29 08:12:44 +0000479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
482
John McCallbcd03502009-12-07 02:54:59 +0000483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump11289f42009-09-09 15:08:12 +0000488
John McCall550e0c22009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493
John Wiegley1c0675e2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall31f82722010-11-12 08:19:04 +0000497 QualType
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
501
502 QualType
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall58f10c32010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000523 SmallVectorImpl<QualType> &PTypes,
524 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000534
John McCall31f82722010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000536
John McCalldadc5752010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000539
Douglas Gregorebe10102009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000546
Douglas Gregord6ff3322009-08-04 16:50:30 +0000547 /// \brief Build a new pointer type given its pointee type.
548 ///
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump11289f42009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558
John McCall70dd5f62009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 ///
John McCall70dd5f62009-10-30 00:06:24 +0000561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000564 ///
John McCall70dd5f62009-10-30 00:06:24 +0000565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
568 bool LValue,
569 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000570
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
573 ///
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000578
Douglas Gregord6ff3322009-08-04 16:50:30 +0000579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
581 /// qualifiers.
582 ///
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
589 Expr *SizeExpr,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000592
Douglas Gregord6ff3322009-08-04 16:50:30 +0000593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000603
Douglas Gregord6ff3322009-08-04 16:50:30 +0000604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000613
Mike Stump11289f42009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump11289f42009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626 /// size modifier, size expression, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
635
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000643
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000653 /// given the element type and number of elements.
654 ///
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new function type.
662 ///
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000671
John McCall550e0c22009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCallb96ec562009-12-04 22:46:56 +0000675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
678
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681 return SemaRef.Context.getTypeDeclType(Typedef);
682 }
683
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
687 }
688
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
692 }
John McCallfcc33b02009-09-05 00:15:47 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000699
Mike Stump11289f42009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Alexis Hunte852b102011-05-24 22:41:36 +0000705 /// \brief Build a new unary transform type.
706 QualType RebuildUnaryTransformType(QualType BaseType,
707 UnaryTransformType::UTTKind UKind,
708 SourceLocation Loc);
709
Mike Stump11289f42009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 ///
712 /// By default, performs semantic analysis when building the decltype type.
713 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000715
Richard Smith30482bc2011-02-20 03:19:35 +0000716 /// \brief Build a new C++0x auto type.
717 ///
718 /// By default, builds a new AutoType with the given deduced type.
719 QualType RebuildAutoType(QualType Deduced) {
720 return SemaRef.Context.getAutoType(Deduced);
721 }
722
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// \brief Build a new template specialization type.
724 ///
725 /// By default, performs semantic analysis when building the template
726 /// specialization type. Subclasses may override this routine to provide
727 /// different behavior.
728 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000731
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000732 /// \brief Build a new parenthesized type.
733 ///
734 /// By default, builds a new ParenType type from the inner type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildParenType(QualType InnerType) {
737 return SemaRef.Context.getParenType(InnerType);
738 }
739
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000742 /// By default, builds a new ElaboratedType type from the keyword,
743 /// the nested-name-specifier and the named type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000752 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000756 /// By default, builds a new DependentNameType type from the
757 /// nested-name-specifier and the given type. Subclasses may override
758 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000771
772 if (InstName.isNull())
773 return QualType();
774
775 // If it's still dependent, make a dependent specialization.
776 if (InstName.getAsDependentTemplateName())
777 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
779 Name,
780 Args);
781
782 // Otherwise, make an elaborated type wrapping a non-dependent
783 // specialization.
784 QualType T =
785 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
786 if (T.isNull()) return QualType();
787
788 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
789 return T;
790
791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
793 T);
794 }
795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new typename type that refers to an identifier.
797 ///
798 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000808
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000810 // If the name is still dependent, just build a new dependent name type.
811 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara6150c882010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarad7548482010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCallbf8c5192010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregore677daf2010-03-31 22:19:08 +0000834 TagDecl *Tag = 0;
835 SemaRef.LookupQualifiedName(Result, DC);
836 switch (Result.getResultKind()) {
837 case LookupResult::NotFound:
838 case LookupResult::NotFoundInCurrentInstantiation:
839 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000840
Douglas Gregore677daf2010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000844
Douglas Gregore677daf2010-03-31 22:19:08 +0000845 case LookupResult::FoundOverloaded:
846 case LookupResult::FoundUnresolvedValue:
847 llvm_unreachable("Tag lookup cannot find non-tags");
848 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000849
Douglas Gregore677daf2010-03-31 22:19:08 +0000850 case LookupResult::Ambiguous:
851 // Let the LookupResult structure handle ambiguities.
852 return QualType();
853 }
854
855 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000856 // Check where the name exists but isn't a tag type and use that to emit
857 // better diagnostics.
858 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859 SemaRef.LookupQualifiedName(Result, DC);
860 switch (Result.getResultKind()) {
861 case LookupResult::Found:
862 case LookupResult::FoundOverloaded:
863 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000872 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000873 default:
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876 << Kind << Id << DC;
877 break;
878 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000881
Richard Trieucaa33d32011-06-10 03:11:26 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000885 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
886 return QualType();
887 }
888
889 // Build the elaborated-type-specifier type.
890 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
893 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000894 }
Mike Stump11289f42009-09-09 15:08:12 +0000895
Douglas Gregor822d0302011-01-12 17:07:58 +0000896 /// \brief Build a new pack expansion type.
897 ///
898 /// By default, builds a new PackExpansionType type from the given pattern.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildPackExpansionType(QualType Pattern,
901 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000906 }
907
Douglas Gregor71dc5092009-08-06 06:41:21 +0000908 /// \brief Build a new template name given a nested name specifier, a flag
909 /// indicating whether the "template" keyword was provided, and the template
910 /// that the template name refers to.
911 ///
912 /// By default, builds the new template name directly. Subclasses may override
913 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000914 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000915 bool TemplateKW,
916 TemplateDecl *Template);
917
Douglas Gregor71dc5092009-08-06 06:41:21 +0000918 /// \brief Build a new template name given a nested name specifier and the
919 /// name that is referred to as a template.
920 ///
921 /// By default, performs semantic analysis to determine whether the name can
922 /// be resolved to a specific template, then builds the appropriate kind of
923 /// template name. Subclasses may override this routine to provide different
924 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000925 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
926 const IdentifierInfo &Name,
927 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000928 QualType ObjectType,
929 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000930
Douglas Gregor71395fa2009-11-04 00:56:37 +0000931 /// \brief Build a new template name given a nested name specifier and the
932 /// overloaded operator name that is referred to as a template.
933 ///
934 /// By default, performs semantic analysis to determine whether the name can
935 /// be resolved to a specific template, then builds the appropriate kind of
936 /// template name. Subclasses may override this routine to provide different
937 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000938 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000939 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000940 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000941 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000942
943 /// \brief Build a new template name given a template template parameter pack
944 /// and the
945 ///
946 /// By default, performs semantic analysis to determine whether the name can
947 /// be resolved to a specific template, then builds the appropriate kind of
948 /// template name. Subclasses may override this routine to provide different
949 /// behavior.
950 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
951 const TemplateArgument &ArgPack) {
952 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
953 }
954
Douglas Gregorebe10102009-08-20 07:17:43 +0000955 /// \brief Build a new compound statement.
956 ///
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000959 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000960 MultiStmtArg Statements,
961 SourceLocation RBraceLoc,
962 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000963 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000964 IsStmtExpr);
965 }
966
967 /// \brief Build a new case statement.
968 ///
969 /// By default, performs semantic analysis to build the new statement.
970 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000971 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000972 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000973 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000974 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000975 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000976 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000977 ColonLoc);
978 }
Mike Stump11289f42009-09-09 15:08:12 +0000979
Douglas Gregorebe10102009-08-20 07:17:43 +0000980 /// \brief Attach the body to a new case statement.
981 ///
982 /// By default, performs semantic analysis to build the new statement.
983 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000984 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000985 getSema().ActOnCaseStmtBody(S, Body);
986 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 }
Mike Stump11289f42009-09-09 15:08:12 +0000988
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 /// \brief Build a new default statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000993 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000994 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000995 Stmt *SubStmt) {
996 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000997 /*CurScope=*/0);
998 }
Mike Stump11289f42009-09-09 15:08:12 +0000999
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 /// \brief Build a new label statement.
1001 ///
1002 /// By default, performs semantic analysis to build the new statement.
1003 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001004 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1005 SourceLocation ColonLoc, Stmt *SubStmt) {
1006 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001007 }
Mike Stump11289f42009-09-09 15:08:12 +00001008
Douglas Gregorebe10102009-08-20 07:17:43 +00001009 /// \brief Build a new "if" statement.
1010 ///
1011 /// By default, performs semantic analysis to build the new statement.
1012 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001013 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001014 VarDecl *CondVar, Stmt *Then,
1015 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001016 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001017 }
Mike Stump11289f42009-09-09 15:08:12 +00001018
Douglas Gregorebe10102009-08-20 07:17:43 +00001019 /// \brief Start building a new switch statement.
1020 ///
1021 /// By default, performs semantic analysis to build the new statement.
1022 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001023 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001024 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001025 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001026 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001027 }
Mike Stump11289f42009-09-09 15:08:12 +00001028
Douglas Gregorebe10102009-08-20 07:17:43 +00001029 /// \brief Attach the body to the switch statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001033 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001034 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001035 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001036 }
1037
1038 /// \brief Build a new while statement.
1039 ///
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001042 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1043 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001044 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001045 }
Mike Stump11289f42009-09-09 15:08:12 +00001046
Douglas Gregorebe10102009-08-20 07:17:43 +00001047 /// \brief Build a new do-while statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001051 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001052 SourceLocation WhileLoc, SourceLocation LParenLoc,
1053 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001054 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1055 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001056 }
1057
1058 /// \brief Build a new for statement.
1059 ///
1060 /// By default, performs semantic analysis to build the new statement.
1061 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001062 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1063 Stmt *Init, Sema::FullExprArg Cond,
1064 VarDecl *CondVar, Sema::FullExprArg Inc,
1065 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001066 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001067 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 }
Mike Stump11289f42009-09-09 15:08:12 +00001069
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 /// \brief Build a new goto statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001074 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1075 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001076 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001077 }
1078
1079 /// \brief Build a new indirect goto statement.
1080 ///
1081 /// By default, performs semantic analysis to build the new statement.
1082 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001083 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001084 SourceLocation StarLoc,
1085 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001086 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 }
Mike Stump11289f42009-09-09 15:08:12 +00001088
Douglas Gregorebe10102009-08-20 07:17:43 +00001089 /// \brief Build a new return statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001093 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001094 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 }
Mike Stump11289f42009-09-09 15:08:12 +00001096
Douglas Gregorebe10102009-08-20 07:17:43 +00001097 /// \brief Build a new declaration statement.
1098 ///
1099 /// By default, performs semantic analysis to build the new statement.
1100 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001101 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001102 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001103 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001104 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1105 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001106 }
Mike Stump11289f42009-09-09 15:08:12 +00001107
Anders Carlssonaaeef072010-01-24 05:50:09 +00001108 /// \brief Build a new inline asm statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001112 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001113 bool IsSimple,
1114 bool IsVolatile,
1115 unsigned NumOutputs,
1116 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001117 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001118 MultiExprArg Constraints,
1119 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001120 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001121 MultiExprArg Clobbers,
1122 SourceLocation RParenLoc,
1123 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001124 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001125 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001126 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001127 RParenLoc, MSAsm);
1128 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001129
1130 /// \brief Build a new Objective-C @try statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001134 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001135 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001136 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001137 Stmt *Finally) {
1138 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1139 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001140 }
1141
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001142 /// \brief Rebuild an Objective-C exception declaration.
1143 ///
1144 /// By default, performs semantic analysis to build the new declaration.
1145 /// Subclasses may override this routine to provide different behavior.
1146 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1147 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001148 return getSema().BuildObjCExceptionDecl(TInfo, T,
1149 ExceptionDecl->getInnerLocStart(),
1150 ExceptionDecl->getLocation(),
1151 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001152 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001153
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001154 /// \brief Build a new Objective-C @catch statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001158 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001159 SourceLocation RParenLoc,
1160 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001161 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001162 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001163 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001164 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001165
Douglas Gregor306de2f2010-04-22 23:59:56 +00001166 /// \brief Build a new Objective-C @finally statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001170 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001171 Stmt *Body) {
1172 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001173 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001174
Douglas Gregor6148de72010-04-22 22:01:21 +00001175 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001180 Expr *Operand) {
1181 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001182 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001183
Douglas Gregor6148de72010-04-22 22:01:21 +00001184 /// \brief Build a new Objective-C @synchronized statement.
1185 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001186 /// By default, performs semantic analysis to build the new statement.
1187 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001188 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001189 Expr *Object,
1190 Stmt *Body) {
1191 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1192 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001193 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001194
John McCall31168b02011-06-15 23:02:42 +00001195 /// \brief Build a new Objective-C @autoreleasepool statement.
1196 ///
1197 /// By default, performs semantic analysis to build the new statement.
1198 /// Subclasses may override this routine to provide different behavior.
1199 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1200 Stmt *Body) {
1201 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1202 }
John McCall53848232011-07-27 01:07:15 +00001203
1204 /// \brief Build the collection operand to a new Objective-C fast
1205 /// enumeration statement.
1206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
1209 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1210 Expr *collection) {
1211 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1212 }
John McCall31168b02011-06-15 23:02:42 +00001213
Douglas Gregorf68a5082010-04-22 23:10:45 +00001214 /// \brief Build a new Objective-C fast enumeration statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001218 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001219 SourceLocation LParenLoc,
1220 Stmt *Element,
1221 Expr *Collection,
1222 SourceLocation RParenLoc,
1223 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001224 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001225 Element,
1226 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001227 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001228 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001229 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001230
Douglas Gregorebe10102009-08-20 07:17:43 +00001231 /// \brief Build a new C++ exception declaration.
1232 ///
1233 /// By default, performs semantic analysis to build the new decaration.
1234 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001235 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001236 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001237 SourceLocation StartLoc,
1238 SourceLocation IdLoc,
1239 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001240 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1241 StartLoc, IdLoc, Id);
1242 if (Var)
1243 getSema().CurContext->addDecl(Var);
1244 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001245 }
1246
1247 /// \brief Build a new C++ catch statement.
1248 ///
1249 /// By default, performs semantic analysis to build the new statement.
1250 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001251 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001252 VarDecl *ExceptionDecl,
1253 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001254 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1255 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Douglas Gregorebe10102009-08-20 07:17:43 +00001258 /// \brief Build a new C++ try statement.
1259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001262 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001263 Stmt *TryBlock,
1264 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001265 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001266 }
Mike Stump11289f42009-09-09 15:08:12 +00001267
Richard Smith02e85f32011-04-14 22:09:26 +00001268 /// \brief Build a new C++0x range-based for statement.
1269 ///
1270 /// By default, performs semantic analysis to build the new statement.
1271 /// Subclasses may override this routine to provide different behavior.
1272 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1273 SourceLocation ColonLoc,
1274 Stmt *Range, Stmt *BeginEnd,
1275 Expr *Cond, Expr *Inc,
1276 Stmt *LoopVar,
1277 SourceLocation RParenLoc) {
1278 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1279 Cond, Inc, LoopVar, RParenLoc);
1280 }
1281
1282 /// \brief Attach body to a C++0x range-based for statement.
1283 ///
1284 /// By default, performs semantic analysis to finish the new statement.
1285 /// Subclasses may override this routine to provide different behavior.
1286 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1287 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1288 }
1289
John Wiegley1c0675e2011-04-28 01:08:34 +00001290 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1291 SourceLocation TryLoc,
1292 Stmt *TryBlock,
1293 Stmt *Handler) {
1294 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1295 }
1296
1297 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1298 Expr *FilterExpr,
1299 Stmt *Block) {
1300 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1301 }
1302
1303 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1304 Stmt *Block) {
1305 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1306 }
1307
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 /// \brief Build a new expression that references a declaration.
1309 ///
1310 /// By default, performs semantic analysis to build the new expression.
1311 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001312 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001313 LookupResult &R,
1314 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001315 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1316 }
1317
1318
1319 /// \brief Build a new expression that references a declaration.
1320 ///
1321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001323 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001324 ValueDecl *VD,
1325 const DeclarationNameInfo &NameInfo,
1326 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001327 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001328 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001329
1330 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001331
1332 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 }
Mike Stump11289f42009-09-09 15:08:12 +00001334
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001336 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 /// By default, performs semantic analysis to build the new expression.
1338 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001339 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001341 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 }
1343
Douglas Gregorad8a3362009-09-04 17:36:40 +00001344 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001345 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +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 RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001349 SourceLocation OperatorLoc,
1350 bool isArrow,
1351 CXXScopeSpec &SS,
1352 TypeSourceInfo *ScopeType,
1353 SourceLocation CCLoc,
1354 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001355 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001356
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 /// \brief Build a new unary operator 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 RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001362 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001363 Expr *SubExpr) {
1364 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 }
Mike Stump11289f42009-09-09 15:08:12 +00001366
Douglas Gregor882211c2010-04-28 22:16:22 +00001367 /// \brief Build a new builtin offsetof expression.
1368 ///
1369 /// By default, performs semantic analysis to build the new expression.
1370 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001371 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001372 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001373 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001374 unsigned NumComponents,
1375 SourceLocation RParenLoc) {
1376 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1377 NumComponents, RParenLoc);
1378 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001379
Peter Collingbournee190dee2011-03-11 19:24:49 +00001380 /// \brief Build a new sizeof, alignof or vec_step expression with a
1381 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001382 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 /// By default, performs semantic analysis to build the new expression.
1384 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001385 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1386 SourceLocation OpLoc,
1387 UnaryExprOrTypeTrait ExprKind,
1388 SourceRange R) {
1389 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 }
1391
Peter Collingbournee190dee2011-03-11 19:24:49 +00001392 /// \brief Build a new sizeof, alignof or vec step expression with an
1393 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001394 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 /// By default, performs semantic analysis to build the new expression.
1396 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001397 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1398 UnaryExprOrTypeTrait ExprKind,
1399 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001400 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001401 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001403 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001404
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 return move(Result);
1406 }
Mike Stump11289f42009-09-09 15:08:12 +00001407
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001409 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 /// By default, performs semantic analysis to build the new expression.
1411 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001412 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001414 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001416 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1417 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 RBracketLoc);
1419 }
1420
1421 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001422 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 /// By default, performs semantic analysis to build the new expression.
1424 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001425 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001427 SourceLocation RParenLoc,
1428 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001429 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001430 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 }
1432
1433 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001434 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 /// By default, performs semantic analysis to build the new expression.
1436 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001437 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001438 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001439 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001440 const DeclarationNameInfo &MemberNameInfo,
1441 ValueDecl *Member,
1442 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001443 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001444 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001445 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001446 // We have a reference to an unnamed field. This is always the
1447 // base of an anonymous struct/union member access, i.e. the
1448 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001449 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001450 assert(Member->getType()->isRecordType() &&
1451 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001452
John Wiegley01296292011-04-08 18:41:53 +00001453 ExprResult BaseResult =
1454 getSema().PerformObjectMemberConversion(Base,
1455 QualifierLoc.getNestedNameSpecifier(),
1456 FoundDecl, Member);
1457 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001458 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001459 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001460 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001461 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001462 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001463 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001464 cast<FieldDecl>(Member)->getType(),
1465 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001466 return getSema().Owned(ME);
1467 }
Mike Stump11289f42009-09-09 15:08:12 +00001468
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001469 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001470 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001471
John Wiegley01296292011-04-08 18:41:53 +00001472 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1473 if (BaseResult.isInvalid())
1474 return ExprError();
1475 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001476 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001477
John McCall16df1e52010-03-30 21:47:33 +00001478 // FIXME: this involves duplicating earlier analysis in a lot of
1479 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001480 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001481 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001482 R.resolveKind();
1483
John McCallb268a282010-08-23 23:25:46 +00001484 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001485 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001486 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 }
Mike Stump11289f42009-09-09 15:08:12 +00001488
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001490 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001493 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001494 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001495 Expr *LHS, Expr *RHS) {
1496 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 }
1498
1499 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001500 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 /// By default, performs semantic analysis to build the new expression.
1502 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001503 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001504 SourceLocation QuestionLoc,
1505 Expr *LHS,
1506 SourceLocation ColonLoc,
1507 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001508 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1509 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 }
1511
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001513 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 /// By default, performs semantic analysis to build the new expression.
1515 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001516 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001517 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001519 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001520 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001521 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 }
Mike Stump11289f42009-09-09 15:08:12 +00001523
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001525 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001528 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001529 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001531 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001532 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001533 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 }
Mike Stump11289f42009-09-09 15:08:12 +00001535
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001537 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001540 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 SourceLocation OpLoc,
1542 SourceLocation AccessorLoc,
1543 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001544
John McCall10eae182009-11-30 22:42:35 +00001545 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001546 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001547 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001548 OpLoc, /*IsArrow*/ false,
1549 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001550 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001551 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 }
Mike Stump11289f42009-09-09 15:08:12 +00001553
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001555 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 /// By default, performs semantic analysis to build the new expression.
1557 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001558 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001559 MultiExprArg Inits,
1560 SourceLocation RBraceLoc,
1561 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001562 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001563 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1564 if (Result.isInvalid() || ResultTy->isDependentType())
1565 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001566
Douglas Gregord3d93062009-11-09 17:16:50 +00001567 // Patch in the result type we were given, which may have been computed
1568 // when the initial InitListExpr was built.
1569 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1570 ILE->setType(ResultTy);
1571 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 }
Mike Stump11289f42009-09-09 15:08:12 +00001573
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001575 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 /// By default, performs semantic analysis to build the new expression.
1577 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001578 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 MultiExprArg ArrayExprs,
1580 SourceLocation EqualOrColonLoc,
1581 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001582 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001583 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001585 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001587 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001588
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 ArrayExprs.release();
1590 return move(Result);
1591 }
Mike Stump11289f42009-09-09 15:08:12 +00001592
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001594 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// By default, builds the implicit value initialization without performing
1596 /// any semantic analysis. Subclasses may override this routine to provide
1597 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001598 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1600 }
Mike Stump11289f42009-09-09 15:08:12 +00001601
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001603 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 /// By default, performs semantic analysis to build the new expression.
1605 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001606 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001607 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001608 SourceLocation RParenLoc) {
1609 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001610 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001611 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 }
1613
1614 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001615 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 /// By default, performs semantic analysis to build the new expression.
1617 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001618 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 MultiExprArg SubExprs,
1620 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001621 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001622 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 }
Mike Stump11289f42009-09-09 15:08:12 +00001624
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001626 ///
1627 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 /// rather than attempting to map the label statement itself.
1629 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001630 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001631 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001632 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 }
Mike Stump11289f42009-09-09 15:08:12 +00001634
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001636 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 /// By default, performs semantic analysis to build the new expression.
1638 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001639 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001640 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001642 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 }
Mike Stump11289f42009-09-09 15:08:12 +00001644
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 /// \brief Build a new __builtin_choose_expr expression.
1646 ///
1647 /// By default, performs semantic analysis to build the new expression.
1648 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001649 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001650 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001651 SourceLocation RParenLoc) {
1652 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001653 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 RParenLoc);
1655 }
Mike Stump11289f42009-09-09 15:08:12 +00001656
Peter Collingbourne91147592011-04-15 00:35:48 +00001657 /// \brief Build a new generic selection expression.
1658 ///
1659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
1661 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1662 SourceLocation DefaultLoc,
1663 SourceLocation RParenLoc,
1664 Expr *ControllingExpr,
1665 TypeSourceInfo **Types,
1666 Expr **Exprs,
1667 unsigned NumAssocs) {
1668 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1669 ControllingExpr, Types, Exprs,
1670 NumAssocs);
1671 }
1672
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 /// \brief Build a new overloaded operator call expression.
1674 ///
1675 /// By default, performs semantic analysis to build the new expression.
1676 /// The semantic analysis provides the behavior of template instantiation,
1677 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001678 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 /// argument-dependent lookup, etc. Subclasses may override this routine to
1680 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001681 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001683 Expr *Callee,
1684 Expr *First,
1685 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001686
1687 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 /// reinterpret_cast.
1689 ///
1690 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001691 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001693 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 Stmt::StmtClass Class,
1695 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001696 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001697 SourceLocation RAngleLoc,
1698 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001699 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001700 SourceLocation RParenLoc) {
1701 switch (Class) {
1702 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001703 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001704 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001705 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001706
1707 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001708 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001709 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001710 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001711
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001713 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001714 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001715 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001716 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001717
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001719 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001720 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001721 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001722
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 default:
1724 assert(false && "Invalid C++ named cast");
1725 break;
1726 }
Mike Stump11289f42009-09-09 15:08:12 +00001727
John McCallfaf5fb42010-08-26 23:41:50 +00001728 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 }
Mike Stump11289f42009-09-09 15:08:12 +00001730
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 /// \brief Build a new C++ static_cast expression.
1732 ///
1733 /// By default, performs semantic analysis to build the new expression.
1734 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001735 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001737 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 SourceLocation RAngleLoc,
1739 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001740 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001742 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001743 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001744 SourceRange(LAngleLoc, RAngleLoc),
1745 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 }
1747
1748 /// \brief Build a new C++ dynamic_cast expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001752 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001754 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 SourceLocation RAngleLoc,
1756 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001757 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001759 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001760 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001761 SourceRange(LAngleLoc, RAngleLoc),
1762 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 }
1764
1765 /// \brief Build a new C++ reinterpret_cast expression.
1766 ///
1767 /// By default, performs semantic analysis to build the new expression.
1768 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001769 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001771 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 SourceLocation RAngleLoc,
1773 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001774 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001776 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001777 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001778 SourceRange(LAngleLoc, RAngleLoc),
1779 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 }
1781
1782 /// \brief Build a new C++ const_cast expression.
1783 ///
1784 /// By default, performs semantic analysis to build the new expression.
1785 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001786 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001788 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 SourceLocation RAngleLoc,
1790 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001791 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001793 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001794 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001795 SourceRange(LAngleLoc, RAngleLoc),
1796 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 }
Mike Stump11289f42009-09-09 15:08:12 +00001798
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 /// \brief Build a new C++ functional-style cast expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001803 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1804 SourceLocation LParenLoc,
1805 Expr *Sub,
1806 SourceLocation RParenLoc) {
1807 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001808 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001809 RParenLoc);
1810 }
Mike Stump11289f42009-09-09 15:08:12 +00001811
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 /// \brief Build a new C++ typeid(type) expression.
1813 ///
1814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001816 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001817 SourceLocation TypeidLoc,
1818 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001820 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001821 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 }
Mike Stump11289f42009-09-09 15:08:12 +00001823
Francois Pichet9f4f2072010-09-08 12:20:18 +00001824
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 /// \brief Build a new C++ typeid(expr) expression.
1826 ///
1827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001829 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001830 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001831 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001832 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001833 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001834 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001835 }
1836
Francois Pichet9f4f2072010-09-08 12:20:18 +00001837 /// \brief Build a new C++ __uuidof(type) expression.
1838 ///
1839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
1841 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1842 SourceLocation TypeidLoc,
1843 TypeSourceInfo *Operand,
1844 SourceLocation RParenLoc) {
1845 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1846 RParenLoc);
1847 }
1848
1849 /// \brief Build a new C++ __uuidof(expr) expression.
1850 ///
1851 /// By default, performs semantic analysis to build the new expression.
1852 /// Subclasses may override this routine to provide different behavior.
1853 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1854 SourceLocation TypeidLoc,
1855 Expr *Operand,
1856 SourceLocation RParenLoc) {
1857 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1858 RParenLoc);
1859 }
1860
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 /// \brief Build a new C++ "this" expression.
1862 ///
1863 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001864 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001866 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001867 QualType ThisType,
1868 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001870 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1871 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001872 }
1873
1874 /// \brief Build a new C++ throw expression.
1875 ///
1876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001878 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1879 bool IsThrownVariableInScope) {
1880 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 }
1882
1883 /// \brief Build a new C++ default-argument expression.
1884 ///
1885 /// By default, builds a new default-argument expression, which does not
1886 /// require any semantic analysis. Subclasses may override this routine to
1887 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001888 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001889 ParmVarDecl *Param) {
1890 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1891 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 }
1893
1894 /// \brief Build a new C++ zero-initialization expression.
1895 ///
1896 /// By default, performs semantic analysis to build the new expression.
1897 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001898 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1899 SourceLocation LParenLoc,
1900 SourceLocation RParenLoc) {
1901 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001902 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001903 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 }
Mike Stump11289f42009-09-09 15:08:12 +00001905
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 /// \brief Build a new C++ "new" expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001910 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001911 bool UseGlobal,
1912 SourceLocation PlacementLParen,
1913 MultiExprArg PlacementArgs,
1914 SourceLocation PlacementRParen,
1915 SourceRange TypeIdParens,
1916 QualType AllocatedType,
1917 TypeSourceInfo *AllocatedTypeInfo,
1918 Expr *ArraySize,
1919 SourceLocation ConstructorLParen,
1920 MultiExprArg ConstructorArgs,
1921 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001922 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 PlacementLParen,
1924 move(PlacementArgs),
1925 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001926 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001927 AllocatedType,
1928 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001929 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 ConstructorLParen,
1931 move(ConstructorArgs),
1932 ConstructorRParen);
1933 }
Mike Stump11289f42009-09-09 15:08:12 +00001934
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 /// \brief Build a new C++ "delete" expression.
1936 ///
1937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001939 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 bool IsGlobalDelete,
1941 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001942 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001944 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 }
Mike Stump11289f42009-09-09 15:08:12 +00001946
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 /// \brief Build a new unary type trait expression.
1948 ///
1949 /// By default, performs semantic analysis to build the new expression.
1950 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001951 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001952 SourceLocation StartLoc,
1953 TypeSourceInfo *T,
1954 SourceLocation RParenLoc) {
1955 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 }
1957
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001958 /// \brief Build a new binary type trait expression.
1959 ///
1960 /// By default, performs semantic analysis to build the new expression.
1961 /// Subclasses may override this routine to provide different behavior.
1962 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1963 SourceLocation StartLoc,
1964 TypeSourceInfo *LhsT,
1965 TypeSourceInfo *RhsT,
1966 SourceLocation RParenLoc) {
1967 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1968 }
1969
John Wiegley6242b6a2011-04-28 00:16:57 +00001970 /// \brief Build a new array type trait expression.
1971 ///
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
1974 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1975 SourceLocation StartLoc,
1976 TypeSourceInfo *TSInfo,
1977 Expr *DimExpr,
1978 SourceLocation RParenLoc) {
1979 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1980 }
1981
John Wiegleyf9f65842011-04-25 06:54:41 +00001982 /// \brief Build a new expression trait expression.
1983 ///
1984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
1986 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1987 SourceLocation StartLoc,
1988 Expr *Queried,
1989 SourceLocation RParenLoc) {
1990 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1991 }
1992
Mike Stump11289f42009-09-09 15:08:12 +00001993 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 /// expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001998 ExprResult RebuildDependentScopeDeclRefExpr(
1999 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002000 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002001 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002003 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002004
2005 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002006 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002007 *TemplateArgs);
2008
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002009 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 }
2011
2012 /// \brief Build a new template-id expression.
2013 ///
2014 /// By default, performs semantic analysis to build the new expression.
2015 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002016 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00002017 LookupResult &R,
2018 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00002019 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00002020 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 }
2022
2023 /// \brief Build a new object-construction expression.
2024 ///
2025 /// By default, performs semantic analysis to build the new expression.
2026 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002027 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002028 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 CXXConstructorDecl *Constructor,
2030 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002031 MultiExprArg Args,
2032 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002033 CXXConstructExpr::ConstructionKind ConstructKind,
2034 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002035 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002036 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002037 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002038 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002039
Douglas Gregordb121ba2009-12-14 16:27:04 +00002040 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002041 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00002042 RequiresZeroInit, ConstructKind,
2043 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 }
2045
2046 /// \brief Build a new object-construction expression.
2047 ///
2048 /// By default, performs semantic analysis to build the new expression.
2049 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002050 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2051 SourceLocation LParenLoc,
2052 MultiExprArg Args,
2053 SourceLocation RParenLoc) {
2054 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002055 LParenLoc,
2056 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 RParenLoc);
2058 }
2059
2060 /// \brief Build a new object-construction expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002064 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2065 SourceLocation LParenLoc,
2066 MultiExprArg Args,
2067 SourceLocation RParenLoc) {
2068 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 LParenLoc,
2070 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 RParenLoc);
2072 }
Mike Stump11289f42009-09-09 15:08:12 +00002073
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 /// \brief Build a new member reference expression.
2075 ///
2076 /// By default, performs semantic analysis to build the new expression.
2077 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002078 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002079 QualType BaseType,
2080 bool IsArrow,
2081 SourceLocation OperatorLoc,
2082 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002083 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002084 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002085 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002087 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002088
John McCallb268a282010-08-23 23:25:46 +00002089 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002090 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002091 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002092 MemberNameInfo,
2093 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 }
2095
John McCall10eae182009-11-30 22:42:35 +00002096 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002097 ///
2098 /// By default, performs semantic analysis to build the new expression.
2099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002100 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002101 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002102 SourceLocation OperatorLoc,
2103 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002104 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002105 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002106 LookupResult &R,
2107 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002108 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002109 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002110
John McCallb268a282010-08-23 23:25:46 +00002111 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002112 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002113 SS, FirstQualifierInScope,
2114 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002115 }
Mike Stump11289f42009-09-09 15:08:12 +00002116
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002117 /// \brief Build a new noexcept expression.
2118 ///
2119 /// By default, performs semantic analysis to build the new expression.
2120 /// Subclasses may override this routine to provide different behavior.
2121 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2122 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2123 }
2124
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002125 /// \brief Build a new expression to compute the length of a parameter pack.
2126 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2127 SourceLocation PackLoc,
2128 SourceLocation RParenLoc,
2129 unsigned Length) {
2130 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2131 OperatorLoc, Pack, PackLoc,
2132 RParenLoc, Length);
2133 }
2134
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 /// \brief Build a new Objective-C @encode expression.
2136 ///
2137 /// By default, performs semantic analysis to build the new expression.
2138 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002139 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002140 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002141 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002142 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002144 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002145
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002146 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002147 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002148 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002149 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002150 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002151 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002152 MultiExprArg Args,
2153 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002154 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2155 ReceiverTypeInfo->getType(),
2156 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002157 Sel, Method, LBracLoc, SelectorLoc,
2158 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002159 }
2160
2161 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002162 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002163 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002164 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002165 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002166 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002167 MultiExprArg Args,
2168 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002169 return SemaRef.BuildInstanceMessage(Receiver,
2170 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002171 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002172 Sel, Method, LBracLoc, SelectorLoc,
2173 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002174 }
2175
Douglas Gregord51d90d2010-04-26 20:11:03 +00002176 /// \brief Build a new Objective-C ivar reference expression.
2177 ///
2178 /// By default, performs semantic analysis to build the new expression.
2179 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002180 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002181 SourceLocation IvarLoc,
2182 bool IsArrow, bool IsFreeIvar) {
2183 // FIXME: We lose track of the IsFreeIvar bit.
2184 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002185 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002186 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2187 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002188 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002189 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002190 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002191 false);
John Wiegley01296292011-04-08 18:41:53 +00002192 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002193 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002194
Douglas Gregord51d90d2010-04-26 20:11:03 +00002195 if (Result.get())
2196 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002197
John Wiegley01296292011-04-08 18:41:53 +00002198 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002199 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002200 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002201 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002202 /*TemplateArgs=*/0);
2203 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002204
2205 /// \brief Build a new Objective-C property reference expression.
2206 ///
2207 /// By default, performs semantic analysis to build the new expression.
2208 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002209 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002210 ObjCPropertyDecl *Property,
2211 SourceLocation PropertyLoc) {
2212 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002213 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002214 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2215 Sema::LookupMemberName);
2216 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002217 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002218 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002219 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002220 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002221 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002222
Douglas Gregor9faee212010-04-26 20:47:02 +00002223 if (Result.get())
2224 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002225
John Wiegley01296292011-04-08 18:41:53 +00002226 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002227 /*FIXME:*/PropertyLoc, IsArrow,
2228 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002229 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002230 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002231 /*TemplateArgs=*/0);
2232 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002233
John McCallb7bd14f2010-12-02 01:19:52 +00002234 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002235 ///
2236 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002237 /// Subclasses may override this routine to provide different behavior.
2238 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2239 ObjCMethodDecl *Getter,
2240 ObjCMethodDecl *Setter,
2241 SourceLocation PropertyLoc) {
2242 // Since these expressions can only be value-dependent, we do not
2243 // need to perform semantic analysis again.
2244 return Owned(
2245 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2246 VK_LValue, OK_ObjCProperty,
2247 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002248 }
2249
Douglas Gregord51d90d2010-04-26 20:11:03 +00002250 /// \brief Build a new Objective-C "isa" expression.
2251 ///
2252 /// By default, performs semantic analysis to build the new expression.
2253 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002254 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002255 bool IsArrow) {
2256 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002257 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002258 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2259 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002260 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002261 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002262 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002263 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002264 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002265
Douglas Gregord51d90d2010-04-26 20:11:03 +00002266 if (Result.get())
2267 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002268
John Wiegley01296292011-04-08 18:41:53 +00002269 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002270 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002271 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002272 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002273 /*TemplateArgs=*/0);
2274 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002275
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 /// \brief Build a new shuffle vector expression.
2277 ///
2278 /// By default, performs semantic analysis to build the new expression.
2279 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002280 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002281 MultiExprArg SubExprs,
2282 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002284 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2286 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2287 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2288 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002289
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 // Build a reference to the __builtin_shufflevector builtin
2291 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002292 ExprResult Callee
2293 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2294 VK_LValue, BuiltinLoc));
2295 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2296 if (Callee.isInvalid())
2297 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002298
2299 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002300 unsigned NumSubExprs = SubExprs.size();
2301 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002302 ExprResult TheCall = SemaRef.Owned(
2303 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002304 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002305 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002306 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002307 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002308
Douglas Gregora16548e2009-08-11 05:31:07 +00002309 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002310 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 }
John McCall31f82722010-11-12 08:19:04 +00002312
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002313 /// \brief Build a new template argument pack expansion.
2314 ///
2315 /// By default, performs semantic analysis to build a new pack expansion
2316 /// for a template argument. Subclasses may override this routine to provide
2317 /// different behavior.
2318 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002319 SourceLocation EllipsisLoc,
2320 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002321 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002322 case TemplateArgument::Expression: {
2323 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002324 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2325 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002326 if (Result.isInvalid())
2327 return TemplateArgumentLoc();
2328
2329 return TemplateArgumentLoc(Result.get(), Result.get());
2330 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002331
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002332 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002333 return TemplateArgumentLoc(TemplateArgument(
2334 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002335 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002336 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002337 Pattern.getTemplateNameLoc(),
2338 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002339
2340 case TemplateArgument::Null:
2341 case TemplateArgument::Integral:
2342 case TemplateArgument::Declaration:
2343 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002344 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002345 llvm_unreachable("Pack expansion pattern has no parameter packs");
2346
2347 case TemplateArgument::Type:
2348 if (TypeSourceInfo *Expansion
2349 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002350 EllipsisLoc,
2351 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002352 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2353 Expansion);
2354 break;
2355 }
2356
2357 return TemplateArgumentLoc();
2358 }
2359
Douglas Gregor968f23a2011-01-03 19:31:53 +00002360 /// \brief Build a new expression pack expansion.
2361 ///
2362 /// By default, performs semantic analysis to build a new pack expansion
2363 /// for an expression. Subclasses may override this routine to provide
2364 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002365 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2366 llvm::Optional<unsigned> NumExpansions) {
2367 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002368 }
2369
John McCall31f82722010-11-12 08:19:04 +00002370private:
Douglas Gregor14454802011-02-25 02:25:35 +00002371 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2372 QualType ObjectType,
2373 NamedDecl *FirstQualifierInScope,
2374 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002375
2376 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2377 QualType ObjectType,
2378 NamedDecl *FirstQualifierInScope,
2379 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002380};
Douglas Gregora16548e2009-08-11 05:31:07 +00002381
Douglas Gregorebe10102009-08-20 07:17:43 +00002382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002383StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002384 if (!S)
2385 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002386
Douglas Gregorebe10102009-08-20 07:17:43 +00002387 switch (S->getStmtClass()) {
2388 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002389
Douglas Gregorebe10102009-08-20 07:17:43 +00002390 // Transform individual statement nodes
2391#define STMT(Node, Parent) \
2392 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002393#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002394#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002395#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002396
Douglas Gregorebe10102009-08-20 07:17:43 +00002397 // Transform expressions by calling TransformExpr.
2398#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002399#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002400#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002401#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002402 {
John McCalldadc5752010-08-24 06:29:42 +00002403 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002404 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002405 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002406
John McCallb268a282010-08-23 23:25:46 +00002407 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002408 }
Mike Stump11289f42009-09-09 15:08:12 +00002409 }
2410
John McCallc3007a22010-10-26 07:05:15 +00002411 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002412}
Mike Stump11289f42009-09-09 15:08:12 +00002413
2414
Douglas Gregore922c772009-08-04 22:27:00 +00002415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002416ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 if (!E)
2418 return SemaRef.Owned(E);
2419
2420 switch (E->getStmtClass()) {
2421 case Stmt::NoStmtClass: break;
2422#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002423#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002424#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002425 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002426#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002427 }
2428
John McCallc3007a22010-10-26 07:05:15 +00002429 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002430}
2431
2432template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002433bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2434 unsigned NumInputs,
2435 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002436 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002437 bool *ArgChanged) {
2438 for (unsigned I = 0; I != NumInputs; ++I) {
2439 // If requested, drop call arguments that need to be dropped.
2440 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2441 if (ArgChanged)
2442 *ArgChanged = true;
2443
2444 break;
2445 }
2446
Douglas Gregor968f23a2011-01-03 19:31:53 +00002447 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2448 Expr *Pattern = Expansion->getPattern();
2449
Chris Lattner01cf8db2011-07-20 06:58:45 +00002450 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002451 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2452 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2453
2454 // Determine whether the set of unexpanded parameter packs can and should
2455 // be expanded.
2456 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002457 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002458 llvm::Optional<unsigned> OrigNumExpansions
2459 = Expansion->getNumExpansions();
2460 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002461 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2462 Pattern->getSourceRange(),
2463 Unexpanded.data(),
2464 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002465 Expand, RetainExpansion,
2466 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002467 return true;
2468
2469 if (!Expand) {
2470 // The transform has determined that we should perform a simple
2471 // transformation on the pack expansion, producing another pack
2472 // expansion.
2473 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2474 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2475 if (OutPattern.isInvalid())
2476 return true;
2477
2478 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002479 Expansion->getEllipsisLoc(),
2480 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002481 if (Out.isInvalid())
2482 return true;
2483
2484 if (ArgChanged)
2485 *ArgChanged = true;
2486 Outputs.push_back(Out.get());
2487 continue;
2488 }
John McCall542e7c62011-07-06 07:30:07 +00002489
2490 // Record right away that the argument was changed. This needs
2491 // to happen even if the array expands to nothing.
2492 if (ArgChanged) *ArgChanged = true;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002493
2494 // The transform has determined that we should perform an elementwise
2495 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002496 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002497 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2498 ExprResult Out = getDerived().TransformExpr(Pattern);
2499 if (Out.isInvalid())
2500 return true;
2501
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002502 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002503 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2504 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002505 if (Out.isInvalid())
2506 return true;
2507 }
2508
Douglas Gregor968f23a2011-01-03 19:31:53 +00002509 Outputs.push_back(Out.get());
2510 }
2511
2512 continue;
2513 }
2514
Douglas Gregora3efea12011-01-03 19:04:46 +00002515 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2516 if (Result.isInvalid())
2517 return true;
2518
2519 if (Result.get() != Inputs[I] && ArgChanged)
2520 *ArgChanged = true;
2521
2522 Outputs.push_back(Result.get());
2523 }
2524
2525 return false;
2526}
2527
2528template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002529NestedNameSpecifierLoc
2530TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2531 NestedNameSpecifierLoc NNS,
2532 QualType ObjectType,
2533 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002534 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregor14454802011-02-25 02:25:35 +00002535 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2536 Qualifier = Qualifier.getPrefix())
2537 Qualifiers.push_back(Qualifier);
2538
2539 CXXScopeSpec SS;
2540 while (!Qualifiers.empty()) {
2541 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2542 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2543
2544 switch (QNNS->getKind()) {
2545 case NestedNameSpecifier::Identifier:
2546 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2547 *QNNS->getAsIdentifier(),
2548 Q.getLocalBeginLoc(),
2549 Q.getLocalEndLoc(),
2550 ObjectType, false, SS,
2551 FirstQualifierInScope, false))
2552 return NestedNameSpecifierLoc();
2553
2554 break;
2555
2556 case NestedNameSpecifier::Namespace: {
2557 NamespaceDecl *NS
2558 = cast_or_null<NamespaceDecl>(
2559 getDerived().TransformDecl(
2560 Q.getLocalBeginLoc(),
2561 QNNS->getAsNamespace()));
2562 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2563 break;
2564 }
2565
2566 case NestedNameSpecifier::NamespaceAlias: {
2567 NamespaceAliasDecl *Alias
2568 = cast_or_null<NamespaceAliasDecl>(
2569 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2570 QNNS->getAsNamespaceAlias()));
2571 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2572 Q.getLocalEndLoc());
2573 break;
2574 }
2575
2576 case NestedNameSpecifier::Global:
2577 // There is no meaningful transformation that one could perform on the
2578 // global scope.
2579 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2580 break;
2581
2582 case NestedNameSpecifier::TypeSpecWithTemplate:
2583 case NestedNameSpecifier::TypeSpec: {
2584 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2585 FirstQualifierInScope, SS);
2586
2587 if (!TL)
2588 return NestedNameSpecifierLoc();
2589
2590 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2591 (SemaRef.getLangOptions().CPlusPlus0x &&
2592 TL.getType()->isEnumeralType())) {
2593 assert(!TL.getType().hasLocalQualifiers() &&
2594 "Can't get cv-qualifiers here");
2595 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2596 Q.getLocalEndLoc());
2597 break;
2598 }
Richard Trieude756fb2011-05-07 01:36:37 +00002599 // If the nested-name-specifier is an invalid type def, don't emit an
2600 // error because a previous error should have already been emitted.
2601 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2602 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2603 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2604 << TL.getType() << SS.getRange();
2605 }
Douglas Gregor14454802011-02-25 02:25:35 +00002606 return NestedNameSpecifierLoc();
2607 }
Douglas Gregore16af532011-02-28 18:50:33 +00002608 }
Douglas Gregor14454802011-02-25 02:25:35 +00002609
Douglas Gregore16af532011-02-28 18:50:33 +00002610 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002611 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002612 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002613 }
2614
2615 // Don't rebuild the nested-name-specifier if we don't have to.
2616 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2617 !getDerived().AlwaysRebuild())
2618 return NNS;
2619
2620 // If we can re-use the source-location data from the original
2621 // nested-name-specifier, do so.
2622 if (SS.location_size() == NNS.getDataLength() &&
2623 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2624 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2625
2626 // Allocate new nested-name-specifier location information.
2627 return SS.getWithLocInContext(SemaRef.Context);
2628}
2629
2630template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002631DeclarationNameInfo
2632TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002633::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002634 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002635 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002636 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002637
2638 switch (Name.getNameKind()) {
2639 case DeclarationName::Identifier:
2640 case DeclarationName::ObjCZeroArgSelector:
2641 case DeclarationName::ObjCOneArgSelector:
2642 case DeclarationName::ObjCMultiArgSelector:
2643 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002644 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002645 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002646 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002647
Douglas Gregorf816bd72009-09-03 22:13:48 +00002648 case DeclarationName::CXXConstructorName:
2649 case DeclarationName::CXXDestructorName:
2650 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002651 TypeSourceInfo *NewTInfo;
2652 CanQualType NewCanTy;
2653 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002654 NewTInfo = getDerived().TransformType(OldTInfo);
2655 if (!NewTInfo)
2656 return DeclarationNameInfo();
2657 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002658 }
2659 else {
2660 NewTInfo = 0;
2661 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002662 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002663 if (NewT.isNull())
2664 return DeclarationNameInfo();
2665 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2666 }
Mike Stump11289f42009-09-09 15:08:12 +00002667
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002668 DeclarationName NewName
2669 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2670 NewCanTy);
2671 DeclarationNameInfo NewNameInfo(NameInfo);
2672 NewNameInfo.setName(NewName);
2673 NewNameInfo.setNamedTypeInfo(NewTInfo);
2674 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002675 }
Mike Stump11289f42009-09-09 15:08:12 +00002676 }
2677
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002678 assert(0 && "Unknown name kind.");
2679 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002680}
2681
2682template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002683TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002684TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2685 TemplateName Name,
2686 SourceLocation NameLoc,
2687 QualType ObjectType,
2688 NamedDecl *FirstQualifierInScope) {
2689 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2690 TemplateDecl *Template = QTN->getTemplateDecl();
2691 assert(Template && "qualified template name must refer to a template");
2692
2693 TemplateDecl *TransTemplate
2694 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2695 Template));
2696 if (!TransTemplate)
2697 return TemplateName();
2698
2699 if (!getDerived().AlwaysRebuild() &&
2700 SS.getScopeRep() == QTN->getQualifier() &&
2701 TransTemplate == Template)
2702 return Name;
2703
2704 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2705 TransTemplate);
2706 }
2707
2708 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2709 if (SS.getScopeRep()) {
2710 // These apply to the scope specifier, not the template.
2711 ObjectType = QualType();
2712 FirstQualifierInScope = 0;
2713 }
2714
2715 if (!getDerived().AlwaysRebuild() &&
2716 SS.getScopeRep() == DTN->getQualifier() &&
2717 ObjectType.isNull())
2718 return Name;
2719
2720 if (DTN->isIdentifier()) {
2721 return getDerived().RebuildTemplateName(SS,
2722 *DTN->getIdentifier(),
2723 NameLoc,
2724 ObjectType,
2725 FirstQualifierInScope);
2726 }
2727
2728 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2729 ObjectType);
2730 }
2731
2732 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2733 TemplateDecl *TransTemplate
2734 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2735 Template));
2736 if (!TransTemplate)
2737 return TemplateName();
2738
2739 if (!getDerived().AlwaysRebuild() &&
2740 TransTemplate == Template)
2741 return Name;
2742
2743 return TemplateName(TransTemplate);
2744 }
2745
2746 if (SubstTemplateTemplateParmPackStorage *SubstPack
2747 = Name.getAsSubstTemplateTemplateParmPack()) {
2748 TemplateTemplateParmDecl *TransParam
2749 = cast_or_null<TemplateTemplateParmDecl>(
2750 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2751 if (!TransParam)
2752 return TemplateName();
2753
2754 if (!getDerived().AlwaysRebuild() &&
2755 TransParam == SubstPack->getParameterPack())
2756 return Name;
2757
2758 return getDerived().RebuildTemplateName(TransParam,
2759 SubstPack->getArgumentPack());
2760 }
2761
2762 // These should be getting filtered out before they reach the AST.
2763 llvm_unreachable("overloaded function decl survived to here");
2764 return TemplateName();
2765}
2766
2767template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002768void TreeTransform<Derived>::InventTemplateArgumentLoc(
2769 const TemplateArgument &Arg,
2770 TemplateArgumentLoc &Output) {
2771 SourceLocation Loc = getDerived().getBaseLocation();
2772 switch (Arg.getKind()) {
2773 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002774 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002775 break;
2776
2777 case TemplateArgument::Type:
2778 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002779 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002780
John McCall0ad16662009-10-29 08:12:44 +00002781 break;
2782
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002783 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002784 case TemplateArgument::TemplateExpansion: {
2785 NestedNameSpecifierLocBuilder Builder;
2786 TemplateName Template = Arg.getAsTemplate();
2787 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2788 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2789 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2790 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2791
2792 if (Arg.getKind() == TemplateArgument::Template)
2793 Output = TemplateArgumentLoc(Arg,
2794 Builder.getWithLocInContext(SemaRef.Context),
2795 Loc);
2796 else
2797 Output = TemplateArgumentLoc(Arg,
2798 Builder.getWithLocInContext(SemaRef.Context),
2799 Loc, Loc);
2800
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002801 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002802 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002803
John McCall0ad16662009-10-29 08:12:44 +00002804 case TemplateArgument::Expression:
2805 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2806 break;
2807
2808 case TemplateArgument::Declaration:
2809 case TemplateArgument::Integral:
2810 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002811 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002812 break;
2813 }
2814}
2815
2816template<typename Derived>
2817bool TreeTransform<Derived>::TransformTemplateArgument(
2818 const TemplateArgumentLoc &Input,
2819 TemplateArgumentLoc &Output) {
2820 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002821 switch (Arg.getKind()) {
2822 case TemplateArgument::Null:
2823 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002824 Output = Input;
2825 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002826
Douglas Gregore922c772009-08-04 22:27:00 +00002827 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002828 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002829 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002830 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002831
2832 DI = getDerived().TransformType(DI);
2833 if (!DI) return true;
2834
2835 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2836 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002837 }
Mike Stump11289f42009-09-09 15:08:12 +00002838
Douglas Gregore922c772009-08-04 22:27:00 +00002839 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002840 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002841 DeclarationName Name;
2842 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2843 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002844 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002845 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002846 if (!D) return true;
2847
John McCall0d07eb32009-10-29 18:45:58 +00002848 Expr *SourceExpr = Input.getSourceDeclExpression();
2849 if (SourceExpr) {
2850 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002851 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002852 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002853 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002854 }
2855
2856 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002857 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002858 }
Mike Stump11289f42009-09-09 15:08:12 +00002859
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002860 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002861 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2862 if (QualifierLoc) {
2863 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2864 if (!QualifierLoc)
2865 return true;
2866 }
2867
Douglas Gregordf846d12011-03-02 18:46:51 +00002868 CXXScopeSpec SS;
2869 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002870 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002871 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2872 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002873 if (Template.isNull())
2874 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002875
Douglas Gregor9d802122011-03-02 17:09:35 +00002876 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002877 Input.getTemplateNameLoc());
2878 return false;
2879 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002880
2881 case TemplateArgument::TemplateExpansion:
2882 llvm_unreachable("Caller should expand pack expansions");
2883
Douglas Gregore922c772009-08-04 22:27:00 +00002884 case TemplateArgument::Expression: {
2885 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002886 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002887 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002888
John McCall0ad16662009-10-29 08:12:44 +00002889 Expr *InputExpr = Input.getSourceExpression();
2890 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2891
Chris Lattnercdb591a2011-04-25 20:37:58 +00002892 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002893 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002894 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002895 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002896 }
Mike Stump11289f42009-09-09 15:08:12 +00002897
Douglas Gregore922c772009-08-04 22:27:00 +00002898 case TemplateArgument::Pack: {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002899 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregore922c772009-08-04 22:27:00 +00002900 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002901 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002902 AEnd = Arg.pack_end();
2903 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002904
John McCall0ad16662009-10-29 08:12:44 +00002905 // FIXME: preserve source information here when we start
2906 // caring about parameter packs.
2907
John McCall0d07eb32009-10-29 18:45:58 +00002908 TemplateArgumentLoc InputArg;
2909 TemplateArgumentLoc OutputArg;
2910 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2911 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002912 return true;
2913
John McCall0d07eb32009-10-29 18:45:58 +00002914 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002915 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002916
2917 TemplateArgument *TransformedArgsPtr
2918 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2919 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2920 TransformedArgsPtr);
2921 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2922 TransformedArgs.size()),
2923 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002924 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002925 }
2926 }
Mike Stump11289f42009-09-09 15:08:12 +00002927
Douglas Gregore922c772009-08-04 22:27:00 +00002928 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002929 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002930}
2931
Douglas Gregorfe921a72010-12-20 23:36:19 +00002932/// \brief Iterator adaptor that invents template argument location information
2933/// for each of the template arguments in its underlying iterator.
2934template<typename Derived, typename InputIterator>
2935class TemplateArgumentLocInventIterator {
2936 TreeTransform<Derived> &Self;
2937 InputIterator Iter;
2938
2939public:
2940 typedef TemplateArgumentLoc value_type;
2941 typedef TemplateArgumentLoc reference;
2942 typedef typename std::iterator_traits<InputIterator>::difference_type
2943 difference_type;
2944 typedef std::input_iterator_tag iterator_category;
2945
2946 class pointer {
2947 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002948
Douglas Gregorfe921a72010-12-20 23:36:19 +00002949 public:
2950 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2951
2952 const TemplateArgumentLoc *operator->() const { return &Arg; }
2953 };
2954
2955 TemplateArgumentLocInventIterator() { }
2956
2957 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2958 InputIterator Iter)
2959 : Self(Self), Iter(Iter) { }
2960
2961 TemplateArgumentLocInventIterator &operator++() {
2962 ++Iter;
2963 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002964 }
2965
Douglas Gregorfe921a72010-12-20 23:36:19 +00002966 TemplateArgumentLocInventIterator operator++(int) {
2967 TemplateArgumentLocInventIterator Old(*this);
2968 ++(*this);
2969 return Old;
2970 }
2971
2972 reference operator*() const {
2973 TemplateArgumentLoc Result;
2974 Self.InventTemplateArgumentLoc(*Iter, Result);
2975 return Result;
2976 }
2977
2978 pointer operator->() const { return pointer(**this); }
2979
2980 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2981 const TemplateArgumentLocInventIterator &Y) {
2982 return X.Iter == Y.Iter;
2983 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002984
Douglas Gregorfe921a72010-12-20 23:36:19 +00002985 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2986 const TemplateArgumentLocInventIterator &Y) {
2987 return X.Iter != Y.Iter;
2988 }
2989};
2990
Douglas Gregor42cafa82010-12-20 17:42:22 +00002991template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002992template<typename InputIterator>
2993bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2994 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002995 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002996 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002997 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002998 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002999
3000 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3001 // Unpack argument packs, which we translate them into separate
3002 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003003 // FIXME: We could do much better if we could guarantee that the
3004 // TemplateArgumentLocInfo for the pack expansion would be usable for
3005 // all of the template arguments in the argument pack.
3006 typedef TemplateArgumentLocInventIterator<Derived,
3007 TemplateArgument::pack_iterator>
3008 PackLocIterator;
3009 if (TransformTemplateArguments(PackLocIterator(*this,
3010 In.getArgument().pack_begin()),
3011 PackLocIterator(*this,
3012 In.getArgument().pack_end()),
3013 Outputs))
3014 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003015
3016 continue;
3017 }
3018
3019 if (In.getArgument().isPackExpansion()) {
3020 // We have a pack expansion, for which we will be substituting into
3021 // the pattern.
3022 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003023 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003024 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003025 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3026 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003027
Chris Lattner01cf8db2011-07-20 06:58:45 +00003028 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003029 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3030 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3031
3032 // Determine whether the set of unexpanded parameter packs can and should
3033 // be expanded.
3034 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003035 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003036 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003037 if (getDerived().TryExpandParameterPacks(Ellipsis,
3038 Pattern.getSourceRange(),
3039 Unexpanded.data(),
3040 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003041 Expand,
3042 RetainExpansion,
3043 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003044 return true;
3045
3046 if (!Expand) {
3047 // The transform has determined that we should perform a simple
3048 // transformation on the pack expansion, producing another pack
3049 // expansion.
3050 TemplateArgumentLoc OutPattern;
3051 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3052 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3053 return true;
3054
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003055 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3056 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003057 if (Out.getArgument().isNull())
3058 return true;
3059
3060 Outputs.addArgument(Out);
3061 continue;
3062 }
3063
3064 // The transform has determined that we should perform an elementwise
3065 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003066 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003067 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3068
3069 if (getDerived().TransformTemplateArgument(Pattern, Out))
3070 return true;
3071
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003072 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003073 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3074 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003075 if (Out.getArgument().isNull())
3076 return true;
3077 }
3078
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003079 Outputs.addArgument(Out);
3080 }
3081
Douglas Gregor48d24112011-01-10 20:53:55 +00003082 // If we're supposed to retain a pack expansion, do so by temporarily
3083 // forgetting the partially-substituted parameter pack.
3084 if (RetainExpansion) {
3085 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3086
3087 if (getDerived().TransformTemplateArgument(Pattern, Out))
3088 return true;
3089
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003090 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3091 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003092 if (Out.getArgument().isNull())
3093 return true;
3094
3095 Outputs.addArgument(Out);
3096 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003097
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003098 continue;
3099 }
3100
3101 // The simple case:
3102 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003103 return true;
3104
3105 Outputs.addArgument(Out);
3106 }
3107
3108 return false;
3109
3110}
3111
Douglas Gregord6ff3322009-08-04 16:50:30 +00003112//===----------------------------------------------------------------------===//
3113// Type transformation
3114//===----------------------------------------------------------------------===//
3115
3116template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003117QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003118 if (getDerived().AlreadyTransformed(T))
3119 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003120
John McCall550e0c22009-10-21 00:40:46 +00003121 // Temporary workaround. All of these transformations should
3122 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003123 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3124 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003125
John McCall31f82722010-11-12 08:19:04 +00003126 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003127
John McCall550e0c22009-10-21 00:40:46 +00003128 if (!NewDI)
3129 return QualType();
3130
3131 return NewDI->getType();
3132}
3133
3134template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003135TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003136 if (getDerived().AlreadyTransformed(DI->getType()))
3137 return DI;
3138
3139 TypeLocBuilder TLB;
3140
3141 TypeLoc TL = DI->getTypeLoc();
3142 TLB.reserve(TL.getFullDataSize());
3143
John McCall31f82722010-11-12 08:19:04 +00003144 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003145 if (Result.isNull())
3146 return 0;
3147
John McCallbcd03502009-12-07 02:54:59 +00003148 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003149}
3150
3151template<typename Derived>
3152QualType
John McCall31f82722010-11-12 08:19:04 +00003153TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003154 switch (T.getTypeLocClass()) {
3155#define ABSTRACT_TYPELOC(CLASS, PARENT)
3156#define TYPELOC(CLASS, PARENT) \
3157 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003158 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003159#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003160 }
Mike Stump11289f42009-09-09 15:08:12 +00003161
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003162 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003163 return QualType();
3164}
3165
3166/// FIXME: By default, this routine adds type qualifiers only to types
3167/// that can have qualifiers, and silently suppresses those qualifiers
3168/// that are not permitted (e.g., qualifiers on reference or function
3169/// types). This is the right thing for template instantiation, but
3170/// probably not for other clients.
3171template<typename Derived>
3172QualType
3173TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003174 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003175 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003176
John McCall31f82722010-11-12 08:19:04 +00003177 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003178 if (Result.isNull())
3179 return QualType();
3180
3181 // Silently suppress qualifiers if the result type can't be qualified.
3182 // FIXME: this is the right thing for template instantiation, but
3183 // probably not for other clients.
3184 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003185 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003186
John McCall31168b02011-06-15 23:02:42 +00003187 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003188 // resulting type.
3189 if (Quals.hasObjCLifetime()) {
3190 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3191 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003192 else if (Result.getObjCLifetime()) {
Douglas Gregore46db902011-06-17 22:11:49 +00003193 // Objective-C ARC:
3194 // A lifetime qualifier applied to a substituted template parameter
3195 // overrides the lifetime qualifier from the template argument.
3196 if (const SubstTemplateTypeParmType *SubstTypeParam
3197 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3198 QualType Replacement = SubstTypeParam->getReplacementType();
3199 Qualifiers Qs = Replacement.getQualifiers();
3200 Qs.removeObjCLifetime();
3201 Replacement
3202 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3203 Qs);
3204 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3205 SubstTypeParam->getReplacedParameter(),
3206 Replacement);
3207 TLB.TypeWasModifiedSafely(Result);
3208 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003209 // Otherwise, complain about the addition of a qualifier to an
3210 // already-qualified type.
3211 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003212 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003213 << Result << R;
3214
Douglas Gregore46db902011-06-17 22:11:49 +00003215 Quals.removeObjCLifetime();
3216 }
3217 }
3218 }
John McCallcb0f89a2010-06-05 06:41:15 +00003219 if (!Quals.empty()) {
3220 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3221 TLB.push<QualifiedTypeLoc>(Result);
3222 // No location information to preserve.
3223 }
John McCall550e0c22009-10-21 00:40:46 +00003224
3225 return Result;
3226}
3227
Douglas Gregor14454802011-02-25 02:25:35 +00003228template<typename Derived>
3229TypeLoc
3230TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3231 QualType ObjectType,
3232 NamedDecl *UnqualLookup,
3233 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003234 QualType T = TL.getType();
3235 if (getDerived().AlreadyTransformed(T))
3236 return TL;
3237
3238 TypeLocBuilder TLB;
3239 QualType Result;
3240
3241 if (isa<TemplateSpecializationType>(T)) {
3242 TemplateSpecializationTypeLoc SpecTL
3243 = cast<TemplateSpecializationTypeLoc>(TL);
3244
3245 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003246 getDerived().TransformTemplateName(SS,
3247 SpecTL.getTypePtr()->getTemplateName(),
3248 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003249 ObjectType, UnqualLookup);
3250 if (Template.isNull())
3251 return TypeLoc();
3252
3253 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3254 Template);
3255 } else if (isa<DependentTemplateSpecializationType>(T)) {
3256 DependentTemplateSpecializationTypeLoc SpecTL
3257 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3258
Douglas Gregor5a064722011-02-28 17:23:35 +00003259 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003260 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003261 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003262 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003263 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003264 if (Template.isNull())
3265 return TypeLoc();
3266
Douglas Gregor14454802011-02-25 02:25:35 +00003267 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003268 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003269 Template,
3270 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003271 } else {
3272 // Nothing special needs to be done for these.
3273 Result = getDerived().TransformType(TLB, TL);
3274 }
3275
3276 if (Result.isNull())
3277 return TypeLoc();
3278
3279 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3280}
3281
Douglas Gregor579c15f2011-03-02 18:32:08 +00003282template<typename Derived>
3283TypeSourceInfo *
3284TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3285 QualType ObjectType,
3286 NamedDecl *UnqualLookup,
3287 CXXScopeSpec &SS) {
3288 // FIXME: Painfully copy-paste from the above!
3289
3290 QualType T = TSInfo->getType();
3291 if (getDerived().AlreadyTransformed(T))
3292 return TSInfo;
3293
3294 TypeLocBuilder TLB;
3295 QualType Result;
3296
3297 TypeLoc TL = TSInfo->getTypeLoc();
3298 if (isa<TemplateSpecializationType>(T)) {
3299 TemplateSpecializationTypeLoc SpecTL
3300 = cast<TemplateSpecializationTypeLoc>(TL);
3301
3302 TemplateName Template
3303 = getDerived().TransformTemplateName(SS,
3304 SpecTL.getTypePtr()->getTemplateName(),
3305 SpecTL.getTemplateNameLoc(),
3306 ObjectType, UnqualLookup);
3307 if (Template.isNull())
3308 return 0;
3309
3310 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3311 Template);
3312 } else if (isa<DependentTemplateSpecializationType>(T)) {
3313 DependentTemplateSpecializationTypeLoc SpecTL
3314 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3315
3316 TemplateName Template
3317 = getDerived().RebuildTemplateName(SS,
3318 *SpecTL.getTypePtr()->getIdentifier(),
3319 SpecTL.getNameLoc(),
3320 ObjectType, UnqualLookup);
3321 if (Template.isNull())
3322 return 0;
3323
3324 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3325 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003326 Template,
3327 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003328 } else {
3329 // Nothing special needs to be done for these.
3330 Result = getDerived().TransformType(TLB, TL);
3331 }
3332
3333 if (Result.isNull())
3334 return 0;
3335
3336 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3337}
3338
John McCall550e0c22009-10-21 00:40:46 +00003339template <class TyLoc> static inline
3340QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3341 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3342 NewT.setNameLoc(T.getNameLoc());
3343 return T.getType();
3344}
3345
John McCall550e0c22009-10-21 00:40:46 +00003346template<typename Derived>
3347QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003348 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003349 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3350 NewT.setBuiltinLoc(T.getBuiltinLoc());
3351 if (T.needsExtraLocalData())
3352 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3353 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003354}
Mike Stump11289f42009-09-09 15:08:12 +00003355
Douglas Gregord6ff3322009-08-04 16:50:30 +00003356template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003357QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003358 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003359 // FIXME: recurse?
3360 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003361}
Mike Stump11289f42009-09-09 15:08:12 +00003362
Douglas Gregord6ff3322009-08-04 16:50:30 +00003363template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003364QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003365 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003366 QualType PointeeType
3367 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003368 if (PointeeType.isNull())
3369 return QualType();
3370
3371 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003372 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003373 // A dependent pointer type 'T *' has is being transformed such
3374 // that an Objective-C class type is being replaced for 'T'. The
3375 // resulting pointer type is an ObjCObjectPointerType, not a
3376 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003377 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003378
John McCall8b07ec22010-05-15 11:32:37 +00003379 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3380 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003381 return Result;
3382 }
John McCall31f82722010-11-12 08:19:04 +00003383
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003384 if (getDerived().AlwaysRebuild() ||
3385 PointeeType != TL.getPointeeLoc().getType()) {
3386 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3387 if (Result.isNull())
3388 return QualType();
3389 }
John McCall31168b02011-06-15 23:02:42 +00003390
3391 // Objective-C ARC can add lifetime qualifiers to the type that we're
3392 // pointing to.
3393 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3394
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003395 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3396 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003397 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003398}
Mike Stump11289f42009-09-09 15:08:12 +00003399
3400template<typename Derived>
3401QualType
John McCall550e0c22009-10-21 00:40:46 +00003402TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003403 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003404 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003405 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3406 if (PointeeType.isNull())
3407 return QualType();
3408
3409 QualType Result = TL.getType();
3410 if (getDerived().AlwaysRebuild() ||
3411 PointeeType != TL.getPointeeLoc().getType()) {
3412 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003413 TL.getSigilLoc());
3414 if (Result.isNull())
3415 return QualType();
3416 }
3417
Douglas Gregor049211a2010-04-22 16:50:51 +00003418 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003419 NewT.setSigilLoc(TL.getSigilLoc());
3420 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003421}
3422
John McCall70dd5f62009-10-30 00:06:24 +00003423/// Transforms a reference type. Note that somewhat paradoxically we
3424/// don't care whether the type itself is an l-value type or an r-value
3425/// type; we only care if the type was *written* as an l-value type
3426/// or an r-value type.
3427template<typename Derived>
3428QualType
3429TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003430 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003431 const ReferenceType *T = TL.getTypePtr();
3432
3433 // Note that this works with the pointee-as-written.
3434 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3435 if (PointeeType.isNull())
3436 return QualType();
3437
3438 QualType Result = TL.getType();
3439 if (getDerived().AlwaysRebuild() ||
3440 PointeeType != T->getPointeeTypeAsWritten()) {
3441 Result = getDerived().RebuildReferenceType(PointeeType,
3442 T->isSpelledAsLValue(),
3443 TL.getSigilLoc());
3444 if (Result.isNull())
3445 return QualType();
3446 }
3447
John McCall31168b02011-06-15 23:02:42 +00003448 // Objective-C ARC can add lifetime qualifiers to the type that we're
3449 // referring to.
3450 TLB.TypeWasModifiedSafely(
3451 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3452
John McCall70dd5f62009-10-30 00:06:24 +00003453 // r-value references can be rebuilt as l-value references.
3454 ReferenceTypeLoc NewTL;
3455 if (isa<LValueReferenceType>(Result))
3456 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3457 else
3458 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3459 NewTL.setSigilLoc(TL.getSigilLoc());
3460
3461 return Result;
3462}
3463
Mike Stump11289f42009-09-09 15:08:12 +00003464template<typename Derived>
3465QualType
John McCall550e0c22009-10-21 00:40:46 +00003466TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003467 LValueReferenceTypeLoc TL) {
3468 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003469}
3470
Mike Stump11289f42009-09-09 15:08:12 +00003471template<typename Derived>
3472QualType
John McCall550e0c22009-10-21 00:40:46 +00003473TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003474 RValueReferenceTypeLoc TL) {
3475 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003476}
Mike Stump11289f42009-09-09 15:08:12 +00003477
Douglas Gregord6ff3322009-08-04 16:50:30 +00003478template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003479QualType
John McCall550e0c22009-10-21 00:40:46 +00003480TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003481 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003482 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003483 if (PointeeType.isNull())
3484 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003485
Abramo Bagnara509357842011-03-05 14:42:21 +00003486 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3487 TypeSourceInfo* NewClsTInfo = 0;
3488 if (OldClsTInfo) {
3489 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3490 if (!NewClsTInfo)
3491 return QualType();
3492 }
3493
3494 const MemberPointerType *T = TL.getTypePtr();
3495 QualType OldClsType = QualType(T->getClass(), 0);
3496 QualType NewClsType;
3497 if (NewClsTInfo)
3498 NewClsType = NewClsTInfo->getType();
3499 else {
3500 NewClsType = getDerived().TransformType(OldClsType);
3501 if (NewClsType.isNull())
3502 return QualType();
3503 }
Mike Stump11289f42009-09-09 15:08:12 +00003504
John McCall550e0c22009-10-21 00:40:46 +00003505 QualType Result = TL.getType();
3506 if (getDerived().AlwaysRebuild() ||
3507 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003508 NewClsType != OldClsType) {
3509 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003510 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003511 if (Result.isNull())
3512 return QualType();
3513 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003514
John McCall550e0c22009-10-21 00:40:46 +00003515 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3516 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003517 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003518
3519 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003520}
3521
Mike Stump11289f42009-09-09 15:08:12 +00003522template<typename Derived>
3523QualType
John McCall550e0c22009-10-21 00:40:46 +00003524TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003525 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003526 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003527 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003528 if (ElementType.isNull())
3529 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003530
John McCall550e0c22009-10-21 00:40:46 +00003531 QualType Result = TL.getType();
3532 if (getDerived().AlwaysRebuild() ||
3533 ElementType != T->getElementType()) {
3534 Result = getDerived().RebuildConstantArrayType(ElementType,
3535 T->getSizeModifier(),
3536 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003537 T->getIndexTypeCVRQualifiers(),
3538 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003539 if (Result.isNull())
3540 return QualType();
3541 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003542
John McCall550e0c22009-10-21 00:40:46 +00003543 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3544 NewTL.setLBracketLoc(TL.getLBracketLoc());
3545 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003546
John McCall550e0c22009-10-21 00:40:46 +00003547 Expr *Size = TL.getSizeExpr();
3548 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003549 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003550 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3551 }
3552 NewTL.setSizeExpr(Size);
3553
3554 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003555}
Mike Stump11289f42009-09-09 15:08:12 +00003556
Douglas Gregord6ff3322009-08-04 16:50:30 +00003557template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003558QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003559 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003560 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003561 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003562 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003563 if (ElementType.isNull())
3564 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003565
John McCall550e0c22009-10-21 00:40:46 +00003566 QualType Result = TL.getType();
3567 if (getDerived().AlwaysRebuild() ||
3568 ElementType != T->getElementType()) {
3569 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003570 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003571 T->getIndexTypeCVRQualifiers(),
3572 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003573 if (Result.isNull())
3574 return QualType();
3575 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003576
John McCall550e0c22009-10-21 00:40:46 +00003577 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3578 NewTL.setLBracketLoc(TL.getLBracketLoc());
3579 NewTL.setRBracketLoc(TL.getRBracketLoc());
3580 NewTL.setSizeExpr(0);
3581
3582 return Result;
3583}
3584
3585template<typename Derived>
3586QualType
3587TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003588 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003589 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003590 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3591 if (ElementType.isNull())
3592 return QualType();
3593
3594 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003595 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003596
John McCalldadc5752010-08-24 06:29:42 +00003597 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003598 = getDerived().TransformExpr(T->getSizeExpr());
3599 if (SizeResult.isInvalid())
3600 return QualType();
3601
John McCallb268a282010-08-23 23:25:46 +00003602 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003603
3604 QualType Result = TL.getType();
3605 if (getDerived().AlwaysRebuild() ||
3606 ElementType != T->getElementType() ||
3607 Size != T->getSizeExpr()) {
3608 Result = getDerived().RebuildVariableArrayType(ElementType,
3609 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003610 Size,
John McCall550e0c22009-10-21 00:40:46 +00003611 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003612 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003613 if (Result.isNull())
3614 return QualType();
3615 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003616
John McCall550e0c22009-10-21 00:40:46 +00003617 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3618 NewTL.setLBracketLoc(TL.getLBracketLoc());
3619 NewTL.setRBracketLoc(TL.getRBracketLoc());
3620 NewTL.setSizeExpr(Size);
3621
3622 return Result;
3623}
3624
3625template<typename Derived>
3626QualType
3627TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003628 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003629 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003630 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3631 if (ElementType.isNull())
3632 return QualType();
3633
3634 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003635 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003636
John McCall33ddac02011-01-19 10:06:00 +00003637 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3638 Expr *origSize = TL.getSizeExpr();
3639 if (!origSize) origSize = T->getSizeExpr();
3640
3641 ExprResult sizeResult
3642 = getDerived().TransformExpr(origSize);
3643 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003644 return QualType();
3645
John McCall33ddac02011-01-19 10:06:00 +00003646 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003647
3648 QualType Result = TL.getType();
3649 if (getDerived().AlwaysRebuild() ||
3650 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003651 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003652 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3653 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003654 size,
John McCall550e0c22009-10-21 00:40:46 +00003655 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003656 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003657 if (Result.isNull())
3658 return QualType();
3659 }
John McCall550e0c22009-10-21 00:40:46 +00003660
3661 // We might have any sort of array type now, but fortunately they
3662 // all have the same location layout.
3663 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3664 NewTL.setLBracketLoc(TL.getLBracketLoc());
3665 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003666 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003667
3668 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003669}
Mike Stump11289f42009-09-09 15:08:12 +00003670
3671template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003672QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003673 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003674 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003675 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003676
3677 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003678 QualType ElementType = getDerived().TransformType(T->getElementType());
3679 if (ElementType.isNull())
3680 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003681
Douglas Gregore922c772009-08-04 22:27:00 +00003682 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003683 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003684
John McCalldadc5752010-08-24 06:29:42 +00003685 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003686 if (Size.isInvalid())
3687 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003688
John McCall550e0c22009-10-21 00:40:46 +00003689 QualType Result = TL.getType();
3690 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003691 ElementType != T->getElementType() ||
3692 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003693 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003694 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003695 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003696 if (Result.isNull())
3697 return QualType();
3698 }
John McCall550e0c22009-10-21 00:40:46 +00003699
3700 // Result might be dependent or not.
3701 if (isa<DependentSizedExtVectorType>(Result)) {
3702 DependentSizedExtVectorTypeLoc NewTL
3703 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3704 NewTL.setNameLoc(TL.getNameLoc());
3705 } else {
3706 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3707 NewTL.setNameLoc(TL.getNameLoc());
3708 }
3709
3710 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003711}
Mike Stump11289f42009-09-09 15:08:12 +00003712
3713template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003714QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003715 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003716 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003717 QualType ElementType = getDerived().TransformType(T->getElementType());
3718 if (ElementType.isNull())
3719 return QualType();
3720
John McCall550e0c22009-10-21 00:40:46 +00003721 QualType Result = TL.getType();
3722 if (getDerived().AlwaysRebuild() ||
3723 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003724 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003725 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003726 if (Result.isNull())
3727 return QualType();
3728 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003729
John McCall550e0c22009-10-21 00:40:46 +00003730 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3731 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003732
John McCall550e0c22009-10-21 00:40:46 +00003733 return Result;
3734}
3735
3736template<typename Derived>
3737QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003738 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003739 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003740 QualType ElementType = getDerived().TransformType(T->getElementType());
3741 if (ElementType.isNull())
3742 return QualType();
3743
3744 QualType Result = TL.getType();
3745 if (getDerived().AlwaysRebuild() ||
3746 ElementType != T->getElementType()) {
3747 Result = getDerived().RebuildExtVectorType(ElementType,
3748 T->getNumElements(),
3749 /*FIXME*/ SourceLocation());
3750 if (Result.isNull())
3751 return QualType();
3752 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003753
John McCall550e0c22009-10-21 00:40:46 +00003754 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3755 NewTL.setNameLoc(TL.getNameLoc());
3756
3757 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003758}
Mike Stump11289f42009-09-09 15:08:12 +00003759
3760template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003761ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003762TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003763 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003764 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003765 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003766 TypeSourceInfo *NewDI = 0;
3767
3768 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3769 // If we're substituting into a pack expansion type and we know the
3770 TypeLoc OldTL = OldDI->getTypeLoc();
3771 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3772
3773 TypeLocBuilder TLB;
3774 TypeLoc NewTL = OldDI->getTypeLoc();
3775 TLB.reserve(NewTL.getFullDataSize());
3776
3777 QualType Result = getDerived().TransformType(TLB,
3778 OldExpansionTL.getPatternLoc());
3779 if (Result.isNull())
3780 return 0;
3781
3782 Result = RebuildPackExpansionType(Result,
3783 OldExpansionTL.getPatternLoc().getSourceRange(),
3784 OldExpansionTL.getEllipsisLoc(),
3785 NumExpansions);
3786 if (Result.isNull())
3787 return 0;
3788
3789 PackExpansionTypeLoc NewExpansionTL
3790 = TLB.push<PackExpansionTypeLoc>(Result);
3791 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3792 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3793 } else
3794 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003795 if (!NewDI)
3796 return 0;
3797
John McCall8fb0d9d2011-05-01 22:35:37 +00003798 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003799 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003800
3801 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3802 OldParm->getDeclContext(),
3803 OldParm->getInnerLocStart(),
3804 OldParm->getLocation(),
3805 OldParm->getIdentifier(),
3806 NewDI->getType(),
3807 NewDI,
3808 OldParm->getStorageClass(),
3809 OldParm->getStorageClassAsWritten(),
3810 /* DefArg */ NULL);
3811 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3812 OldParm->getFunctionScopeIndex() + indexAdjustment);
3813 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003814}
3815
3816template<typename Derived>
3817bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003818 TransformFunctionTypeParams(SourceLocation Loc,
3819 ParmVarDecl **Params, unsigned NumParams,
3820 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003821 SmallVectorImpl<QualType> &OutParamTypes,
3822 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003823 int indexAdjustment = 0;
3824
Douglas Gregordd472162011-01-07 00:20:55 +00003825 for (unsigned i = 0; i != NumParams; ++i) {
3826 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003827 assert(OldParm->getFunctionScopeIndex() == i);
3828
Douglas Gregor715e4612011-01-14 22:40:04 +00003829 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003830 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003831 if (OldParm->isParameterPack()) {
3832 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00003833 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003834
Douglas Gregor5499af42011-01-05 23:12:31 +00003835 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003836 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3837 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3838 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3839 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003840 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3841
Douglas Gregor5499af42011-01-05 23:12:31 +00003842 // Determine whether we should expand the parameter packs.
3843 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003844 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003845 llvm::Optional<unsigned> OrigNumExpansions
3846 = ExpansionTL.getTypePtr()->getNumExpansions();
3847 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003848 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3849 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003850 Unexpanded.data(),
3851 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003852 ShouldExpand,
3853 RetainExpansion,
3854 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003855 return true;
3856 }
3857
3858 if (ShouldExpand) {
3859 // Expand the function parameter pack into multiple, separate
3860 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003861 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003862 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003863 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3864 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003865 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003866 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003867 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003868 if (!NewParm)
3869 return true;
3870
Douglas Gregordd472162011-01-07 00:20:55 +00003871 OutParamTypes.push_back(NewParm->getType());
3872 if (PVars)
3873 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003874 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003875
3876 // If we're supposed to retain a pack expansion, do so by temporarily
3877 // forgetting the partially-substituted parameter pack.
3878 if (RetainExpansion) {
3879 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3880 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003881 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003882 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003883 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003884 if (!NewParm)
3885 return true;
3886
3887 OutParamTypes.push_back(NewParm->getType());
3888 if (PVars)
3889 PVars->push_back(NewParm);
3890 }
3891
John McCall8fb0d9d2011-05-01 22:35:37 +00003892 // The next parameter should have the same adjustment as the
3893 // last thing we pushed, but we post-incremented indexAdjustment
3894 // on every push. Also, if we push nothing, the adjustment should
3895 // go down by one.
3896 indexAdjustment--;
3897
Douglas Gregor5499af42011-01-05 23:12:31 +00003898 // We're done with the pack expansion.
3899 continue;
3900 }
3901
3902 // We'll substitute the parameter now without expanding the pack
3903 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003904 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3905 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003906 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003907 NumExpansions);
3908 } else {
3909 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003910 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003911 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003912 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003913
John McCall58f10c32010-03-11 09:03:00 +00003914 if (!NewParm)
3915 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003916
Douglas Gregordd472162011-01-07 00:20:55 +00003917 OutParamTypes.push_back(NewParm->getType());
3918 if (PVars)
3919 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003920 continue;
3921 }
John McCall58f10c32010-03-11 09:03:00 +00003922
3923 // Deal with the possibility that we don't have a parameter
3924 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003925 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003926 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003927 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003928 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003929 if (const PackExpansionType *Expansion
3930 = dyn_cast<PackExpansionType>(OldType)) {
3931 // We have a function parameter pack that may need to be expanded.
3932 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00003933 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00003934 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3935
3936 // Determine whether we should expand the parameter packs.
3937 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003938 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003939 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003940 Unexpanded.data(),
3941 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003942 ShouldExpand,
3943 RetainExpansion,
3944 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003945 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003946 }
3947
3948 if (ShouldExpand) {
3949 // Expand the function parameter pack into multiple, separate
3950 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003951 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003952 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3953 QualType NewType = getDerived().TransformType(Pattern);
3954 if (NewType.isNull())
3955 return true;
John McCall58f10c32010-03-11 09:03:00 +00003956
Douglas Gregordd472162011-01-07 00:20:55 +00003957 OutParamTypes.push_back(NewType);
3958 if (PVars)
3959 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003960 }
3961
3962 // We're done with the pack expansion.
3963 continue;
3964 }
3965
Douglas Gregor48d24112011-01-10 20:53:55 +00003966 // If we're supposed to retain a pack expansion, do so by temporarily
3967 // forgetting the partially-substituted parameter pack.
3968 if (RetainExpansion) {
3969 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3970 QualType NewType = getDerived().TransformType(Pattern);
3971 if (NewType.isNull())
3972 return true;
3973
3974 OutParamTypes.push_back(NewType);
3975 if (PVars)
3976 PVars->push_back(0);
3977 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003978
Douglas Gregor5499af42011-01-05 23:12:31 +00003979 // We'll substitute the parameter now without expanding the pack
3980 // expansion.
3981 OldType = Expansion->getPattern();
3982 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003983 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3984 NewType = getDerived().TransformType(OldType);
3985 } else {
3986 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003987 }
3988
Douglas Gregor5499af42011-01-05 23:12:31 +00003989 if (NewType.isNull())
3990 return true;
3991
3992 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003993 NewType = getSema().Context.getPackExpansionType(NewType,
3994 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003995
Douglas Gregordd472162011-01-07 00:20:55 +00003996 OutParamTypes.push_back(NewType);
3997 if (PVars)
3998 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003999 }
4000
John McCall8fb0d9d2011-05-01 22:35:37 +00004001#ifndef NDEBUG
4002 if (PVars) {
4003 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4004 if (ParmVarDecl *parm = (*PVars)[i])
4005 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004006 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004007#endif
4008
4009 return false;
4010}
John McCall58f10c32010-03-11 09:03:00 +00004011
4012template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004013QualType
John McCall550e0c22009-10-21 00:40:46 +00004014TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004015 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004016 // Transform the parameters and return type.
4017 //
4018 // We instantiate in source order, with the return type first followed by
4019 // the parameters, because users tend to expect this (even if they shouldn't
4020 // rely on it!).
4021 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00004022 // When the function has a trailing return type, we instantiate the
4023 // parameters before the return type, since the return type can then refer
4024 // to the parameters themselves (via decltype, sizeof, etc.).
4025 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004026 SmallVector<QualType, 4> ParamTypes;
4027 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004028 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004029
Douglas Gregor7fb25412010-10-01 18:44:50 +00004030 QualType ResultType;
4031
4032 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004033 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4034 TL.getParmArray(),
4035 TL.getNumArgs(),
4036 TL.getTypePtr()->arg_type_begin(),
4037 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004038 return QualType();
4039
4040 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4041 if (ResultType.isNull())
4042 return QualType();
4043 }
4044 else {
4045 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4046 if (ResultType.isNull())
4047 return QualType();
4048
Douglas Gregordd472162011-01-07 00:20:55 +00004049 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4050 TL.getParmArray(),
4051 TL.getNumArgs(),
4052 TL.getTypePtr()->arg_type_begin(),
4053 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004054 return QualType();
4055 }
4056
John McCall550e0c22009-10-21 00:40:46 +00004057 QualType Result = TL.getType();
4058 if (getDerived().AlwaysRebuild() ||
4059 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004060 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004061 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4062 Result = getDerived().RebuildFunctionProtoType(ResultType,
4063 ParamTypes.data(),
4064 ParamTypes.size(),
4065 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004066 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004067 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004068 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004069 if (Result.isNull())
4070 return QualType();
4071 }
Mike Stump11289f42009-09-09 15:08:12 +00004072
John McCall550e0c22009-10-21 00:40:46 +00004073 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004074 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4075 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004076 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004077 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4078 NewTL.setArg(i, ParamDecls[i]);
4079
4080 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004081}
Mike Stump11289f42009-09-09 15:08:12 +00004082
Douglas Gregord6ff3322009-08-04 16:50:30 +00004083template<typename Derived>
4084QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004085 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004086 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004087 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004088 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4089 if (ResultType.isNull())
4090 return QualType();
4091
4092 QualType Result = TL.getType();
4093 if (getDerived().AlwaysRebuild() ||
4094 ResultType != T->getResultType())
4095 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4096
4097 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004098 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4099 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004100 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004101
4102 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004103}
Mike Stump11289f42009-09-09 15:08:12 +00004104
John McCallb96ec562009-12-04 22:46:56 +00004105template<typename Derived> QualType
4106TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004107 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004108 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004109 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004110 if (!D)
4111 return QualType();
4112
4113 QualType Result = TL.getType();
4114 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4115 Result = getDerived().RebuildUnresolvedUsingType(D);
4116 if (Result.isNull())
4117 return QualType();
4118 }
4119
4120 // We might get an arbitrary type spec type back. We should at
4121 // least always get a type spec type, though.
4122 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4123 NewTL.setNameLoc(TL.getNameLoc());
4124
4125 return Result;
4126}
4127
Douglas Gregord6ff3322009-08-04 16:50:30 +00004128template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004129QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004130 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004131 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004132 TypedefNameDecl *Typedef
4133 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4134 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004135 if (!Typedef)
4136 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004137
John McCall550e0c22009-10-21 00:40:46 +00004138 QualType Result = TL.getType();
4139 if (getDerived().AlwaysRebuild() ||
4140 Typedef != T->getDecl()) {
4141 Result = getDerived().RebuildTypedefType(Typedef);
4142 if (Result.isNull())
4143 return QualType();
4144 }
Mike Stump11289f42009-09-09 15:08:12 +00004145
John McCall550e0c22009-10-21 00:40:46 +00004146 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4147 NewTL.setNameLoc(TL.getNameLoc());
4148
4149 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004150}
Mike Stump11289f42009-09-09 15:08:12 +00004151
Douglas Gregord6ff3322009-08-04 16:50:30 +00004152template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004153QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004154 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004155 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004156 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004157
John McCalldadc5752010-08-24 06:29:42 +00004158 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004159 if (E.isInvalid())
4160 return QualType();
4161
John McCall550e0c22009-10-21 00:40:46 +00004162 QualType Result = TL.getType();
4163 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004164 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004165 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004166 if (Result.isNull())
4167 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004168 }
John McCall550e0c22009-10-21 00:40:46 +00004169 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004170
John McCall550e0c22009-10-21 00:40:46 +00004171 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004172 NewTL.setTypeofLoc(TL.getTypeofLoc());
4173 NewTL.setLParenLoc(TL.getLParenLoc());
4174 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004175
4176 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004177}
Mike Stump11289f42009-09-09 15:08:12 +00004178
4179template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004180QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004181 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004182 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4183 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4184 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004185 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004186
John McCall550e0c22009-10-21 00:40:46 +00004187 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004188 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4189 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004190 if (Result.isNull())
4191 return QualType();
4192 }
Mike Stump11289f42009-09-09 15:08:12 +00004193
John McCall550e0c22009-10-21 00:40:46 +00004194 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004195 NewTL.setTypeofLoc(TL.getTypeofLoc());
4196 NewTL.setLParenLoc(TL.getLParenLoc());
4197 NewTL.setRParenLoc(TL.getRParenLoc());
4198 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004199
4200 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004201}
Mike Stump11289f42009-09-09 15:08:12 +00004202
4203template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004204QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004205 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004206 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004207
Douglas Gregore922c772009-08-04 22:27:00 +00004208 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004209 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004210
John McCalldadc5752010-08-24 06:29:42 +00004211 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004212 if (E.isInvalid())
4213 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004214
John McCall550e0c22009-10-21 00:40:46 +00004215 QualType Result = TL.getType();
4216 if (getDerived().AlwaysRebuild() ||
4217 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004218 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004219 if (Result.isNull())
4220 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004221 }
John McCall550e0c22009-10-21 00:40:46 +00004222 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004223
John McCall550e0c22009-10-21 00:40:46 +00004224 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4225 NewTL.setNameLoc(TL.getNameLoc());
4226
4227 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004228}
4229
4230template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004231QualType TreeTransform<Derived>::TransformUnaryTransformType(
4232 TypeLocBuilder &TLB,
4233 UnaryTransformTypeLoc TL) {
4234 QualType Result = TL.getType();
4235 if (Result->isDependentType()) {
4236 const UnaryTransformType *T = TL.getTypePtr();
4237 QualType NewBase =
4238 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4239 Result = getDerived().RebuildUnaryTransformType(NewBase,
4240 T->getUTTKind(),
4241 TL.getKWLoc());
4242 if (Result.isNull())
4243 return QualType();
4244 }
4245
4246 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4247 NewTL.setKWLoc(TL.getKWLoc());
4248 NewTL.setParensRange(TL.getParensRange());
4249 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4250 return Result;
4251}
4252
4253template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004254QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4255 AutoTypeLoc TL) {
4256 const AutoType *T = TL.getTypePtr();
4257 QualType OldDeduced = T->getDeducedType();
4258 QualType NewDeduced;
4259 if (!OldDeduced.isNull()) {
4260 NewDeduced = getDerived().TransformType(OldDeduced);
4261 if (NewDeduced.isNull())
4262 return QualType();
4263 }
4264
4265 QualType Result = TL.getType();
4266 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4267 Result = getDerived().RebuildAutoType(NewDeduced);
4268 if (Result.isNull())
4269 return QualType();
4270 }
4271
4272 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4273 NewTL.setNameLoc(TL.getNameLoc());
4274
4275 return Result;
4276}
4277
4278template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004279QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004280 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004281 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004282 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004283 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4284 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004285 if (!Record)
4286 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004287
John McCall550e0c22009-10-21 00:40:46 +00004288 QualType Result = TL.getType();
4289 if (getDerived().AlwaysRebuild() ||
4290 Record != T->getDecl()) {
4291 Result = getDerived().RebuildRecordType(Record);
4292 if (Result.isNull())
4293 return QualType();
4294 }
Mike Stump11289f42009-09-09 15:08:12 +00004295
John McCall550e0c22009-10-21 00:40:46 +00004296 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4297 NewTL.setNameLoc(TL.getNameLoc());
4298
4299 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004300}
Mike Stump11289f42009-09-09 15:08:12 +00004301
4302template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004303QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004304 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004305 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004306 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004307 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4308 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004309 if (!Enum)
4310 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004311
John McCall550e0c22009-10-21 00:40:46 +00004312 QualType Result = TL.getType();
4313 if (getDerived().AlwaysRebuild() ||
4314 Enum != T->getDecl()) {
4315 Result = getDerived().RebuildEnumType(Enum);
4316 if (Result.isNull())
4317 return QualType();
4318 }
Mike Stump11289f42009-09-09 15:08:12 +00004319
John McCall550e0c22009-10-21 00:40:46 +00004320 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4321 NewTL.setNameLoc(TL.getNameLoc());
4322
4323 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004324}
John McCallfcc33b02009-09-05 00:15:47 +00004325
John McCalle78aac42010-03-10 03:28:59 +00004326template<typename Derived>
4327QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4328 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004329 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004330 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4331 TL.getTypePtr()->getDecl());
4332 if (!D) return QualType();
4333
4334 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4335 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4336 return T;
4337}
4338
Douglas Gregord6ff3322009-08-04 16:50:30 +00004339template<typename Derived>
4340QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004341 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004342 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004343 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004344}
4345
Mike Stump11289f42009-09-09 15:08:12 +00004346template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004347QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004348 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004349 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004350 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4351
4352 // Substitute into the replacement type, which itself might involve something
4353 // that needs to be transformed. This only tends to occur with default
4354 // template arguments of template template parameters.
4355 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4356 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4357 if (Replacement.isNull())
4358 return QualType();
4359
4360 // Always canonicalize the replacement type.
4361 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4362 QualType Result
4363 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4364 Replacement);
4365
4366 // Propagate type-source information.
4367 SubstTemplateTypeParmTypeLoc NewTL
4368 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4369 NewTL.setNameLoc(TL.getNameLoc());
4370 return Result;
4371
John McCallcebee162009-10-18 09:09:24 +00004372}
4373
4374template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004375QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4376 TypeLocBuilder &TLB,
4377 SubstTemplateTypeParmPackTypeLoc TL) {
4378 return TransformTypeSpecType(TLB, TL);
4379}
4380
4381template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004382QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004383 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004384 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004385 const TemplateSpecializationType *T = TL.getTypePtr();
4386
Douglas Gregordf846d12011-03-02 18:46:51 +00004387 // The nested-name-specifier never matters in a TemplateSpecializationType,
4388 // because we can't have a dependent nested-name-specifier anyway.
4389 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004390 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004391 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4392 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004393 if (Template.isNull())
4394 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004395
John McCall31f82722010-11-12 08:19:04 +00004396 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4397}
4398
Douglas Gregorfe921a72010-12-20 23:36:19 +00004399namespace {
4400 /// \brief Simple iterator that traverses the template arguments in a
4401 /// container that provides a \c getArgLoc() member function.
4402 ///
4403 /// This iterator is intended to be used with the iterator form of
4404 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4405 template<typename ArgLocContainer>
4406 class TemplateArgumentLocContainerIterator {
4407 ArgLocContainer *Container;
4408 unsigned Index;
4409
4410 public:
4411 typedef TemplateArgumentLoc value_type;
4412 typedef TemplateArgumentLoc reference;
4413 typedef int difference_type;
4414 typedef std::input_iterator_tag iterator_category;
4415
4416 class pointer {
4417 TemplateArgumentLoc Arg;
4418
4419 public:
4420 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4421
4422 const TemplateArgumentLoc *operator->() const {
4423 return &Arg;
4424 }
4425 };
4426
4427
4428 TemplateArgumentLocContainerIterator() {}
4429
4430 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4431 unsigned Index)
4432 : Container(&Container), Index(Index) { }
4433
4434 TemplateArgumentLocContainerIterator &operator++() {
4435 ++Index;
4436 return *this;
4437 }
4438
4439 TemplateArgumentLocContainerIterator operator++(int) {
4440 TemplateArgumentLocContainerIterator Old(*this);
4441 ++(*this);
4442 return Old;
4443 }
4444
4445 TemplateArgumentLoc operator*() const {
4446 return Container->getArgLoc(Index);
4447 }
4448
4449 pointer operator->() const {
4450 return pointer(Container->getArgLoc(Index));
4451 }
4452
4453 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004454 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004455 return X.Container == Y.Container && X.Index == Y.Index;
4456 }
4457
4458 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004459 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004460 return !(X == Y);
4461 }
4462 };
4463}
4464
4465
John McCall31f82722010-11-12 08:19:04 +00004466template <typename Derived>
4467QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4468 TypeLocBuilder &TLB,
4469 TemplateSpecializationTypeLoc TL,
4470 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004471 TemplateArgumentListInfo NewTemplateArgs;
4472 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4473 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004474 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4475 ArgIterator;
4476 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4477 ArgIterator(TL, TL.getNumArgs()),
4478 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004479 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004480
John McCall0ad16662009-10-29 08:12:44 +00004481 // FIXME: maybe don't rebuild if all the template arguments are the same.
4482
4483 QualType Result =
4484 getDerived().RebuildTemplateSpecializationType(Template,
4485 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004486 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004487
4488 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004489 // Specializations of template template parameters are represented as
4490 // TemplateSpecializationTypes, and substitution of type alias templates
4491 // within a dependent context can transform them into
4492 // DependentTemplateSpecializationTypes.
4493 if (isa<DependentTemplateSpecializationType>(Result)) {
4494 DependentTemplateSpecializationTypeLoc NewTL
4495 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4496 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4497 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4498 NewTL.setNameLoc(TL.getTemplateNameLoc());
4499 NewTL.setLAngleLoc(TL.getLAngleLoc());
4500 NewTL.setRAngleLoc(TL.getRAngleLoc());
4501 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4502 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4503 return Result;
4504 }
4505
John McCall0ad16662009-10-29 08:12:44 +00004506 TemplateSpecializationTypeLoc NewTL
4507 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4508 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4509 NewTL.setLAngleLoc(TL.getLAngleLoc());
4510 NewTL.setRAngleLoc(TL.getRAngleLoc());
4511 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4512 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004513 }
Mike Stump11289f42009-09-09 15:08:12 +00004514
John McCall0ad16662009-10-29 08:12:44 +00004515 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004516}
Mike Stump11289f42009-09-09 15:08:12 +00004517
Douglas Gregor5a064722011-02-28 17:23:35 +00004518template <typename Derived>
4519QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4520 TypeLocBuilder &TLB,
4521 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004522 TemplateName Template,
4523 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004524 TemplateArgumentListInfo NewTemplateArgs;
4525 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4526 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4527 typedef TemplateArgumentLocContainerIterator<
4528 DependentTemplateSpecializationTypeLoc> ArgIterator;
4529 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4530 ArgIterator(TL, TL.getNumArgs()),
4531 NewTemplateArgs))
4532 return QualType();
4533
4534 // FIXME: maybe don't rebuild if all the template arguments are the same.
4535
4536 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4537 QualType Result
4538 = getSema().Context.getDependentTemplateSpecializationType(
4539 TL.getTypePtr()->getKeyword(),
4540 DTN->getQualifier(),
4541 DTN->getIdentifier(),
4542 NewTemplateArgs);
4543
4544 DependentTemplateSpecializationTypeLoc NewTL
4545 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4546 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004547
Douglas Gregora7a795b2011-03-01 20:11:18 +00004548 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004549 NewTL.setNameLoc(TL.getNameLoc());
4550 NewTL.setLAngleLoc(TL.getLAngleLoc());
4551 NewTL.setRAngleLoc(TL.getRAngleLoc());
4552 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4553 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4554 return Result;
4555 }
4556
4557 QualType Result
4558 = getDerived().RebuildTemplateSpecializationType(Template,
4559 TL.getNameLoc(),
4560 NewTemplateArgs);
4561
4562 if (!Result.isNull()) {
4563 /// FIXME: Wrap this in an elaborated-type-specifier?
4564 TemplateSpecializationTypeLoc NewTL
4565 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4566 NewTL.setTemplateNameLoc(TL.getNameLoc());
4567 NewTL.setLAngleLoc(TL.getLAngleLoc());
4568 NewTL.setRAngleLoc(TL.getRAngleLoc());
4569 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4570 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4571 }
4572
4573 return Result;
4574}
4575
Mike Stump11289f42009-09-09 15:08:12 +00004576template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004577QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004578TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004579 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004580 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004581
Douglas Gregor844cb502011-03-01 18:12:44 +00004582 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004583 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004584 if (TL.getQualifierLoc()) {
4585 QualifierLoc
4586 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4587 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004588 return QualType();
4589 }
Mike Stump11289f42009-09-09 15:08:12 +00004590
John McCall31f82722010-11-12 08:19:04 +00004591 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4592 if (NamedT.isNull())
4593 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004594
Richard Smith3f1b5d02011-05-05 21:57:07 +00004595 // C++0x [dcl.type.elab]p2:
4596 // If the identifier resolves to a typedef-name or the simple-template-id
4597 // resolves to an alias template specialization, the
4598 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004599 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4600 if (const TemplateSpecializationType *TST =
4601 NamedT->getAs<TemplateSpecializationType>()) {
4602 TemplateName Template = TST->getTemplateName();
4603 if (TypeAliasTemplateDecl *TAT =
4604 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4605 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4606 diag::err_tag_reference_non_tag) << 4;
4607 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4608 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004609 }
4610 }
4611
John McCall550e0c22009-10-21 00:40:46 +00004612 QualType Result = TL.getType();
4613 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004614 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004615 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004616 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004617 T->getKeyword(),
4618 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004619 if (Result.isNull())
4620 return QualType();
4621 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004622
Abramo Bagnara6150c882010-05-11 21:36:43 +00004623 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004624 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004625 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004626 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004627}
Mike Stump11289f42009-09-09 15:08:12 +00004628
4629template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004630QualType TreeTransform<Derived>::TransformAttributedType(
4631 TypeLocBuilder &TLB,
4632 AttributedTypeLoc TL) {
4633 const AttributedType *oldType = TL.getTypePtr();
4634 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4635 if (modifiedType.isNull())
4636 return QualType();
4637
4638 QualType result = TL.getType();
4639
4640 // FIXME: dependent operand expressions?
4641 if (getDerived().AlwaysRebuild() ||
4642 modifiedType != oldType->getModifiedType()) {
4643 // TODO: this is really lame; we should really be rebuilding the
4644 // equivalent type from first principles.
4645 QualType equivalentType
4646 = getDerived().TransformType(oldType->getEquivalentType());
4647 if (equivalentType.isNull())
4648 return QualType();
4649 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4650 modifiedType,
4651 equivalentType);
4652 }
4653
4654 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4655 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4656 if (TL.hasAttrOperand())
4657 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4658 if (TL.hasAttrExprOperand())
4659 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4660 else if (TL.hasAttrEnumOperand())
4661 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4662
4663 return result;
4664}
4665
4666template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004667QualType
4668TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4669 ParenTypeLoc TL) {
4670 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4671 if (Inner.isNull())
4672 return QualType();
4673
4674 QualType Result = TL.getType();
4675 if (getDerived().AlwaysRebuild() ||
4676 Inner != TL.getInnerLoc().getType()) {
4677 Result = getDerived().RebuildParenType(Inner);
4678 if (Result.isNull())
4679 return QualType();
4680 }
4681
4682 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4683 NewTL.setLParenLoc(TL.getLParenLoc());
4684 NewTL.setRParenLoc(TL.getRParenLoc());
4685 return Result;
4686}
4687
4688template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004689QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004690 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004691 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004692
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004693 NestedNameSpecifierLoc QualifierLoc
4694 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4695 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004696 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004697
John McCallc392f372010-06-11 00:33:02 +00004698 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004699 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004700 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004701 QualifierLoc,
4702 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004703 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004704 if (Result.isNull())
4705 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004706
Abramo Bagnarad7548482010-05-19 21:37:53 +00004707 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4708 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004709 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4710
Abramo Bagnarad7548482010-05-19 21:37:53 +00004711 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4712 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004713 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004714 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004715 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4716 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004717 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004718 NewTL.setNameLoc(TL.getNameLoc());
4719 }
John McCall550e0c22009-10-21 00:40:46 +00004720 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004721}
Mike Stump11289f42009-09-09 15:08:12 +00004722
Douglas Gregord6ff3322009-08-04 16:50:30 +00004723template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004724QualType TreeTransform<Derived>::
4725 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004726 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004727 NestedNameSpecifierLoc QualifierLoc;
4728 if (TL.getQualifierLoc()) {
4729 QualifierLoc
4730 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4731 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004732 return QualType();
4733 }
4734
John McCall31f82722010-11-12 08:19:04 +00004735 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004736 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004737}
4738
4739template<typename Derived>
4740QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004741TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4742 DependentTemplateSpecializationTypeLoc TL,
4743 NestedNameSpecifierLoc QualifierLoc) {
4744 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4745
4746 TemplateArgumentListInfo NewTemplateArgs;
4747 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4748 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4749
4750 typedef TemplateArgumentLocContainerIterator<
4751 DependentTemplateSpecializationTypeLoc> ArgIterator;
4752 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4753 ArgIterator(TL, TL.getNumArgs()),
4754 NewTemplateArgs))
4755 return QualType();
4756
4757 QualType Result
4758 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4759 QualifierLoc,
4760 T->getIdentifier(),
4761 TL.getNameLoc(),
4762 NewTemplateArgs);
4763 if (Result.isNull())
4764 return QualType();
4765
4766 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4767 QualType NamedT = ElabT->getNamedType();
4768
4769 // Copy information relevant to the template specialization.
4770 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004771 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004772 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004773 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4774 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004775 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004776 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004777
4778 // Copy information relevant to the elaborated type.
4779 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4780 NewTL.setKeywordLoc(TL.getKeywordLoc());
4781 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004782 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4783 DependentTemplateSpecializationTypeLoc SpecTL
4784 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004785 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004786 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004787 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004788 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4789 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004790 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004791 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004792 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004793 TemplateSpecializationTypeLoc SpecTL
4794 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004795 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004796 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4797 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004798 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004799 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004800 }
4801 return Result;
4802}
4803
4804template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004805QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4806 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004807 QualType Pattern
4808 = getDerived().TransformType(TLB, TL.getPatternLoc());
4809 if (Pattern.isNull())
4810 return QualType();
4811
4812 QualType Result = TL.getType();
4813 if (getDerived().AlwaysRebuild() ||
4814 Pattern != TL.getPatternLoc().getType()) {
4815 Result = getDerived().RebuildPackExpansionType(Pattern,
4816 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004817 TL.getEllipsisLoc(),
4818 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004819 if (Result.isNull())
4820 return QualType();
4821 }
4822
4823 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4824 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4825 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004826}
4827
4828template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004829QualType
4830TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004831 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004832 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004833 TLB.pushFullCopy(TL);
4834 return TL.getType();
4835}
4836
4837template<typename Derived>
4838QualType
4839TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004840 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004841 // ObjCObjectType is never dependent.
4842 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004843 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004844}
Mike Stump11289f42009-09-09 15:08:12 +00004845
4846template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004847QualType
4848TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004849 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004850 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004851 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004852 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004853}
4854
Douglas Gregord6ff3322009-08-04 16:50:30 +00004855//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004856// Statement transformation
4857//===----------------------------------------------------------------------===//
4858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004859StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004860TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004861 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004862}
4863
4864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004865StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004866TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4867 return getDerived().TransformCompoundStmt(S, false);
4868}
4869
4870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004871StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004872TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004873 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004874 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004875 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004876 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004877 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4878 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004879 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004880 if (Result.isInvalid()) {
4881 // Immediately fail if this was a DeclStmt, since it's very
4882 // likely that this will cause problems for future statements.
4883 if (isa<DeclStmt>(*B))
4884 return StmtError();
4885
4886 // Otherwise, just keep processing substatements and fail later.
4887 SubStmtInvalid = true;
4888 continue;
4889 }
Mike Stump11289f42009-09-09 15:08:12 +00004890
Douglas Gregorebe10102009-08-20 07:17:43 +00004891 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4892 Statements.push_back(Result.takeAs<Stmt>());
4893 }
Mike Stump11289f42009-09-09 15:08:12 +00004894
John McCall1ababa62010-08-27 19:56:05 +00004895 if (SubStmtInvalid)
4896 return StmtError();
4897
Douglas Gregorebe10102009-08-20 07:17:43 +00004898 if (!getDerived().AlwaysRebuild() &&
4899 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004900 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004901
4902 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4903 move_arg(Statements),
4904 S->getRBracLoc(),
4905 IsStmtExpr);
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>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004911 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004912 {
4913 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004914 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004915
Eli Friedman06577382009-11-19 03:14:00 +00004916 // Transform the left-hand case value.
4917 LHS = getDerived().TransformExpr(S->getLHS());
4918 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004919 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004920
Eli Friedman06577382009-11-19 03:14:00 +00004921 // Transform the right-hand case value (for the GNU case-range extension).
4922 RHS = getDerived().TransformExpr(S->getRHS());
4923 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004924 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004925 }
Mike Stump11289f42009-09-09 15:08:12 +00004926
Douglas Gregorebe10102009-08-20 07:17:43 +00004927 // Build the case statement.
4928 // Case statements are always rebuilt so that they will attached to their
4929 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004930 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004931 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004932 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004933 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004934 S->getColonLoc());
4935 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004936 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004937
Douglas Gregorebe10102009-08-20 07:17:43 +00004938 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004939 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004940 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004941 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004942
Douglas Gregorebe10102009-08-20 07:17:43 +00004943 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004944 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004945}
4946
4947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004948StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004949TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004950 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004951 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004952 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004953 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004954
Douglas Gregorebe10102009-08-20 07:17:43 +00004955 // Default statements are always rebuilt
4956 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004957 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004958}
Mike Stump11289f42009-09-09 15:08:12 +00004959
Douglas Gregorebe10102009-08-20 07:17:43 +00004960template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004961StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004962TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004963 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004964 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004965 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004966
Chris Lattnercab02a62011-02-17 20:34:02 +00004967 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4968 S->getDecl());
4969 if (!LD)
4970 return StmtError();
4971
4972
Douglas Gregorebe10102009-08-20 07:17:43 +00004973 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004974 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004975 cast<LabelDecl>(LD), SourceLocation(),
4976 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004977}
Mike Stump11289f42009-09-09 15:08:12 +00004978
Douglas Gregorebe10102009-08-20 07:17:43 +00004979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004980StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004981TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004982 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004983 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004984 VarDecl *ConditionVar = 0;
4985 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004986 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004987 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004988 getDerived().TransformDefinition(
4989 S->getConditionVariable()->getLocation(),
4990 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004991 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004992 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004993 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004994 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004995
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004996 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004997 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004998
4999 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005000 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005001 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5002 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005003 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005004 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005005
John McCallb268a282010-08-23 23:25:46 +00005006 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005007 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005008 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005009
John McCallb268a282010-08-23 23:25:46 +00005010 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5011 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005012 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005013
Douglas Gregorebe10102009-08-20 07:17:43 +00005014 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005015 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005016 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005017 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005018
Douglas Gregorebe10102009-08-20 07:17:43 +00005019 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005020 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005021 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005022 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005023
Douglas Gregorebe10102009-08-20 07:17:43 +00005024 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005025 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005026 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005027 Then.get() == S->getThen() &&
5028 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005029 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005030
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005031 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005032 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005033 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005034}
5035
5036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005037StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005038TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005039 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005040 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005041 VarDecl *ConditionVar = 0;
5042 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005043 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005044 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005045 getDerived().TransformDefinition(
5046 S->getConditionVariable()->getLocation(),
5047 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005048 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005049 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005050 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005051 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005052
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005053 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005054 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005055 }
Mike Stump11289f42009-09-09 15:08:12 +00005056
Douglas Gregorebe10102009-08-20 07:17:43 +00005057 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005058 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005059 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005060 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005061 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005062 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005063
Douglas Gregorebe10102009-08-20 07:17:43 +00005064 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005065 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005066 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005067 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005068
Douglas Gregorebe10102009-08-20 07:17:43 +00005069 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005070 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5071 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005072}
Mike Stump11289f42009-09-09 15:08:12 +00005073
Douglas Gregorebe10102009-08-20 07:17:43 +00005074template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005075StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005076TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005077 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005078 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005079 VarDecl *ConditionVar = 0;
5080 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005081 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005082 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005083 getDerived().TransformDefinition(
5084 S->getConditionVariable()->getLocation(),
5085 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005086 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005087 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005088 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005089 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005090
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005091 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005092 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005093
5094 if (S->getCond()) {
5095 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005096 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5097 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005098 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005099 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005100 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005101 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005102 }
Mike Stump11289f42009-09-09 15:08:12 +00005103
John McCallb268a282010-08-23 23:25:46 +00005104 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5105 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005106 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005107
Douglas Gregorebe10102009-08-20 07:17:43 +00005108 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005109 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005110 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005111 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005112
Douglas Gregorebe10102009-08-20 07:17:43 +00005113 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005114 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005115 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005116 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005117 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005118
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005119 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005120 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005121}
Mike Stump11289f42009-09-09 15:08:12 +00005122
Douglas Gregorebe10102009-08-20 07:17:43 +00005123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005124StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005125TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005126 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005127 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005128 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005129 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005130
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005131 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005132 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005133 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005134 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005135
Douglas Gregorebe10102009-08-20 07:17:43 +00005136 if (!getDerived().AlwaysRebuild() &&
5137 Cond.get() == S->getCond() &&
5138 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005139 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005140
John McCallb268a282010-08-23 23:25:46 +00005141 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5142 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005143 S->getRParenLoc());
5144}
Mike Stump11289f42009-09-09 15:08:12 +00005145
Douglas Gregorebe10102009-08-20 07:17:43 +00005146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005147StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005148TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005149 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005150 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005151 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005152 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005153
Douglas Gregorebe10102009-08-20 07:17:43 +00005154 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005155 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005156 VarDecl *ConditionVar = 0;
5157 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005158 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005159 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005160 getDerived().TransformDefinition(
5161 S->getConditionVariable()->getLocation(),
5162 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005163 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005164 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005165 } else {
5166 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005167
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005168 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005169 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005170
5171 if (S->getCond()) {
5172 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005173 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5174 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005175 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005176 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005177
John McCallb268a282010-08-23 23:25:46 +00005178 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005179 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005180 }
Mike Stump11289f42009-09-09 15:08:12 +00005181
John McCallb268a282010-08-23 23:25:46 +00005182 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5183 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005184 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005185
Douglas Gregorebe10102009-08-20 07:17:43 +00005186 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005187 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005188 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005189 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005190
John McCallb268a282010-08-23 23:25:46 +00005191 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5192 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005193 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005194
Douglas Gregorebe10102009-08-20 07:17:43 +00005195 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005196 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005197 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005198 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005199
Douglas Gregorebe10102009-08-20 07:17:43 +00005200 if (!getDerived().AlwaysRebuild() &&
5201 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005202 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005203 Inc.get() == S->getInc() &&
5204 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005205 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005206
Douglas Gregorebe10102009-08-20 07:17:43 +00005207 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005208 Init.get(), FullCond, ConditionVar,
5209 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005210}
5211
5212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005213StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005214TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005215 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5216 S->getLabel());
5217 if (!LD)
5218 return StmtError();
5219
Douglas Gregorebe10102009-08-20 07:17:43 +00005220 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005221 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005222 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005223}
5224
5225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005226StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005227TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005228 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005229 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005230 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005231
Douglas Gregorebe10102009-08-20 07:17:43 +00005232 if (!getDerived().AlwaysRebuild() &&
5233 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005234 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005235
5236 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005237 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005238}
5239
5240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005241StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005242TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005243 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005244}
Mike Stump11289f42009-09-09 15:08:12 +00005245
Douglas Gregorebe10102009-08-20 07:17:43 +00005246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005247StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005248TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005249 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005250}
Mike Stump11289f42009-09-09 15:08:12 +00005251
Douglas Gregorebe10102009-08-20 07:17:43 +00005252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005253StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005254TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005255 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005256 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005257 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005258
Mike Stump11289f42009-09-09 15:08:12 +00005259 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005260 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005261 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005262}
Mike Stump11289f42009-09-09 15:08:12 +00005263
Douglas Gregorebe10102009-08-20 07:17:43 +00005264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005265StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005266TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005267 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005268 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005269 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5270 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005271 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5272 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005273 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005274 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005275
Douglas Gregorebe10102009-08-20 07:17:43 +00005276 if (Transformed != *D)
5277 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005278
Douglas Gregorebe10102009-08-20 07:17:43 +00005279 Decls.push_back(Transformed);
5280 }
Mike Stump11289f42009-09-09 15:08:12 +00005281
Douglas Gregorebe10102009-08-20 07:17:43 +00005282 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005283 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005284
5285 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005286 S->getStartLoc(), S->getEndLoc());
5287}
Mike Stump11289f42009-09-09 15:08:12 +00005288
Douglas Gregorebe10102009-08-20 07:17:43 +00005289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005290StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005291TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005292
John McCall37ad5512010-08-23 06:44:23 +00005293 ASTOwningVector<Expr*> Constraints(getSema());
5294 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner01cf8db2011-07-20 06:58:45 +00005295 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005296
John McCalldadc5752010-08-24 06:29:42 +00005297 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005298 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005299
5300 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005301
Anders Carlssonaaeef072010-01-24 05:50:09 +00005302 // Go through the outputs.
5303 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005304 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005305
Anders Carlssonaaeef072010-01-24 05:50:09 +00005306 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005307 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005308
Anders Carlssonaaeef072010-01-24 05:50:09 +00005309 // Transform the output expr.
5310 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005311 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005312 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005313 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005314
Anders Carlssonaaeef072010-01-24 05:50:09 +00005315 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005316
John McCallb268a282010-08-23 23:25:46 +00005317 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005318 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005319
Anders Carlssonaaeef072010-01-24 05:50:09 +00005320 // Go through the inputs.
5321 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005322 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005323
Anders Carlssonaaeef072010-01-24 05:50:09 +00005324 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005325 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005326
Anders Carlssonaaeef072010-01-24 05:50:09 +00005327 // Transform the input expr.
5328 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005329 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005330 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005331 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005332
Anders Carlssonaaeef072010-01-24 05:50:09 +00005333 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005334
John McCallb268a282010-08-23 23:25:46 +00005335 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005336 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005337
Anders Carlssonaaeef072010-01-24 05:50:09 +00005338 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005339 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005340
5341 // Go through the clobbers.
5342 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005343 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005344
5345 // No need to transform the asm string literal.
5346 AsmString = SemaRef.Owned(S->getAsmString());
5347
5348 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5349 S->isSimple(),
5350 S->isVolatile(),
5351 S->getNumOutputs(),
5352 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005353 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005354 move_arg(Constraints),
5355 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005356 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005357 move_arg(Clobbers),
5358 S->getRParenLoc(),
5359 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005360}
5361
5362
5363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005364StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005365TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005366 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005367 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005368 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005369 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005370
Douglas Gregor96c79492010-04-23 22:50:49 +00005371 // Transform the @catch statements (if present).
5372 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005373 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005374 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005375 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005376 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005377 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005378 if (Catch.get() != S->getCatchStmt(I))
5379 AnyCatchChanged = true;
5380 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005381 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005382
Douglas Gregor306de2f2010-04-22 23:59:56 +00005383 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005384 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005385 if (S->getFinallyStmt()) {
5386 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5387 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005388 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005389 }
5390
5391 // If nothing changed, just retain this statement.
5392 if (!getDerived().AlwaysRebuild() &&
5393 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005394 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005395 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005396 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005397
Douglas Gregor306de2f2010-04-22 23:59:56 +00005398 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005399 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5400 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005401}
Mike Stump11289f42009-09-09 15:08:12 +00005402
Douglas Gregorebe10102009-08-20 07:17:43 +00005403template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005404StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005405TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005406 // Transform the @catch parameter, if there is one.
5407 VarDecl *Var = 0;
5408 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5409 TypeSourceInfo *TSInfo = 0;
5410 if (FromVar->getTypeSourceInfo()) {
5411 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5412 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005413 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005414 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005415
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005416 QualType T;
5417 if (TSInfo)
5418 T = TSInfo->getType();
5419 else {
5420 T = getDerived().TransformType(FromVar->getType());
5421 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005422 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005423 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005424
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005425 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5426 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005427 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005428 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005429
John McCalldadc5752010-08-24 06:29:42 +00005430 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005431 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005432 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005433
5434 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005435 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005436 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005437}
Mike Stump11289f42009-09-09 15:08:12 +00005438
Douglas Gregorebe10102009-08-20 07:17:43 +00005439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005440StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005441TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005442 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005443 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005444 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005445 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005446
Douglas Gregor306de2f2010-04-22 23:59:56 +00005447 // If nothing changed, just retain this statement.
5448 if (!getDerived().AlwaysRebuild() &&
5449 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005450 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005451
5452 // Build a new statement.
5453 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005454 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005455}
Mike Stump11289f42009-09-09 15:08:12 +00005456
Douglas Gregorebe10102009-08-20 07:17:43 +00005457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005458StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005459TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005460 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005461 if (S->getThrowExpr()) {
5462 Operand = getDerived().TransformExpr(S->getThrowExpr());
5463 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005464 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005465 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005466
Douglas Gregor2900c162010-04-22 21:44:01 +00005467 if (!getDerived().AlwaysRebuild() &&
5468 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005469 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005470
John McCallb268a282010-08-23 23:25:46 +00005471 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005472}
Mike Stump11289f42009-09-09 15:08:12 +00005473
Douglas Gregorebe10102009-08-20 07:17:43 +00005474template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005475StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005476TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005477 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005478 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005479 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005480 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005481 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005482
Douglas Gregor6148de72010-04-22 22:01:21 +00005483 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005484 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005485 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005486 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005487
Douglas Gregor6148de72010-04-22 22:01:21 +00005488 // If nothing change, just retain the current statement.
5489 if (!getDerived().AlwaysRebuild() &&
5490 Object.get() == S->getSynchExpr() &&
5491 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005492 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005493
5494 // Build a new statement.
5495 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005496 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005497}
5498
5499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005500StmtResult
John McCall31168b02011-06-15 23:02:42 +00005501TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5502 ObjCAutoreleasePoolStmt *S) {
5503 // Transform the body.
5504 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5505 if (Body.isInvalid())
5506 return StmtError();
5507
5508 // If nothing changed, just retain this statement.
5509 if (!getDerived().AlwaysRebuild() &&
5510 Body.get() == S->getSubStmt())
5511 return SemaRef.Owned(S);
5512
5513 // Build a new statement.
5514 return getDerived().RebuildObjCAutoreleasePoolStmt(
5515 S->getAtLoc(), Body.get());
5516}
5517
5518template<typename Derived>
5519StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005520TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005521 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005522 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005523 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005524 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005525 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005526
Douglas Gregorf68a5082010-04-22 23:10:45 +00005527 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005528 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005529 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005530 return StmtError();
John McCall53848232011-07-27 01:07:15 +00005531 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5532 Collection.take());
5533 if (Collection.isInvalid())
5534 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005535
Douglas Gregorf68a5082010-04-22 23:10:45 +00005536 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005537 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005538 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005539 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005540
Douglas Gregorf68a5082010-04-22 23:10:45 +00005541 // If nothing changed, just retain this statement.
5542 if (!getDerived().AlwaysRebuild() &&
5543 Element.get() == S->getElement() &&
5544 Collection.get() == S->getCollection() &&
5545 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005546 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005547
Douglas Gregorf68a5082010-04-22 23:10:45 +00005548 // Build a new statement.
5549 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5550 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005551 Element.get(),
5552 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005553 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005554 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005555}
5556
5557
5558template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005559StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005560TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5561 // Transform the exception declaration, if any.
5562 VarDecl *Var = 0;
5563 if (S->getExceptionDecl()) {
5564 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005565 TypeSourceInfo *T = getDerived().TransformType(
5566 ExceptionDecl->getTypeSourceInfo());
5567 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005568 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005569
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005570 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005571 ExceptionDecl->getInnerLocStart(),
5572 ExceptionDecl->getLocation(),
5573 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005574 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005575 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005576 }
Mike Stump11289f42009-09-09 15:08:12 +00005577
Douglas Gregorebe10102009-08-20 07:17:43 +00005578 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005579 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005580 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005581 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005582
Douglas Gregorebe10102009-08-20 07:17:43 +00005583 if (!getDerived().AlwaysRebuild() &&
5584 !Var &&
5585 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005586 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005587
5588 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5589 Var,
John McCallb268a282010-08-23 23:25:46 +00005590 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005591}
Mike Stump11289f42009-09-09 15:08:12 +00005592
Douglas Gregorebe10102009-08-20 07:17:43 +00005593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005594StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005595TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5596 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005597 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005598 = getDerived().TransformCompoundStmt(S->getTryBlock());
5599 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005600 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005601
Douglas Gregorebe10102009-08-20 07:17:43 +00005602 // Transform the handlers.
5603 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005604 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005605 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005606 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005607 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5608 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005609 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005610
Douglas Gregorebe10102009-08-20 07:17:43 +00005611 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5612 Handlers.push_back(Handler.takeAs<Stmt>());
5613 }
Mike Stump11289f42009-09-09 15:08:12 +00005614
Douglas Gregorebe10102009-08-20 07:17:43 +00005615 if (!getDerived().AlwaysRebuild() &&
5616 TryBlock.get() == S->getTryBlock() &&
5617 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005618 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005619
John McCallb268a282010-08-23 23:25:46 +00005620 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005621 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005622}
Mike Stump11289f42009-09-09 15:08:12 +00005623
Richard Smith02e85f32011-04-14 22:09:26 +00005624template<typename Derived>
5625StmtResult
5626TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5627 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5628 if (Range.isInvalid())
5629 return StmtError();
5630
5631 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5632 if (BeginEnd.isInvalid())
5633 return StmtError();
5634
5635 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5636 if (Cond.isInvalid())
5637 return StmtError();
5638
5639 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5640 if (Inc.isInvalid())
5641 return StmtError();
5642
5643 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5644 if (LoopVar.isInvalid())
5645 return StmtError();
5646
5647 StmtResult NewStmt = S;
5648 if (getDerived().AlwaysRebuild() ||
5649 Range.get() != S->getRangeStmt() ||
5650 BeginEnd.get() != S->getBeginEndStmt() ||
5651 Cond.get() != S->getCond() ||
5652 Inc.get() != S->getInc() ||
5653 LoopVar.get() != S->getLoopVarStmt())
5654 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5655 S->getColonLoc(), Range.get(),
5656 BeginEnd.get(), Cond.get(),
5657 Inc.get(), LoopVar.get(),
5658 S->getRParenLoc());
5659
5660 StmtResult Body = getDerived().TransformStmt(S->getBody());
5661 if (Body.isInvalid())
5662 return StmtError();
5663
5664 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5665 // it now so we have a new statement to attach the body to.
5666 if (Body.get() != S->getBody() && NewStmt.get() == S)
5667 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5668 S->getColonLoc(), Range.get(),
5669 BeginEnd.get(), Cond.get(),
5670 Inc.get(), LoopVar.get(),
5671 S->getRParenLoc());
5672
5673 if (NewStmt.get() == S)
5674 return SemaRef.Owned(S);
5675
5676 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5677}
5678
John Wiegley1c0675e2011-04-28 01:08:34 +00005679template<typename Derived>
5680StmtResult
5681TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5682 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5683 if(TryBlock.isInvalid()) return StmtError();
5684
5685 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5686 if(!getDerived().AlwaysRebuild() &&
5687 TryBlock.get() == S->getTryBlock() &&
5688 Handler.get() == S->getHandler())
5689 return SemaRef.Owned(S);
5690
5691 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5692 S->getTryLoc(),
5693 TryBlock.take(),
5694 Handler.take());
5695}
5696
5697template<typename Derived>
5698StmtResult
5699TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5700 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5701 if(Block.isInvalid()) return StmtError();
5702
5703 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5704 Block.take());
5705}
5706
5707template<typename Derived>
5708StmtResult
5709TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5710 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5711 if(FilterExpr.isInvalid()) return StmtError();
5712
5713 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5714 if(Block.isInvalid()) return StmtError();
5715
5716 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5717 FilterExpr.take(),
5718 Block.take());
5719}
5720
5721template<typename Derived>
5722StmtResult
5723TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5724 if(isa<SEHFinallyStmt>(Handler))
5725 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5726 else
5727 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5728}
5729
Douglas Gregorebe10102009-08-20 07:17:43 +00005730//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005731// Expression transformation
5732//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005734ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005735TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005736 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005737}
Mike Stump11289f42009-09-09 15:08:12 +00005738
5739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005740ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005741TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005742 NestedNameSpecifierLoc QualifierLoc;
5743 if (E->getQualifierLoc()) {
5744 QualifierLoc
5745 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5746 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005747 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005748 }
John McCallce546572009-12-08 09:08:17 +00005749
5750 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005751 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5752 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005753 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005755
John McCall815039a2010-08-17 21:27:17 +00005756 DeclarationNameInfo NameInfo = E->getNameInfo();
5757 if (NameInfo.getName()) {
5758 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5759 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005760 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005761 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005762
5763 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005764 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005765 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005766 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005767 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005768
5769 // Mark it referenced in the new context regardless.
5770 // FIXME: this is a bit instantiation-specific.
5771 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5772
John McCallc3007a22010-10-26 07:05:15 +00005773 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005774 }
John McCallce546572009-12-08 09:08:17 +00005775
5776 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005777 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005778 TemplateArgs = &TransArgs;
5779 TransArgs.setLAngleLoc(E->getLAngleLoc());
5780 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005781 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5782 E->getNumTemplateArgs(),
5783 TransArgs))
5784 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005785 }
5786
Douglas Gregorea972d32011-02-28 21:54:11 +00005787 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5788 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005789}
Mike Stump11289f42009-09-09 15:08:12 +00005790
Douglas Gregora16548e2009-08-11 05:31:07 +00005791template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005792ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005793TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005794 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005795}
Mike Stump11289f42009-09-09 15:08:12 +00005796
Douglas Gregora16548e2009-08-11 05:31:07 +00005797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005798ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005799TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005800 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005801}
Mike Stump11289f42009-09-09 15:08:12 +00005802
Douglas Gregora16548e2009-08-11 05:31:07 +00005803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005805TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005806 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005807}
Mike Stump11289f42009-09-09 15:08:12 +00005808
Douglas Gregora16548e2009-08-11 05:31:07 +00005809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005810ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005811TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005812 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005813}
Mike Stump11289f42009-09-09 15:08:12 +00005814
Douglas Gregora16548e2009-08-11 05:31:07 +00005815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005816ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005817TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005818 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005819}
5820
5821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005822ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005823TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5824 ExprResult ControllingExpr =
5825 getDerived().TransformExpr(E->getControllingExpr());
5826 if (ControllingExpr.isInvalid())
5827 return ExprError();
5828
Chris Lattner01cf8db2011-07-20 06:58:45 +00005829 SmallVector<Expr *, 4> AssocExprs;
5830 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00005831 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5832 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5833 if (TS) {
5834 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5835 if (!AssocType)
5836 return ExprError();
5837 AssocTypes.push_back(AssocType);
5838 } else {
5839 AssocTypes.push_back(0);
5840 }
5841
5842 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5843 if (AssocExpr.isInvalid())
5844 return ExprError();
5845 AssocExprs.push_back(AssocExpr.release());
5846 }
5847
5848 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5849 E->getDefaultLoc(),
5850 E->getRParenLoc(),
5851 ControllingExpr.release(),
5852 AssocTypes.data(),
5853 AssocExprs.data(),
5854 E->getNumAssocs());
5855}
5856
5857template<typename Derived>
5858ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005859TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005860 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005861 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005863
Douglas Gregora16548e2009-08-11 05:31:07 +00005864 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005865 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005866
John McCallb268a282010-08-23 23:25:46 +00005867 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005868 E->getRParen());
5869}
5870
Mike Stump11289f42009-09-09 15:08:12 +00005871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005872ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005873TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005874 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005875 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005876 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005877
Douglas Gregora16548e2009-08-11 05:31:07 +00005878 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005879 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005880
Douglas Gregora16548e2009-08-11 05:31:07 +00005881 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5882 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005883 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005884}
Mike Stump11289f42009-09-09 15:08:12 +00005885
Douglas Gregora16548e2009-08-11 05:31:07 +00005886template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005887ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005888TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5889 // Transform the type.
5890 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5891 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005892 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005893
Douglas Gregor882211c2010-04-28 22:16:22 +00005894 // Transform all of the components into components similar to what the
5895 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005896 // FIXME: It would be slightly more efficient in the non-dependent case to
5897 // just map FieldDecls, rather than requiring the rebuilder to look for
5898 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005899 // template code that we don't care.
5900 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005901 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005902 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005903 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00005904 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5905 const Node &ON = E->getComponent(I);
5906 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005907 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005908 Comp.LocStart = ON.getSourceRange().getBegin();
5909 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005910 switch (ON.getKind()) {
5911 case Node::Array: {
5912 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005913 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005914 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005915 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005916
Douglas Gregor882211c2010-04-28 22:16:22 +00005917 ExprChanged = ExprChanged || Index.get() != FromIndex;
5918 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005919 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005920 break;
5921 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005922
Douglas Gregor882211c2010-04-28 22:16:22 +00005923 case Node::Field:
5924 case Node::Identifier:
5925 Comp.isBrackets = false;
5926 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005927 if (!Comp.U.IdentInfo)
5928 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005929
Douglas Gregor882211c2010-04-28 22:16:22 +00005930 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005931
Douglas Gregord1702062010-04-29 00:18:15 +00005932 case Node::Base:
5933 // Will be recomputed during the rebuild.
5934 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005935 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005936
Douglas Gregor882211c2010-04-28 22:16:22 +00005937 Components.push_back(Comp);
5938 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005939
Douglas Gregor882211c2010-04-28 22:16:22 +00005940 // If nothing changed, retain the existing expression.
5941 if (!getDerived().AlwaysRebuild() &&
5942 Type == E->getTypeSourceInfo() &&
5943 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005944 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005945
Douglas Gregor882211c2010-04-28 22:16:22 +00005946 // Build a new offsetof expression.
5947 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5948 Components.data(), Components.size(),
5949 E->getRParenLoc());
5950}
5951
5952template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005953ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005954TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5955 assert(getDerived().AlreadyTransformed(E->getType()) &&
5956 "opaque value expression requires transformation");
5957 return SemaRef.Owned(E);
5958}
5959
5960template<typename Derived>
5961ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005962TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5963 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005964 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005965 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005966
John McCallbcd03502009-12-07 02:54:59 +00005967 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005968 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005969 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005970
John McCall4c98fd82009-11-04 07:28:41 +00005971 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005972 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005973
Peter Collingbournee190dee2011-03-11 19:24:49 +00005974 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5975 E->getKind(),
5976 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005977 }
Mike Stump11289f42009-09-09 15:08:12 +00005978
John McCalldadc5752010-08-24 06:29:42 +00005979 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005980 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005981 // C++0x [expr.sizeof]p1:
5982 // The operand is either an expression, which is an unevaluated operand
5983 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005984 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005985
Douglas Gregora16548e2009-08-11 05:31:07 +00005986 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5987 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005988 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005989
Douglas Gregora16548e2009-08-11 05:31:07 +00005990 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005991 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005992 }
Mike Stump11289f42009-09-09 15:08:12 +00005993
Peter Collingbournee190dee2011-03-11 19:24:49 +00005994 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5995 E->getOperatorLoc(),
5996 E->getKind(),
5997 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005998}
Mike Stump11289f42009-09-09 15:08:12 +00005999
Douglas Gregora16548e2009-08-11 05:31:07 +00006000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006001ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006002TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006003 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006004 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006005 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006006
John McCalldadc5752010-08-24 06:29:42 +00006007 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006008 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006009 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006010
6011
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 if (!getDerived().AlwaysRebuild() &&
6013 LHS.get() == E->getLHS() &&
6014 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006015 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006016
John McCallb268a282010-08-23 23:25:46 +00006017 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006018 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006019 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006020 E->getRBracketLoc());
6021}
Mike Stump11289f42009-09-09 15:08:12 +00006022
6023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006024ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006025TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006026 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006027 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006028 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006029 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006030
6031 // Transform arguments.
6032 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006033 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006034 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6035 &ArgChanged))
6036 return ExprError();
6037
Douglas Gregora16548e2009-08-11 05:31:07 +00006038 if (!getDerived().AlwaysRebuild() &&
6039 Callee.get() == E->getCallee() &&
6040 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006041 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006042
Douglas Gregora16548e2009-08-11 05:31:07 +00006043 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006044 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006045 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006046 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006047 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006048 E->getRParenLoc());
6049}
Mike Stump11289f42009-09-09 15:08:12 +00006050
6051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006052ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006053TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006054 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006055 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006057
Douglas Gregorea972d32011-02-28 21:54:11 +00006058 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006059 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006060 QualifierLoc
6061 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6062
6063 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006064 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006065 }
Mike Stump11289f42009-09-09 15:08:12 +00006066
Eli Friedman2cfcef62009-12-04 06:40:45 +00006067 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006068 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6069 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006070 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006071 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006072
John McCall16df1e52010-03-30 21:47:33 +00006073 NamedDecl *FoundDecl = E->getFoundDecl();
6074 if (FoundDecl == E->getMemberDecl()) {
6075 FoundDecl = Member;
6076 } else {
6077 FoundDecl = cast_or_null<NamedDecl>(
6078 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6079 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006080 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006081 }
6082
Douglas Gregora16548e2009-08-11 05:31:07 +00006083 if (!getDerived().AlwaysRebuild() &&
6084 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006085 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006086 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006087 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006088 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006089
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006090 // Mark it referenced in the new context regardless.
6091 // FIXME: this is a bit instantiation-specific.
6092 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00006093 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006094 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006095
John McCall6b51f282009-11-23 01:53:49 +00006096 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006097 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006098 TransArgs.setLAngleLoc(E->getLAngleLoc());
6099 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006100 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6101 E->getNumTemplateArgs(),
6102 TransArgs))
6103 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006104 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006105
Douglas Gregora16548e2009-08-11 05:31:07 +00006106 // FIXME: Bogus source location for the operator
6107 SourceLocation FakeOperatorLoc
6108 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6109
John McCall38836f02010-01-15 08:34:02 +00006110 // FIXME: to do this check properly, we will need to preserve the
6111 // first-qualifier-in-scope here, just in case we had a dependent
6112 // base (and therefore couldn't do the check) and a
6113 // nested-name-qualifier (and therefore could do the lookup).
6114 NamedDecl *FirstQualifierInScope = 0;
6115
John McCallb268a282010-08-23 23:25:46 +00006116 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006117 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006118 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006119 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006120 Member,
John McCall16df1e52010-03-30 21:47:33 +00006121 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006122 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006123 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006124 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006125}
Mike Stump11289f42009-09-09 15:08:12 +00006126
Douglas Gregora16548e2009-08-11 05:31:07 +00006127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006128ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006129TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006130 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006131 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006133
John McCalldadc5752010-08-24 06:29:42 +00006134 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006135 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006136 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006137
Douglas Gregora16548e2009-08-11 05:31:07 +00006138 if (!getDerived().AlwaysRebuild() &&
6139 LHS.get() == E->getLHS() &&
6140 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006141 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006142
Douglas Gregora16548e2009-08-11 05:31:07 +00006143 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006144 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006145}
6146
Mike Stump11289f42009-09-09 15:08:12 +00006147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006148ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006149TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006150 CompoundAssignOperator *E) {
6151 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006152}
Mike Stump11289f42009-09-09 15:08:12 +00006153
Douglas Gregora16548e2009-08-11 05:31:07 +00006154template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006155ExprResult TreeTransform<Derived>::
6156TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6157 // Just rebuild the common and RHS expressions and see whether we
6158 // get any changes.
6159
6160 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6161 if (commonExpr.isInvalid())
6162 return ExprError();
6163
6164 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6165 if (rhs.isInvalid())
6166 return ExprError();
6167
6168 if (!getDerived().AlwaysRebuild() &&
6169 commonExpr.get() == e->getCommon() &&
6170 rhs.get() == e->getFalseExpr())
6171 return SemaRef.Owned(e);
6172
6173 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6174 e->getQuestionLoc(),
6175 0,
6176 e->getColonLoc(),
6177 rhs.get());
6178}
6179
6180template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006181ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006182TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006183 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006184 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006185 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006186
John McCalldadc5752010-08-24 06:29:42 +00006187 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006188 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006189 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006190
John McCalldadc5752010-08-24 06:29:42 +00006191 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006192 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006193 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006194
Douglas Gregora16548e2009-08-11 05:31:07 +00006195 if (!getDerived().AlwaysRebuild() &&
6196 Cond.get() == E->getCond() &&
6197 LHS.get() == E->getLHS() &&
6198 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006199 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006200
John McCallb268a282010-08-23 23:25:46 +00006201 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006202 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006203 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006204 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006205 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006206}
Mike Stump11289f42009-09-09 15:08:12 +00006207
6208template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006209ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006210TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006211 // Implicit casts are eliminated during transformation, since they
6212 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006213 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006214}
Mike Stump11289f42009-09-09 15:08:12 +00006215
Douglas Gregora16548e2009-08-11 05:31:07 +00006216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006217ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006218TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006219 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6220 if (!Type)
6221 return ExprError();
6222
John McCalldadc5752010-08-24 06:29:42 +00006223 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006224 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006225 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006227
Douglas Gregora16548e2009-08-11 05:31:07 +00006228 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006229 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006230 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006231 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006232
John McCall97513962010-01-15 18:39:57 +00006233 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006234 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006235 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006236 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006237}
Mike Stump11289f42009-09-09 15:08:12 +00006238
Douglas Gregora16548e2009-08-11 05:31:07 +00006239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006240ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006241TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006242 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6243 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6244 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006245 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006246
John McCalldadc5752010-08-24 06:29:42 +00006247 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006248 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006249 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006250
Douglas Gregora16548e2009-08-11 05:31:07 +00006251 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006252 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006253 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006254 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006255
John McCall5d7aa7f2010-01-19 22:33:45 +00006256 // Note: the expression type doesn't necessarily match the
6257 // type-as-written, but that's okay, because it should always be
6258 // derivable from the initializer.
6259
John McCalle15bbff2010-01-18 19:35:47 +00006260 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006261 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006262 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006263}
Mike Stump11289f42009-09-09 15:08:12 +00006264
Douglas Gregora16548e2009-08-11 05:31:07 +00006265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006266ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006267TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006268 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006269 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006270 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006271
Douglas Gregora16548e2009-08-11 05:31:07 +00006272 if (!getDerived().AlwaysRebuild() &&
6273 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006274 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006275
Douglas Gregora16548e2009-08-11 05:31:07 +00006276 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006277 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006278 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006279 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006280 E->getAccessorLoc(),
6281 E->getAccessor());
6282}
Mike Stump11289f42009-09-09 15:08:12 +00006283
Douglas Gregora16548e2009-08-11 05:31:07 +00006284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006286TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006287 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006288
John McCall37ad5512010-08-23 06:44:23 +00006289 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006290 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6291 Inits, &InitChanged))
6292 return ExprError();
6293
Douglas Gregora16548e2009-08-11 05:31:07 +00006294 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006295 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006296
Douglas Gregora16548e2009-08-11 05:31:07 +00006297 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006298 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006299}
Mike Stump11289f42009-09-09 15:08:12 +00006300
Douglas Gregora16548e2009-08-11 05:31:07 +00006301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006302ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006303TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006304 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006305
Douglas Gregorebe10102009-08-20 07:17:43 +00006306 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006307 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006308 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006309 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006310
Douglas Gregorebe10102009-08-20 07:17:43 +00006311 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006312 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006313 bool ExprChanged = false;
6314 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6315 DEnd = E->designators_end();
6316 D != DEnd; ++D) {
6317 if (D->isFieldDesignator()) {
6318 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6319 D->getDotLoc(),
6320 D->getFieldLoc()));
6321 continue;
6322 }
Mike Stump11289f42009-09-09 15:08:12 +00006323
Douglas Gregora16548e2009-08-11 05:31:07 +00006324 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006325 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006326 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006327 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006328
6329 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006330 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006331
Douglas Gregora16548e2009-08-11 05:31:07 +00006332 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6333 ArrayExprs.push_back(Index.release());
6334 continue;
6335 }
Mike Stump11289f42009-09-09 15:08:12 +00006336
Douglas Gregora16548e2009-08-11 05:31:07 +00006337 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006338 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006339 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6340 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006341 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006342
John McCalldadc5752010-08-24 06:29:42 +00006343 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006344 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006345 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006346
6347 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006348 End.get(),
6349 D->getLBracketLoc(),
6350 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006351
Douglas Gregora16548e2009-08-11 05:31:07 +00006352 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6353 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006354
Douglas Gregora16548e2009-08-11 05:31:07 +00006355 ArrayExprs.push_back(Start.release());
6356 ArrayExprs.push_back(End.release());
6357 }
Mike Stump11289f42009-09-09 15:08:12 +00006358
Douglas Gregora16548e2009-08-11 05:31:07 +00006359 if (!getDerived().AlwaysRebuild() &&
6360 Init.get() == E->getInit() &&
6361 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006362 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006363
Douglas Gregora16548e2009-08-11 05:31:07 +00006364 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6365 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006366 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006367}
Mike Stump11289f42009-09-09 15:08:12 +00006368
Douglas Gregora16548e2009-08-11 05:31:07 +00006369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006370ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006371TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006372 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006373 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006374
Douglas Gregor3da3c062009-10-28 00:29:27 +00006375 // FIXME: Will we ever have proper type location here? Will we actually
6376 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006377 QualType T = getDerived().TransformType(E->getType());
6378 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006379 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006380
Douglas Gregora16548e2009-08-11 05:31:07 +00006381 if (!getDerived().AlwaysRebuild() &&
6382 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006383 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006384
Douglas Gregora16548e2009-08-11 05:31:07 +00006385 return getDerived().RebuildImplicitValueInitExpr(T);
6386}
Mike Stump11289f42009-09-09 15:08:12 +00006387
Douglas Gregora16548e2009-08-11 05:31:07 +00006388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006389ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006390TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006391 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6392 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006393 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006394
John McCalldadc5752010-08-24 06:29:42 +00006395 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006396 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006397 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006398
Douglas Gregora16548e2009-08-11 05:31:07 +00006399 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006400 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006401 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006402 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006403
John McCallb268a282010-08-23 23:25:46 +00006404 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006405 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006406}
6407
6408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006409ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006410TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006411 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006412 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006413 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6414 &ArgumentChanged))
6415 return ExprError();
6416
Douglas Gregora16548e2009-08-11 05:31:07 +00006417 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6418 move_arg(Inits),
6419 E->getRParenLoc());
6420}
Mike Stump11289f42009-09-09 15:08:12 +00006421
Douglas Gregora16548e2009-08-11 05:31:07 +00006422/// \brief Transform an address-of-label expression.
6423///
6424/// By default, the transformation of an address-of-label expression always
6425/// rebuilds the expression, so that the label identifier can be resolved to
6426/// the corresponding label statement by semantic analysis.
6427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006428ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006429TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006430 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6431 E->getLabel());
6432 if (!LD)
6433 return ExprError();
6434
Douglas Gregora16548e2009-08-11 05:31:07 +00006435 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006436 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006437}
Mike Stump11289f42009-09-09 15:08:12 +00006438
6439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006440ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006441TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006442 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006443 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6444 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006445 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006446
Douglas Gregora16548e2009-08-11 05:31:07 +00006447 if (!getDerived().AlwaysRebuild() &&
6448 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006449 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006450
6451 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006452 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006453 E->getRParenLoc());
6454}
Mike Stump11289f42009-09-09 15:08:12 +00006455
Douglas Gregora16548e2009-08-11 05:31:07 +00006456template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006457ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006458TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006459 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006460 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006461 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006462
John McCalldadc5752010-08-24 06:29:42 +00006463 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006464 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006465 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006466
John McCalldadc5752010-08-24 06:29:42 +00006467 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006468 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006469 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006470
Douglas Gregora16548e2009-08-11 05:31:07 +00006471 if (!getDerived().AlwaysRebuild() &&
6472 Cond.get() == E->getCond() &&
6473 LHS.get() == E->getLHS() &&
6474 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006475 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006476
Douglas Gregora16548e2009-08-11 05:31:07 +00006477 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006478 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006479 E->getRParenLoc());
6480}
Mike Stump11289f42009-09-09 15:08:12 +00006481
Douglas Gregora16548e2009-08-11 05:31:07 +00006482template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006483ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006484TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006485 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006486}
6487
6488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006489ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006490TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006491 switch (E->getOperator()) {
6492 case OO_New:
6493 case OO_Delete:
6494 case OO_Array_New:
6495 case OO_Array_Delete:
6496 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006497 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006498
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006499 case OO_Call: {
6500 // This is a call to an object's operator().
6501 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6502
6503 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006504 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006505 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006506 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006507
6508 // FIXME: Poor location information
6509 SourceLocation FakeLParenLoc
6510 = SemaRef.PP.getLocForEndOfToken(
6511 static_cast<Expr *>(Object.get())->getLocEnd());
6512
6513 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006514 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006515 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6516 Args))
6517 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006518
John McCallb268a282010-08-23 23:25:46 +00006519 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006520 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006521 E->getLocEnd());
6522 }
6523
6524#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6525 case OO_##Name:
6526#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6527#include "clang/Basic/OperatorKinds.def"
6528 case OO_Subscript:
6529 // Handled below.
6530 break;
6531
6532 case OO_Conditional:
6533 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006534 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006535
6536 case OO_None:
6537 case NUM_OVERLOADED_OPERATORS:
6538 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006539 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006540 }
6541
John McCalldadc5752010-08-24 06:29:42 +00006542 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006543 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006544 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006545
John McCalldadc5752010-08-24 06:29:42 +00006546 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006547 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006548 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006549
John McCalldadc5752010-08-24 06:29:42 +00006550 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006551 if (E->getNumArgs() == 2) {
6552 Second = getDerived().TransformExpr(E->getArg(1));
6553 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006554 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006555 }
Mike Stump11289f42009-09-09 15:08:12 +00006556
Douglas Gregora16548e2009-08-11 05:31:07 +00006557 if (!getDerived().AlwaysRebuild() &&
6558 Callee.get() == E->getCallee() &&
6559 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006560 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006561 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006562
Douglas Gregora16548e2009-08-11 05:31:07 +00006563 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6564 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006565 Callee.get(),
6566 First.get(),
6567 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006568}
Mike Stump11289f42009-09-09 15:08:12 +00006569
Douglas Gregora16548e2009-08-11 05:31:07 +00006570template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006571ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006572TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6573 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006574}
Mike Stump11289f42009-09-09 15:08:12 +00006575
Douglas Gregora16548e2009-08-11 05:31:07 +00006576template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006577ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006578TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6579 // Transform the callee.
6580 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6581 if (Callee.isInvalid())
6582 return ExprError();
6583
6584 // Transform exec config.
6585 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6586 if (EC.isInvalid())
6587 return ExprError();
6588
6589 // Transform arguments.
6590 bool ArgChanged = false;
6591 ASTOwningVector<Expr*> Args(SemaRef);
6592 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6593 &ArgChanged))
6594 return ExprError();
6595
6596 if (!getDerived().AlwaysRebuild() &&
6597 Callee.get() == E->getCallee() &&
6598 !ArgChanged)
6599 return SemaRef.Owned(E);
6600
6601 // FIXME: Wrong source location information for the '('.
6602 SourceLocation FakeLParenLoc
6603 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6604 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6605 move_arg(Args),
6606 E->getRParenLoc(), EC.get());
6607}
6608
6609template<typename Derived>
6610ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006611TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006612 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6613 if (!Type)
6614 return ExprError();
6615
John McCalldadc5752010-08-24 06:29:42 +00006616 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006617 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006618 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006619 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006620
Douglas Gregora16548e2009-08-11 05:31:07 +00006621 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006622 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006623 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006624 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006625
Douglas Gregora16548e2009-08-11 05:31:07 +00006626 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006627 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006628 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6629 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6630 SourceLocation FakeRParenLoc
6631 = SemaRef.PP.getLocForEndOfToken(
6632 E->getSubExpr()->getSourceRange().getEnd());
6633 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006634 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006635 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006636 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006637 FakeRAngleLoc,
6638 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006639 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006640 FakeRParenLoc);
6641}
Mike Stump11289f42009-09-09 15:08:12 +00006642
Douglas Gregora16548e2009-08-11 05:31:07 +00006643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006644ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006645TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6646 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006647}
Mike Stump11289f42009-09-09 15:08:12 +00006648
6649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006650ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006651TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6652 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006653}
6654
Douglas Gregora16548e2009-08-11 05:31:07 +00006655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006656ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006657TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006658 CXXReinterpretCastExpr *E) {
6659 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006660}
Mike Stump11289f42009-09-09 15:08:12 +00006661
Douglas Gregora16548e2009-08-11 05:31:07 +00006662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006663ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006664TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6665 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006666}
Mike Stump11289f42009-09-09 15:08:12 +00006667
Douglas Gregora16548e2009-08-11 05:31:07 +00006668template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006669ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006670TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006671 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006672 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6673 if (!Type)
6674 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006675
John McCalldadc5752010-08-24 06:29:42 +00006676 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006677 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006678 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006679 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006680
Douglas Gregora16548e2009-08-11 05:31:07 +00006681 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006682 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006683 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006684 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006685
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006686 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006687 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006688 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006689 E->getRParenLoc());
6690}
Mike Stump11289f42009-09-09 15:08:12 +00006691
Douglas Gregora16548e2009-08-11 05:31:07 +00006692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006694TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006695 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006696 TypeSourceInfo *TInfo
6697 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6698 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006699 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006700
Douglas Gregora16548e2009-08-11 05:31:07 +00006701 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006702 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006703 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006704
Douglas Gregor9da64192010-04-26 22:37:10 +00006705 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6706 E->getLocStart(),
6707 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006708 E->getLocEnd());
6709 }
Mike Stump11289f42009-09-09 15:08:12 +00006710
Douglas Gregora16548e2009-08-11 05:31:07 +00006711 // We don't know whether the expression is potentially evaluated until
6712 // after we perform semantic analysis, so the expression is potentially
6713 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006714 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006715 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006716
John McCalldadc5752010-08-24 06:29:42 +00006717 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006718 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006719 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006720
Douglas Gregora16548e2009-08-11 05:31:07 +00006721 if (!getDerived().AlwaysRebuild() &&
6722 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006723 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006724
Douglas Gregor9da64192010-04-26 22:37:10 +00006725 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6726 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006727 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006728 E->getLocEnd());
6729}
6730
6731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006732ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006733TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6734 if (E->isTypeOperand()) {
6735 TypeSourceInfo *TInfo
6736 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6737 if (!TInfo)
6738 return ExprError();
6739
6740 if (!getDerived().AlwaysRebuild() &&
6741 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006742 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006743
Douglas Gregor69735112011-03-06 17:40:41 +00006744 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006745 E->getLocStart(),
6746 TInfo,
6747 E->getLocEnd());
6748 }
6749
6750 // We don't know whether the expression is potentially evaluated until
6751 // after we perform semantic analysis, so the expression is potentially
6752 // potentially evaluated.
6753 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6754
6755 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6756 if (SubExpr.isInvalid())
6757 return ExprError();
6758
6759 if (!getDerived().AlwaysRebuild() &&
6760 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006761 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006762
6763 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6764 E->getLocStart(),
6765 SubExpr.get(),
6766 E->getLocEnd());
6767}
6768
6769template<typename Derived>
6770ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006771TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006772 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006773}
Mike Stump11289f42009-09-09 15:08:12 +00006774
Douglas Gregora16548e2009-08-11 05:31:07 +00006775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006776ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006777TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006778 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006779 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006780}
Mike Stump11289f42009-09-09 15:08:12 +00006781
Douglas Gregora16548e2009-08-11 05:31:07 +00006782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006783ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006784TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006785 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith938f40b2011-06-11 17:19:42 +00006786 QualType T;
6787 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6788 T = MD->getThisType(getSema().Context);
6789 else
6790 T = getSema().Context.getPointerType(
6791 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump11289f42009-09-09 15:08:12 +00006792
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006793 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006794 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006795
Douglas Gregorb15af892010-01-07 23:12:05 +00006796 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006797}
Mike Stump11289f42009-09-09 15:08:12 +00006798
Douglas Gregora16548e2009-08-11 05:31:07 +00006799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006800ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006801TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006802 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006803 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006804 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006805
Douglas Gregora16548e2009-08-11 05:31:07 +00006806 if (!getDerived().AlwaysRebuild() &&
6807 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006808 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006809
Douglas Gregor53e191ed2011-07-06 22:04:06 +00006810 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6811 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00006812}
Mike Stump11289f42009-09-09 15:08:12 +00006813
Douglas Gregora16548e2009-08-11 05:31:07 +00006814template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006815ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006816TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006817 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006818 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6819 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006820 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006821 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006822
Chandler Carruth794da4c2010-02-08 06:42:49 +00006823 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006824 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006825 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006826
Douglas Gregor033f6752009-12-23 23:03:06 +00006827 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006828}
Mike Stump11289f42009-09-09 15:08:12 +00006829
Douglas Gregora16548e2009-08-11 05:31:07 +00006830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006831ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006832TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6833 CXXScalarValueInitExpr *E) {
6834 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6835 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006836 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006837
Douglas Gregora16548e2009-08-11 05:31:07 +00006838 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006839 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006840 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006841
Douglas Gregor2b88c112010-09-08 00:15:04 +00006842 return getDerived().RebuildCXXScalarValueInitExpr(T,
6843 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006844 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006845}
Mike Stump11289f42009-09-09 15:08:12 +00006846
Douglas Gregora16548e2009-08-11 05:31:07 +00006847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006848ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006849TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006850 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006851 TypeSourceInfo *AllocTypeInfo
6852 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6853 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006854 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006855
Douglas Gregora16548e2009-08-11 05:31:07 +00006856 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006857 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006858 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006859 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006860
Douglas Gregora16548e2009-08-11 05:31:07 +00006861 // Transform the placement arguments (if any).
6862 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006863 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006864 if (getDerived().TransformExprs(E->getPlacementArgs(),
6865 E->getNumPlacementArgs(), true,
6866 PlacementArgs, &ArgumentChanged))
6867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006868
Douglas Gregorebe10102009-08-20 07:17:43 +00006869 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006870 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006871 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6872 ConstructorArgs, &ArgumentChanged))
6873 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006874
Douglas Gregord2d9da02010-02-26 00:38:10 +00006875 // Transform constructor, new operator, and delete operator.
6876 CXXConstructorDecl *Constructor = 0;
6877 if (E->getConstructor()) {
6878 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006879 getDerived().TransformDecl(E->getLocStart(),
6880 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006881 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006882 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006883 }
6884
6885 FunctionDecl *OperatorNew = 0;
6886 if (E->getOperatorNew()) {
6887 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006888 getDerived().TransformDecl(E->getLocStart(),
6889 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006890 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006891 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006892 }
6893
6894 FunctionDecl *OperatorDelete = 0;
6895 if (E->getOperatorDelete()) {
6896 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006897 getDerived().TransformDecl(E->getLocStart(),
6898 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006899 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006900 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006901 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006902
Douglas Gregora16548e2009-08-11 05:31:07 +00006903 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006904 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006905 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006906 Constructor == E->getConstructor() &&
6907 OperatorNew == E->getOperatorNew() &&
6908 OperatorDelete == E->getOperatorDelete() &&
6909 !ArgumentChanged) {
6910 // Mark any declarations we need as referenced.
6911 // FIXME: instantiation-specific.
6912 if (Constructor)
6913 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6914 if (OperatorNew)
6915 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6916 if (OperatorDelete)
6917 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor72912fb2011-07-26 15:11:03 +00006918
6919 if (E->isArray() && Constructor &&
6920 !E->getAllocatedType()->isDependentType()) {
6921 QualType ElementType
6922 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
6923 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
6924 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
6925 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
6926 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
6927 }
6928 }
6929 }
6930
John McCallc3007a22010-10-26 07:05:15 +00006931 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006932 }
Mike Stump11289f42009-09-09 15:08:12 +00006933
Douglas Gregor0744ef62010-09-07 21:49:58 +00006934 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006935 if (!ArraySize.get()) {
6936 // If no array size was specified, but the new expression was
6937 // instantiated with an array type (e.g., "new T" where T is
6938 // instantiated with "int[4]"), extract the outer bound from the
6939 // array type as our array size. We do this with constant and
6940 // dependently-sized array types.
6941 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6942 if (!ArrayT) {
6943 // Do nothing
6944 } else if (const ConstantArrayType *ConsArrayT
6945 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006946 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006947 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6948 ConsArrayT->getSize(),
6949 SemaRef.Context.getSizeType(),
6950 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006951 AllocType = ConsArrayT->getElementType();
6952 } else if (const DependentSizedArrayType *DepArrayT
6953 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6954 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006955 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006956 AllocType = DepArrayT->getElementType();
6957 }
6958 }
6959 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006960
Douglas Gregora16548e2009-08-11 05:31:07 +00006961 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6962 E->isGlobalNew(),
6963 /*FIXME:*/E->getLocStart(),
6964 move_arg(PlacementArgs),
6965 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006966 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006967 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006968 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006969 ArraySize.get(),
Douglas Gregor3bdcff52011-06-27 16:55:54 +00006970 /*FIXME:*/E->hasInitializer()
6971 ? E->getLocStart()
6972 : SourceLocation(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006973 move_arg(ConstructorArgs),
Douglas Gregor3bdcff52011-06-27 16:55:54 +00006974 /*FIXME:*/E->hasInitializer()
6975 ? E->getLocEnd()
6976 : SourceLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006977}
Mike Stump11289f42009-09-09 15:08:12 +00006978
Douglas Gregora16548e2009-08-11 05:31:07 +00006979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006980ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006981TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006982 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006983 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006984 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006985
Douglas Gregord2d9da02010-02-26 00:38:10 +00006986 // Transform the delete operator, if known.
6987 FunctionDecl *OperatorDelete = 0;
6988 if (E->getOperatorDelete()) {
6989 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006990 getDerived().TransformDecl(E->getLocStart(),
6991 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006992 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006993 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006994 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006995
Douglas Gregora16548e2009-08-11 05:31:07 +00006996 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006997 Operand.get() == E->getArgument() &&
6998 OperatorDelete == E->getOperatorDelete()) {
6999 // Mark any declarations we need as referenced.
7000 // FIXME: instantiation-specific.
7001 if (OperatorDelete)
7002 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007003
7004 if (!E->getArgument()->isTypeDependent()) {
7005 QualType Destroyed = SemaRef.Context.getBaseElementType(
7006 E->getDestroyedType());
7007 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7008 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7009 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7010 SemaRef.LookupDestructor(Record));
7011 }
7012 }
7013
John McCallc3007a22010-10-26 07:05:15 +00007014 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007015 }
Mike Stump11289f42009-09-09 15:08:12 +00007016
Douglas Gregora16548e2009-08-11 05:31:07 +00007017 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7018 E->isGlobalDelete(),
7019 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007020 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007021}
Mike Stump11289f42009-09-09 15:08:12 +00007022
Douglas Gregora16548e2009-08-11 05:31:07 +00007023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007024ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007025TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007026 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007027 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007028 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007029 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007030
John McCallba7bf592010-08-24 05:47:05 +00007031 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007032 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007033 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007034 E->getOperatorLoc(),
7035 E->isArrow()? tok::arrow : tok::period,
7036 ObjectTypePtr,
7037 MayBePseudoDestructor);
7038 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007039 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007040
John McCallba7bf592010-08-24 05:47:05 +00007041 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007042 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7043 if (QualifierLoc) {
7044 QualifierLoc
7045 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7046 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007047 return ExprError();
7048 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007049 CXXScopeSpec SS;
7050 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007051
Douglas Gregor678f90d2010-02-25 01:56:36 +00007052 PseudoDestructorTypeStorage Destroyed;
7053 if (E->getDestroyedTypeInfo()) {
7054 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007055 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007056 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007057 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007058 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007059 Destroyed = DestroyedTypeInfo;
7060 } else if (ObjectType->isDependentType()) {
7061 // We aren't likely to be able to resolve the identifier down to a type
7062 // now anyway, so just retain the identifier.
7063 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7064 E->getDestroyedTypeLoc());
7065 } else {
7066 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007067 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007068 *E->getDestroyedTypeIdentifier(),
7069 E->getDestroyedTypeLoc(),
7070 /*Scope=*/0,
7071 SS, ObjectTypePtr,
7072 false);
7073 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007074 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007075
Douglas Gregor678f90d2010-02-25 01:56:36 +00007076 Destroyed
7077 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7078 E->getDestroyedTypeLoc());
7079 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007080
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007081 TypeSourceInfo *ScopeTypeInfo = 0;
7082 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00007083 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007084 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007085 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007086 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007087
John McCallb268a282010-08-23 23:25:46 +00007088 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007089 E->getOperatorLoc(),
7090 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007091 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007092 ScopeTypeInfo,
7093 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007094 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007095 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007096}
Mike Stump11289f42009-09-09 15:08:12 +00007097
Douglas Gregorad8a3362009-09-04 17:36:40 +00007098template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007099ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007100TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007101 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007102 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7103 Sema::LookupOrdinaryName);
7104
7105 // Transform all the decls.
7106 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7107 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007108 NamedDecl *InstD = static_cast<NamedDecl*>(
7109 getDerived().TransformDecl(Old->getNameLoc(),
7110 *I));
John McCall84d87672009-12-10 09:41:52 +00007111 if (!InstD) {
7112 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7113 // This can happen because of dependent hiding.
7114 if (isa<UsingShadowDecl>(*I))
7115 continue;
7116 else
John McCallfaf5fb42010-08-26 23:41:50 +00007117 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007118 }
John McCalle66edc12009-11-24 19:00:30 +00007119
7120 // Expand using declarations.
7121 if (isa<UsingDecl>(InstD)) {
7122 UsingDecl *UD = cast<UsingDecl>(InstD);
7123 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7124 E = UD->shadow_end(); I != E; ++I)
7125 R.addDecl(*I);
7126 continue;
7127 }
7128
7129 R.addDecl(InstD);
7130 }
7131
7132 // Resolve a kind, but don't do any further analysis. If it's
7133 // ambiguous, the callee needs to deal with it.
7134 R.resolveKind();
7135
7136 // Rebuild the nested-name qualifier, if present.
7137 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007138 if (Old->getQualifierLoc()) {
7139 NestedNameSpecifierLoc QualifierLoc
7140 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7141 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007142 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007143
Douglas Gregor0da1d432011-02-28 20:01:57 +00007144 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007145 }
7146
Douglas Gregor9262f472010-04-27 18:19:34 +00007147 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007148 CXXRecordDecl *NamingClass
7149 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7150 Old->getNameLoc(),
7151 Old->getNamingClass()));
7152 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007153 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007154
Douglas Gregorda7be082010-04-27 16:10:10 +00007155 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007156 }
7157
7158 // If we have no template arguments, it's a normal declaration name.
7159 if (!Old->hasExplicitTemplateArgs())
7160 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7161
7162 // If we have template arguments, rebuild them, then rebuild the
7163 // templateid expression.
7164 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007165 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7166 Old->getNumTemplateArgs(),
7167 TransArgs))
7168 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007169
7170 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7171 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007172}
Mike Stump11289f42009-09-09 15:08:12 +00007173
Douglas Gregora16548e2009-08-11 05:31:07 +00007174template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007175ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007176TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007177 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7178 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007179 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007180
Douglas Gregora16548e2009-08-11 05:31:07 +00007181 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007182 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007183 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007184
Mike Stump11289f42009-09-09 15:08:12 +00007185 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007186 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007187 T,
7188 E->getLocEnd());
7189}
Mike Stump11289f42009-09-09 15:08:12 +00007190
Douglas Gregora16548e2009-08-11 05:31:07 +00007191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007192ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007193TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7194 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7195 if (!LhsT)
7196 return ExprError();
7197
7198 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7199 if (!RhsT)
7200 return ExprError();
7201
7202 if (!getDerived().AlwaysRebuild() &&
7203 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7204 return SemaRef.Owned(E);
7205
7206 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7207 E->getLocStart(),
7208 LhsT, RhsT,
7209 E->getLocEnd());
7210}
7211
7212template<typename Derived>
7213ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007214TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7215 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7216 if (!T)
7217 return ExprError();
7218
7219 if (!getDerived().AlwaysRebuild() &&
7220 T == E->getQueriedTypeSourceInfo())
7221 return SemaRef.Owned(E);
7222
7223 ExprResult SubExpr;
7224 {
7225 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7226 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7227 if (SubExpr.isInvalid())
7228 return ExprError();
7229
7230 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7231 return SemaRef.Owned(E);
7232 }
7233
7234 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7235 E->getLocStart(),
7236 T,
7237 SubExpr.get(),
7238 E->getLocEnd());
7239}
7240
7241template<typename Derived>
7242ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007243TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7244 ExprResult SubExpr;
7245 {
7246 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7247 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7248 if (SubExpr.isInvalid())
7249 return ExprError();
7250
7251 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7252 return SemaRef.Owned(E);
7253 }
7254
7255 return getDerived().RebuildExpressionTrait(
7256 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7257}
7258
7259template<typename Derived>
7260ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007261TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007262 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007263 NestedNameSpecifierLoc QualifierLoc
7264 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7265 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007266 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007267
John McCall31f82722010-11-12 08:19:04 +00007268 // TODO: If this is a conversion-function-id, verify that the
7269 // destination type name (if present) resolves the same way after
7270 // instantiation as it did in the local scope.
7271
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007272 DeclarationNameInfo NameInfo
7273 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7274 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007275 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007276
John McCalle66edc12009-11-24 19:00:30 +00007277 if (!E->hasExplicitTemplateArgs()) {
7278 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007279 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007280 // Note: it is sufficient to compare the Name component of NameInfo:
7281 // if name has not changed, DNLoc has not changed either.
7282 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007283 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007284
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007285 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007286 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007287 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007288 }
John McCall6b51f282009-11-23 01:53:49 +00007289
7290 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007291 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7292 E->getNumTemplateArgs(),
7293 TransArgs))
7294 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007295
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007296 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007297 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007298 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007299}
7300
7301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007302ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007303TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007304 // CXXConstructExprs are always implicit, so when we have a
7305 // 1-argument construction we just transform that argument.
7306 if (E->getNumArgs() == 1 ||
7307 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7308 return getDerived().TransformExpr(E->getArg(0));
7309
Douglas Gregora16548e2009-08-11 05:31:07 +00007310 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7311
7312 QualType T = getDerived().TransformType(E->getType());
7313 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007314 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007315
7316 CXXConstructorDecl *Constructor
7317 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007318 getDerived().TransformDecl(E->getLocStart(),
7319 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007320 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007321 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007322
Douglas Gregora16548e2009-08-11 05:31:07 +00007323 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007324 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007325 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7326 &ArgumentChanged))
7327 return ExprError();
7328
Douglas Gregora16548e2009-08-11 05:31:07 +00007329 if (!getDerived().AlwaysRebuild() &&
7330 T == E->getType() &&
7331 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007332 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007333 // Mark the constructor as referenced.
7334 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007335 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007336 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007337 }
Mike Stump11289f42009-09-09 15:08:12 +00007338
Douglas Gregordb121ba2009-12-14 16:27:04 +00007339 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7340 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007341 move_arg(Args),
7342 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007343 E->getConstructionKind(),
7344 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007345}
Mike Stump11289f42009-09-09 15:08:12 +00007346
Douglas Gregora16548e2009-08-11 05:31:07 +00007347/// \brief Transform a C++ temporary-binding expression.
7348///
Douglas Gregor363b1512009-12-24 18:51:59 +00007349/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7350/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007351template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007352ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007353TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007354 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007355}
Mike Stump11289f42009-09-09 15:08:12 +00007356
John McCall5d413782010-12-06 08:20:24 +00007357/// \brief Transform a C++ expression that contains cleanups that should
7358/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007359///
John McCall5d413782010-12-06 08:20:24 +00007360/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007361/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007363ExprResult
John McCall5d413782010-12-06 08:20:24 +00007364TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007365 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007366}
Mike Stump11289f42009-09-09 15:08:12 +00007367
Douglas Gregora16548e2009-08-11 05:31:07 +00007368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007369ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007370TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007371 CXXTemporaryObjectExpr *E) {
7372 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7373 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007374 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007375
Douglas Gregora16548e2009-08-11 05:31:07 +00007376 CXXConstructorDecl *Constructor
7377 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007378 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007379 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007380 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007381 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007382
Douglas Gregora16548e2009-08-11 05:31:07 +00007383 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007384 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007385 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007386 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7387 &ArgumentChanged))
7388 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007389
Douglas Gregora16548e2009-08-11 05:31:07 +00007390 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007391 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007392 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007393 !ArgumentChanged) {
7394 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007395 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007396 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007397 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007398
7399 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7400 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007401 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007402 E->getLocEnd());
7403}
Mike Stump11289f42009-09-09 15:08:12 +00007404
Douglas Gregora16548e2009-08-11 05:31:07 +00007405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007406ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007407TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007408 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007409 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7410 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007411 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007412
Douglas Gregora16548e2009-08-11 05:31:07 +00007413 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007414 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007415 Args.reserve(E->arg_size());
7416 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7417 &ArgumentChanged))
7418 return ExprError();
7419
Douglas Gregora16548e2009-08-11 05:31:07 +00007420 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007421 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007422 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007423 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007424
Douglas Gregora16548e2009-08-11 05:31:07 +00007425 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007426 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007427 E->getLParenLoc(),
7428 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007429 E->getRParenLoc());
7430}
Mike Stump11289f42009-09-09 15:08:12 +00007431
Douglas Gregora16548e2009-08-11 05:31:07 +00007432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007433ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007434TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007435 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007436 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007437 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007438 Expr *OldBase;
7439 QualType BaseType;
7440 QualType ObjectType;
7441 if (!E->isImplicitAccess()) {
7442 OldBase = E->getBase();
7443 Base = getDerived().TransformExpr(OldBase);
7444 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007445 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007446
John McCall2d74de92009-12-01 22:10:20 +00007447 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007448 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007449 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007450 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007451 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007452 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007453 ObjectTy,
7454 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007455 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007456 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007457
John McCallba7bf592010-08-24 05:47:05 +00007458 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007459 BaseType = ((Expr*) Base.get())->getType();
7460 } else {
7461 OldBase = 0;
7462 BaseType = getDerived().TransformType(E->getBaseType());
7463 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7464 }
Mike Stump11289f42009-09-09 15:08:12 +00007465
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007466 // Transform the first part of the nested-name-specifier that qualifies
7467 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007468 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007469 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007470 E->getFirstQualifierFoundInScope(),
7471 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007472
Douglas Gregore16af532011-02-28 18:50:33 +00007473 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007474 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007475 QualifierLoc
7476 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7477 ObjectType,
7478 FirstQualifierInScope);
7479 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007480 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007481 }
Mike Stump11289f42009-09-09 15:08:12 +00007482
John McCall31f82722010-11-12 08:19:04 +00007483 // TODO: If this is a conversion-function-id, verify that the
7484 // destination type name (if present) resolves the same way after
7485 // instantiation as it did in the local scope.
7486
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007487 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007488 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007489 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007490 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007491
John McCall2d74de92009-12-01 22:10:20 +00007492 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007493 // This is a reference to a member without an explicitly-specified
7494 // template argument list. Optimize for this common case.
7495 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007496 Base.get() == OldBase &&
7497 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007498 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007499 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007500 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007501 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007502
John McCallb268a282010-08-23 23:25:46 +00007503 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007504 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007505 E->isArrow(),
7506 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007507 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007508 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007509 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007510 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007511 }
7512
John McCall6b51f282009-11-23 01:53:49 +00007513 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007514 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7515 E->getNumTemplateArgs(),
7516 TransArgs))
7517 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007518
John McCallb268a282010-08-23 23:25:46 +00007519 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007520 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007521 E->isArrow(),
7522 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007523 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007524 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007525 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007526 &TransArgs);
7527}
7528
7529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007530ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007531TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007532 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007533 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007534 QualType BaseType;
7535 if (!Old->isImplicitAccess()) {
7536 Base = getDerived().TransformExpr(Old->getBase());
7537 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007538 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007539 BaseType = ((Expr*) Base.get())->getType();
7540 } else {
7541 BaseType = getDerived().TransformType(Old->getBaseType());
7542 }
John McCall10eae182009-11-30 22:42:35 +00007543
Douglas Gregor0da1d432011-02-28 20:01:57 +00007544 NestedNameSpecifierLoc QualifierLoc;
7545 if (Old->getQualifierLoc()) {
7546 QualifierLoc
7547 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7548 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007549 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007550 }
7551
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007552 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007553 Sema::LookupOrdinaryName);
7554
7555 // Transform all the decls.
7556 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7557 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007558 NamedDecl *InstD = static_cast<NamedDecl*>(
7559 getDerived().TransformDecl(Old->getMemberLoc(),
7560 *I));
John McCall84d87672009-12-10 09:41:52 +00007561 if (!InstD) {
7562 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7563 // This can happen because of dependent hiding.
7564 if (isa<UsingShadowDecl>(*I))
7565 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007566 else {
7567 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007568 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007569 }
John McCall84d87672009-12-10 09:41:52 +00007570 }
John McCall10eae182009-11-30 22:42:35 +00007571
7572 // Expand using declarations.
7573 if (isa<UsingDecl>(InstD)) {
7574 UsingDecl *UD = cast<UsingDecl>(InstD);
7575 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7576 E = UD->shadow_end(); I != E; ++I)
7577 R.addDecl(*I);
7578 continue;
7579 }
7580
7581 R.addDecl(InstD);
7582 }
7583
7584 R.resolveKind();
7585
Douglas Gregor9262f472010-04-27 18:19:34 +00007586 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007587 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007588 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007589 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007590 Old->getMemberLoc(),
7591 Old->getNamingClass()));
7592 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007593 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007594
Douglas Gregorda7be082010-04-27 16:10:10 +00007595 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007596 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007597
John McCall10eae182009-11-30 22:42:35 +00007598 TemplateArgumentListInfo TransArgs;
7599 if (Old->hasExplicitTemplateArgs()) {
7600 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7601 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007602 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7603 Old->getNumTemplateArgs(),
7604 TransArgs))
7605 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007606 }
John McCall38836f02010-01-15 08:34:02 +00007607
7608 // FIXME: to do this check properly, we will need to preserve the
7609 // first-qualifier-in-scope here, just in case we had a dependent
7610 // base (and therefore couldn't do the check) and a
7611 // nested-name-qualifier (and therefore could do the lookup).
7612 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007613
John McCallb268a282010-08-23 23:25:46 +00007614 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007615 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007616 Old->getOperatorLoc(),
7617 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007618 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007619 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007620 R,
7621 (Old->hasExplicitTemplateArgs()
7622 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007623}
7624
7625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007626ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007627TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00007628 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007629 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7630 if (SubExpr.isInvalid())
7631 return ExprError();
7632
7633 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007634 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007635
7636 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7637}
7638
7639template<typename Derived>
7640ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007641TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007642 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7643 if (Pattern.isInvalid())
7644 return ExprError();
7645
7646 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7647 return SemaRef.Owned(E);
7648
Douglas Gregorb8840002011-01-14 21:20:45 +00007649 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7650 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007651}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007652
7653template<typename Derived>
7654ExprResult
7655TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7656 // If E is not value-dependent, then nothing will change when we transform it.
7657 // Note: This is an instantiation-centric view.
7658 if (!E->isValueDependent())
7659 return SemaRef.Owned(E);
7660
7661 // Note: None of the implementations of TryExpandParameterPacks can ever
7662 // produce a diagnostic when given only a single unexpanded parameter pack,
7663 // so
7664 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7665 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007666 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007667 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007668 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7669 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007670 ShouldExpand, RetainExpansion,
7671 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007672 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007673
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007674 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007675 return SemaRef.Owned(E);
7676
7677 // We now know the length of the parameter pack, so build a new expression
7678 // that stores that length.
7679 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7680 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007681 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007682}
7683
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007684template<typename Derived>
7685ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007686TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7687 SubstNonTypeTemplateParmPackExpr *E) {
7688 // Default behavior is to do nothing with this transformation.
7689 return SemaRef.Owned(E);
7690}
7691
7692template<typename Derived>
7693ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00007694TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7695 SubstNonTypeTemplateParmExpr *E) {
7696 // Default behavior is to do nothing with this transformation.
7697 return SemaRef.Owned(E);
7698}
7699
7700template<typename Derived>
7701ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00007702TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7703 MaterializeTemporaryExpr *E) {
7704 return getDerived().TransformExpr(E->GetTemporaryExpr());
7705}
7706
7707template<typename Derived>
7708ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007709TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007710 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007711}
7712
Mike Stump11289f42009-09-09 15:08:12 +00007713template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007714ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007715TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007716 TypeSourceInfo *EncodedTypeInfo
7717 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7718 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007719 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007720
Douglas Gregora16548e2009-08-11 05:31:07 +00007721 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007722 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007723 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007724
7725 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007726 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007727 E->getRParenLoc());
7728}
Mike Stump11289f42009-09-09 15:08:12 +00007729
Douglas Gregora16548e2009-08-11 05:31:07 +00007730template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00007731ExprResult TreeTransform<Derived>::
7732TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7733 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7734 if (result.isInvalid()) return ExprError();
7735 Expr *subExpr = result.take();
7736
7737 if (!getDerived().AlwaysRebuild() &&
7738 subExpr == E->getSubExpr())
7739 return SemaRef.Owned(E);
7740
7741 return SemaRef.Owned(new(SemaRef.Context)
7742 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7743}
7744
7745template<typename Derived>
7746ExprResult TreeTransform<Derived>::
7747TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7748 TypeSourceInfo *TSInfo
7749 = getDerived().TransformType(E->getTypeInfoAsWritten());
7750 if (!TSInfo)
7751 return ExprError();
7752
7753 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7754 if (Result.isInvalid())
7755 return ExprError();
7756
7757 if (!getDerived().AlwaysRebuild() &&
7758 TSInfo == E->getTypeInfoAsWritten() &&
7759 Result.get() == E->getSubExpr())
7760 return SemaRef.Owned(E);
7761
7762 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7763 E->getBridgeKeywordLoc(), TSInfo,
7764 Result.get());
7765}
7766
7767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007768ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007769TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007770 // Transform arguments.
7771 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007772 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007773 Args.reserve(E->getNumArgs());
7774 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7775 &ArgChanged))
7776 return ExprError();
7777
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007778 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7779 // Class message: transform the receiver type.
7780 TypeSourceInfo *ReceiverTypeInfo
7781 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7782 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007783 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007784
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007785 // If nothing changed, just retain the existing message send.
7786 if (!getDerived().AlwaysRebuild() &&
7787 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007788 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007789
7790 // Build a new class message send.
7791 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7792 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007793 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007794 E->getMethodDecl(),
7795 E->getLeftLoc(),
7796 move_arg(Args),
7797 E->getRightLoc());
7798 }
7799
7800 // Instance message: transform the receiver
7801 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7802 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007803 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007804 = getDerived().TransformExpr(E->getInstanceReceiver());
7805 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007806 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007807
7808 // If nothing changed, just retain the existing message send.
7809 if (!getDerived().AlwaysRebuild() &&
7810 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007811 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007812
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007813 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007814 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007815 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007816 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007817 E->getMethodDecl(),
7818 E->getLeftLoc(),
7819 move_arg(Args),
7820 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007821}
7822
Mike Stump11289f42009-09-09 15:08:12 +00007823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007824ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007825TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007826 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007827}
7828
Mike Stump11289f42009-09-09 15:08:12 +00007829template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007830ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007831TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007832 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007833}
7834
Mike Stump11289f42009-09-09 15:08:12 +00007835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007836ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007837TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007838 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007839 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007840 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007841 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007842
7843 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007844
Douglas Gregord51d90d2010-04-26 20:11:03 +00007845 // If nothing changed, just retain the existing expression.
7846 if (!getDerived().AlwaysRebuild() &&
7847 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007848 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007849
John McCallb268a282010-08-23 23:25:46 +00007850 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007851 E->getLocation(),
7852 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007853}
7854
Mike Stump11289f42009-09-09 15:08:12 +00007855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007856ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007857TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007858 // 'super' and types never change. Property never changes. Just
7859 // retain the existing expression.
7860 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007861 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007862
Douglas Gregor9faee212010-04-26 20:47:02 +00007863 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007864 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007865 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007866 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007867
Douglas Gregor9faee212010-04-26 20:47:02 +00007868 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007869
Douglas Gregor9faee212010-04-26 20:47:02 +00007870 // If nothing changed, just retain the existing expression.
7871 if (!getDerived().AlwaysRebuild() &&
7872 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007873 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007874
John McCallb7bd14f2010-12-02 01:19:52 +00007875 if (E->isExplicitProperty())
7876 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7877 E->getExplicitProperty(),
7878 E->getLocation());
7879
7880 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7881 E->getType(),
7882 E->getImplicitPropertyGetter(),
7883 E->getImplicitPropertySetter(),
7884 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007885}
7886
Mike Stump11289f42009-09-09 15:08:12 +00007887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007888ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007889TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007890 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007891 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007892 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007893 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007894
Douglas Gregord51d90d2010-04-26 20:11:03 +00007895 // If nothing changed, just retain the existing expression.
7896 if (!getDerived().AlwaysRebuild() &&
7897 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007898 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007899
John McCallb268a282010-08-23 23:25:46 +00007900 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007901 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007902}
7903
Mike Stump11289f42009-09-09 15:08:12 +00007904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007906TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007907 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007908 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007909 SubExprs.reserve(E->getNumSubExprs());
7910 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7911 SubExprs, &ArgumentChanged))
7912 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007913
Douglas Gregora16548e2009-08-11 05:31:07 +00007914 if (!getDerived().AlwaysRebuild() &&
7915 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007916 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007917
Douglas Gregora16548e2009-08-11 05:31:07 +00007918 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7919 move_arg(SubExprs),
7920 E->getRParenLoc());
7921}
7922
Mike Stump11289f42009-09-09 15:08:12 +00007923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007924ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007925TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007926 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007927
John McCall490112f2011-02-04 18:33:18 +00007928 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7929 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7930
7931 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00007932 // We built a new blockScopeInfo in call to ActOnBlockStart
7933 // in above, CapturesCXXThis need be set here from the block
7934 // expression.
7935 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7936
Chris Lattner01cf8db2011-07-20 06:58:45 +00007937 SmallVector<ParmVarDecl*, 4> params;
7938 SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007939
7940 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007941 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7942 oldBlock->param_begin(),
7943 oldBlock->param_size(),
7944 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007945 return true;
John McCall490112f2011-02-04 18:33:18 +00007946
7947 const FunctionType *exprFunctionType = E->getFunctionType();
7948 QualType exprResultType = exprFunctionType->getResultType();
7949 if (!exprResultType.isNull()) {
7950 if (!exprResultType->isDependentType())
7951 blockScope->ReturnType = exprResultType;
7952 else if (exprResultType != getSema().Context.DependentTy)
7953 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007954 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007955
7956 // If the return type has not been determined yet, leave it as a dependent
7957 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007958 if (blockScope->ReturnType.isNull())
7959 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007960
7961 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007962 if (blockScope->ReturnType->isObjCObjectType()) {
7963 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007964 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007965 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007966 return ExprError();
7967 }
John McCall3882ace2011-01-05 12:14:39 +00007968
John McCall490112f2011-02-04 18:33:18 +00007969 QualType functionType = getDerived().RebuildFunctionProtoType(
7970 blockScope->ReturnType,
7971 paramTypes.data(),
7972 paramTypes.size(),
7973 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007974 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007975 exprFunctionType->getExtInfo());
7976 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007977
7978 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007979 if (!params.empty())
7980 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007981
7982 // If the return type wasn't explicitly set, it will have been marked as a
7983 // dependent type (DependentTy); clear out the return type setting so
7984 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007985 if (blockScope->ReturnType == getSema().Context.DependentTy)
7986 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007987
John McCall3882ace2011-01-05 12:14:39 +00007988 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007989 StmtResult body = getDerived().TransformStmt(E->getBody());
7990 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007991 return ExprError();
7992
John McCall490112f2011-02-04 18:33:18 +00007993#ifndef NDEBUG
7994 // In builds with assertions, make sure that we captured everything we
7995 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007996 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
7997 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7998 e = oldBlock->capture_end(); i != e; ++i) {
7999 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00008000
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008001 // Ignore parameter packs.
8002 if (isa<ParmVarDecl>(oldCapture) &&
8003 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8004 continue;
John McCall490112f2011-02-04 18:33:18 +00008005
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008006 VarDecl *newCapture =
8007 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8008 oldCapture));
8009 assert(blockScope->CaptureMap.count(newCapture));
8010 }
John McCall490112f2011-02-04 18:33:18 +00008011 }
8012#endif
8013
8014 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8015 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008016}
8017
Mike Stump11289f42009-09-09 15:08:12 +00008018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008019ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008020TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008021 ValueDecl *ND
8022 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8023 E->getDecl()));
8024 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008025 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008026
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008027 if (!getDerived().AlwaysRebuild() &&
8028 ND == E->getDecl()) {
8029 // Mark it referenced in the new context regardless.
8030 // FIXME: this is a bit instantiation-specific.
8031 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8032
John McCallc3007a22010-10-26 07:05:15 +00008033 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008034 }
8035
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008036 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00008037 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008038 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008039}
Mike Stump11289f42009-09-09 15:08:12 +00008040
Tanya Lattner55808c12011-06-04 00:47:47 +00008041template<typename Derived>
8042ExprResult
8043TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
8044 assert(false && "Cannot transform asType expressions yet");
8045 return SemaRef.Owned(E);
8046}
8047
Douglas Gregora16548e2009-08-11 05:31:07 +00008048//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008049// Type reconstruction
8050//===----------------------------------------------------------------------===//
8051
Mike Stump11289f42009-09-09 15:08:12 +00008052template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008053QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8054 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008055 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008056 getDerived().getBaseEntity());
8057}
8058
Mike Stump11289f42009-09-09 15:08:12 +00008059template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008060QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8061 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008062 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008063 getDerived().getBaseEntity());
8064}
8065
Mike Stump11289f42009-09-09 15:08:12 +00008066template<typename Derived>
8067QualType
John McCall70dd5f62009-10-30 00:06:24 +00008068TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8069 bool WrittenAsLValue,
8070 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008071 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00008072 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008073}
8074
8075template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008076QualType
John McCall70dd5f62009-10-30 00:06:24 +00008077TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8078 QualType ClassType,
8079 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008080 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00008081 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008082}
8083
8084template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008085QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00008086TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8087 ArrayType::ArraySizeModifier SizeMod,
8088 const llvm::APInt *Size,
8089 Expr *SizeExpr,
8090 unsigned IndexTypeQuals,
8091 SourceRange BracketsRange) {
8092 if (SizeExpr || !Size)
8093 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8094 IndexTypeQuals, BracketsRange,
8095 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00008096
8097 QualType Types[] = {
8098 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8099 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8100 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00008101 };
8102 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8103 QualType SizeType;
8104 for (unsigned I = 0; I != NumTypes; ++I)
8105 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8106 SizeType = Types[I];
8107 break;
8108 }
Mike Stump11289f42009-09-09 15:08:12 +00008109
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008110 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8111 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00008112 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008113 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00008114 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008115}
Mike Stump11289f42009-09-09 15:08:12 +00008116
Douglas Gregord6ff3322009-08-04 16:50:30 +00008117template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008118QualType
8119TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008120 ArrayType::ArraySizeModifier SizeMod,
8121 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00008122 unsigned IndexTypeQuals,
8123 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008124 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008125 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008126}
8127
8128template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008129QualType
Mike Stump11289f42009-09-09 15:08:12 +00008130TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008131 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00008132 unsigned IndexTypeQuals,
8133 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008134 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008135 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008136}
Mike Stump11289f42009-09-09 15:08:12 +00008137
Douglas Gregord6ff3322009-08-04 16:50:30 +00008138template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008139QualType
8140TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008141 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008142 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008143 unsigned IndexTypeQuals,
8144 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008145 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008146 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008147 IndexTypeQuals, BracketsRange);
8148}
8149
8150template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008151QualType
8152TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008153 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008154 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008155 unsigned IndexTypeQuals,
8156 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008157 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008158 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008159 IndexTypeQuals, BracketsRange);
8160}
8161
8162template<typename Derived>
8163QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00008164 unsigned NumElements,
8165 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00008166 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00008167 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008168}
Mike Stump11289f42009-09-09 15:08:12 +00008169
Douglas Gregord6ff3322009-08-04 16:50:30 +00008170template<typename Derived>
8171QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8172 unsigned NumElements,
8173 SourceLocation AttributeLoc) {
8174 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8175 NumElements, true);
8176 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008177 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8178 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00008179 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008180}
Mike Stump11289f42009-09-09 15:08:12 +00008181
Douglas Gregord6ff3322009-08-04 16:50:30 +00008182template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008183QualType
8184TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00008185 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008186 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00008187 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008188}
Mike Stump11289f42009-09-09 15:08:12 +00008189
Douglas Gregord6ff3322009-08-04 16:50:30 +00008190template<typename Derived>
8191QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00008192 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008193 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00008194 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00008195 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008196 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00008197 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00008198 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008199 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008200 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008201 getDerived().getBaseEntity(),
8202 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008203}
Mike Stump11289f42009-09-09 15:08:12 +00008204
Douglas Gregord6ff3322009-08-04 16:50:30 +00008205template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008206QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8207 return SemaRef.Context.getFunctionNoProtoType(T);
8208}
8209
8210template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008211QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8212 assert(D && "no decl found");
8213 if (D->isInvalidDecl()) return QualType();
8214
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008215 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008216 TypeDecl *Ty;
8217 if (isa<UsingDecl>(D)) {
8218 UsingDecl *Using = cast<UsingDecl>(D);
8219 assert(Using->isTypeName() &&
8220 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8221
8222 // A valid resolved using typename decl points to exactly one type decl.
8223 assert(++Using->shadow_begin() == Using->shadow_end());
8224 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008225
John McCallb96ec562009-12-04 22:46:56 +00008226 } else {
8227 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8228 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8229 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8230 }
8231
8232 return SemaRef.Context.getTypeDeclType(Ty);
8233}
8234
8235template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008236QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8237 SourceLocation Loc) {
8238 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008239}
8240
8241template<typename Derived>
8242QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8243 return SemaRef.Context.getTypeOfType(Underlying);
8244}
8245
8246template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008247QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8248 SourceLocation Loc) {
8249 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008250}
8251
8252template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00008253QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8254 UnaryTransformType::UTTKind UKind,
8255 SourceLocation Loc) {
8256 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8257}
8258
8259template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00008260QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008261 TemplateName Template,
8262 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008263 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008264 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008265}
Mike Stump11289f42009-09-09 15:08:12 +00008266
Douglas Gregor1135c352009-08-06 05:28:30 +00008267template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008268TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008269TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008270 bool TemplateKW,
8271 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008272 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008273 Template);
8274}
8275
8276template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008277TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008278TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8279 const IdentifierInfo &Name,
8280 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008281 QualType ObjectType,
8282 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008283 UnqualifiedId TemplateName;
8284 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008285 Sema::TemplateTy Template;
8286 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008287 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008288 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008289 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008290 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008291 /*EnteringContext=*/false,
8292 Template);
John McCall31f82722010-11-12 08:19:04 +00008293 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008294}
Mike Stump11289f42009-09-09 15:08:12 +00008295
Douglas Gregora16548e2009-08-11 05:31:07 +00008296template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008297TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008298TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008299 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008300 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008301 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008302 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008303 // FIXME: Bogus location information.
8304 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8305 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008306 Sema::TemplateTy Template;
8307 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008308 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008309 SS,
8310 Name,
John McCallba7bf592010-08-24 05:47:05 +00008311 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008312 /*EnteringContext=*/false,
8313 Template);
8314 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008315}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008316
Douglas Gregor71395fa2009-11-04 00:56:37 +00008317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008318ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008319TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8320 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008321 Expr *OrigCallee,
8322 Expr *First,
8323 Expr *Second) {
8324 Expr *Callee = OrigCallee->IgnoreParenCasts();
8325 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008326
Douglas Gregora16548e2009-08-11 05:31:07 +00008327 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008328 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008329 if (!First->getType()->isOverloadableType() &&
8330 !Second->getType()->isOverloadableType())
8331 return getSema().CreateBuiltinArraySubscriptExpr(First,
8332 Callee->getLocStart(),
8333 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008334 } else if (Op == OO_Arrow) {
8335 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008336 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8337 } else if (Second == 0 || isPostIncDec) {
8338 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008339 // The argument is not of overloadable type, so try to create a
8340 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008341 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008342 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008343
John McCallb268a282010-08-23 23:25:46 +00008344 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008345 }
8346 } else {
John McCallb268a282010-08-23 23:25:46 +00008347 if (!First->getType()->isOverloadableType() &&
8348 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008349 // Neither of the arguments is an overloadable type, so try to
8350 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008351 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008352 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008353 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008354 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008356
Douglas Gregora16548e2009-08-11 05:31:07 +00008357 return move(Result);
8358 }
8359 }
Mike Stump11289f42009-09-09 15:08:12 +00008360
8361 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008362 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008363 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008364
John McCallb268a282010-08-23 23:25:46 +00008365 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008366 assert(ULE->requiresADL());
8367
8368 // FIXME: Do we have to check
8369 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008370 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008371 } else {
John McCallb268a282010-08-23 23:25:46 +00008372 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008373 }
Mike Stump11289f42009-09-09 15:08:12 +00008374
Douglas Gregora16548e2009-08-11 05:31:07 +00008375 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008376 Expr *Args[2] = { First, Second };
8377 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008378
Douglas Gregora16548e2009-08-11 05:31:07 +00008379 // Create the overloaded operator invocation for unary operators.
8380 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008381 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008382 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008383 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008384 }
Mike Stump11289f42009-09-09 15:08:12 +00008385
Douglas Gregore9d62932011-07-15 16:25:15 +00008386 if (Op == OO_Subscript) {
8387 SourceLocation LBrace;
8388 SourceLocation RBrace;
8389
8390 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8391 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8392 LBrace = SourceLocation::getFromRawEncoding(
8393 NameLoc.CXXOperatorName.BeginOpNameLoc);
8394 RBrace = SourceLocation::getFromRawEncoding(
8395 NameLoc.CXXOperatorName.EndOpNameLoc);
8396 } else {
8397 LBrace = Callee->getLocStart();
8398 RBrace = OpLoc;
8399 }
8400
8401 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8402 First, Second);
8403 }
Sebastian Redladba46e2009-10-29 20:17:01 +00008404
Douglas Gregora16548e2009-08-11 05:31:07 +00008405 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008406 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008407 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008408 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8409 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008410 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008411
Mike Stump11289f42009-09-09 15:08:12 +00008412 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008413}
Mike Stump11289f42009-09-09 15:08:12 +00008414
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008416ExprResult
John McCallb268a282010-08-23 23:25:46 +00008417TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008418 SourceLocation OperatorLoc,
8419 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008420 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008421 TypeSourceInfo *ScopeType,
8422 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008423 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008424 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008425 QualType BaseType = Base->getType();
8426 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008427 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008428 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008429 !BaseType->getAs<PointerType>()->getPointeeType()
8430 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008431 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008432 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008433 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008434 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008435 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008436 /*FIXME?*/true);
8437 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008438
Douglas Gregor678f90d2010-02-25 01:56:36 +00008439 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008440 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8441 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8442 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8443 NameInfo.setNamedTypeInfo(DestroyedType);
8444
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008445 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008446
John McCallb268a282010-08-23 23:25:46 +00008447 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008448 OperatorLoc, isArrow,
8449 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008450 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008451 /*TemplateArgs*/ 0);
8452}
8453
Douglas Gregord6ff3322009-08-04 16:50:30 +00008454} // end namespace clang
8455
8456#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H