blob: 2a18afafd9bc62abc9b65ea7ba453ad532668ad4 [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"
David Blaikieb9c168a2011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
101
102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
106
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000114
Mike Stump11289f42009-09-09 15:08:12 +0000115public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000116 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000117 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000118
Douglas Gregord6ff3322009-08-04 16:50:30 +0000119 /// \brief Retrieves a reference to the derived class.
120 Derived &getDerived() { return static_cast<Derived&>(*this); }
121
122 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000123 const Derived &getDerived() const {
124 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 }
126
John McCalldadc5752010-08-24 06:29:42 +0000127 static inline ExprResult Owned(Expr *E) { return E; }
128 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Retrieves a reference to the semantic analysis object used for
131 /// this tree transform.
132 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000133
Douglas Gregord6ff3322009-08-04 16:50:30 +0000134 /// \brief Whether the transformation should always rebuild AST nodes, even
135 /// if none of the children have changed.
136 ///
137 /// Subclasses may override this function to specify when the transformation
138 /// should rebuild all AST nodes.
139 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000140
Douglas Gregord6ff3322009-08-04 16:50:30 +0000141 /// \brief Returns the location of the entity being transformed, if that
142 /// information was not available elsewhere in the AST.
143 ///
Mike Stump11289f42009-09-09 15:08:12 +0000144 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000145 /// provide an alternative implementation that provides better location
146 /// information.
147 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregord6ff3322009-08-04 16:50:30 +0000149 /// \brief Returns the name of the entity being transformed, if that
150 /// information was not available elsewhere in the AST.
151 ///
152 /// By default, returns an empty name. Subclasses can provide an alternative
153 /// implementation with a more precise name.
154 DeclarationName getBaseEntity() { return DeclarationName(); }
155
Douglas Gregora16548e2009-08-11 05:31:07 +0000156 /// \brief Sets the "base" location and entity when that
157 /// information is known based on another transformation.
158 ///
159 /// By default, the source location and entity are ignored. Subclasses can
160 /// override this function to provide a customized implementation.
161 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000162
Douglas Gregora16548e2009-08-11 05:31:07 +0000163 /// \brief RAII object that temporarily sets the base location and entity
164 /// used for reporting diagnostics in types.
165 class TemporaryBase {
166 TreeTransform &Self;
167 SourceLocation OldLocation;
168 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000169
Douglas Gregora16548e2009-08-11 05:31:07 +0000170 public:
171 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000172 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 OldLocation = Self.getDerived().getBaseLocation();
174 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000175
176 if (Location.isValid())
177 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 }
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 ~TemporaryBase() {
181 Self.getDerived().setBase(OldLocation, OldEntity);
182 }
183 };
Mike Stump11289f42009-09-09 15:08:12 +0000184
185 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000186 /// transformed.
187 ///
188 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000189 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000190 /// not change. For example, template instantiation need not traverse
191 /// non-dependent types.
192 bool AlreadyTransformed(QualType T) {
193 return T.isNull();
194 }
195
Douglas Gregord196a582009-12-14 19:27:10 +0000196 /// \brief Determine whether the given call argument should be dropped, e.g.,
197 /// because it is a default argument.
198 ///
199 /// Subclasses can provide an alternative implementation of this routine to
200 /// determine which kinds of call arguments get dropped. By default,
201 /// CXXDefaultArgument nodes are dropped (prior to transformation).
202 bool DropCallArgument(Expr *E) {
203 return E->isDefaultArgument();
204 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000205
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000206 /// \brief Determine whether we should expand a pack expansion with the
207 /// given set of parameter packs into separate arguments by repeatedly
208 /// transforming the pattern.
209 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000210 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000211 /// Subclasses can override this routine to provide different behavior.
212 ///
213 /// \param EllipsisLoc The location of the ellipsis that identifies the
214 /// pack expansion.
215 ///
216 /// \param PatternRange The source range that covers the entire pattern of
217 /// the pack expansion.
218 ///
219 /// \param Unexpanded The set of unexpanded parameter packs within the
220 /// pattern.
221 ///
222 /// \param NumUnexpanded The number of unexpanded parameter packs in
223 /// \p Unexpanded.
224 ///
225 /// \param ShouldExpand Will be set to \c true if the transformer should
226 /// expand the corresponding pack expansions into separate arguments. When
227 /// set, \c NumExpansions must also be set.
228 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000229 /// \param RetainExpansion Whether the caller should add an unexpanded
230 /// pack expansion after all of the expanded arguments. This is used
231 /// when extending explicitly-specified template argument packs per
232 /// C++0x [temp.arg.explicit]p9.
233 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000234 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000235 /// the expanded form of the corresponding pack expansion. This is both an
236 /// input and an output parameter, which can be set by the caller if the
237 /// number of expansions is known a priori (e.g., due to a prior substitution)
238 /// and will be set by the callee when the number of expansions is known.
239 /// The callee must set this value when \c ShouldExpand is \c true; it may
240 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 ///
242 /// \returns true if an error occurred (e.g., because the parameter packs
243 /// are to be instantiated with arguments of different lengths), false
244 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
245 /// must be set.
246 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
247 SourceRange PatternRange,
David Blaikieb9c168a2011-09-22 02:34:54 +0000248 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000249 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
Eli Friedman0dfb8892011-10-06 23:00:33 +0000908 /// \brief Build a new atomic type given its value type.
909 ///
910 /// By default, performs semantic analysis when building the atomic type.
911 /// Subclasses may override this routine to provide different behavior.
912 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
913
Douglas Gregor71dc5092009-08-06 06:41:21 +0000914 /// \brief Build a new template name given a nested name specifier, a flag
915 /// indicating whether the "template" keyword was provided, and the template
916 /// that the template name refers to.
917 ///
918 /// By default, builds the new template name directly. Subclasses may override
919 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000920 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000921 bool TemplateKW,
922 TemplateDecl *Template);
923
Douglas Gregor71dc5092009-08-06 06:41:21 +0000924 /// \brief Build a new template name given a nested name specifier and the
925 /// name that is referred to as a template.
926 ///
927 /// By default, performs semantic analysis to determine whether the name can
928 /// be resolved to a specific template, then builds the appropriate kind of
929 /// template name. Subclasses may override this routine to provide different
930 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000931 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
932 const IdentifierInfo &Name,
933 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000934 QualType ObjectType,
935 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000936
Douglas Gregor71395fa2009-11-04 00:56:37 +0000937 /// \brief Build a new template name given a nested name specifier and the
938 /// overloaded operator name that is referred to as a template.
939 ///
940 /// By default, performs semantic analysis to determine whether the name can
941 /// be resolved to a specific template, then builds the appropriate kind of
942 /// template name. Subclasses may override this routine to provide different
943 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000944 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000945 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000946 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000947 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000948
949 /// \brief Build a new template name given a template template parameter pack
950 /// and the
951 ///
952 /// By default, performs semantic analysis to determine whether the name can
953 /// be resolved to a specific template, then builds the appropriate kind of
954 /// template name. Subclasses may override this routine to provide different
955 /// behavior.
956 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
957 const TemplateArgument &ArgPack) {
958 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
959 }
960
Douglas Gregorebe10102009-08-20 07:17:43 +0000961 /// \brief Build a new compound statement.
962 ///
963 /// By default, performs semantic analysis to build the new statement.
964 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000965 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000966 MultiStmtArg Statements,
967 SourceLocation RBraceLoc,
968 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000969 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000970 IsStmtExpr);
971 }
972
973 /// \brief Build a new case statement.
974 ///
975 /// By default, performs semantic analysis to build the new statement.
976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000977 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000978 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000979 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000980 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000981 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000982 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 ColonLoc);
984 }
Mike Stump11289f42009-09-09 15:08:12 +0000985
Douglas Gregorebe10102009-08-20 07:17:43 +0000986 /// \brief Attach the body to a new case statement.
987 ///
988 /// By default, performs semantic analysis to build the new statement.
989 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000990 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000991 getSema().ActOnCaseStmtBody(S, Body);
992 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 }
Mike Stump11289f42009-09-09 15:08:12 +0000994
Douglas Gregorebe10102009-08-20 07:17:43 +0000995 /// \brief Build a new default statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000999 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001001 Stmt *SubStmt) {
1002 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 /*CurScope=*/0);
1004 }
Mike Stump11289f42009-09-09 15:08:12 +00001005
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 /// \brief Build a new label statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001010 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1011 SourceLocation ColonLoc, Stmt *SubStmt) {
1012 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001013 }
Mike Stump11289f42009-09-09 15:08:12 +00001014
Douglas Gregorebe10102009-08-20 07:17:43 +00001015 /// \brief Build a new "if" statement.
1016 ///
1017 /// By default, performs semantic analysis to build the new statement.
1018 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001019 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001020 VarDecl *CondVar, Stmt *Then,
1021 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001022 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001023 }
Mike Stump11289f42009-09-09 15:08:12 +00001024
Douglas Gregorebe10102009-08-20 07:17:43 +00001025 /// \brief Start building a new switch statement.
1026 ///
1027 /// By default, performs semantic analysis to build the new statement.
1028 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001029 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001030 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001031 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001032 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001033 }
Mike Stump11289f42009-09-09 15:08:12 +00001034
Douglas Gregorebe10102009-08-20 07:17:43 +00001035 /// \brief Attach the body to the switch statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001039 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001040 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001041 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001042 }
1043
1044 /// \brief Build a new while statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001048 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1049 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001050 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 }
Mike Stump11289f42009-09-09 15:08:12 +00001052
Douglas Gregorebe10102009-08-20 07:17:43 +00001053 /// \brief Build a new do-while statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001058 SourceLocation WhileLoc, SourceLocation LParenLoc,
1059 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001060 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1061 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 }
1063
1064 /// \brief Build a new for statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001068 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1069 Stmt *Init, Sema::FullExprArg Cond,
1070 VarDecl *CondVar, Sema::FullExprArg Inc,
1071 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001072 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001073 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001074 }
Mike Stump11289f42009-09-09 15:08:12 +00001075
Douglas Gregorebe10102009-08-20 07:17:43 +00001076 /// \brief Build a new goto statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001080 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1081 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001082 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001083 }
1084
1085 /// \brief Build a new indirect goto statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001089 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001090 SourceLocation StarLoc,
1091 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001092 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 /// \brief Build a new return statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001099 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001100 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001101 }
Mike Stump11289f42009-09-09 15:08:12 +00001102
Douglas Gregorebe10102009-08-20 07:17:43 +00001103 /// \brief Build a new declaration statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001107 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001108 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001110 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1111 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001112 }
Mike Stump11289f42009-09-09 15:08:12 +00001113
Anders Carlssonaaeef072010-01-24 05:50:09 +00001114 /// \brief Build a new inline asm statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001118 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001119 bool IsSimple,
1120 bool IsVolatile,
1121 unsigned NumOutputs,
1122 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001123 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001124 MultiExprArg Constraints,
1125 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001126 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001127 MultiExprArg Clobbers,
1128 SourceLocation RParenLoc,
1129 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001130 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001131 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001132 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001133 RParenLoc, MSAsm);
1134 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001135
1136 /// \brief Build a new Objective-C @try statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001140 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001141 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001142 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001143 Stmt *Finally) {
1144 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1145 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001146 }
1147
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001148 /// \brief Rebuild an Objective-C exception declaration.
1149 ///
1150 /// By default, performs semantic analysis to build the new declaration.
1151 /// Subclasses may override this routine to provide different behavior.
1152 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1153 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001154 return getSema().BuildObjCExceptionDecl(TInfo, T,
1155 ExceptionDecl->getInnerLocStart(),
1156 ExceptionDecl->getLocation(),
1157 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001158 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001159
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001160 /// \brief Build a new Objective-C @catch statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001165 SourceLocation RParenLoc,
1166 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001167 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001168 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001169 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001170 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001171
Douglas Gregor306de2f2010-04-22 23:59:56 +00001172 /// \brief Build a new Objective-C @finally statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001176 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001177 Stmt *Body) {
1178 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001179 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001180
Douglas Gregor6148de72010-04-22 22:01:21 +00001181 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001185 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001186 Expr *Operand) {
1187 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001188 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001189
John McCalld9bb7432011-07-27 21:50:02 +00001190 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1191 ///
1192 /// By default, performs semantic analysis to build the new statement.
1193 /// Subclasses may override this routine to provide different behavior.
1194 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1195 Expr *object) {
1196 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1197 }
1198
Douglas Gregor6148de72010-04-22 22:01:21 +00001199 /// \brief Build a new Objective-C @synchronized statement.
1200 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001201 /// By default, performs semantic analysis to build the new statement.
1202 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001203 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001204 Expr *Object, Stmt *Body) {
1205 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001206 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001207
John McCall31168b02011-06-15 23:02:42 +00001208 /// \brief Build a new Objective-C @autoreleasepool statement.
1209 ///
1210 /// By default, performs semantic analysis to build the new statement.
1211 /// Subclasses may override this routine to provide different behavior.
1212 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1213 Stmt *Body) {
1214 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1215 }
John McCall53848232011-07-27 01:07:15 +00001216
1217 /// \brief Build the collection operand to a new Objective-C fast
1218 /// enumeration statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
1222 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1223 Expr *collection) {
1224 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1225 }
John McCall31168b02011-06-15 23:02:42 +00001226
Douglas Gregorf68a5082010-04-22 23:10:45 +00001227 /// \brief Build a new Objective-C fast enumeration statement.
1228 ///
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001231 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001232 SourceLocation LParenLoc,
1233 Stmt *Element,
1234 Expr *Collection,
1235 SourceLocation RParenLoc,
1236 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001237 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001238 Element,
1239 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001240 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001241 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001242 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001243
Douglas Gregorebe10102009-08-20 07:17:43 +00001244 /// \brief Build a new C++ exception declaration.
1245 ///
1246 /// By default, performs semantic analysis to build the new decaration.
1247 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001248 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001249 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001250 SourceLocation StartLoc,
1251 SourceLocation IdLoc,
1252 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001253 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1254 StartLoc, IdLoc, Id);
1255 if (Var)
1256 getSema().CurContext->addDecl(Var);
1257 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001258 }
1259
1260 /// \brief Build a new C++ catch statement.
1261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001264 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001265 VarDecl *ExceptionDecl,
1266 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001267 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1268 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001269 }
Mike Stump11289f42009-09-09 15:08:12 +00001270
Douglas Gregorebe10102009-08-20 07:17:43 +00001271 /// \brief Build a new C++ try statement.
1272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001275 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001276 Stmt *TryBlock,
1277 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001278 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001279 }
Mike Stump11289f42009-09-09 15:08:12 +00001280
Richard Smith02e85f32011-04-14 22:09:26 +00001281 /// \brief Build a new C++0x range-based for statement.
1282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
1285 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1286 SourceLocation ColonLoc,
1287 Stmt *Range, Stmt *BeginEnd,
1288 Expr *Cond, Expr *Inc,
1289 Stmt *LoopVar,
1290 SourceLocation RParenLoc) {
1291 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1292 Cond, Inc, LoopVar, RParenLoc);
1293 }
1294
1295 /// \brief Attach body to a C++0x range-based for statement.
1296 ///
1297 /// By default, performs semantic analysis to finish the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
1299 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1300 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1301 }
1302
John Wiegley1c0675e2011-04-28 01:08:34 +00001303 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1304 SourceLocation TryLoc,
1305 Stmt *TryBlock,
1306 Stmt *Handler) {
1307 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1308 }
1309
1310 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1311 Expr *FilterExpr,
1312 Stmt *Block) {
1313 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1314 }
1315
1316 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1317 Stmt *Block) {
1318 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1319 }
1320
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// \brief Build a new expression that references a declaration.
1322 ///
1323 /// By default, performs semantic analysis to build the new expression.
1324 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001325 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001326 LookupResult &R,
1327 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001328 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1329 }
1330
1331
1332 /// \brief Build a new expression that references a declaration.
1333 ///
1334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001336 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001337 ValueDecl *VD,
1338 const DeclarationNameInfo &NameInfo,
1339 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001340 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001341 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001342
1343 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001344
1345 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 }
Mike Stump11289f42009-09-09 15:08:12 +00001347
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001349 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 /// By default, performs semantic analysis to build the new expression.
1351 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001352 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001354 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 }
1356
Douglas Gregorad8a3362009-09-04 17:36:40 +00001357 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001358 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +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 RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001362 SourceLocation OperatorLoc,
1363 bool isArrow,
1364 CXXScopeSpec &SS,
1365 TypeSourceInfo *ScopeType,
1366 SourceLocation CCLoc,
1367 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001368 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001369
Douglas Gregora16548e2009-08-11 05:31:07 +00001370 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001371 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001374 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001375 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001376 Expr *SubExpr) {
1377 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 }
Mike Stump11289f42009-09-09 15:08:12 +00001379
Douglas Gregor882211c2010-04-28 22:16:22 +00001380 /// \brief Build a new builtin offsetof expression.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001384 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001385 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001386 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001387 unsigned NumComponents,
1388 SourceLocation RParenLoc) {
1389 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1390 NumComponents, RParenLoc);
1391 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001392
Peter Collingbournee190dee2011-03-11 19:24:49 +00001393 /// \brief Build a new sizeof, alignof or vec_step expression with a
1394 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001395 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001396 /// By default, performs semantic analysis to build the new expression.
1397 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001398 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1399 SourceLocation OpLoc,
1400 UnaryExprOrTypeTrait ExprKind,
1401 SourceRange R) {
1402 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001403 }
1404
Peter Collingbournee190dee2011-03-11 19:24:49 +00001405 /// \brief Build a new sizeof, alignof or vec step expression with an
1406 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001407 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 /// By default, performs semantic analysis to build the new expression.
1409 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001410 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1411 UnaryExprOrTypeTrait ExprKind,
1412 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001413 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001414 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001416 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001417
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 return move(Result);
1419 }
Mike Stump11289f42009-09-09 15:08:12 +00001420
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 /// \brief Build a new array subscript 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 RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001427 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001429 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1430 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 RBracketLoc);
1432 }
1433
1434 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001435 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001438 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001440 SourceLocation RParenLoc,
1441 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001442 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001443 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 }
1445
1446 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001447 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001450 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001451 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001452 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001453 const DeclarationNameInfo &MemberNameInfo,
1454 ValueDecl *Member,
1455 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001456 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001457 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001458 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001459 // We have a reference to an unnamed field. This is always the
1460 // base of an anonymous struct/union member access, i.e. the
1461 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001462 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001463 assert(Member->getType()->isRecordType() &&
1464 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001465
John Wiegley01296292011-04-08 18:41:53 +00001466 ExprResult BaseResult =
1467 getSema().PerformObjectMemberConversion(Base,
1468 QualifierLoc.getNestedNameSpecifier(),
1469 FoundDecl, Member);
1470 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001471 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001472 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001473 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001474 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001475 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001476 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001477 cast<FieldDecl>(Member)->getType(),
1478 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001479 return getSema().Owned(ME);
1480 }
Mike Stump11289f42009-09-09 15:08:12 +00001481
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001482 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001483 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001484
John Wiegley01296292011-04-08 18:41:53 +00001485 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1486 if (BaseResult.isInvalid())
1487 return ExprError();
1488 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001489 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001490
John McCall16df1e52010-03-30 21:47:33 +00001491 // FIXME: this involves duplicating earlier analysis in a lot of
1492 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001493 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001494 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001495 R.resolveKind();
1496
John McCallb268a282010-08-23 23:25:46 +00001497 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001498 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001499 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 }
Mike Stump11289f42009-09-09 15:08:12 +00001501
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001503 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001506 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001507 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001508 Expr *LHS, Expr *RHS) {
1509 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 }
1511
1512 /// \brief Build a new conditional operator 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 RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001517 SourceLocation QuestionLoc,
1518 Expr *LHS,
1519 SourceLocation ColonLoc,
1520 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001521 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1522 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 }
1524
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001526 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001529 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001530 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001532 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001533 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001534 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 }
Mike Stump11289f42009-09-09 15:08:12 +00001536
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001538 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001541 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001542 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001544 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001545 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001546 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 }
Mike Stump11289f42009-09-09 15:08:12 +00001548
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001550 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001553 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 SourceLocation OpLoc,
1555 SourceLocation AccessorLoc,
1556 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001557
John McCall10eae182009-11-30 22:42:35 +00001558 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001559 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001560 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001561 OpLoc, /*IsArrow*/ false,
1562 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001563 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001564 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 }
Mike Stump11289f42009-09-09 15:08:12 +00001566
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001568 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001571 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001572 MultiExprArg Inits,
1573 SourceLocation RBraceLoc,
1574 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001575 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001576 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1577 if (Result.isInvalid() || ResultTy->isDependentType())
1578 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001579
Douglas Gregord3d93062009-11-09 17:16:50 +00001580 // Patch in the result type we were given, which may have been computed
1581 // when the initial InitListExpr was built.
1582 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1583 ILE->setType(ResultTy);
1584 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 }
Mike Stump11289f42009-09-09 15:08:12 +00001586
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001588 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 /// By default, performs semantic analysis to build the new expression.
1590 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001591 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 MultiExprArg ArrayExprs,
1593 SourceLocation EqualOrColonLoc,
1594 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001595 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001596 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001598 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001601
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 ArrayExprs.release();
1603 return move(Result);
1604 }
Mike Stump11289f42009-09-09 15:08:12 +00001605
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001607 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 /// By default, builds the implicit value initialization without performing
1609 /// any semantic analysis. Subclasses may override this routine to provide
1610 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001611 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1613 }
Mike Stump11289f42009-09-09 15:08:12 +00001614
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001616 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 /// By default, performs semantic analysis to build the new expression.
1618 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001619 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001620 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001621 SourceLocation RParenLoc) {
1622 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001623 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001624 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 }
1626
1627 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001628 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001631 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 MultiExprArg SubExprs,
1633 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001634 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001635 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 }
Mike Stump11289f42009-09-09 15:08:12 +00001637
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001639 ///
1640 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 /// rather than attempting to map the label statement itself.
1642 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001643 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001644 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001645 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 }
Mike Stump11289f42009-09-09 15:08:12 +00001647
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001649 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001652 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001653 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001655 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 }
Mike Stump11289f42009-09-09 15:08:12 +00001657
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 /// \brief Build a new __builtin_choose_expr expression.
1659 ///
1660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001662 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001663 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 SourceLocation RParenLoc) {
1665 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001666 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 RParenLoc);
1668 }
Mike Stump11289f42009-09-09 15:08:12 +00001669
Peter Collingbourne91147592011-04-15 00:35:48 +00001670 /// \brief Build a new generic selection expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
1674 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1675 SourceLocation DefaultLoc,
1676 SourceLocation RParenLoc,
1677 Expr *ControllingExpr,
1678 TypeSourceInfo **Types,
1679 Expr **Exprs,
1680 unsigned NumAssocs) {
1681 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1682 ControllingExpr, Types, Exprs,
1683 NumAssocs);
1684 }
1685
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 /// \brief Build a new overloaded operator call expression.
1687 ///
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// The semantic analysis provides the behavior of template instantiation,
1690 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001691 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 /// argument-dependent lookup, etc. Subclasses may override this routine to
1693 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001694 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001696 Expr *Callee,
1697 Expr *First,
1698 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001699
1700 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 /// reinterpret_cast.
1702 ///
1703 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001704 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001706 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 Stmt::StmtClass Class,
1708 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001709 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 SourceLocation RAngleLoc,
1711 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001712 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 SourceLocation RParenLoc) {
1714 switch (Class) {
1715 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001716 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001717 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001718 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001719
1720 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001721 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001722 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001723 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001724
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001726 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001727 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001728 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001730
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001732 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001733 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001734 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001735
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001737 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 }
Mike Stump11289f42009-09-09 15:08:12 +00001739
John McCallfaf5fb42010-08-26 23:41:50 +00001740 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 }
Mike Stump11289f42009-09-09 15:08:12 +00001742
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 /// \brief Build a new C++ static_cast expression.
1744 ///
1745 /// By default, performs semantic analysis to build the new expression.
1746 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001747 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001749 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001750 SourceLocation RAngleLoc,
1751 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001752 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001754 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001755 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001756 SourceRange(LAngleLoc, RAngleLoc),
1757 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 }
1759
1760 /// \brief Build a new C++ dynamic_cast expression.
1761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001764 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001766 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 SourceLocation RAngleLoc,
1768 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001769 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001771 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001772 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001773 SourceRange(LAngleLoc, RAngleLoc),
1774 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 }
1776
1777 /// \brief Build a new C++ reinterpret_cast expression.
1778 ///
1779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001781 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001783 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001784 SourceLocation RAngleLoc,
1785 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001786 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001788 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001789 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001790 SourceRange(LAngleLoc, RAngleLoc),
1791 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 }
1793
1794 /// \brief Build a new C++ const_cast expression.
1795 ///
1796 /// By default, performs semantic analysis to build the new expression.
1797 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001798 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001800 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001801 SourceLocation RAngleLoc,
1802 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001803 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001805 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001806 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001807 SourceRange(LAngleLoc, RAngleLoc),
1808 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001809 }
Mike Stump11289f42009-09-09 15:08:12 +00001810
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 /// \brief Build a new C++ functional-style cast expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001815 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1816 SourceLocation LParenLoc,
1817 Expr *Sub,
1818 SourceLocation RParenLoc) {
1819 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001820 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 RParenLoc);
1822 }
Mike Stump11289f42009-09-09 15:08:12 +00001823
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 /// \brief Build a new C++ typeid(type) expression.
1825 ///
1826 /// By default, performs semantic analysis to build the new expression.
1827 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001828 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001829 SourceLocation TypeidLoc,
1830 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001832 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001833 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 }
Mike Stump11289f42009-09-09 15:08:12 +00001835
Francois Pichet9f4f2072010-09-08 12:20:18 +00001836
Douglas Gregora16548e2009-08-11 05:31:07 +00001837 /// \brief Build a new C++ typeid(expr) expression.
1838 ///
1839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001841 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001842 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001843 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001845 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001846 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001847 }
1848
Francois Pichet9f4f2072010-09-08 12:20:18 +00001849 /// \brief Build a new C++ __uuidof(type) 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 TypeSourceInfo *Operand,
1856 SourceLocation RParenLoc) {
1857 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1858 RParenLoc);
1859 }
1860
1861 /// \brief Build a new C++ __uuidof(expr) expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
1865 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1866 SourceLocation TypeidLoc,
1867 Expr *Operand,
1868 SourceLocation RParenLoc) {
1869 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1870 RParenLoc);
1871 }
1872
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 /// \brief Build a new C++ "this" expression.
1874 ///
1875 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001876 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001878 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001879 QualType ThisType,
1880 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001882 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1883 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001884 }
1885
1886 /// \brief Build a new C++ throw expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001890 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1891 bool IsThrownVariableInScope) {
1892 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 }
1894
1895 /// \brief Build a new C++ default-argument expression.
1896 ///
1897 /// By default, builds a new default-argument expression, which does not
1898 /// require any semantic analysis. Subclasses may override this routine to
1899 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001900 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001901 ParmVarDecl *Param) {
1902 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1903 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 }
1905
1906 /// \brief Build a new C++ zero-initialization expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001910 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1911 SourceLocation LParenLoc,
1912 SourceLocation RParenLoc) {
1913 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001914 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001915 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 }
Mike Stump11289f42009-09-09 15:08:12 +00001917
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 /// \brief Build a new C++ "new" expression.
1919 ///
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001922 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001923 bool UseGlobal,
1924 SourceLocation PlacementLParen,
1925 MultiExprArg PlacementArgs,
1926 SourceLocation PlacementRParen,
1927 SourceRange TypeIdParens,
1928 QualType AllocatedType,
1929 TypeSourceInfo *AllocatedTypeInfo,
1930 Expr *ArraySize,
1931 SourceLocation ConstructorLParen,
1932 MultiExprArg ConstructorArgs,
1933 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001934 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 PlacementLParen,
1936 move(PlacementArgs),
1937 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001938 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001939 AllocatedType,
1940 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001941 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 ConstructorLParen,
1943 move(ConstructorArgs),
1944 ConstructorRParen);
1945 }
Mike Stump11289f42009-09-09 15:08:12 +00001946
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 /// \brief Build a new C++ "delete" 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 RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 bool IsGlobalDelete,
1953 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001954 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001956 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 }
Mike Stump11289f42009-09-09 15:08:12 +00001958
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 /// \brief Build a new unary type trait expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001963 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001964 SourceLocation StartLoc,
1965 TypeSourceInfo *T,
1966 SourceLocation RParenLoc) {
1967 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 }
1969
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001970 /// \brief Build a new binary 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 RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1975 SourceLocation StartLoc,
1976 TypeSourceInfo *LhsT,
1977 TypeSourceInfo *RhsT,
1978 SourceLocation RParenLoc) {
1979 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1980 }
1981
John Wiegley6242b6a2011-04-28 00:16:57 +00001982 /// \brief Build a new array type 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 RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1987 SourceLocation StartLoc,
1988 TypeSourceInfo *TSInfo,
1989 Expr *DimExpr,
1990 SourceLocation RParenLoc) {
1991 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1992 }
1993
John Wiegleyf9f65842011-04-25 06:54:41 +00001994 /// \brief Build a new expression trait expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
1998 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1999 SourceLocation StartLoc,
2000 Expr *Queried,
2001 SourceLocation RParenLoc) {
2002 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2003 }
2004
Mike Stump11289f42009-09-09 15:08:12 +00002005 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 /// expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002010 ExprResult RebuildDependentScopeDeclRefExpr(
2011 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002012 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002013 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002015 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002016
2017 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002018 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002019 *TemplateArgs);
2020
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002021 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00002022 }
2023
2024 /// \brief Build a new template-id expression.
2025 ///
2026 /// By default, performs semantic analysis to build the new expression.
2027 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002028 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00002029 LookupResult &R,
2030 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00002031 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00002032 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 }
2034
2035 /// \brief Build a new object-construction expression.
2036 ///
2037 /// By default, performs semantic analysis to build the new expression.
2038 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002039 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002040 SourceLocation Loc,
2041 CXXConstructorDecl *Constructor,
2042 bool IsElidable,
2043 MultiExprArg Args,
2044 bool HadMultipleCandidates,
2045 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002046 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002047 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002048 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002049 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002050 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002051 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002052
Douglas Gregordb121ba2009-12-14 16:27:04 +00002053 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002054 move_arg(ConvertedArgs),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002055 HadMultipleCandidates,
Chandler Carruth01718152010-10-25 08:47:36 +00002056 RequiresZeroInit, ConstructKind,
2057 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 }
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 RebuildCXXTemporaryObjectExpr(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 }
2073
2074 /// \brief Build a new object-construction expression.
2075 ///
2076 /// By default, performs semantic analysis to build the new expression.
2077 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002078 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2079 SourceLocation LParenLoc,
2080 MultiExprArg Args,
2081 SourceLocation RParenLoc) {
2082 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002083 LParenLoc,
2084 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002085 RParenLoc);
2086 }
Mike Stump11289f42009-09-09 15:08:12 +00002087
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 /// \brief Build a new member reference expression.
2089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002092 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002093 QualType BaseType,
2094 bool IsArrow,
2095 SourceLocation OperatorLoc,
2096 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002097 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002098 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002099 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002101 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002102
John McCallb268a282010-08-23 23:25:46 +00002103 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002104 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002105 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002106 MemberNameInfo,
2107 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 }
2109
John McCall10eae182009-11-30 22:42:35 +00002110 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002111 ///
2112 /// By default, performs semantic analysis to build the new expression.
2113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002114 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002115 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002116 SourceLocation OperatorLoc,
2117 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002118 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002119 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002120 LookupResult &R,
2121 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002122 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002123 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002124
John McCallb268a282010-08-23 23:25:46 +00002125 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002126 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002127 SS, FirstQualifierInScope,
2128 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002129 }
Mike Stump11289f42009-09-09 15:08:12 +00002130
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002131 /// \brief Build a new noexcept expression.
2132 ///
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
2135 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2136 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2137 }
2138
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002139 /// \brief Build a new expression to compute the length of a parameter pack.
2140 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2141 SourceLocation PackLoc,
2142 SourceLocation RParenLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002143 llvm::Optional<unsigned> Length) {
2144 if (Length)
2145 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2146 OperatorLoc, Pack, PackLoc,
2147 RParenLoc, *Length);
2148
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002149 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2150 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002151 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002152 }
2153
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 /// \brief Build a new Objective-C @encode expression.
2155 ///
2156 /// By default, performs semantic analysis to build the new expression.
2157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002158 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002159 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002161 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002162 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002163 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002164
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002165 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002166 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002167 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002168 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002169 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002170 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002171 MultiExprArg Args,
2172 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002173 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2174 ReceiverTypeInfo->getType(),
2175 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002176 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002177 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002178 }
2179
2180 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002181 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002182 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002183 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002184 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002185 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002186 MultiExprArg Args,
2187 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002188 return SemaRef.BuildInstanceMessage(Receiver,
2189 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002190 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002191 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002192 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002193 }
2194
Douglas Gregord51d90d2010-04-26 20:11:03 +00002195 /// \brief Build a new Objective-C ivar reference expression.
2196 ///
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002199 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002200 SourceLocation IvarLoc,
2201 bool IsArrow, bool IsFreeIvar) {
2202 // FIXME: We lose track of the IsFreeIvar bit.
2203 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002204 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002205 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2206 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002207 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002208 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002209 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002210 false);
John Wiegley01296292011-04-08 18:41:53 +00002211 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002212 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002213
Douglas Gregord51d90d2010-04-26 20:11:03 +00002214 if (Result.get())
2215 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002216
John Wiegley01296292011-04-08 18:41:53 +00002217 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002218 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002219 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002220 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002221 /*TemplateArgs=*/0);
2222 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002223
2224 /// \brief Build a new Objective-C property reference expression.
2225 ///
2226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002228 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002229 ObjCPropertyDecl *Property,
2230 SourceLocation PropertyLoc) {
2231 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002232 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002233 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2234 Sema::LookupMemberName);
2235 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002236 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002237 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002238 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002239 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002240 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002241
Douglas Gregor9faee212010-04-26 20:47:02 +00002242 if (Result.get())
2243 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002244
John Wiegley01296292011-04-08 18:41:53 +00002245 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002246 /*FIXME:*/PropertyLoc, IsArrow,
2247 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002248 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002249 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002250 /*TemplateArgs=*/0);
2251 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002252
John McCallb7bd14f2010-12-02 01:19:52 +00002253 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002254 ///
2255 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002256 /// Subclasses may override this routine to provide different behavior.
2257 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2258 ObjCMethodDecl *Getter,
2259 ObjCMethodDecl *Setter,
2260 SourceLocation PropertyLoc) {
2261 // Since these expressions can only be value-dependent, we do not
2262 // need to perform semantic analysis again.
2263 return Owned(
2264 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2265 VK_LValue, OK_ObjCProperty,
2266 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002267 }
2268
Douglas Gregord51d90d2010-04-26 20:11:03 +00002269 /// \brief Build a new Objective-C "isa" expression.
2270 ///
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002273 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002274 bool IsArrow) {
2275 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002276 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002277 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2278 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002279 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002280 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002281 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002282 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002283 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002284
Douglas Gregord51d90d2010-04-26 20:11:03 +00002285 if (Result.get())
2286 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002287
John Wiegley01296292011-04-08 18:41:53 +00002288 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002289 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002290 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002291 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002292 /*TemplateArgs=*/0);
2293 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002294
Douglas Gregora16548e2009-08-11 05:31:07 +00002295 /// \brief Build a new shuffle vector expression.
2296 ///
2297 /// By default, performs semantic analysis to build the new expression.
2298 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002299 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002300 MultiExprArg SubExprs,
2301 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002302 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002303 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002304 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2305 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2306 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2307 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002308
Douglas Gregora16548e2009-08-11 05:31:07 +00002309 // Build a reference to the __builtin_shufflevector builtin
2310 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002311 ExprResult Callee
2312 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2313 VK_LValue, BuiltinLoc));
2314 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2315 if (Callee.isInvalid())
2316 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002317
2318 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 unsigned NumSubExprs = SubExprs.size();
2320 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002321 ExprResult TheCall = SemaRef.Owned(
2322 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002324 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002325 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002326 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002327
Douglas Gregora16548e2009-08-11 05:31:07 +00002328 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002329 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002330 }
John McCall31f82722010-11-12 08:19:04 +00002331
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002332 /// \brief Build a new template argument pack expansion.
2333 ///
2334 /// By default, performs semantic analysis to build a new pack expansion
2335 /// for a template argument. Subclasses may override this routine to provide
2336 /// different behavior.
2337 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002338 SourceLocation EllipsisLoc,
2339 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002340 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002341 case TemplateArgument::Expression: {
2342 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002343 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2344 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002345 if (Result.isInvalid())
2346 return TemplateArgumentLoc();
2347
2348 return TemplateArgumentLoc(Result.get(), Result.get());
2349 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002350
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002351 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002352 return TemplateArgumentLoc(TemplateArgument(
2353 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002354 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002355 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002356 Pattern.getTemplateNameLoc(),
2357 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002358
2359 case TemplateArgument::Null:
2360 case TemplateArgument::Integral:
2361 case TemplateArgument::Declaration:
2362 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002363 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002364 llvm_unreachable("Pack expansion pattern has no parameter packs");
2365
2366 case TemplateArgument::Type:
2367 if (TypeSourceInfo *Expansion
2368 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002369 EllipsisLoc,
2370 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002371 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2372 Expansion);
2373 break;
2374 }
2375
2376 return TemplateArgumentLoc();
2377 }
2378
Douglas Gregor968f23a2011-01-03 19:31:53 +00002379 /// \brief Build a new expression pack expansion.
2380 ///
2381 /// By default, performs semantic analysis to build a new pack expansion
2382 /// for an expression. Subclasses may override this routine to provide
2383 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002384 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2385 llvm::Optional<unsigned> NumExpansions) {
2386 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002387 }
2388
John McCall31f82722010-11-12 08:19:04 +00002389private:
Douglas Gregor14454802011-02-25 02:25:35 +00002390 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2391 QualType ObjectType,
2392 NamedDecl *FirstQualifierInScope,
2393 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002394
2395 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2396 QualType ObjectType,
2397 NamedDecl *FirstQualifierInScope,
2398 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002399};
Douglas Gregora16548e2009-08-11 05:31:07 +00002400
Douglas Gregorebe10102009-08-20 07:17:43 +00002401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002402StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002403 if (!S)
2404 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002405
Douglas Gregorebe10102009-08-20 07:17:43 +00002406 switch (S->getStmtClass()) {
2407 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002408
Douglas Gregorebe10102009-08-20 07:17:43 +00002409 // Transform individual statement nodes
2410#define STMT(Node, Parent) \
2411 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002412#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002413#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002414#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002415
Douglas Gregorebe10102009-08-20 07:17:43 +00002416 // Transform expressions by calling TransformExpr.
2417#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002418#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002419#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002420#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002421 {
John McCalldadc5752010-08-24 06:29:42 +00002422 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002423 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002424 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002425
John McCallb268a282010-08-23 23:25:46 +00002426 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002427 }
Mike Stump11289f42009-09-09 15:08:12 +00002428 }
2429
John McCallc3007a22010-10-26 07:05:15 +00002430 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002431}
Mike Stump11289f42009-09-09 15:08:12 +00002432
2433
Douglas Gregore922c772009-08-04 22:27:00 +00002434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002435ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002436 if (!E)
2437 return SemaRef.Owned(E);
2438
2439 switch (E->getStmtClass()) {
2440 case Stmt::NoStmtClass: break;
2441#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002442#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002443#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002444 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002445#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002446 }
2447
John McCallc3007a22010-10-26 07:05:15 +00002448 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002449}
2450
2451template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002452bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2453 unsigned NumInputs,
2454 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002455 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002456 bool *ArgChanged) {
2457 for (unsigned I = 0; I != NumInputs; ++I) {
2458 // If requested, drop call arguments that need to be dropped.
2459 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2460 if (ArgChanged)
2461 *ArgChanged = true;
2462
2463 break;
2464 }
2465
Douglas Gregor968f23a2011-01-03 19:31:53 +00002466 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2467 Expr *Pattern = Expansion->getPattern();
2468
Chris Lattner01cf8db2011-07-20 06:58:45 +00002469 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002470 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2471 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2472
2473 // Determine whether the set of unexpanded parameter packs can and should
2474 // be expanded.
2475 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002476 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002477 llvm::Optional<unsigned> OrigNumExpansions
2478 = Expansion->getNumExpansions();
2479 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002480 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2481 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002482 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002483 Expand, RetainExpansion,
2484 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002485 return true;
2486
2487 if (!Expand) {
2488 // The transform has determined that we should perform a simple
2489 // transformation on the pack expansion, producing another pack
2490 // expansion.
2491 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2492 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2493 if (OutPattern.isInvalid())
2494 return true;
2495
2496 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002497 Expansion->getEllipsisLoc(),
2498 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002499 if (Out.isInvalid())
2500 return true;
2501
2502 if (ArgChanged)
2503 *ArgChanged = true;
2504 Outputs.push_back(Out.get());
2505 continue;
2506 }
John McCall542e7c62011-07-06 07:30:07 +00002507
2508 // Record right away that the argument was changed. This needs
2509 // to happen even if the array expands to nothing.
2510 if (ArgChanged) *ArgChanged = true;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002511
2512 // The transform has determined that we should perform an elementwise
2513 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002514 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002515 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2516 ExprResult Out = getDerived().TransformExpr(Pattern);
2517 if (Out.isInvalid())
2518 return true;
2519
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002520 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002521 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2522 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002523 if (Out.isInvalid())
2524 return true;
2525 }
2526
Douglas Gregor968f23a2011-01-03 19:31:53 +00002527 Outputs.push_back(Out.get());
2528 }
2529
2530 continue;
2531 }
2532
Douglas Gregora3efea12011-01-03 19:04:46 +00002533 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2534 if (Result.isInvalid())
2535 return true;
2536
2537 if (Result.get() != Inputs[I] && ArgChanged)
2538 *ArgChanged = true;
2539
2540 Outputs.push_back(Result.get());
2541 }
2542
2543 return false;
2544}
2545
2546template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002547NestedNameSpecifierLoc
2548TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2549 NestedNameSpecifierLoc NNS,
2550 QualType ObjectType,
2551 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002552 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregor14454802011-02-25 02:25:35 +00002553 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2554 Qualifier = Qualifier.getPrefix())
2555 Qualifiers.push_back(Qualifier);
2556
2557 CXXScopeSpec SS;
2558 while (!Qualifiers.empty()) {
2559 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2560 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2561
2562 switch (QNNS->getKind()) {
2563 case NestedNameSpecifier::Identifier:
2564 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2565 *QNNS->getAsIdentifier(),
2566 Q.getLocalBeginLoc(),
2567 Q.getLocalEndLoc(),
2568 ObjectType, false, SS,
2569 FirstQualifierInScope, false))
2570 return NestedNameSpecifierLoc();
2571
2572 break;
2573
2574 case NestedNameSpecifier::Namespace: {
2575 NamespaceDecl *NS
2576 = cast_or_null<NamespaceDecl>(
2577 getDerived().TransformDecl(
2578 Q.getLocalBeginLoc(),
2579 QNNS->getAsNamespace()));
2580 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2581 break;
2582 }
2583
2584 case NestedNameSpecifier::NamespaceAlias: {
2585 NamespaceAliasDecl *Alias
2586 = cast_or_null<NamespaceAliasDecl>(
2587 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2588 QNNS->getAsNamespaceAlias()));
2589 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2590 Q.getLocalEndLoc());
2591 break;
2592 }
2593
2594 case NestedNameSpecifier::Global:
2595 // There is no meaningful transformation that one could perform on the
2596 // global scope.
2597 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2598 break;
2599
2600 case NestedNameSpecifier::TypeSpecWithTemplate:
2601 case NestedNameSpecifier::TypeSpec: {
2602 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2603 FirstQualifierInScope, SS);
2604
2605 if (!TL)
2606 return NestedNameSpecifierLoc();
2607
2608 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2609 (SemaRef.getLangOptions().CPlusPlus0x &&
2610 TL.getType()->isEnumeralType())) {
2611 assert(!TL.getType().hasLocalQualifiers() &&
2612 "Can't get cv-qualifiers here");
2613 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2614 Q.getLocalEndLoc());
2615 break;
2616 }
Richard Trieude756fb2011-05-07 01:36:37 +00002617 // If the nested-name-specifier is an invalid type def, don't emit an
2618 // error because a previous error should have already been emitted.
2619 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2620 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2621 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2622 << TL.getType() << SS.getRange();
2623 }
Douglas Gregor14454802011-02-25 02:25:35 +00002624 return NestedNameSpecifierLoc();
2625 }
Douglas Gregore16af532011-02-28 18:50:33 +00002626 }
Douglas Gregor14454802011-02-25 02:25:35 +00002627
Douglas Gregore16af532011-02-28 18:50:33 +00002628 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002629 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002630 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002631 }
2632
2633 // Don't rebuild the nested-name-specifier if we don't have to.
2634 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2635 !getDerived().AlwaysRebuild())
2636 return NNS;
2637
2638 // If we can re-use the source-location data from the original
2639 // nested-name-specifier, do so.
2640 if (SS.location_size() == NNS.getDataLength() &&
2641 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2642 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2643
2644 // Allocate new nested-name-specifier location information.
2645 return SS.getWithLocInContext(SemaRef.Context);
2646}
2647
2648template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002649DeclarationNameInfo
2650TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002651::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002652 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002653 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002654 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002655
2656 switch (Name.getNameKind()) {
2657 case DeclarationName::Identifier:
2658 case DeclarationName::ObjCZeroArgSelector:
2659 case DeclarationName::ObjCOneArgSelector:
2660 case DeclarationName::ObjCMultiArgSelector:
2661 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002662 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002663 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002664 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002665
Douglas Gregorf816bd72009-09-03 22:13:48 +00002666 case DeclarationName::CXXConstructorName:
2667 case DeclarationName::CXXDestructorName:
2668 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002669 TypeSourceInfo *NewTInfo;
2670 CanQualType NewCanTy;
2671 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002672 NewTInfo = getDerived().TransformType(OldTInfo);
2673 if (!NewTInfo)
2674 return DeclarationNameInfo();
2675 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002676 }
2677 else {
2678 NewTInfo = 0;
2679 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002680 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002681 if (NewT.isNull())
2682 return DeclarationNameInfo();
2683 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2684 }
Mike Stump11289f42009-09-09 15:08:12 +00002685
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002686 DeclarationName NewName
2687 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2688 NewCanTy);
2689 DeclarationNameInfo NewNameInfo(NameInfo);
2690 NewNameInfo.setName(NewName);
2691 NewNameInfo.setNamedTypeInfo(NewTInfo);
2692 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002693 }
Mike Stump11289f42009-09-09 15:08:12 +00002694 }
2695
David Blaikie83d382b2011-09-23 05:06:16 +00002696 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00002697}
2698
2699template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002700TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002701TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2702 TemplateName Name,
2703 SourceLocation NameLoc,
2704 QualType ObjectType,
2705 NamedDecl *FirstQualifierInScope) {
2706 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2707 TemplateDecl *Template = QTN->getTemplateDecl();
2708 assert(Template && "qualified template name must refer to a template");
2709
2710 TemplateDecl *TransTemplate
2711 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2712 Template));
2713 if (!TransTemplate)
2714 return TemplateName();
2715
2716 if (!getDerived().AlwaysRebuild() &&
2717 SS.getScopeRep() == QTN->getQualifier() &&
2718 TransTemplate == Template)
2719 return Name;
2720
2721 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2722 TransTemplate);
2723 }
2724
2725 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2726 if (SS.getScopeRep()) {
2727 // These apply to the scope specifier, not the template.
2728 ObjectType = QualType();
2729 FirstQualifierInScope = 0;
2730 }
2731
2732 if (!getDerived().AlwaysRebuild() &&
2733 SS.getScopeRep() == DTN->getQualifier() &&
2734 ObjectType.isNull())
2735 return Name;
2736
2737 if (DTN->isIdentifier()) {
2738 return getDerived().RebuildTemplateName(SS,
2739 *DTN->getIdentifier(),
2740 NameLoc,
2741 ObjectType,
2742 FirstQualifierInScope);
2743 }
2744
2745 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2746 ObjectType);
2747 }
2748
2749 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2750 TemplateDecl *TransTemplate
2751 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2752 Template));
2753 if (!TransTemplate)
2754 return TemplateName();
2755
2756 if (!getDerived().AlwaysRebuild() &&
2757 TransTemplate == Template)
2758 return Name;
2759
2760 return TemplateName(TransTemplate);
2761 }
2762
2763 if (SubstTemplateTemplateParmPackStorage *SubstPack
2764 = Name.getAsSubstTemplateTemplateParmPack()) {
2765 TemplateTemplateParmDecl *TransParam
2766 = cast_or_null<TemplateTemplateParmDecl>(
2767 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2768 if (!TransParam)
2769 return TemplateName();
2770
2771 if (!getDerived().AlwaysRebuild() &&
2772 TransParam == SubstPack->getParameterPack())
2773 return Name;
2774
2775 return getDerived().RebuildTemplateName(TransParam,
2776 SubstPack->getArgumentPack());
2777 }
2778
2779 // These should be getting filtered out before they reach the AST.
2780 llvm_unreachable("overloaded function decl survived to here");
2781 return TemplateName();
2782}
2783
2784template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002785void TreeTransform<Derived>::InventTemplateArgumentLoc(
2786 const TemplateArgument &Arg,
2787 TemplateArgumentLoc &Output) {
2788 SourceLocation Loc = getDerived().getBaseLocation();
2789 switch (Arg.getKind()) {
2790 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002791 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002792 break;
2793
2794 case TemplateArgument::Type:
2795 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002796 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002797
John McCall0ad16662009-10-29 08:12:44 +00002798 break;
2799
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002800 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002801 case TemplateArgument::TemplateExpansion: {
2802 NestedNameSpecifierLocBuilder Builder;
2803 TemplateName Template = Arg.getAsTemplate();
2804 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2805 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2806 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2807 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2808
2809 if (Arg.getKind() == TemplateArgument::Template)
2810 Output = TemplateArgumentLoc(Arg,
2811 Builder.getWithLocInContext(SemaRef.Context),
2812 Loc);
2813 else
2814 Output = TemplateArgumentLoc(Arg,
2815 Builder.getWithLocInContext(SemaRef.Context),
2816 Loc, Loc);
2817
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002818 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002819 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002820
John McCall0ad16662009-10-29 08:12:44 +00002821 case TemplateArgument::Expression:
2822 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2823 break;
2824
2825 case TemplateArgument::Declaration:
2826 case TemplateArgument::Integral:
2827 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002828 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002829 break;
2830 }
2831}
2832
2833template<typename Derived>
2834bool TreeTransform<Derived>::TransformTemplateArgument(
2835 const TemplateArgumentLoc &Input,
2836 TemplateArgumentLoc &Output) {
2837 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002838 switch (Arg.getKind()) {
2839 case TemplateArgument::Null:
2840 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002841 Output = Input;
2842 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002843
Douglas Gregore922c772009-08-04 22:27:00 +00002844 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002845 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002846 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002847 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002848
2849 DI = getDerived().TransformType(DI);
2850 if (!DI) return true;
2851
2852 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2853 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002854 }
Mike Stump11289f42009-09-09 15:08:12 +00002855
Douglas Gregore922c772009-08-04 22:27:00 +00002856 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002857 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002858 DeclarationName Name;
2859 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2860 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002861 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002862 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002863 if (!D) return true;
2864
John McCall0d07eb32009-10-29 18:45:58 +00002865 Expr *SourceExpr = Input.getSourceDeclExpression();
2866 if (SourceExpr) {
2867 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002868 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002869 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002870 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002871 }
2872
2873 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002874 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002875 }
Mike Stump11289f42009-09-09 15:08:12 +00002876
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002877 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002878 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2879 if (QualifierLoc) {
2880 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2881 if (!QualifierLoc)
2882 return true;
2883 }
2884
Douglas Gregordf846d12011-03-02 18:46:51 +00002885 CXXScopeSpec SS;
2886 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002887 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002888 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2889 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002890 if (Template.isNull())
2891 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002892
Douglas Gregor9d802122011-03-02 17:09:35 +00002893 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002894 Input.getTemplateNameLoc());
2895 return false;
2896 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002897
2898 case TemplateArgument::TemplateExpansion:
2899 llvm_unreachable("Caller should expand pack expansions");
2900
Douglas Gregore922c772009-08-04 22:27:00 +00002901 case TemplateArgument::Expression: {
2902 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002903 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002904 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002905
John McCall0ad16662009-10-29 08:12:44 +00002906 Expr *InputExpr = Input.getSourceExpression();
2907 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2908
Chris Lattnercdb591a2011-04-25 20:37:58 +00002909 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002910 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002911 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002912 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002913 }
Mike Stump11289f42009-09-09 15:08:12 +00002914
Douglas Gregore922c772009-08-04 22:27:00 +00002915 case TemplateArgument::Pack: {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002916 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregore922c772009-08-04 22:27:00 +00002917 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002918 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002919 AEnd = Arg.pack_end();
2920 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002921
John McCall0ad16662009-10-29 08:12:44 +00002922 // FIXME: preserve source information here when we start
2923 // caring about parameter packs.
2924
John McCall0d07eb32009-10-29 18:45:58 +00002925 TemplateArgumentLoc InputArg;
2926 TemplateArgumentLoc OutputArg;
2927 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2928 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002929 return true;
2930
John McCall0d07eb32009-10-29 18:45:58 +00002931 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002932 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002933
2934 TemplateArgument *TransformedArgsPtr
2935 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2936 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2937 TransformedArgsPtr);
2938 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2939 TransformedArgs.size()),
2940 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002941 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002942 }
2943 }
Mike Stump11289f42009-09-09 15:08:12 +00002944
Douglas Gregore922c772009-08-04 22:27:00 +00002945 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002946 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002947}
2948
Douglas Gregorfe921a72010-12-20 23:36:19 +00002949/// \brief Iterator adaptor that invents template argument location information
2950/// for each of the template arguments in its underlying iterator.
2951template<typename Derived, typename InputIterator>
2952class TemplateArgumentLocInventIterator {
2953 TreeTransform<Derived> &Self;
2954 InputIterator Iter;
2955
2956public:
2957 typedef TemplateArgumentLoc value_type;
2958 typedef TemplateArgumentLoc reference;
2959 typedef typename std::iterator_traits<InputIterator>::difference_type
2960 difference_type;
2961 typedef std::input_iterator_tag iterator_category;
2962
2963 class pointer {
2964 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002965
Douglas Gregorfe921a72010-12-20 23:36:19 +00002966 public:
2967 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2968
2969 const TemplateArgumentLoc *operator->() const { return &Arg; }
2970 };
2971
2972 TemplateArgumentLocInventIterator() { }
2973
2974 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2975 InputIterator Iter)
2976 : Self(Self), Iter(Iter) { }
2977
2978 TemplateArgumentLocInventIterator &operator++() {
2979 ++Iter;
2980 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002981 }
2982
Douglas Gregorfe921a72010-12-20 23:36:19 +00002983 TemplateArgumentLocInventIterator operator++(int) {
2984 TemplateArgumentLocInventIterator Old(*this);
2985 ++(*this);
2986 return Old;
2987 }
2988
2989 reference operator*() const {
2990 TemplateArgumentLoc Result;
2991 Self.InventTemplateArgumentLoc(*Iter, Result);
2992 return Result;
2993 }
2994
2995 pointer operator->() const { return pointer(**this); }
2996
2997 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2998 const TemplateArgumentLocInventIterator &Y) {
2999 return X.Iter == Y.Iter;
3000 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003001
Douglas Gregorfe921a72010-12-20 23:36:19 +00003002 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3003 const TemplateArgumentLocInventIterator &Y) {
3004 return X.Iter != Y.Iter;
3005 }
3006};
3007
Douglas Gregor42cafa82010-12-20 17:42:22 +00003008template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003009template<typename InputIterator>
3010bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3011 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003012 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003013 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003014 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003015 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003016
3017 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3018 // Unpack argument packs, which we translate them into separate
3019 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003020 // FIXME: We could do much better if we could guarantee that the
3021 // TemplateArgumentLocInfo for the pack expansion would be usable for
3022 // all of the template arguments in the argument pack.
3023 typedef TemplateArgumentLocInventIterator<Derived,
3024 TemplateArgument::pack_iterator>
3025 PackLocIterator;
3026 if (TransformTemplateArguments(PackLocIterator(*this,
3027 In.getArgument().pack_begin()),
3028 PackLocIterator(*this,
3029 In.getArgument().pack_end()),
3030 Outputs))
3031 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003032
3033 continue;
3034 }
3035
3036 if (In.getArgument().isPackExpansion()) {
3037 // We have a pack expansion, for which we will be substituting into
3038 // the pattern.
3039 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003040 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003041 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003042 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3043 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003044
Chris Lattner01cf8db2011-07-20 06:58:45 +00003045 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003046 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3047 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3048
3049 // Determine whether the set of unexpanded parameter packs can and should
3050 // be expanded.
3051 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003052 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003053 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003054 if (getDerived().TryExpandParameterPacks(Ellipsis,
3055 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003056 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003057 Expand,
3058 RetainExpansion,
3059 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003060 return true;
3061
3062 if (!Expand) {
3063 // The transform has determined that we should perform a simple
3064 // transformation on the pack expansion, producing another pack
3065 // expansion.
3066 TemplateArgumentLoc OutPattern;
3067 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3068 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3069 return true;
3070
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003071 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3072 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003073 if (Out.getArgument().isNull())
3074 return true;
3075
3076 Outputs.addArgument(Out);
3077 continue;
3078 }
3079
3080 // The transform has determined that we should perform an elementwise
3081 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003082 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003083 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3084
3085 if (getDerived().TransformTemplateArgument(Pattern, Out))
3086 return true;
3087
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003088 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003089 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3090 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003091 if (Out.getArgument().isNull())
3092 return true;
3093 }
3094
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003095 Outputs.addArgument(Out);
3096 }
3097
Douglas Gregor48d24112011-01-10 20:53:55 +00003098 // If we're supposed to retain a pack expansion, do so by temporarily
3099 // forgetting the partially-substituted parameter pack.
3100 if (RetainExpansion) {
3101 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3102
3103 if (getDerived().TransformTemplateArgument(Pattern, Out))
3104 return true;
3105
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003106 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3107 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003108 if (Out.getArgument().isNull())
3109 return true;
3110
3111 Outputs.addArgument(Out);
3112 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003113
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003114 continue;
3115 }
3116
3117 // The simple case:
3118 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003119 return true;
3120
3121 Outputs.addArgument(Out);
3122 }
3123
3124 return false;
3125
3126}
3127
Douglas Gregord6ff3322009-08-04 16:50:30 +00003128//===----------------------------------------------------------------------===//
3129// Type transformation
3130//===----------------------------------------------------------------------===//
3131
3132template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003133QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003134 if (getDerived().AlreadyTransformed(T))
3135 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003136
John McCall550e0c22009-10-21 00:40:46 +00003137 // Temporary workaround. All of these transformations should
3138 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003139 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3140 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003141
John McCall31f82722010-11-12 08:19:04 +00003142 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003143
John McCall550e0c22009-10-21 00:40:46 +00003144 if (!NewDI)
3145 return QualType();
3146
3147 return NewDI->getType();
3148}
3149
3150template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003151TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003152 if (getDerived().AlreadyTransformed(DI->getType()))
3153 return DI;
3154
3155 TypeLocBuilder TLB;
3156
3157 TypeLoc TL = DI->getTypeLoc();
3158 TLB.reserve(TL.getFullDataSize());
3159
John McCall31f82722010-11-12 08:19:04 +00003160 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003161 if (Result.isNull())
3162 return 0;
3163
John McCallbcd03502009-12-07 02:54:59 +00003164 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003165}
3166
3167template<typename Derived>
3168QualType
John McCall31f82722010-11-12 08:19:04 +00003169TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003170 switch (T.getTypeLocClass()) {
3171#define ABSTRACT_TYPELOC(CLASS, PARENT)
3172#define TYPELOC(CLASS, PARENT) \
3173 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003174 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003175#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003176 }
Mike Stump11289f42009-09-09 15:08:12 +00003177
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003178 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003179 return QualType();
3180}
3181
3182/// FIXME: By default, this routine adds type qualifiers only to types
3183/// that can have qualifiers, and silently suppresses those qualifiers
3184/// that are not permitted (e.g., qualifiers on reference or function
3185/// types). This is the right thing for template instantiation, but
3186/// probably not for other clients.
3187template<typename Derived>
3188QualType
3189TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003190 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003191 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003192
John McCall31f82722010-11-12 08:19:04 +00003193 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003194 if (Result.isNull())
3195 return QualType();
3196
3197 // Silently suppress qualifiers if the result type can't be qualified.
3198 // FIXME: this is the right thing for template instantiation, but
3199 // probably not for other clients.
3200 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003201 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003202
John McCall31168b02011-06-15 23:02:42 +00003203 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003204 // resulting type.
3205 if (Quals.hasObjCLifetime()) {
3206 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3207 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003208 else if (Result.getObjCLifetime()) {
Douglas Gregore46db902011-06-17 22:11:49 +00003209 // Objective-C ARC:
3210 // A lifetime qualifier applied to a substituted template parameter
3211 // overrides the lifetime qualifier from the template argument.
3212 if (const SubstTemplateTypeParmType *SubstTypeParam
3213 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3214 QualType Replacement = SubstTypeParam->getReplacementType();
3215 Qualifiers Qs = Replacement.getQualifiers();
3216 Qs.removeObjCLifetime();
3217 Replacement
3218 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3219 Qs);
3220 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3221 SubstTypeParam->getReplacedParameter(),
3222 Replacement);
3223 TLB.TypeWasModifiedSafely(Result);
3224 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003225 // Otherwise, complain about the addition of a qualifier to an
3226 // already-qualified type.
3227 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003228 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003229 << Result << R;
3230
Douglas Gregore46db902011-06-17 22:11:49 +00003231 Quals.removeObjCLifetime();
3232 }
3233 }
3234 }
John McCallcb0f89a2010-06-05 06:41:15 +00003235 if (!Quals.empty()) {
3236 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3237 TLB.push<QualifiedTypeLoc>(Result);
3238 // No location information to preserve.
3239 }
John McCall550e0c22009-10-21 00:40:46 +00003240
3241 return Result;
3242}
3243
Douglas Gregor14454802011-02-25 02:25:35 +00003244template<typename Derived>
3245TypeLoc
3246TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3247 QualType ObjectType,
3248 NamedDecl *UnqualLookup,
3249 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003250 QualType T = TL.getType();
3251 if (getDerived().AlreadyTransformed(T))
3252 return TL;
3253
3254 TypeLocBuilder TLB;
3255 QualType Result;
3256
3257 if (isa<TemplateSpecializationType>(T)) {
3258 TemplateSpecializationTypeLoc SpecTL
3259 = cast<TemplateSpecializationTypeLoc>(TL);
3260
3261 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003262 getDerived().TransformTemplateName(SS,
3263 SpecTL.getTypePtr()->getTemplateName(),
3264 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003265 ObjectType, UnqualLookup);
3266 if (Template.isNull())
3267 return TypeLoc();
3268
3269 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3270 Template);
3271 } else if (isa<DependentTemplateSpecializationType>(T)) {
3272 DependentTemplateSpecializationTypeLoc SpecTL
3273 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3274
Douglas Gregor5a064722011-02-28 17:23:35 +00003275 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003276 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003277 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003278 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003279 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003280 if (Template.isNull())
3281 return TypeLoc();
3282
Douglas Gregor14454802011-02-25 02:25:35 +00003283 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003284 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003285 Template,
3286 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003287 } else {
3288 // Nothing special needs to be done for these.
3289 Result = getDerived().TransformType(TLB, TL);
3290 }
3291
3292 if (Result.isNull())
3293 return TypeLoc();
3294
3295 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3296}
3297
Douglas Gregor579c15f2011-03-02 18:32:08 +00003298template<typename Derived>
3299TypeSourceInfo *
3300TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3301 QualType ObjectType,
3302 NamedDecl *UnqualLookup,
3303 CXXScopeSpec &SS) {
3304 // FIXME: Painfully copy-paste from the above!
3305
3306 QualType T = TSInfo->getType();
3307 if (getDerived().AlreadyTransformed(T))
3308 return TSInfo;
3309
3310 TypeLocBuilder TLB;
3311 QualType Result;
3312
3313 TypeLoc TL = TSInfo->getTypeLoc();
3314 if (isa<TemplateSpecializationType>(T)) {
3315 TemplateSpecializationTypeLoc SpecTL
3316 = cast<TemplateSpecializationTypeLoc>(TL);
3317
3318 TemplateName Template
3319 = getDerived().TransformTemplateName(SS,
3320 SpecTL.getTypePtr()->getTemplateName(),
3321 SpecTL.getTemplateNameLoc(),
3322 ObjectType, UnqualLookup);
3323 if (Template.isNull())
3324 return 0;
3325
3326 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3327 Template);
3328 } else if (isa<DependentTemplateSpecializationType>(T)) {
3329 DependentTemplateSpecializationTypeLoc SpecTL
3330 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3331
3332 TemplateName Template
3333 = getDerived().RebuildTemplateName(SS,
3334 *SpecTL.getTypePtr()->getIdentifier(),
3335 SpecTL.getNameLoc(),
3336 ObjectType, UnqualLookup);
3337 if (Template.isNull())
3338 return 0;
3339
3340 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3341 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003342 Template,
3343 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003344 } else {
3345 // Nothing special needs to be done for these.
3346 Result = getDerived().TransformType(TLB, TL);
3347 }
3348
3349 if (Result.isNull())
3350 return 0;
3351
3352 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3353}
3354
John McCall550e0c22009-10-21 00:40:46 +00003355template <class TyLoc> static inline
3356QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3357 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3358 NewT.setNameLoc(T.getNameLoc());
3359 return T.getType();
3360}
3361
John McCall550e0c22009-10-21 00:40:46 +00003362template<typename Derived>
3363QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003364 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003365 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3366 NewT.setBuiltinLoc(T.getBuiltinLoc());
3367 if (T.needsExtraLocalData())
3368 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3369 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003370}
Mike Stump11289f42009-09-09 15:08:12 +00003371
Douglas Gregord6ff3322009-08-04 16:50:30 +00003372template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003373QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003374 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003375 // FIXME: recurse?
3376 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003377}
Mike Stump11289f42009-09-09 15:08:12 +00003378
Douglas Gregord6ff3322009-08-04 16:50:30 +00003379template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003380QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003381 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003382 QualType PointeeType
3383 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003384 if (PointeeType.isNull())
3385 return QualType();
3386
3387 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003388 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003389 // A dependent pointer type 'T *' has is being transformed such
3390 // that an Objective-C class type is being replaced for 'T'. The
3391 // resulting pointer type is an ObjCObjectPointerType, not a
3392 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003393 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003394
John McCall8b07ec22010-05-15 11:32:37 +00003395 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3396 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003397 return Result;
3398 }
John McCall31f82722010-11-12 08:19:04 +00003399
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003400 if (getDerived().AlwaysRebuild() ||
3401 PointeeType != TL.getPointeeLoc().getType()) {
3402 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3403 if (Result.isNull())
3404 return QualType();
3405 }
John McCall31168b02011-06-15 23:02:42 +00003406
3407 // Objective-C ARC can add lifetime qualifiers to the type that we're
3408 // pointing to.
3409 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3410
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003411 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3412 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003413 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003414}
Mike Stump11289f42009-09-09 15:08:12 +00003415
3416template<typename Derived>
3417QualType
John McCall550e0c22009-10-21 00:40:46 +00003418TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003419 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003420 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003421 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3422 if (PointeeType.isNull())
3423 return QualType();
3424
3425 QualType Result = TL.getType();
3426 if (getDerived().AlwaysRebuild() ||
3427 PointeeType != TL.getPointeeLoc().getType()) {
3428 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003429 TL.getSigilLoc());
3430 if (Result.isNull())
3431 return QualType();
3432 }
3433
Douglas Gregor049211a2010-04-22 16:50:51 +00003434 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003435 NewT.setSigilLoc(TL.getSigilLoc());
3436 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003437}
3438
John McCall70dd5f62009-10-30 00:06:24 +00003439/// Transforms a reference type. Note that somewhat paradoxically we
3440/// don't care whether the type itself is an l-value type or an r-value
3441/// type; we only care if the type was *written* as an l-value type
3442/// or an r-value type.
3443template<typename Derived>
3444QualType
3445TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003446 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003447 const ReferenceType *T = TL.getTypePtr();
3448
3449 // Note that this works with the pointee-as-written.
3450 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3451 if (PointeeType.isNull())
3452 return QualType();
3453
3454 QualType Result = TL.getType();
3455 if (getDerived().AlwaysRebuild() ||
3456 PointeeType != T->getPointeeTypeAsWritten()) {
3457 Result = getDerived().RebuildReferenceType(PointeeType,
3458 T->isSpelledAsLValue(),
3459 TL.getSigilLoc());
3460 if (Result.isNull())
3461 return QualType();
3462 }
3463
John McCall31168b02011-06-15 23:02:42 +00003464 // Objective-C ARC can add lifetime qualifiers to the type that we're
3465 // referring to.
3466 TLB.TypeWasModifiedSafely(
3467 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3468
John McCall70dd5f62009-10-30 00:06:24 +00003469 // r-value references can be rebuilt as l-value references.
3470 ReferenceTypeLoc NewTL;
3471 if (isa<LValueReferenceType>(Result))
3472 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3473 else
3474 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3475 NewTL.setSigilLoc(TL.getSigilLoc());
3476
3477 return Result;
3478}
3479
Mike Stump11289f42009-09-09 15:08:12 +00003480template<typename Derived>
3481QualType
John McCall550e0c22009-10-21 00:40:46 +00003482TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003483 LValueReferenceTypeLoc TL) {
3484 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003485}
3486
Mike Stump11289f42009-09-09 15:08:12 +00003487template<typename Derived>
3488QualType
John McCall550e0c22009-10-21 00:40:46 +00003489TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003490 RValueReferenceTypeLoc TL) {
3491 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003492}
Mike Stump11289f42009-09-09 15:08:12 +00003493
Douglas Gregord6ff3322009-08-04 16:50:30 +00003494template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003495QualType
John McCall550e0c22009-10-21 00:40:46 +00003496TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003497 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003498 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003499 if (PointeeType.isNull())
3500 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003501
Abramo Bagnara509357842011-03-05 14:42:21 +00003502 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3503 TypeSourceInfo* NewClsTInfo = 0;
3504 if (OldClsTInfo) {
3505 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3506 if (!NewClsTInfo)
3507 return QualType();
3508 }
3509
3510 const MemberPointerType *T = TL.getTypePtr();
3511 QualType OldClsType = QualType(T->getClass(), 0);
3512 QualType NewClsType;
3513 if (NewClsTInfo)
3514 NewClsType = NewClsTInfo->getType();
3515 else {
3516 NewClsType = getDerived().TransformType(OldClsType);
3517 if (NewClsType.isNull())
3518 return QualType();
3519 }
Mike Stump11289f42009-09-09 15:08:12 +00003520
John McCall550e0c22009-10-21 00:40:46 +00003521 QualType Result = TL.getType();
3522 if (getDerived().AlwaysRebuild() ||
3523 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003524 NewClsType != OldClsType) {
3525 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003526 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003527 if (Result.isNull())
3528 return QualType();
3529 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003530
John McCall550e0c22009-10-21 00:40:46 +00003531 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3532 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003533 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003534
3535 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003536}
3537
Mike Stump11289f42009-09-09 15:08:12 +00003538template<typename Derived>
3539QualType
John McCall550e0c22009-10-21 00:40:46 +00003540TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003541 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003542 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003543 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003544 if (ElementType.isNull())
3545 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003546
John McCall550e0c22009-10-21 00:40:46 +00003547 QualType Result = TL.getType();
3548 if (getDerived().AlwaysRebuild() ||
3549 ElementType != T->getElementType()) {
3550 Result = getDerived().RebuildConstantArrayType(ElementType,
3551 T->getSizeModifier(),
3552 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003553 T->getIndexTypeCVRQualifiers(),
3554 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003555 if (Result.isNull())
3556 return QualType();
3557 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003558
John McCall550e0c22009-10-21 00:40:46 +00003559 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3560 NewTL.setLBracketLoc(TL.getLBracketLoc());
3561 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003562
John McCall550e0c22009-10-21 00:40:46 +00003563 Expr *Size = TL.getSizeExpr();
3564 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003565 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003566 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3567 }
3568 NewTL.setSizeExpr(Size);
3569
3570 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003571}
Mike Stump11289f42009-09-09 15:08:12 +00003572
Douglas Gregord6ff3322009-08-04 16:50:30 +00003573template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003574QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003575 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003576 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003577 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003578 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003579 if (ElementType.isNull())
3580 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003581
John McCall550e0c22009-10-21 00:40:46 +00003582 QualType Result = TL.getType();
3583 if (getDerived().AlwaysRebuild() ||
3584 ElementType != T->getElementType()) {
3585 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003586 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003587 T->getIndexTypeCVRQualifiers(),
3588 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003589 if (Result.isNull())
3590 return QualType();
3591 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003592
John McCall550e0c22009-10-21 00:40:46 +00003593 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3594 NewTL.setLBracketLoc(TL.getLBracketLoc());
3595 NewTL.setRBracketLoc(TL.getRBracketLoc());
3596 NewTL.setSizeExpr(0);
3597
3598 return Result;
3599}
3600
3601template<typename Derived>
3602QualType
3603TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003604 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003605 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003606 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3607 if (ElementType.isNull())
3608 return QualType();
3609
3610 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003611 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003612
John McCalldadc5752010-08-24 06:29:42 +00003613 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003614 = getDerived().TransformExpr(T->getSizeExpr());
3615 if (SizeResult.isInvalid())
3616 return QualType();
3617
John McCallb268a282010-08-23 23:25:46 +00003618 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003619
3620 QualType Result = TL.getType();
3621 if (getDerived().AlwaysRebuild() ||
3622 ElementType != T->getElementType() ||
3623 Size != T->getSizeExpr()) {
3624 Result = getDerived().RebuildVariableArrayType(ElementType,
3625 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003626 Size,
John McCall550e0c22009-10-21 00:40:46 +00003627 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003628 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003629 if (Result.isNull())
3630 return QualType();
3631 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003632
John McCall550e0c22009-10-21 00:40:46 +00003633 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3634 NewTL.setLBracketLoc(TL.getLBracketLoc());
3635 NewTL.setRBracketLoc(TL.getRBracketLoc());
3636 NewTL.setSizeExpr(Size);
3637
3638 return Result;
3639}
3640
3641template<typename Derived>
3642QualType
3643TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003644 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003645 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003646 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3647 if (ElementType.isNull())
3648 return QualType();
3649
3650 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003651 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003652
John McCall33ddac02011-01-19 10:06:00 +00003653 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3654 Expr *origSize = TL.getSizeExpr();
3655 if (!origSize) origSize = T->getSizeExpr();
3656
3657 ExprResult sizeResult
3658 = getDerived().TransformExpr(origSize);
3659 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003660 return QualType();
3661
John McCall33ddac02011-01-19 10:06:00 +00003662 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003663
3664 QualType Result = TL.getType();
3665 if (getDerived().AlwaysRebuild() ||
3666 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003667 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003668 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3669 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003670 size,
John McCall550e0c22009-10-21 00:40:46 +00003671 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003672 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003673 if (Result.isNull())
3674 return QualType();
3675 }
John McCall550e0c22009-10-21 00:40:46 +00003676
3677 // We might have any sort of array type now, but fortunately they
3678 // all have the same location layout.
3679 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3680 NewTL.setLBracketLoc(TL.getLBracketLoc());
3681 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003682 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003683
3684 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003685}
Mike Stump11289f42009-09-09 15:08:12 +00003686
3687template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003688QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003689 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003690 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003691 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003692
3693 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003694 QualType ElementType = getDerived().TransformType(T->getElementType());
3695 if (ElementType.isNull())
3696 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003697
Douglas Gregore922c772009-08-04 22:27:00 +00003698 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003699 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003700
John McCalldadc5752010-08-24 06:29:42 +00003701 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003702 if (Size.isInvalid())
3703 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003704
John McCall550e0c22009-10-21 00:40:46 +00003705 QualType Result = TL.getType();
3706 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003707 ElementType != T->getElementType() ||
3708 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003709 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003710 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003711 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003712 if (Result.isNull())
3713 return QualType();
3714 }
John McCall550e0c22009-10-21 00:40:46 +00003715
3716 // Result might be dependent or not.
3717 if (isa<DependentSizedExtVectorType>(Result)) {
3718 DependentSizedExtVectorTypeLoc NewTL
3719 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3720 NewTL.setNameLoc(TL.getNameLoc());
3721 } else {
3722 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3723 NewTL.setNameLoc(TL.getNameLoc());
3724 }
3725
3726 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003727}
Mike Stump11289f42009-09-09 15:08:12 +00003728
3729template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003730QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003731 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003732 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003733 QualType ElementType = getDerived().TransformType(T->getElementType());
3734 if (ElementType.isNull())
3735 return QualType();
3736
John McCall550e0c22009-10-21 00:40:46 +00003737 QualType Result = TL.getType();
3738 if (getDerived().AlwaysRebuild() ||
3739 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003740 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003741 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003742 if (Result.isNull())
3743 return QualType();
3744 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003745
John McCall550e0c22009-10-21 00:40:46 +00003746 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3747 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003748
John McCall550e0c22009-10-21 00:40:46 +00003749 return Result;
3750}
3751
3752template<typename Derived>
3753QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003754 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003755 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003756 QualType ElementType = getDerived().TransformType(T->getElementType());
3757 if (ElementType.isNull())
3758 return QualType();
3759
3760 QualType Result = TL.getType();
3761 if (getDerived().AlwaysRebuild() ||
3762 ElementType != T->getElementType()) {
3763 Result = getDerived().RebuildExtVectorType(ElementType,
3764 T->getNumElements(),
3765 /*FIXME*/ SourceLocation());
3766 if (Result.isNull())
3767 return QualType();
3768 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003769
John McCall550e0c22009-10-21 00:40:46 +00003770 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3771 NewTL.setNameLoc(TL.getNameLoc());
3772
3773 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003774}
Mike Stump11289f42009-09-09 15:08:12 +00003775
3776template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003777ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003778TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003779 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003780 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003781 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003782 TypeSourceInfo *NewDI = 0;
3783
3784 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3785 // If we're substituting into a pack expansion type and we know the
3786 TypeLoc OldTL = OldDI->getTypeLoc();
3787 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3788
3789 TypeLocBuilder TLB;
3790 TypeLoc NewTL = OldDI->getTypeLoc();
3791 TLB.reserve(NewTL.getFullDataSize());
3792
3793 QualType Result = getDerived().TransformType(TLB,
3794 OldExpansionTL.getPatternLoc());
3795 if (Result.isNull())
3796 return 0;
3797
3798 Result = RebuildPackExpansionType(Result,
3799 OldExpansionTL.getPatternLoc().getSourceRange(),
3800 OldExpansionTL.getEllipsisLoc(),
3801 NumExpansions);
3802 if (Result.isNull())
3803 return 0;
3804
3805 PackExpansionTypeLoc NewExpansionTL
3806 = TLB.push<PackExpansionTypeLoc>(Result);
3807 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3808 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3809 } else
3810 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003811 if (!NewDI)
3812 return 0;
3813
John McCall8fb0d9d2011-05-01 22:35:37 +00003814 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003815 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003816
3817 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3818 OldParm->getDeclContext(),
3819 OldParm->getInnerLocStart(),
3820 OldParm->getLocation(),
3821 OldParm->getIdentifier(),
3822 NewDI->getType(),
3823 NewDI,
3824 OldParm->getStorageClass(),
3825 OldParm->getStorageClassAsWritten(),
3826 /* DefArg */ NULL);
3827 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3828 OldParm->getFunctionScopeIndex() + indexAdjustment);
3829 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003830}
3831
3832template<typename Derived>
3833bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003834 TransformFunctionTypeParams(SourceLocation Loc,
3835 ParmVarDecl **Params, unsigned NumParams,
3836 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003837 SmallVectorImpl<QualType> &OutParamTypes,
3838 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003839 int indexAdjustment = 0;
3840
Douglas Gregordd472162011-01-07 00:20:55 +00003841 for (unsigned i = 0; i != NumParams; ++i) {
3842 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003843 assert(OldParm->getFunctionScopeIndex() == i);
3844
Douglas Gregor715e4612011-01-14 22:40:04 +00003845 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003846 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003847 if (OldParm->isParameterPack()) {
3848 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00003849 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003850
Douglas Gregor5499af42011-01-05 23:12:31 +00003851 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003852 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3853 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3854 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3855 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003856 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3857
Douglas Gregor5499af42011-01-05 23:12:31 +00003858 // Determine whether we should expand the parameter packs.
3859 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003860 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003861 llvm::Optional<unsigned> OrigNumExpansions
3862 = ExpansionTL.getTypePtr()->getNumExpansions();
3863 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003864 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3865 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003866 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003867 ShouldExpand,
3868 RetainExpansion,
3869 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003870 return true;
3871 }
3872
3873 if (ShouldExpand) {
3874 // Expand the function parameter pack into multiple, separate
3875 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003876 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003877 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003878 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3879 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003880 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003881 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003882 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003883 if (!NewParm)
3884 return true;
3885
Douglas Gregordd472162011-01-07 00:20:55 +00003886 OutParamTypes.push_back(NewParm->getType());
3887 if (PVars)
3888 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003889 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003890
3891 // If we're supposed to retain a pack expansion, do so by temporarily
3892 // forgetting the partially-substituted parameter pack.
3893 if (RetainExpansion) {
3894 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3895 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003896 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003897 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003898 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003899 if (!NewParm)
3900 return true;
3901
3902 OutParamTypes.push_back(NewParm->getType());
3903 if (PVars)
3904 PVars->push_back(NewParm);
3905 }
3906
John McCall8fb0d9d2011-05-01 22:35:37 +00003907 // The next parameter should have the same adjustment as the
3908 // last thing we pushed, but we post-incremented indexAdjustment
3909 // on every push. Also, if we push nothing, the adjustment should
3910 // go down by one.
3911 indexAdjustment--;
3912
Douglas Gregor5499af42011-01-05 23:12:31 +00003913 // We're done with the pack expansion.
3914 continue;
3915 }
3916
3917 // We'll substitute the parameter now without expanding the pack
3918 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003919 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3920 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003921 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003922 NumExpansions);
3923 } else {
3924 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003925 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003926 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003927 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003928
John McCall58f10c32010-03-11 09:03:00 +00003929 if (!NewParm)
3930 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003931
Douglas Gregordd472162011-01-07 00:20:55 +00003932 OutParamTypes.push_back(NewParm->getType());
3933 if (PVars)
3934 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003935 continue;
3936 }
John McCall58f10c32010-03-11 09:03:00 +00003937
3938 // Deal with the possibility that we don't have a parameter
3939 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003940 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003941 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003942 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003943 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003944 if (const PackExpansionType *Expansion
3945 = dyn_cast<PackExpansionType>(OldType)) {
3946 // We have a function parameter pack that may need to be expanded.
3947 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00003948 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00003949 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3950
3951 // Determine whether we should expand the parameter packs.
3952 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003953 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003954 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003955 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003956 ShouldExpand,
3957 RetainExpansion,
3958 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003959 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003960 }
3961
3962 if (ShouldExpand) {
3963 // Expand the function parameter pack into multiple, separate
3964 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003965 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003966 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3967 QualType NewType = getDerived().TransformType(Pattern);
3968 if (NewType.isNull())
3969 return true;
John McCall58f10c32010-03-11 09:03:00 +00003970
Douglas Gregordd472162011-01-07 00:20:55 +00003971 OutParamTypes.push_back(NewType);
3972 if (PVars)
3973 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003974 }
3975
3976 // We're done with the pack expansion.
3977 continue;
3978 }
3979
Douglas Gregor48d24112011-01-10 20:53:55 +00003980 // If we're supposed to retain a pack expansion, do so by temporarily
3981 // forgetting the partially-substituted parameter pack.
3982 if (RetainExpansion) {
3983 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3984 QualType NewType = getDerived().TransformType(Pattern);
3985 if (NewType.isNull())
3986 return true;
3987
3988 OutParamTypes.push_back(NewType);
3989 if (PVars)
3990 PVars->push_back(0);
3991 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003992
Douglas Gregor5499af42011-01-05 23:12:31 +00003993 // We'll substitute the parameter now without expanding the pack
3994 // expansion.
3995 OldType = Expansion->getPattern();
3996 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003997 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3998 NewType = getDerived().TransformType(OldType);
3999 } else {
4000 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004001 }
4002
Douglas Gregor5499af42011-01-05 23:12:31 +00004003 if (NewType.isNull())
4004 return true;
4005
4006 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004007 NewType = getSema().Context.getPackExpansionType(NewType,
4008 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00004009
Douglas Gregordd472162011-01-07 00:20:55 +00004010 OutParamTypes.push_back(NewType);
4011 if (PVars)
4012 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004013 }
4014
John McCall8fb0d9d2011-05-01 22:35:37 +00004015#ifndef NDEBUG
4016 if (PVars) {
4017 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4018 if (ParmVarDecl *parm = (*PVars)[i])
4019 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004020 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004021#endif
4022
4023 return false;
4024}
John McCall58f10c32010-03-11 09:03:00 +00004025
4026template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004027QualType
John McCall550e0c22009-10-21 00:40:46 +00004028TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004029 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004030 // Transform the parameters and return type.
4031 //
4032 // We instantiate in source order, with the return type first followed by
4033 // the parameters, because users tend to expect this (even if they shouldn't
4034 // rely on it!).
4035 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00004036 // When the function has a trailing return type, we instantiate the
4037 // parameters before the return type, since the return type can then refer
4038 // to the parameters themselves (via decltype, sizeof, etc.).
4039 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004040 SmallVector<QualType, 4> ParamTypes;
4041 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004042 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004043
Douglas Gregor7fb25412010-10-01 18:44:50 +00004044 QualType ResultType;
4045
4046 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004047 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4048 TL.getParmArray(),
4049 TL.getNumArgs(),
4050 TL.getTypePtr()->arg_type_begin(),
4051 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004052 return QualType();
4053
4054 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4055 if (ResultType.isNull())
4056 return QualType();
4057 }
4058 else {
4059 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4060 if (ResultType.isNull())
4061 return QualType();
4062
Douglas Gregordd472162011-01-07 00:20:55 +00004063 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4064 TL.getParmArray(),
4065 TL.getNumArgs(),
4066 TL.getTypePtr()->arg_type_begin(),
4067 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004068 return QualType();
4069 }
4070
John McCall550e0c22009-10-21 00:40:46 +00004071 QualType Result = TL.getType();
4072 if (getDerived().AlwaysRebuild() ||
4073 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004074 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004075 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4076 Result = getDerived().RebuildFunctionProtoType(ResultType,
4077 ParamTypes.data(),
4078 ParamTypes.size(),
4079 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004080 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004081 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004082 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004083 if (Result.isNull())
4084 return QualType();
4085 }
Mike Stump11289f42009-09-09 15:08:12 +00004086
John McCall550e0c22009-10-21 00:40:46 +00004087 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004088 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4089 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004090 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004091 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4092 NewTL.setArg(i, ParamDecls[i]);
4093
4094 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004095}
Mike Stump11289f42009-09-09 15:08:12 +00004096
Douglas Gregord6ff3322009-08-04 16:50:30 +00004097template<typename Derived>
4098QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004099 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004100 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004101 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004102 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4103 if (ResultType.isNull())
4104 return QualType();
4105
4106 QualType Result = TL.getType();
4107 if (getDerived().AlwaysRebuild() ||
4108 ResultType != T->getResultType())
4109 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4110
4111 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004112 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4113 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004114 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004115
4116 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004117}
Mike Stump11289f42009-09-09 15:08:12 +00004118
John McCallb96ec562009-12-04 22:46:56 +00004119template<typename Derived> QualType
4120TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004121 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004122 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004123 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004124 if (!D)
4125 return QualType();
4126
4127 QualType Result = TL.getType();
4128 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4129 Result = getDerived().RebuildUnresolvedUsingType(D);
4130 if (Result.isNull())
4131 return QualType();
4132 }
4133
4134 // We might get an arbitrary type spec type back. We should at
4135 // least always get a type spec type, though.
4136 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4137 NewTL.setNameLoc(TL.getNameLoc());
4138
4139 return Result;
4140}
4141
Douglas Gregord6ff3322009-08-04 16:50:30 +00004142template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004143QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004144 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004145 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004146 TypedefNameDecl *Typedef
4147 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4148 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004149 if (!Typedef)
4150 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004151
John McCall550e0c22009-10-21 00:40:46 +00004152 QualType Result = TL.getType();
4153 if (getDerived().AlwaysRebuild() ||
4154 Typedef != T->getDecl()) {
4155 Result = getDerived().RebuildTypedefType(Typedef);
4156 if (Result.isNull())
4157 return QualType();
4158 }
Mike Stump11289f42009-09-09 15:08:12 +00004159
John McCall550e0c22009-10-21 00:40:46 +00004160 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4161 NewTL.setNameLoc(TL.getNameLoc());
4162
4163 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004164}
Mike Stump11289f42009-09-09 15:08:12 +00004165
Douglas Gregord6ff3322009-08-04 16:50:30 +00004166template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004167QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004168 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004169 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004170 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004171
John McCalldadc5752010-08-24 06:29:42 +00004172 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004173 if (E.isInvalid())
4174 return QualType();
4175
John McCall550e0c22009-10-21 00:40:46 +00004176 QualType Result = TL.getType();
4177 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004178 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004179 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004180 if (Result.isNull())
4181 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004182 }
John McCall550e0c22009-10-21 00:40:46 +00004183 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004184
John McCall550e0c22009-10-21 00:40:46 +00004185 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004186 NewTL.setTypeofLoc(TL.getTypeofLoc());
4187 NewTL.setLParenLoc(TL.getLParenLoc());
4188 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004189
4190 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004191}
Mike Stump11289f42009-09-09 15:08:12 +00004192
4193template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004194QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004195 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004196 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4197 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4198 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004199 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004200
John McCall550e0c22009-10-21 00:40:46 +00004201 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004202 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4203 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004204 if (Result.isNull())
4205 return QualType();
4206 }
Mike Stump11289f42009-09-09 15:08:12 +00004207
John McCall550e0c22009-10-21 00:40:46 +00004208 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004209 NewTL.setTypeofLoc(TL.getTypeofLoc());
4210 NewTL.setLParenLoc(TL.getLParenLoc());
4211 NewTL.setRParenLoc(TL.getRParenLoc());
4212 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004213
4214 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004215}
Mike Stump11289f42009-09-09 15:08:12 +00004216
4217template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004218QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004219 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004220 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004221
Douglas Gregore922c772009-08-04 22:27:00 +00004222 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004223 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004224
John McCalldadc5752010-08-24 06:29:42 +00004225 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004226 if (E.isInvalid())
4227 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004228
John McCall550e0c22009-10-21 00:40:46 +00004229 QualType Result = TL.getType();
4230 if (getDerived().AlwaysRebuild() ||
4231 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004232 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004233 if (Result.isNull())
4234 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004235 }
John McCall550e0c22009-10-21 00:40:46 +00004236 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004237
John McCall550e0c22009-10-21 00:40:46 +00004238 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4239 NewTL.setNameLoc(TL.getNameLoc());
4240
4241 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004242}
4243
4244template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004245QualType TreeTransform<Derived>::TransformUnaryTransformType(
4246 TypeLocBuilder &TLB,
4247 UnaryTransformTypeLoc TL) {
4248 QualType Result = TL.getType();
4249 if (Result->isDependentType()) {
4250 const UnaryTransformType *T = TL.getTypePtr();
4251 QualType NewBase =
4252 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4253 Result = getDerived().RebuildUnaryTransformType(NewBase,
4254 T->getUTTKind(),
4255 TL.getKWLoc());
4256 if (Result.isNull())
4257 return QualType();
4258 }
4259
4260 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4261 NewTL.setKWLoc(TL.getKWLoc());
4262 NewTL.setParensRange(TL.getParensRange());
4263 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4264 return Result;
4265}
4266
4267template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004268QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4269 AutoTypeLoc TL) {
4270 const AutoType *T = TL.getTypePtr();
4271 QualType OldDeduced = T->getDeducedType();
4272 QualType NewDeduced;
4273 if (!OldDeduced.isNull()) {
4274 NewDeduced = getDerived().TransformType(OldDeduced);
4275 if (NewDeduced.isNull())
4276 return QualType();
4277 }
4278
4279 QualType Result = TL.getType();
4280 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4281 Result = getDerived().RebuildAutoType(NewDeduced);
4282 if (Result.isNull())
4283 return QualType();
4284 }
4285
4286 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4287 NewTL.setNameLoc(TL.getNameLoc());
4288
4289 return Result;
4290}
4291
4292template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004293QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004294 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004295 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004296 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004297 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4298 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004299 if (!Record)
4300 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004301
John McCall550e0c22009-10-21 00:40:46 +00004302 QualType Result = TL.getType();
4303 if (getDerived().AlwaysRebuild() ||
4304 Record != T->getDecl()) {
4305 Result = getDerived().RebuildRecordType(Record);
4306 if (Result.isNull())
4307 return QualType();
4308 }
Mike Stump11289f42009-09-09 15:08:12 +00004309
John McCall550e0c22009-10-21 00:40:46 +00004310 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4311 NewTL.setNameLoc(TL.getNameLoc());
4312
4313 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004314}
Mike Stump11289f42009-09-09 15:08:12 +00004315
4316template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004317QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004318 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004319 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004320 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004321 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4322 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004323 if (!Enum)
4324 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004325
John McCall550e0c22009-10-21 00:40:46 +00004326 QualType Result = TL.getType();
4327 if (getDerived().AlwaysRebuild() ||
4328 Enum != T->getDecl()) {
4329 Result = getDerived().RebuildEnumType(Enum);
4330 if (Result.isNull())
4331 return QualType();
4332 }
Mike Stump11289f42009-09-09 15:08:12 +00004333
John McCall550e0c22009-10-21 00:40:46 +00004334 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4335 NewTL.setNameLoc(TL.getNameLoc());
4336
4337 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004338}
John McCallfcc33b02009-09-05 00:15:47 +00004339
John McCalle78aac42010-03-10 03:28:59 +00004340template<typename Derived>
4341QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4342 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004343 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004344 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4345 TL.getTypePtr()->getDecl());
4346 if (!D) return QualType();
4347
4348 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4349 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4350 return T;
4351}
4352
Douglas Gregord6ff3322009-08-04 16:50:30 +00004353template<typename Derived>
4354QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004355 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004356 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004357 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004358}
4359
Mike Stump11289f42009-09-09 15:08:12 +00004360template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004361QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004362 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004363 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004364 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4365
4366 // Substitute into the replacement type, which itself might involve something
4367 // that needs to be transformed. This only tends to occur with default
4368 // template arguments of template template parameters.
4369 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4370 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4371 if (Replacement.isNull())
4372 return QualType();
4373
4374 // Always canonicalize the replacement type.
4375 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4376 QualType Result
4377 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4378 Replacement);
4379
4380 // Propagate type-source information.
4381 SubstTemplateTypeParmTypeLoc NewTL
4382 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4383 NewTL.setNameLoc(TL.getNameLoc());
4384 return Result;
4385
John McCallcebee162009-10-18 09:09:24 +00004386}
4387
4388template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004389QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4390 TypeLocBuilder &TLB,
4391 SubstTemplateTypeParmPackTypeLoc TL) {
4392 return TransformTypeSpecType(TLB, TL);
4393}
4394
4395template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004396QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004397 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004398 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004399 const TemplateSpecializationType *T = TL.getTypePtr();
4400
Douglas Gregordf846d12011-03-02 18:46:51 +00004401 // The nested-name-specifier never matters in a TemplateSpecializationType,
4402 // because we can't have a dependent nested-name-specifier anyway.
4403 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004404 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004405 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4406 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004407 if (Template.isNull())
4408 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004409
John McCall31f82722010-11-12 08:19:04 +00004410 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4411}
4412
Eli Friedman0dfb8892011-10-06 23:00:33 +00004413template<typename Derived>
4414QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4415 AtomicTypeLoc TL) {
4416 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4417 if (ValueType.isNull())
4418 return QualType();
4419
4420 QualType Result = TL.getType();
4421 if (getDerived().AlwaysRebuild() ||
4422 ValueType != TL.getValueLoc().getType()) {
4423 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4424 if (Result.isNull())
4425 return QualType();
4426 }
4427
4428 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4429 NewTL.setKWLoc(TL.getKWLoc());
4430 NewTL.setLParenLoc(TL.getLParenLoc());
4431 NewTL.setRParenLoc(TL.getRParenLoc());
4432
4433 return Result;
4434}
4435
Douglas Gregorfe921a72010-12-20 23:36:19 +00004436namespace {
4437 /// \brief Simple iterator that traverses the template arguments in a
4438 /// container that provides a \c getArgLoc() member function.
4439 ///
4440 /// This iterator is intended to be used with the iterator form of
4441 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4442 template<typename ArgLocContainer>
4443 class TemplateArgumentLocContainerIterator {
4444 ArgLocContainer *Container;
4445 unsigned Index;
4446
4447 public:
4448 typedef TemplateArgumentLoc value_type;
4449 typedef TemplateArgumentLoc reference;
4450 typedef int difference_type;
4451 typedef std::input_iterator_tag iterator_category;
4452
4453 class pointer {
4454 TemplateArgumentLoc Arg;
4455
4456 public:
4457 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4458
4459 const TemplateArgumentLoc *operator->() const {
4460 return &Arg;
4461 }
4462 };
4463
4464
4465 TemplateArgumentLocContainerIterator() {}
4466
4467 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4468 unsigned Index)
4469 : Container(&Container), Index(Index) { }
4470
4471 TemplateArgumentLocContainerIterator &operator++() {
4472 ++Index;
4473 return *this;
4474 }
4475
4476 TemplateArgumentLocContainerIterator operator++(int) {
4477 TemplateArgumentLocContainerIterator Old(*this);
4478 ++(*this);
4479 return Old;
4480 }
4481
4482 TemplateArgumentLoc operator*() const {
4483 return Container->getArgLoc(Index);
4484 }
4485
4486 pointer operator->() const {
4487 return pointer(Container->getArgLoc(Index));
4488 }
4489
4490 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004491 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004492 return X.Container == Y.Container && X.Index == Y.Index;
4493 }
4494
4495 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004496 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004497 return !(X == Y);
4498 }
4499 };
4500}
4501
4502
John McCall31f82722010-11-12 08:19:04 +00004503template <typename Derived>
4504QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4505 TypeLocBuilder &TLB,
4506 TemplateSpecializationTypeLoc TL,
4507 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004508 TemplateArgumentListInfo NewTemplateArgs;
4509 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4510 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004511 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4512 ArgIterator;
4513 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4514 ArgIterator(TL, TL.getNumArgs()),
4515 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004516 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004517
John McCall0ad16662009-10-29 08:12:44 +00004518 // FIXME: maybe don't rebuild if all the template arguments are the same.
4519
4520 QualType Result =
4521 getDerived().RebuildTemplateSpecializationType(Template,
4522 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004523 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004524
4525 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004526 // Specializations of template template parameters are represented as
4527 // TemplateSpecializationTypes, and substitution of type alias templates
4528 // within a dependent context can transform them into
4529 // DependentTemplateSpecializationTypes.
4530 if (isa<DependentTemplateSpecializationType>(Result)) {
4531 DependentTemplateSpecializationTypeLoc NewTL
4532 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4533 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4534 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4535 NewTL.setNameLoc(TL.getTemplateNameLoc());
4536 NewTL.setLAngleLoc(TL.getLAngleLoc());
4537 NewTL.setRAngleLoc(TL.getRAngleLoc());
4538 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4539 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4540 return Result;
4541 }
4542
John McCall0ad16662009-10-29 08:12:44 +00004543 TemplateSpecializationTypeLoc NewTL
4544 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4545 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4546 NewTL.setLAngleLoc(TL.getLAngleLoc());
4547 NewTL.setRAngleLoc(TL.getRAngleLoc());
4548 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4549 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004550 }
Mike Stump11289f42009-09-09 15:08:12 +00004551
John McCall0ad16662009-10-29 08:12:44 +00004552 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004553}
Mike Stump11289f42009-09-09 15:08:12 +00004554
Douglas Gregor5a064722011-02-28 17:23:35 +00004555template <typename Derived>
4556QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4557 TypeLocBuilder &TLB,
4558 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004559 TemplateName Template,
4560 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004561 TemplateArgumentListInfo NewTemplateArgs;
4562 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4563 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4564 typedef TemplateArgumentLocContainerIterator<
4565 DependentTemplateSpecializationTypeLoc> ArgIterator;
4566 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4567 ArgIterator(TL, TL.getNumArgs()),
4568 NewTemplateArgs))
4569 return QualType();
4570
4571 // FIXME: maybe don't rebuild if all the template arguments are the same.
4572
4573 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4574 QualType Result
4575 = getSema().Context.getDependentTemplateSpecializationType(
4576 TL.getTypePtr()->getKeyword(),
4577 DTN->getQualifier(),
4578 DTN->getIdentifier(),
4579 NewTemplateArgs);
4580
4581 DependentTemplateSpecializationTypeLoc NewTL
4582 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4583 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004584
Douglas Gregora7a795b2011-03-01 20:11:18 +00004585 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004586 NewTL.setNameLoc(TL.getNameLoc());
4587 NewTL.setLAngleLoc(TL.getLAngleLoc());
4588 NewTL.setRAngleLoc(TL.getRAngleLoc());
4589 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4590 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4591 return Result;
4592 }
4593
4594 QualType Result
4595 = getDerived().RebuildTemplateSpecializationType(Template,
4596 TL.getNameLoc(),
4597 NewTemplateArgs);
4598
4599 if (!Result.isNull()) {
4600 /// FIXME: Wrap this in an elaborated-type-specifier?
4601 TemplateSpecializationTypeLoc NewTL
4602 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4603 NewTL.setTemplateNameLoc(TL.getNameLoc());
4604 NewTL.setLAngleLoc(TL.getLAngleLoc());
4605 NewTL.setRAngleLoc(TL.getRAngleLoc());
4606 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4607 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4608 }
4609
4610 return Result;
4611}
4612
Mike Stump11289f42009-09-09 15:08:12 +00004613template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004614QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004615TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004616 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004617 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004618
Douglas Gregor844cb502011-03-01 18:12:44 +00004619 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004620 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004621 if (TL.getQualifierLoc()) {
4622 QualifierLoc
4623 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4624 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004625 return QualType();
4626 }
Mike Stump11289f42009-09-09 15:08:12 +00004627
John McCall31f82722010-11-12 08:19:04 +00004628 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4629 if (NamedT.isNull())
4630 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004631
Richard Smith3f1b5d02011-05-05 21:57:07 +00004632 // C++0x [dcl.type.elab]p2:
4633 // If the identifier resolves to a typedef-name or the simple-template-id
4634 // resolves to an alias template specialization, the
4635 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004636 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4637 if (const TemplateSpecializationType *TST =
4638 NamedT->getAs<TemplateSpecializationType>()) {
4639 TemplateName Template = TST->getTemplateName();
4640 if (TypeAliasTemplateDecl *TAT =
4641 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4642 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4643 diag::err_tag_reference_non_tag) << 4;
4644 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4645 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004646 }
4647 }
4648
John McCall550e0c22009-10-21 00:40:46 +00004649 QualType Result = TL.getType();
4650 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004651 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004652 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004653 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004654 T->getKeyword(),
4655 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004656 if (Result.isNull())
4657 return QualType();
4658 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004659
Abramo Bagnara6150c882010-05-11 21:36:43 +00004660 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004661 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004662 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004663 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004664}
Mike Stump11289f42009-09-09 15:08:12 +00004665
4666template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004667QualType TreeTransform<Derived>::TransformAttributedType(
4668 TypeLocBuilder &TLB,
4669 AttributedTypeLoc TL) {
4670 const AttributedType *oldType = TL.getTypePtr();
4671 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4672 if (modifiedType.isNull())
4673 return QualType();
4674
4675 QualType result = TL.getType();
4676
4677 // FIXME: dependent operand expressions?
4678 if (getDerived().AlwaysRebuild() ||
4679 modifiedType != oldType->getModifiedType()) {
4680 // TODO: this is really lame; we should really be rebuilding the
4681 // equivalent type from first principles.
4682 QualType equivalentType
4683 = getDerived().TransformType(oldType->getEquivalentType());
4684 if (equivalentType.isNull())
4685 return QualType();
4686 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4687 modifiedType,
4688 equivalentType);
4689 }
4690
4691 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4692 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4693 if (TL.hasAttrOperand())
4694 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4695 if (TL.hasAttrExprOperand())
4696 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4697 else if (TL.hasAttrEnumOperand())
4698 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4699
4700 return result;
4701}
4702
4703template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004704QualType
4705TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4706 ParenTypeLoc TL) {
4707 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4708 if (Inner.isNull())
4709 return QualType();
4710
4711 QualType Result = TL.getType();
4712 if (getDerived().AlwaysRebuild() ||
4713 Inner != TL.getInnerLoc().getType()) {
4714 Result = getDerived().RebuildParenType(Inner);
4715 if (Result.isNull())
4716 return QualType();
4717 }
4718
4719 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4720 NewTL.setLParenLoc(TL.getLParenLoc());
4721 NewTL.setRParenLoc(TL.getRParenLoc());
4722 return Result;
4723}
4724
4725template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004726QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004727 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004728 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004729
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004730 NestedNameSpecifierLoc QualifierLoc
4731 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4732 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004733 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004734
John McCallc392f372010-06-11 00:33:02 +00004735 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004736 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004737 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004738 QualifierLoc,
4739 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004740 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004741 if (Result.isNull())
4742 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004743
Abramo Bagnarad7548482010-05-19 21:37:53 +00004744 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4745 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004746 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4747
Abramo Bagnarad7548482010-05-19 21:37:53 +00004748 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4749 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004750 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004751 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004752 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4753 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004754 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004755 NewTL.setNameLoc(TL.getNameLoc());
4756 }
John McCall550e0c22009-10-21 00:40:46 +00004757 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004758}
Mike Stump11289f42009-09-09 15:08:12 +00004759
Douglas Gregord6ff3322009-08-04 16:50:30 +00004760template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004761QualType TreeTransform<Derived>::
4762 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004763 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004764 NestedNameSpecifierLoc QualifierLoc;
4765 if (TL.getQualifierLoc()) {
4766 QualifierLoc
4767 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4768 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004769 return QualType();
4770 }
4771
John McCall31f82722010-11-12 08:19:04 +00004772 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004773 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004774}
4775
4776template<typename Derived>
4777QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004778TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4779 DependentTemplateSpecializationTypeLoc TL,
4780 NestedNameSpecifierLoc QualifierLoc) {
4781 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4782
4783 TemplateArgumentListInfo NewTemplateArgs;
4784 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4785 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4786
4787 typedef TemplateArgumentLocContainerIterator<
4788 DependentTemplateSpecializationTypeLoc> ArgIterator;
4789 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4790 ArgIterator(TL, TL.getNumArgs()),
4791 NewTemplateArgs))
4792 return QualType();
4793
4794 QualType Result
4795 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4796 QualifierLoc,
4797 T->getIdentifier(),
4798 TL.getNameLoc(),
4799 NewTemplateArgs);
4800 if (Result.isNull())
4801 return QualType();
4802
4803 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4804 QualType NamedT = ElabT->getNamedType();
4805
4806 // Copy information relevant to the template specialization.
4807 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004808 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004809 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004810 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4811 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004812 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004813 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004814
4815 // Copy information relevant to the elaborated type.
4816 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4817 NewTL.setKeywordLoc(TL.getKeywordLoc());
4818 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004819 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4820 DependentTemplateSpecializationTypeLoc SpecTL
4821 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004822 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004823 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004824 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004825 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4826 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004827 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004828 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004829 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004830 TemplateSpecializationTypeLoc SpecTL
4831 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004832 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004833 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4834 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004835 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004836 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004837 }
4838 return Result;
4839}
4840
4841template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004842QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4843 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004844 QualType Pattern
4845 = getDerived().TransformType(TLB, TL.getPatternLoc());
4846 if (Pattern.isNull())
4847 return QualType();
4848
4849 QualType Result = TL.getType();
4850 if (getDerived().AlwaysRebuild() ||
4851 Pattern != TL.getPatternLoc().getType()) {
4852 Result = getDerived().RebuildPackExpansionType(Pattern,
4853 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004854 TL.getEllipsisLoc(),
4855 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004856 if (Result.isNull())
4857 return QualType();
4858 }
4859
4860 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4861 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4862 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004863}
4864
4865template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004866QualType
4867TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004868 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004869 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004870 TLB.pushFullCopy(TL);
4871 return TL.getType();
4872}
4873
4874template<typename Derived>
4875QualType
4876TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004877 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004878 // ObjCObjectType is never dependent.
4879 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004880 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004881}
Mike Stump11289f42009-09-09 15:08:12 +00004882
4883template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004884QualType
4885TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004886 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004887 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004888 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004889 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004890}
4891
Douglas Gregord6ff3322009-08-04 16:50:30 +00004892//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004893// Statement transformation
4894//===----------------------------------------------------------------------===//
4895template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004896StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004897TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004898 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004899}
4900
4901template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004902StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004903TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4904 return getDerived().TransformCompoundStmt(S, false);
4905}
4906
4907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004908StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004909TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004910 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004911 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004912 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004913 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004914 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4915 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004916 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004917 if (Result.isInvalid()) {
4918 // Immediately fail if this was a DeclStmt, since it's very
4919 // likely that this will cause problems for future statements.
4920 if (isa<DeclStmt>(*B))
4921 return StmtError();
4922
4923 // Otherwise, just keep processing substatements and fail later.
4924 SubStmtInvalid = true;
4925 continue;
4926 }
Mike Stump11289f42009-09-09 15:08:12 +00004927
Douglas Gregorebe10102009-08-20 07:17:43 +00004928 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4929 Statements.push_back(Result.takeAs<Stmt>());
4930 }
Mike Stump11289f42009-09-09 15:08:12 +00004931
John McCall1ababa62010-08-27 19:56:05 +00004932 if (SubStmtInvalid)
4933 return StmtError();
4934
Douglas Gregorebe10102009-08-20 07:17:43 +00004935 if (!getDerived().AlwaysRebuild() &&
4936 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004937 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004938
4939 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4940 move_arg(Statements),
4941 S->getRBracLoc(),
4942 IsStmtExpr);
4943}
Mike Stump11289f42009-09-09 15:08:12 +00004944
Douglas Gregorebe10102009-08-20 07:17:43 +00004945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004946StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004947TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004948 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004949 {
4950 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004951 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004952
Eli Friedman06577382009-11-19 03:14:00 +00004953 // Transform the left-hand case value.
4954 LHS = getDerived().TransformExpr(S->getLHS());
4955 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004956 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004957
Eli Friedman06577382009-11-19 03:14:00 +00004958 // Transform the right-hand case value (for the GNU case-range extension).
4959 RHS = getDerived().TransformExpr(S->getRHS());
4960 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004961 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004962 }
Mike Stump11289f42009-09-09 15:08:12 +00004963
Douglas Gregorebe10102009-08-20 07:17:43 +00004964 // Build the case statement.
4965 // Case statements are always rebuilt so that they will attached to their
4966 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004967 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004968 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004969 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004970 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004971 S->getColonLoc());
4972 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004973 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004974
Douglas Gregorebe10102009-08-20 07:17:43 +00004975 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004976 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004977 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004978 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004979
Douglas Gregorebe10102009-08-20 07:17:43 +00004980 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004981 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004982}
4983
4984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004985StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004986TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004987 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004988 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004989 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004990 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004991
Douglas Gregorebe10102009-08-20 07:17:43 +00004992 // Default statements are always rebuilt
4993 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004994 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004995}
Mike Stump11289f42009-09-09 15:08:12 +00004996
Douglas Gregorebe10102009-08-20 07:17:43 +00004997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004998StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004999TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005000 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005001 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005002 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005003
Chris Lattnercab02a62011-02-17 20:34:02 +00005004 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5005 S->getDecl());
5006 if (!LD)
5007 return StmtError();
5008
5009
Douglas Gregorebe10102009-08-20 07:17:43 +00005010 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005011 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005012 cast<LabelDecl>(LD), SourceLocation(),
5013 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005014}
Mike Stump11289f42009-09-09 15:08:12 +00005015
Douglas Gregorebe10102009-08-20 07:17:43 +00005016template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005017StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005018TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005019 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005020 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005021 VarDecl *ConditionVar = 0;
5022 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005023 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005024 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005025 getDerived().TransformDefinition(
5026 S->getConditionVariable()->getLocation(),
5027 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005028 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005029 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005030 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005031 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005032
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005033 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005034 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005035
5036 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005037 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005038 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5039 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005040 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005041 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005042
John McCallb268a282010-08-23 23:25:46 +00005043 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005044 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005045 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005046
John McCallb268a282010-08-23 23:25:46 +00005047 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5048 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005049 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005050
Douglas Gregorebe10102009-08-20 07:17:43 +00005051 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005052 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005053 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005054 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005055
Douglas Gregorebe10102009-08-20 07:17:43 +00005056 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005057 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005058 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005059 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005060
Douglas Gregorebe10102009-08-20 07:17:43 +00005061 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005062 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005063 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005064 Then.get() == S->getThen() &&
5065 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005066 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005067
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005068 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005069 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005070 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005071}
5072
5073template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005074StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005075TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005076 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005077 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005078 VarDecl *ConditionVar = 0;
5079 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005080 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005081 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005082 getDerived().TransformDefinition(
5083 S->getConditionVariable()->getLocation(),
5084 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005085 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005086 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005087 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005088 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005089
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005090 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005091 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005092 }
Mike Stump11289f42009-09-09 15:08:12 +00005093
Douglas Gregorebe10102009-08-20 07:17:43 +00005094 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005095 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005096 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005097 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005098 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005099 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005100
Douglas Gregorebe10102009-08-20 07:17:43 +00005101 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005102 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005103 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005104 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005105
Douglas Gregorebe10102009-08-20 07:17:43 +00005106 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005107 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5108 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005109}
Mike Stump11289f42009-09-09 15:08:12 +00005110
Douglas Gregorebe10102009-08-20 07:17:43 +00005111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005112StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005113TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005114 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005115 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005116 VarDecl *ConditionVar = 0;
5117 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005118 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005119 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005120 getDerived().TransformDefinition(
5121 S->getConditionVariable()->getLocation(),
5122 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005123 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005124 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005125 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005126 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005127
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005128 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005129 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005130
5131 if (S->getCond()) {
5132 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005133 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5134 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005135 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005136 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005137 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005138 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005139 }
Mike Stump11289f42009-09-09 15:08:12 +00005140
John McCallb268a282010-08-23 23:25:46 +00005141 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5142 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005143 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005144
Douglas Gregorebe10102009-08-20 07:17:43 +00005145 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005146 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005147 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005148 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005149
Douglas Gregorebe10102009-08-20 07:17:43 +00005150 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005151 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005152 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005153 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005154 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005155
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005156 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005157 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005158}
Mike Stump11289f42009-09-09 15:08:12 +00005159
Douglas Gregorebe10102009-08-20 07:17:43 +00005160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005161StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005162TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005163 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005164 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005165 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005166 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005167
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005168 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005169 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005170 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005171 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005172
Douglas Gregorebe10102009-08-20 07:17:43 +00005173 if (!getDerived().AlwaysRebuild() &&
5174 Cond.get() == S->getCond() &&
5175 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005176 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005177
John McCallb268a282010-08-23 23:25:46 +00005178 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5179 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005180 S->getRParenLoc());
5181}
Mike Stump11289f42009-09-09 15:08:12 +00005182
Douglas Gregorebe10102009-08-20 07:17:43 +00005183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005184StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005185TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005186 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005187 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005188 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005189 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005190
Douglas Gregorebe10102009-08-20 07:17:43 +00005191 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005192 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005193 VarDecl *ConditionVar = 0;
5194 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005195 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005196 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005197 getDerived().TransformDefinition(
5198 S->getConditionVariable()->getLocation(),
5199 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005200 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005201 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005202 } else {
5203 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005204
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005205 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005206 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005207
5208 if (S->getCond()) {
5209 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005210 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5211 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005212 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005213 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005214
John McCallb268a282010-08-23 23:25:46 +00005215 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005216 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005217 }
Mike Stump11289f42009-09-09 15:08:12 +00005218
John McCallb268a282010-08-23 23:25:46 +00005219 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5220 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005221 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005222
Douglas Gregorebe10102009-08-20 07:17:43 +00005223 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005224 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005225 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005226 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005227
John McCallb268a282010-08-23 23:25:46 +00005228 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5229 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005230 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005231
Douglas Gregorebe10102009-08-20 07:17:43 +00005232 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005233 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005234 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005235 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005236
Douglas Gregorebe10102009-08-20 07:17:43 +00005237 if (!getDerived().AlwaysRebuild() &&
5238 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005239 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005240 Inc.get() == S->getInc() &&
5241 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005242 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005243
Douglas Gregorebe10102009-08-20 07:17:43 +00005244 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005245 Init.get(), FullCond, ConditionVar,
5246 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005247}
5248
5249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005250StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005251TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005252 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5253 S->getLabel());
5254 if (!LD)
5255 return StmtError();
5256
Douglas Gregorebe10102009-08-20 07:17:43 +00005257 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005258 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005259 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005260}
5261
5262template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005263StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005264TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005265 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005266 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005267 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005268
Douglas Gregorebe10102009-08-20 07:17:43 +00005269 if (!getDerived().AlwaysRebuild() &&
5270 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005271 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005272
5273 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005274 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005275}
5276
5277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005278StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005279TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005280 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005281}
Mike Stump11289f42009-09-09 15:08:12 +00005282
Douglas Gregorebe10102009-08-20 07:17:43 +00005283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005284StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005285TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005286 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005287}
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
Mike Stump11289f42009-09-09 15:08:12 +00005291TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005292 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005293 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005294 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005295
Mike Stump11289f42009-09-09 15:08:12 +00005296 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005297 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005298 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005299}
Mike Stump11289f42009-09-09 15:08:12 +00005300
Douglas Gregorebe10102009-08-20 07:17:43 +00005301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005302StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005303TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005304 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005305 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005306 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5307 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005308 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5309 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005310 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005311 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005312
Douglas Gregorebe10102009-08-20 07:17:43 +00005313 if (Transformed != *D)
5314 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005315
Douglas Gregorebe10102009-08-20 07:17:43 +00005316 Decls.push_back(Transformed);
5317 }
Mike Stump11289f42009-09-09 15:08:12 +00005318
Douglas Gregorebe10102009-08-20 07:17:43 +00005319 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005320 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005321
5322 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005323 S->getStartLoc(), S->getEndLoc());
5324}
Mike Stump11289f42009-09-09 15:08:12 +00005325
Douglas Gregorebe10102009-08-20 07:17:43 +00005326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005327StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005328TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005329
John McCall37ad5512010-08-23 06:44:23 +00005330 ASTOwningVector<Expr*> Constraints(getSema());
5331 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner01cf8db2011-07-20 06:58:45 +00005332 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005333
John McCalldadc5752010-08-24 06:29:42 +00005334 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005335 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005336
5337 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005338
Anders Carlssonaaeef072010-01-24 05:50:09 +00005339 // Go through the outputs.
5340 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005341 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005342
Anders Carlssonaaeef072010-01-24 05:50:09 +00005343 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005344 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005345
Anders Carlssonaaeef072010-01-24 05:50:09 +00005346 // Transform the output expr.
5347 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005348 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005349 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005350 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005351
Anders Carlssonaaeef072010-01-24 05:50:09 +00005352 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005353
John McCallb268a282010-08-23 23:25:46 +00005354 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005355 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005356
Anders Carlssonaaeef072010-01-24 05:50:09 +00005357 // Go through the inputs.
5358 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005359 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005360
Anders Carlssonaaeef072010-01-24 05:50:09 +00005361 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005362 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005363
Anders Carlssonaaeef072010-01-24 05:50:09 +00005364 // Transform the input expr.
5365 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005366 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005367 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005368 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005369
Anders Carlssonaaeef072010-01-24 05:50:09 +00005370 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005371
John McCallb268a282010-08-23 23:25:46 +00005372 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005373 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005374
Anders Carlssonaaeef072010-01-24 05:50:09 +00005375 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005376 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005377
5378 // Go through the clobbers.
5379 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005380 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005381
5382 // No need to transform the asm string literal.
5383 AsmString = SemaRef.Owned(S->getAsmString());
5384
5385 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5386 S->isSimple(),
5387 S->isVolatile(),
5388 S->getNumOutputs(),
5389 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005390 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005391 move_arg(Constraints),
5392 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005393 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005394 move_arg(Clobbers),
5395 S->getRParenLoc(),
5396 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005397}
5398
5399
5400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005401StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005402TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005403 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005404 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005405 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005406 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005407
Douglas Gregor96c79492010-04-23 22:50:49 +00005408 // Transform the @catch statements (if present).
5409 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005410 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005411 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005412 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005413 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005414 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005415 if (Catch.get() != S->getCatchStmt(I))
5416 AnyCatchChanged = true;
5417 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005418 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005419
Douglas Gregor306de2f2010-04-22 23:59:56 +00005420 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005421 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005422 if (S->getFinallyStmt()) {
5423 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5424 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005425 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005426 }
5427
5428 // If nothing changed, just retain this statement.
5429 if (!getDerived().AlwaysRebuild() &&
5430 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005431 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005432 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005433 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005434
Douglas Gregor306de2f2010-04-22 23:59:56 +00005435 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005436 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5437 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005438}
Mike Stump11289f42009-09-09 15:08:12 +00005439
Douglas Gregorebe10102009-08-20 07:17:43 +00005440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005441StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005442TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005443 // Transform the @catch parameter, if there is one.
5444 VarDecl *Var = 0;
5445 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5446 TypeSourceInfo *TSInfo = 0;
5447 if (FromVar->getTypeSourceInfo()) {
5448 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5449 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005450 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005451 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005452
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005453 QualType T;
5454 if (TSInfo)
5455 T = TSInfo->getType();
5456 else {
5457 T = getDerived().TransformType(FromVar->getType());
5458 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005459 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005460 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005461
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005462 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5463 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005464 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005465 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005466
John McCalldadc5752010-08-24 06:29:42 +00005467 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005468 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005469 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005470
5471 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005472 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005473 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005474}
Mike Stump11289f42009-09-09 15:08:12 +00005475
Douglas Gregorebe10102009-08-20 07:17:43 +00005476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005477StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005478TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005479 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005480 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005481 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005482 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005483
Douglas Gregor306de2f2010-04-22 23:59:56 +00005484 // If nothing changed, just retain this statement.
5485 if (!getDerived().AlwaysRebuild() &&
5486 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005487 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005488
5489 // Build a new statement.
5490 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005491 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005492}
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregorebe10102009-08-20 07:17:43 +00005494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005495StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005496TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005497 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005498 if (S->getThrowExpr()) {
5499 Operand = getDerived().TransformExpr(S->getThrowExpr());
5500 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005501 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005502 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005503
Douglas Gregor2900c162010-04-22 21:44:01 +00005504 if (!getDerived().AlwaysRebuild() &&
5505 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005506 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005507
John McCallb268a282010-08-23 23:25:46 +00005508 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005509}
Mike Stump11289f42009-09-09 15:08:12 +00005510
Douglas Gregorebe10102009-08-20 07:17:43 +00005511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005512StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005513TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005514 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005515 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005516 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005517 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005518 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005519 Object =
5520 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5521 Object.get());
5522 if (Object.isInvalid())
5523 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005524
Douglas Gregor6148de72010-04-22 22:01:21 +00005525 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005526 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005527 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005528 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005529
Douglas Gregor6148de72010-04-22 22:01:21 +00005530 // If nothing change, just retain the current statement.
5531 if (!getDerived().AlwaysRebuild() &&
5532 Object.get() == S->getSynchExpr() &&
5533 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005534 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005535
5536 // Build a new statement.
5537 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005538 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005539}
5540
5541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005542StmtResult
John McCall31168b02011-06-15 23:02:42 +00005543TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5544 ObjCAutoreleasePoolStmt *S) {
5545 // Transform the body.
5546 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5547 if (Body.isInvalid())
5548 return StmtError();
5549
5550 // If nothing changed, just retain this statement.
5551 if (!getDerived().AlwaysRebuild() &&
5552 Body.get() == S->getSubStmt())
5553 return SemaRef.Owned(S);
5554
5555 // Build a new statement.
5556 return getDerived().RebuildObjCAutoreleasePoolStmt(
5557 S->getAtLoc(), Body.get());
5558}
5559
5560template<typename Derived>
5561StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005562TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005563 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005564 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005565 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005566 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005567 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005568
Douglas Gregorf68a5082010-04-22 23:10:45 +00005569 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005570 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005571 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005572 return StmtError();
John McCall53848232011-07-27 01:07:15 +00005573 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5574 Collection.take());
5575 if (Collection.isInvalid())
5576 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005577
Douglas Gregorf68a5082010-04-22 23:10:45 +00005578 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005579 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005580 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005581 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005582
Douglas Gregorf68a5082010-04-22 23:10:45 +00005583 // If nothing changed, just retain this statement.
5584 if (!getDerived().AlwaysRebuild() &&
5585 Element.get() == S->getElement() &&
5586 Collection.get() == S->getCollection() &&
5587 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005588 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005589
Douglas Gregorf68a5082010-04-22 23:10:45 +00005590 // Build a new statement.
5591 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5592 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005593 Element.get(),
5594 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005595 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005596 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005597}
5598
5599
5600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005601StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005602TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5603 // Transform the exception declaration, if any.
5604 VarDecl *Var = 0;
5605 if (S->getExceptionDecl()) {
5606 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005607 TypeSourceInfo *T = getDerived().TransformType(
5608 ExceptionDecl->getTypeSourceInfo());
5609 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005610 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005611
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005612 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005613 ExceptionDecl->getInnerLocStart(),
5614 ExceptionDecl->getLocation(),
5615 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005616 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005617 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005618 }
Mike Stump11289f42009-09-09 15:08:12 +00005619
Douglas Gregorebe10102009-08-20 07:17:43 +00005620 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005621 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005622 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005623 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005624
Douglas Gregorebe10102009-08-20 07:17:43 +00005625 if (!getDerived().AlwaysRebuild() &&
5626 !Var &&
5627 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005628 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005629
5630 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5631 Var,
John McCallb268a282010-08-23 23:25:46 +00005632 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005633}
Mike Stump11289f42009-09-09 15:08:12 +00005634
Douglas Gregorebe10102009-08-20 07:17:43 +00005635template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005636StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005637TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5638 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005639 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005640 = getDerived().TransformCompoundStmt(S->getTryBlock());
5641 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005642 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005643
Douglas Gregorebe10102009-08-20 07:17:43 +00005644 // Transform the handlers.
5645 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005646 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005647 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005648 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005649 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5650 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005651 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005652
Douglas Gregorebe10102009-08-20 07:17:43 +00005653 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5654 Handlers.push_back(Handler.takeAs<Stmt>());
5655 }
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregorebe10102009-08-20 07:17:43 +00005657 if (!getDerived().AlwaysRebuild() &&
5658 TryBlock.get() == S->getTryBlock() &&
5659 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005660 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005661
John McCallb268a282010-08-23 23:25:46 +00005662 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005663 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005664}
Mike Stump11289f42009-09-09 15:08:12 +00005665
Richard Smith02e85f32011-04-14 22:09:26 +00005666template<typename Derived>
5667StmtResult
5668TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5669 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5670 if (Range.isInvalid())
5671 return StmtError();
5672
5673 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5674 if (BeginEnd.isInvalid())
5675 return StmtError();
5676
5677 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5678 if (Cond.isInvalid())
5679 return StmtError();
5680
5681 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5682 if (Inc.isInvalid())
5683 return StmtError();
5684
5685 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5686 if (LoopVar.isInvalid())
5687 return StmtError();
5688
5689 StmtResult NewStmt = S;
5690 if (getDerived().AlwaysRebuild() ||
5691 Range.get() != S->getRangeStmt() ||
5692 BeginEnd.get() != S->getBeginEndStmt() ||
5693 Cond.get() != S->getCond() ||
5694 Inc.get() != S->getInc() ||
5695 LoopVar.get() != S->getLoopVarStmt())
5696 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5697 S->getColonLoc(), Range.get(),
5698 BeginEnd.get(), Cond.get(),
5699 Inc.get(), LoopVar.get(),
5700 S->getRParenLoc());
5701
5702 StmtResult Body = getDerived().TransformStmt(S->getBody());
5703 if (Body.isInvalid())
5704 return StmtError();
5705
5706 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5707 // it now so we have a new statement to attach the body to.
5708 if (Body.get() != S->getBody() && NewStmt.get() == S)
5709 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5710 S->getColonLoc(), Range.get(),
5711 BeginEnd.get(), Cond.get(),
5712 Inc.get(), LoopVar.get(),
5713 S->getRParenLoc());
5714
5715 if (NewStmt.get() == S)
5716 return SemaRef.Owned(S);
5717
5718 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5719}
5720
John Wiegley1c0675e2011-04-28 01:08:34 +00005721template<typename Derived>
5722StmtResult
5723TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5724 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5725 if(TryBlock.isInvalid()) return StmtError();
5726
5727 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5728 if(!getDerived().AlwaysRebuild() &&
5729 TryBlock.get() == S->getTryBlock() &&
5730 Handler.get() == S->getHandler())
5731 return SemaRef.Owned(S);
5732
5733 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5734 S->getTryLoc(),
5735 TryBlock.take(),
5736 Handler.take());
5737}
5738
5739template<typename Derived>
5740StmtResult
5741TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5742 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5743 if(Block.isInvalid()) return StmtError();
5744
5745 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5746 Block.take());
5747}
5748
5749template<typename Derived>
5750StmtResult
5751TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5752 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5753 if(FilterExpr.isInvalid()) return StmtError();
5754
5755 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5756 if(Block.isInvalid()) return StmtError();
5757
5758 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5759 FilterExpr.take(),
5760 Block.take());
5761}
5762
5763template<typename Derived>
5764StmtResult
5765TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5766 if(isa<SEHFinallyStmt>(Handler))
5767 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5768 else
5769 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5770}
5771
Douglas Gregorebe10102009-08-20 07:17:43 +00005772//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005773// Expression transformation
5774//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005776ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005777TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005778 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005779}
Mike Stump11289f42009-09-09 15:08:12 +00005780
5781template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005782ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005783TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005784 NestedNameSpecifierLoc QualifierLoc;
5785 if (E->getQualifierLoc()) {
5786 QualifierLoc
5787 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5788 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005789 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005790 }
John McCallce546572009-12-08 09:08:17 +00005791
5792 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005793 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5794 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005795 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005796 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005797
John McCall815039a2010-08-17 21:27:17 +00005798 DeclarationNameInfo NameInfo = E->getNameInfo();
5799 if (NameInfo.getName()) {
5800 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5801 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005802 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005803 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005804
5805 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005806 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005807 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005808 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005809 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005810
5811 // Mark it referenced in the new context regardless.
5812 // FIXME: this is a bit instantiation-specific.
5813 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5814
John McCallc3007a22010-10-26 07:05:15 +00005815 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005816 }
John McCallce546572009-12-08 09:08:17 +00005817
5818 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005819 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005820 TemplateArgs = &TransArgs;
5821 TransArgs.setLAngleLoc(E->getLAngleLoc());
5822 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005823 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5824 E->getNumTemplateArgs(),
5825 TransArgs))
5826 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005827 }
5828
Douglas Gregorea972d32011-02-28 21:54:11 +00005829 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5830 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005831}
Mike Stump11289f42009-09-09 15:08:12 +00005832
Douglas Gregora16548e2009-08-11 05:31:07 +00005833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005834ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005835TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005836 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005837}
Mike Stump11289f42009-09-09 15:08:12 +00005838
Douglas Gregora16548e2009-08-11 05:31:07 +00005839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005840ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005841TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005842 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005843}
Mike Stump11289f42009-09-09 15:08:12 +00005844
Douglas Gregora16548e2009-08-11 05:31:07 +00005845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005846ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005847TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005848 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005849}
Mike Stump11289f42009-09-09 15:08:12 +00005850
Douglas Gregora16548e2009-08-11 05:31:07 +00005851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005852ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005853TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005854 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005855}
Mike Stump11289f42009-09-09 15:08:12 +00005856
Douglas Gregora16548e2009-08-11 05:31:07 +00005857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005858ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005859TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005860 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005861}
5862
5863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005864ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005865TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5866 ExprResult ControllingExpr =
5867 getDerived().TransformExpr(E->getControllingExpr());
5868 if (ControllingExpr.isInvalid())
5869 return ExprError();
5870
Chris Lattner01cf8db2011-07-20 06:58:45 +00005871 SmallVector<Expr *, 4> AssocExprs;
5872 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00005873 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5874 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5875 if (TS) {
5876 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5877 if (!AssocType)
5878 return ExprError();
5879 AssocTypes.push_back(AssocType);
5880 } else {
5881 AssocTypes.push_back(0);
5882 }
5883
5884 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5885 if (AssocExpr.isInvalid())
5886 return ExprError();
5887 AssocExprs.push_back(AssocExpr.release());
5888 }
5889
5890 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5891 E->getDefaultLoc(),
5892 E->getRParenLoc(),
5893 ControllingExpr.release(),
5894 AssocTypes.data(),
5895 AssocExprs.data(),
5896 E->getNumAssocs());
5897}
5898
5899template<typename Derived>
5900ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005901TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005902 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005903 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005905
Douglas Gregora16548e2009-08-11 05:31:07 +00005906 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005907 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005908
John McCallb268a282010-08-23 23:25:46 +00005909 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005910 E->getRParen());
5911}
5912
Mike Stump11289f42009-09-09 15:08:12 +00005913template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005914ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005915TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005916 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005917 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005918 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005919
Douglas Gregora16548e2009-08-11 05:31:07 +00005920 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005921 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005922
Douglas Gregora16548e2009-08-11 05:31:07 +00005923 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5924 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005925 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005926}
Mike Stump11289f42009-09-09 15:08:12 +00005927
Douglas Gregora16548e2009-08-11 05:31:07 +00005928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005929ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005930TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5931 // Transform the type.
5932 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5933 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005934 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005935
Douglas Gregor882211c2010-04-28 22:16:22 +00005936 // Transform all of the components into components similar to what the
5937 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005938 // FIXME: It would be slightly more efficient in the non-dependent case to
5939 // just map FieldDecls, rather than requiring the rebuilder to look for
5940 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005941 // template code that we don't care.
5942 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005943 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005944 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005945 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00005946 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5947 const Node &ON = E->getComponent(I);
5948 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005949 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005950 Comp.LocStart = ON.getSourceRange().getBegin();
5951 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005952 switch (ON.getKind()) {
5953 case Node::Array: {
5954 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005955 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005956 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005957 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005958
Douglas Gregor882211c2010-04-28 22:16:22 +00005959 ExprChanged = ExprChanged || Index.get() != FromIndex;
5960 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005961 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005962 break;
5963 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005964
Douglas Gregor882211c2010-04-28 22:16:22 +00005965 case Node::Field:
5966 case Node::Identifier:
5967 Comp.isBrackets = false;
5968 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005969 if (!Comp.U.IdentInfo)
5970 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005971
Douglas Gregor882211c2010-04-28 22:16:22 +00005972 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005973
Douglas Gregord1702062010-04-29 00:18:15 +00005974 case Node::Base:
5975 // Will be recomputed during the rebuild.
5976 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005977 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005978
Douglas Gregor882211c2010-04-28 22:16:22 +00005979 Components.push_back(Comp);
5980 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005981
Douglas Gregor882211c2010-04-28 22:16:22 +00005982 // If nothing changed, retain the existing expression.
5983 if (!getDerived().AlwaysRebuild() &&
5984 Type == E->getTypeSourceInfo() &&
5985 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005986 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005987
Douglas Gregor882211c2010-04-28 22:16:22 +00005988 // Build a new offsetof expression.
5989 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5990 Components.data(), Components.size(),
5991 E->getRParenLoc());
5992}
5993
5994template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005995ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005996TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5997 assert(getDerived().AlreadyTransformed(E->getType()) &&
5998 "opaque value expression requires transformation");
5999 return SemaRef.Owned(E);
6000}
6001
6002template<typename Derived>
6003ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006004TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6005 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006006 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006007 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006008
John McCallbcd03502009-12-07 02:54:59 +00006009 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006010 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006012
John McCall4c98fd82009-11-04 07:28:41 +00006013 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006014 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006015
Peter Collingbournee190dee2011-03-11 19:24:49 +00006016 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6017 E->getKind(),
6018 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006019 }
Mike Stump11289f42009-09-09 15:08:12 +00006020
John McCalldadc5752010-08-24 06:29:42 +00006021 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00006022 {
Douglas Gregora16548e2009-08-11 05:31:07 +00006023 // C++0x [expr.sizeof]p1:
6024 // The operand is either an expression, which is an unevaluated operand
6025 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00006026 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006027
Douglas Gregora16548e2009-08-11 05:31:07 +00006028 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6029 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006031
Douglas Gregora16548e2009-08-11 05:31:07 +00006032 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00006033 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006034 }
Mike Stump11289f42009-09-09 15:08:12 +00006035
Peter Collingbournee190dee2011-03-11 19:24:49 +00006036 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6037 E->getOperatorLoc(),
6038 E->getKind(),
6039 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006040}
Mike Stump11289f42009-09-09 15:08:12 +00006041
Douglas Gregora16548e2009-08-11 05:31:07 +00006042template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006043ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006044TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006045 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006046 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006047 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006048
John McCalldadc5752010-08-24 06:29:42 +00006049 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006050 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006052
6053
Douglas Gregora16548e2009-08-11 05:31:07 +00006054 if (!getDerived().AlwaysRebuild() &&
6055 LHS.get() == E->getLHS() &&
6056 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006057 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006058
John McCallb268a282010-08-23 23:25:46 +00006059 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006060 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006061 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006062 E->getRBracketLoc());
6063}
Mike Stump11289f42009-09-09 15:08:12 +00006064
6065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006066ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006067TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006068 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006069 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006070 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006071 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006072
6073 // Transform arguments.
6074 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006075 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006076 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6077 &ArgChanged))
6078 return ExprError();
6079
Douglas Gregora16548e2009-08-11 05:31:07 +00006080 if (!getDerived().AlwaysRebuild() &&
6081 Callee.get() == E->getCallee() &&
6082 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006083 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006084
Douglas Gregora16548e2009-08-11 05:31:07 +00006085 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006086 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006087 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006088 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006089 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006090 E->getRParenLoc());
6091}
Mike Stump11289f42009-09-09 15:08:12 +00006092
6093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006094ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006095TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006096 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006097 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006098 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006099
Douglas Gregorea972d32011-02-28 21:54:11 +00006100 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006101 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006102 QualifierLoc
6103 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6104
6105 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006106 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006107 }
Mike Stump11289f42009-09-09 15:08:12 +00006108
Eli Friedman2cfcef62009-12-04 06:40:45 +00006109 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006110 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6111 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006112 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006114
John McCall16df1e52010-03-30 21:47:33 +00006115 NamedDecl *FoundDecl = E->getFoundDecl();
6116 if (FoundDecl == E->getMemberDecl()) {
6117 FoundDecl = Member;
6118 } else {
6119 FoundDecl = cast_or_null<NamedDecl>(
6120 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6121 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006122 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006123 }
6124
Douglas Gregora16548e2009-08-11 05:31:07 +00006125 if (!getDerived().AlwaysRebuild() &&
6126 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006127 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006128 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006129 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006130 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006131
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006132 // Mark it referenced in the new context regardless.
6133 // FIXME: this is a bit instantiation-specific.
6134 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00006135 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006136 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006137
John McCall6b51f282009-11-23 01:53:49 +00006138 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006139 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006140 TransArgs.setLAngleLoc(E->getLAngleLoc());
6141 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006142 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6143 E->getNumTemplateArgs(),
6144 TransArgs))
6145 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006146 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006147
Douglas Gregora16548e2009-08-11 05:31:07 +00006148 // FIXME: Bogus source location for the operator
6149 SourceLocation FakeOperatorLoc
6150 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6151
John McCall38836f02010-01-15 08:34:02 +00006152 // FIXME: to do this check properly, we will need to preserve the
6153 // first-qualifier-in-scope here, just in case we had a dependent
6154 // base (and therefore couldn't do the check) and a
6155 // nested-name-qualifier (and therefore could do the lookup).
6156 NamedDecl *FirstQualifierInScope = 0;
6157
John McCallb268a282010-08-23 23:25:46 +00006158 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006159 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006160 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006161 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006162 Member,
John McCall16df1e52010-03-30 21:47:33 +00006163 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006164 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006165 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006166 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006167}
Mike Stump11289f42009-09-09 15:08:12 +00006168
Douglas Gregora16548e2009-08-11 05:31:07 +00006169template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006170ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006171TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006172 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006173 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006174 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006175
John McCalldadc5752010-08-24 06:29:42 +00006176 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006177 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006179
Douglas Gregora16548e2009-08-11 05:31:07 +00006180 if (!getDerived().AlwaysRebuild() &&
6181 LHS.get() == E->getLHS() &&
6182 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006183 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006184
Douglas Gregora16548e2009-08-11 05:31:07 +00006185 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006186 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006187}
6188
Mike Stump11289f42009-09-09 15:08:12 +00006189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006190ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006191TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006192 CompoundAssignOperator *E) {
6193 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006194}
Mike Stump11289f42009-09-09 15:08:12 +00006195
Douglas Gregora16548e2009-08-11 05:31:07 +00006196template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006197ExprResult TreeTransform<Derived>::
6198TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6199 // Just rebuild the common and RHS expressions and see whether we
6200 // get any changes.
6201
6202 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6203 if (commonExpr.isInvalid())
6204 return ExprError();
6205
6206 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6207 if (rhs.isInvalid())
6208 return ExprError();
6209
6210 if (!getDerived().AlwaysRebuild() &&
6211 commonExpr.get() == e->getCommon() &&
6212 rhs.get() == e->getFalseExpr())
6213 return SemaRef.Owned(e);
6214
6215 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6216 e->getQuestionLoc(),
6217 0,
6218 e->getColonLoc(),
6219 rhs.get());
6220}
6221
6222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006223ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006224TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006225 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006226 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006227 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006228
John McCalldadc5752010-08-24 06:29:42 +00006229 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006230 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006231 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006232
John McCalldadc5752010-08-24 06:29:42 +00006233 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006234 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006236
Douglas Gregora16548e2009-08-11 05:31:07 +00006237 if (!getDerived().AlwaysRebuild() &&
6238 Cond.get() == E->getCond() &&
6239 LHS.get() == E->getLHS() &&
6240 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006241 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006242
John McCallb268a282010-08-23 23:25:46 +00006243 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006244 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006245 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006246 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006247 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006248}
Mike Stump11289f42009-09-09 15:08:12 +00006249
6250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006251ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006252TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006253 // Implicit casts are eliminated during transformation, since they
6254 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006255 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006256}
Mike Stump11289f42009-09-09 15:08:12 +00006257
Douglas Gregora16548e2009-08-11 05:31:07 +00006258template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006259ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006260TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006261 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6262 if (!Type)
6263 return ExprError();
6264
John McCalldadc5752010-08-24 06:29:42 +00006265 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006266 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006267 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006269
Douglas Gregora16548e2009-08-11 05:31:07 +00006270 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006271 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006272 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006273 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006274
John McCall97513962010-01-15 18:39:57 +00006275 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006276 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006277 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006278 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006279}
Mike Stump11289f42009-09-09 15:08:12 +00006280
Douglas Gregora16548e2009-08-11 05:31:07 +00006281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006282ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006283TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006284 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6285 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6286 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006288
John McCalldadc5752010-08-24 06:29:42 +00006289 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006290 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006292
Douglas Gregora16548e2009-08-11 05:31:07 +00006293 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006294 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006295 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006296 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006297
John McCall5d7aa7f2010-01-19 22:33:45 +00006298 // Note: the expression type doesn't necessarily match the
6299 // type-as-written, but that's okay, because it should always be
6300 // derivable from the initializer.
6301
John McCalle15bbff2010-01-18 19:35:47 +00006302 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006303 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006304 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006305}
Mike Stump11289f42009-09-09 15:08:12 +00006306
Douglas Gregora16548e2009-08-11 05:31:07 +00006307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006309TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006310 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006311 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006312 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006313
Douglas Gregora16548e2009-08-11 05:31:07 +00006314 if (!getDerived().AlwaysRebuild() &&
6315 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006316 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006317
Douglas Gregora16548e2009-08-11 05:31:07 +00006318 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006319 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006320 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006321 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006322 E->getAccessorLoc(),
6323 E->getAccessor());
6324}
Mike Stump11289f42009-09-09 15:08:12 +00006325
Douglas Gregora16548e2009-08-11 05:31:07 +00006326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006327ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006328TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006329 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006330
John McCall37ad5512010-08-23 06:44:23 +00006331 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006332 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6333 Inits, &InitChanged))
6334 return ExprError();
6335
Douglas Gregora16548e2009-08-11 05:31:07 +00006336 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006337 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006338
Douglas Gregora16548e2009-08-11 05:31:07 +00006339 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006340 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006341}
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregora16548e2009-08-11 05:31:07 +00006343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006344ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006345TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006346 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006347
Douglas Gregorebe10102009-08-20 07:17:43 +00006348 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006349 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006350 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006351 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006352
Douglas Gregorebe10102009-08-20 07:17:43 +00006353 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006354 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006355 bool ExprChanged = false;
6356 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6357 DEnd = E->designators_end();
6358 D != DEnd; ++D) {
6359 if (D->isFieldDesignator()) {
6360 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6361 D->getDotLoc(),
6362 D->getFieldLoc()));
6363 continue;
6364 }
Mike Stump11289f42009-09-09 15:08:12 +00006365
Douglas Gregora16548e2009-08-11 05:31:07 +00006366 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006367 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006368 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006369 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006370
6371 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006372 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006373
Douglas Gregora16548e2009-08-11 05:31:07 +00006374 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6375 ArrayExprs.push_back(Index.release());
6376 continue;
6377 }
Mike Stump11289f42009-09-09 15:08:12 +00006378
Douglas Gregora16548e2009-08-11 05:31:07 +00006379 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006380 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006381 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6382 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006383 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006384
John McCalldadc5752010-08-24 06:29:42 +00006385 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006386 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006387 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006388
6389 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006390 End.get(),
6391 D->getLBracketLoc(),
6392 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006393
Douglas Gregora16548e2009-08-11 05:31:07 +00006394 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6395 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006396
Douglas Gregora16548e2009-08-11 05:31:07 +00006397 ArrayExprs.push_back(Start.release());
6398 ArrayExprs.push_back(End.release());
6399 }
Mike Stump11289f42009-09-09 15:08:12 +00006400
Douglas Gregora16548e2009-08-11 05:31:07 +00006401 if (!getDerived().AlwaysRebuild() &&
6402 Init.get() == E->getInit() &&
6403 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006404 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006405
Douglas Gregora16548e2009-08-11 05:31:07 +00006406 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6407 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006408 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006409}
Mike Stump11289f42009-09-09 15:08:12 +00006410
Douglas Gregora16548e2009-08-11 05:31:07 +00006411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006412ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006413TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006414 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006415 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006416
Douglas Gregor3da3c062009-10-28 00:29:27 +00006417 // FIXME: Will we ever have proper type location here? Will we actually
6418 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006419 QualType T = getDerived().TransformType(E->getType());
6420 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006421 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006422
Douglas Gregora16548e2009-08-11 05:31:07 +00006423 if (!getDerived().AlwaysRebuild() &&
6424 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006425 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006426
Douglas Gregora16548e2009-08-11 05:31:07 +00006427 return getDerived().RebuildImplicitValueInitExpr(T);
6428}
Mike Stump11289f42009-09-09 15:08:12 +00006429
Douglas Gregora16548e2009-08-11 05:31:07 +00006430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006431ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006432TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006433 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6434 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006435 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006436
John McCalldadc5752010-08-24 06:29:42 +00006437 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006439 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006440
Douglas Gregora16548e2009-08-11 05:31:07 +00006441 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006442 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006443 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006444 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006445
John McCallb268a282010-08-23 23:25:46 +00006446 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006447 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006448}
6449
6450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006451ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006452TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006453 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006454 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006455 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6456 &ArgumentChanged))
6457 return ExprError();
6458
Douglas Gregora16548e2009-08-11 05:31:07 +00006459 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6460 move_arg(Inits),
6461 E->getRParenLoc());
6462}
Mike Stump11289f42009-09-09 15:08:12 +00006463
Douglas Gregora16548e2009-08-11 05:31:07 +00006464/// \brief Transform an address-of-label expression.
6465///
6466/// By default, the transformation of an address-of-label expression always
6467/// rebuilds the expression, so that the label identifier can be resolved to
6468/// the corresponding label statement by semantic analysis.
6469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006471TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006472 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6473 E->getLabel());
6474 if (!LD)
6475 return ExprError();
6476
Douglas Gregora16548e2009-08-11 05:31:07 +00006477 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006478 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006479}
Mike Stump11289f42009-09-09 15:08:12 +00006480
6481template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006482ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006483TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006484 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006485 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6486 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006487 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006488
Douglas Gregora16548e2009-08-11 05:31:07 +00006489 if (!getDerived().AlwaysRebuild() &&
6490 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006491 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006492
6493 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006494 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006495 E->getRParenLoc());
6496}
Mike Stump11289f42009-09-09 15:08:12 +00006497
Douglas Gregora16548e2009-08-11 05:31:07 +00006498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006499ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006500TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006501 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006502 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006503 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006504
John McCalldadc5752010-08-24 06:29:42 +00006505 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006506 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006507 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006508
John McCalldadc5752010-08-24 06:29:42 +00006509 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006510 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006511 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006512
Douglas Gregora16548e2009-08-11 05:31:07 +00006513 if (!getDerived().AlwaysRebuild() &&
6514 Cond.get() == E->getCond() &&
6515 LHS.get() == E->getLHS() &&
6516 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006517 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006518
Douglas Gregora16548e2009-08-11 05:31:07 +00006519 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006520 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006521 E->getRParenLoc());
6522}
Mike Stump11289f42009-09-09 15:08:12 +00006523
Douglas Gregora16548e2009-08-11 05:31:07 +00006524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006525ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006526TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006527 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006528}
6529
6530template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006531ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006532TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006533 switch (E->getOperator()) {
6534 case OO_New:
6535 case OO_Delete:
6536 case OO_Array_New:
6537 case OO_Array_Delete:
6538 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006539 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006540
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006541 case OO_Call: {
6542 // This is a call to an object's operator().
6543 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6544
6545 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006546 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006547 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006548 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006549
6550 // FIXME: Poor location information
6551 SourceLocation FakeLParenLoc
6552 = SemaRef.PP.getLocForEndOfToken(
6553 static_cast<Expr *>(Object.get())->getLocEnd());
6554
6555 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006556 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006557 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6558 Args))
6559 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006560
John McCallb268a282010-08-23 23:25:46 +00006561 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006562 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006563 E->getLocEnd());
6564 }
6565
6566#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6567 case OO_##Name:
6568#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6569#include "clang/Basic/OperatorKinds.def"
6570 case OO_Subscript:
6571 // Handled below.
6572 break;
6573
6574 case OO_Conditional:
6575 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006576 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006577
6578 case OO_None:
6579 case NUM_OVERLOADED_OPERATORS:
6580 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006581 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006582 }
6583
John McCalldadc5752010-08-24 06:29:42 +00006584 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006585 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006586 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006587
John McCalldadc5752010-08-24 06:29:42 +00006588 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006589 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006590 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006591
John McCalldadc5752010-08-24 06:29:42 +00006592 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006593 if (E->getNumArgs() == 2) {
6594 Second = getDerived().TransformExpr(E->getArg(1));
6595 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006596 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006597 }
Mike Stump11289f42009-09-09 15:08:12 +00006598
Douglas Gregora16548e2009-08-11 05:31:07 +00006599 if (!getDerived().AlwaysRebuild() &&
6600 Callee.get() == E->getCallee() &&
6601 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006602 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006603 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006604
Douglas Gregora16548e2009-08-11 05:31:07 +00006605 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6606 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006607 Callee.get(),
6608 First.get(),
6609 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006610}
Mike Stump11289f42009-09-09 15:08:12 +00006611
Douglas Gregora16548e2009-08-11 05:31:07 +00006612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006613ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006614TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6615 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006616}
Mike Stump11289f42009-09-09 15:08:12 +00006617
Douglas Gregora16548e2009-08-11 05:31:07 +00006618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006619ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006620TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6621 // Transform the callee.
6622 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6623 if (Callee.isInvalid())
6624 return ExprError();
6625
6626 // Transform exec config.
6627 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6628 if (EC.isInvalid())
6629 return ExprError();
6630
6631 // Transform arguments.
6632 bool ArgChanged = false;
6633 ASTOwningVector<Expr*> Args(SemaRef);
6634 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6635 &ArgChanged))
6636 return ExprError();
6637
6638 if (!getDerived().AlwaysRebuild() &&
6639 Callee.get() == E->getCallee() &&
6640 !ArgChanged)
6641 return SemaRef.Owned(E);
6642
6643 // FIXME: Wrong source location information for the '('.
6644 SourceLocation FakeLParenLoc
6645 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6646 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6647 move_arg(Args),
6648 E->getRParenLoc(), EC.get());
6649}
6650
6651template<typename Derived>
6652ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006653TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006654 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6655 if (!Type)
6656 return ExprError();
6657
John McCalldadc5752010-08-24 06:29:42 +00006658 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006659 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006660 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006662
Douglas Gregora16548e2009-08-11 05:31:07 +00006663 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006664 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006665 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006666 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006667
Douglas Gregora16548e2009-08-11 05:31:07 +00006668 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006669 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006670 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6671 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6672 SourceLocation FakeRParenLoc
6673 = SemaRef.PP.getLocForEndOfToken(
6674 E->getSubExpr()->getSourceRange().getEnd());
6675 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006676 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006677 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006678 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006679 FakeRAngleLoc,
6680 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006681 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 FakeRParenLoc);
6683}
Mike Stump11289f42009-09-09 15:08:12 +00006684
Douglas Gregora16548e2009-08-11 05:31:07 +00006685template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006686ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006687TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6688 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006689}
Mike Stump11289f42009-09-09 15:08:12 +00006690
6691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006692ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006693TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6694 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006695}
6696
Douglas Gregora16548e2009-08-11 05:31:07 +00006697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006698ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006699TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006700 CXXReinterpretCastExpr *E) {
6701 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006702}
Mike Stump11289f42009-09-09 15:08:12 +00006703
Douglas Gregora16548e2009-08-11 05:31:07 +00006704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006705ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006706TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6707 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006708}
Mike Stump11289f42009-09-09 15:08:12 +00006709
Douglas Gregora16548e2009-08-11 05:31:07 +00006710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006711ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006712TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006713 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006714 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6715 if (!Type)
6716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006717
John McCalldadc5752010-08-24 06:29:42 +00006718 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006719 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006720 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006722
Douglas Gregora16548e2009-08-11 05:31:07 +00006723 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006724 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006725 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006726 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006727
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006728 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006729 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006730 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006731 E->getRParenLoc());
6732}
Mike Stump11289f42009-09-09 15:08:12 +00006733
Douglas Gregora16548e2009-08-11 05:31:07 +00006734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006736TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006737 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006738 TypeSourceInfo *TInfo
6739 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6740 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006741 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006742
Douglas Gregora16548e2009-08-11 05:31:07 +00006743 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006744 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006745 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006746
Douglas Gregor9da64192010-04-26 22:37:10 +00006747 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6748 E->getLocStart(),
6749 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006750 E->getLocEnd());
6751 }
Mike Stump11289f42009-09-09 15:08:12 +00006752
Douglas Gregora16548e2009-08-11 05:31:07 +00006753 // We don't know whether the expression is potentially evaluated until
6754 // after we perform semantic analysis, so the expression is potentially
6755 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006756 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006757 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006758
John McCalldadc5752010-08-24 06:29:42 +00006759 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006760 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006761 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006762
Douglas Gregora16548e2009-08-11 05:31:07 +00006763 if (!getDerived().AlwaysRebuild() &&
6764 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006765 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006766
Douglas Gregor9da64192010-04-26 22:37:10 +00006767 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6768 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006769 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006770 E->getLocEnd());
6771}
6772
6773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006774ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006775TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6776 if (E->isTypeOperand()) {
6777 TypeSourceInfo *TInfo
6778 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6779 if (!TInfo)
6780 return ExprError();
6781
6782 if (!getDerived().AlwaysRebuild() &&
6783 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006784 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006785
Douglas Gregor69735112011-03-06 17:40:41 +00006786 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006787 E->getLocStart(),
6788 TInfo,
6789 E->getLocEnd());
6790 }
6791
6792 // We don't know whether the expression is potentially evaluated until
6793 // after we perform semantic analysis, so the expression is potentially
6794 // potentially evaluated.
6795 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6796
6797 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6798 if (SubExpr.isInvalid())
6799 return ExprError();
6800
6801 if (!getDerived().AlwaysRebuild() &&
6802 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006803 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006804
6805 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6806 E->getLocStart(),
6807 SubExpr.get(),
6808 E->getLocEnd());
6809}
6810
6811template<typename Derived>
6812ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006813TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006814 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006815}
Mike Stump11289f42009-09-09 15:08:12 +00006816
Douglas Gregora16548e2009-08-11 05:31:07 +00006817template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006818ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006819TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006820 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006821 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006822}
Mike Stump11289f42009-09-09 15:08:12 +00006823
Douglas Gregora16548e2009-08-11 05:31:07 +00006824template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006825ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006826TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006827 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith938f40b2011-06-11 17:19:42 +00006828 QualType T;
6829 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6830 T = MD->getThisType(getSema().Context);
6831 else
6832 T = getSema().Context.getPointerType(
6833 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump11289f42009-09-09 15:08:12 +00006834
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006835 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006836 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006837
Douglas Gregorb15af892010-01-07 23:12:05 +00006838 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006839}
Mike Stump11289f42009-09-09 15:08:12 +00006840
Douglas Gregora16548e2009-08-11 05:31:07 +00006841template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006842ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006843TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006844 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006845 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006846 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006847
Douglas Gregora16548e2009-08-11 05:31:07 +00006848 if (!getDerived().AlwaysRebuild() &&
6849 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006850 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006851
Douglas Gregor53e191ed2011-07-06 22:04:06 +00006852 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6853 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00006854}
Mike Stump11289f42009-09-09 15:08:12 +00006855
Douglas Gregora16548e2009-08-11 05:31:07 +00006856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006857ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006858TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006859 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006860 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6861 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006862 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006864
Chandler Carruth794da4c2010-02-08 06:42:49 +00006865 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006866 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006867 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006868
Douglas Gregor033f6752009-12-23 23:03:06 +00006869 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006870}
Mike Stump11289f42009-09-09 15:08:12 +00006871
Douglas Gregora16548e2009-08-11 05:31:07 +00006872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006873ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006874TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6875 CXXScalarValueInitExpr *E) {
6876 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6877 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006878 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006879
Douglas Gregora16548e2009-08-11 05:31:07 +00006880 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006881 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006882 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006883
Douglas Gregor2b88c112010-09-08 00:15:04 +00006884 return getDerived().RebuildCXXScalarValueInitExpr(T,
6885 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006886 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006887}
Mike Stump11289f42009-09-09 15:08:12 +00006888
Douglas Gregora16548e2009-08-11 05:31:07 +00006889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006890ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006891TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006892 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006893 TypeSourceInfo *AllocTypeInfo
6894 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6895 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006896 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006897
Douglas Gregora16548e2009-08-11 05:31:07 +00006898 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006899 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006900 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006901 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006902
Douglas Gregora16548e2009-08-11 05:31:07 +00006903 // Transform the placement arguments (if any).
6904 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006905 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006906 if (getDerived().TransformExprs(E->getPlacementArgs(),
6907 E->getNumPlacementArgs(), true,
6908 PlacementArgs, &ArgumentChanged))
6909 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006910
Douglas Gregorebe10102009-08-20 07:17:43 +00006911 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006912 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006913 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6914 ConstructorArgs, &ArgumentChanged))
6915 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006916
Douglas Gregord2d9da02010-02-26 00:38:10 +00006917 // Transform constructor, new operator, and delete operator.
6918 CXXConstructorDecl *Constructor = 0;
6919 if (E->getConstructor()) {
6920 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006921 getDerived().TransformDecl(E->getLocStart(),
6922 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006923 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006924 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006925 }
6926
6927 FunctionDecl *OperatorNew = 0;
6928 if (E->getOperatorNew()) {
6929 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006930 getDerived().TransformDecl(E->getLocStart(),
6931 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006932 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006933 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006934 }
6935
6936 FunctionDecl *OperatorDelete = 0;
6937 if (E->getOperatorDelete()) {
6938 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006939 getDerived().TransformDecl(E->getLocStart(),
6940 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006941 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006942 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006943 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006944
Douglas Gregora16548e2009-08-11 05:31:07 +00006945 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006946 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006947 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006948 Constructor == E->getConstructor() &&
6949 OperatorNew == E->getOperatorNew() &&
6950 OperatorDelete == E->getOperatorDelete() &&
6951 !ArgumentChanged) {
6952 // Mark any declarations we need as referenced.
6953 // FIXME: instantiation-specific.
6954 if (Constructor)
6955 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6956 if (OperatorNew)
6957 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6958 if (OperatorDelete)
6959 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor72912fb2011-07-26 15:11:03 +00006960
6961 if (E->isArray() && Constructor &&
6962 !E->getAllocatedType()->isDependentType()) {
6963 QualType ElementType
6964 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
6965 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
6966 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
6967 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
6968 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
6969 }
6970 }
6971 }
6972
John McCallc3007a22010-10-26 07:05:15 +00006973 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006974 }
Mike Stump11289f42009-09-09 15:08:12 +00006975
Douglas Gregor0744ef62010-09-07 21:49:58 +00006976 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006977 if (!ArraySize.get()) {
6978 // If no array size was specified, but the new expression was
6979 // instantiated with an array type (e.g., "new T" where T is
6980 // instantiated with "int[4]"), extract the outer bound from the
6981 // array type as our array size. We do this with constant and
6982 // dependently-sized array types.
6983 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6984 if (!ArrayT) {
6985 // Do nothing
6986 } else if (const ConstantArrayType *ConsArrayT
6987 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006988 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006989 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6990 ConsArrayT->getSize(),
6991 SemaRef.Context.getSizeType(),
6992 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006993 AllocType = ConsArrayT->getElementType();
6994 } else if (const DependentSizedArrayType *DepArrayT
6995 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6996 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006997 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006998 AllocType = DepArrayT->getElementType();
6999 }
7000 }
7001 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00007002
Douglas Gregora16548e2009-08-11 05:31:07 +00007003 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7004 E->isGlobalNew(),
7005 /*FIXME:*/E->getLocStart(),
7006 move_arg(PlacementArgs),
7007 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007008 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007009 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007010 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007011 ArraySize.get(),
Douglas Gregor3bdcff52011-06-27 16:55:54 +00007012 /*FIXME:*/E->hasInitializer()
7013 ? E->getLocStart()
7014 : SourceLocation(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007015 move_arg(ConstructorArgs),
Douglas Gregor3bdcff52011-06-27 16:55:54 +00007016 /*FIXME:*/E->hasInitializer()
7017 ? E->getLocEnd()
7018 : SourceLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007019}
Mike Stump11289f42009-09-09 15:08:12 +00007020
Douglas Gregora16548e2009-08-11 05:31:07 +00007021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007023TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007024 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007025 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007026 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007027
Douglas Gregord2d9da02010-02-26 00:38:10 +00007028 // Transform the delete operator, if known.
7029 FunctionDecl *OperatorDelete = 0;
7030 if (E->getOperatorDelete()) {
7031 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007032 getDerived().TransformDecl(E->getLocStart(),
7033 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007034 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007035 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007036 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007037
Douglas Gregora16548e2009-08-11 05:31:07 +00007038 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007039 Operand.get() == E->getArgument() &&
7040 OperatorDelete == E->getOperatorDelete()) {
7041 // Mark any declarations we need as referenced.
7042 // FIXME: instantiation-specific.
7043 if (OperatorDelete)
7044 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007045
7046 if (!E->getArgument()->isTypeDependent()) {
7047 QualType Destroyed = SemaRef.Context.getBaseElementType(
7048 E->getDestroyedType());
7049 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7050 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7051 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7052 SemaRef.LookupDestructor(Record));
7053 }
7054 }
7055
John McCallc3007a22010-10-26 07:05:15 +00007056 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007057 }
Mike Stump11289f42009-09-09 15:08:12 +00007058
Douglas Gregora16548e2009-08-11 05:31:07 +00007059 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7060 E->isGlobalDelete(),
7061 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007062 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007063}
Mike Stump11289f42009-09-09 15:08:12 +00007064
Douglas Gregora16548e2009-08-11 05:31:07 +00007065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007066ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007067TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007068 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007069 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007070 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007071 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007072
John McCallba7bf592010-08-24 05:47:05 +00007073 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007074 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007075 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007076 E->getOperatorLoc(),
7077 E->isArrow()? tok::arrow : tok::period,
7078 ObjectTypePtr,
7079 MayBePseudoDestructor);
7080 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007081 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007082
John McCallba7bf592010-08-24 05:47:05 +00007083 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007084 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7085 if (QualifierLoc) {
7086 QualifierLoc
7087 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7088 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007089 return ExprError();
7090 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007091 CXXScopeSpec SS;
7092 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007093
Douglas Gregor678f90d2010-02-25 01:56:36 +00007094 PseudoDestructorTypeStorage Destroyed;
7095 if (E->getDestroyedTypeInfo()) {
7096 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007097 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007098 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007099 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007100 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007101 Destroyed = DestroyedTypeInfo;
7102 } else if (ObjectType->isDependentType()) {
7103 // We aren't likely to be able to resolve the identifier down to a type
7104 // now anyway, so just retain the identifier.
7105 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7106 E->getDestroyedTypeLoc());
7107 } else {
7108 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007109 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007110 *E->getDestroyedTypeIdentifier(),
7111 E->getDestroyedTypeLoc(),
7112 /*Scope=*/0,
7113 SS, ObjectTypePtr,
7114 false);
7115 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007116 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007117
Douglas Gregor678f90d2010-02-25 01:56:36 +00007118 Destroyed
7119 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7120 E->getDestroyedTypeLoc());
7121 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007122
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007123 TypeSourceInfo *ScopeTypeInfo = 0;
7124 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00007125 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007126 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007127 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007128 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007129
John McCallb268a282010-08-23 23:25:46 +00007130 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007131 E->getOperatorLoc(),
7132 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007133 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007134 ScopeTypeInfo,
7135 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007136 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007137 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007138}
Mike Stump11289f42009-09-09 15:08:12 +00007139
Douglas Gregorad8a3362009-09-04 17:36:40 +00007140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007141ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007142TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007143 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007144 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7145 Sema::LookupOrdinaryName);
7146
7147 // Transform all the decls.
7148 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7149 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007150 NamedDecl *InstD = static_cast<NamedDecl*>(
7151 getDerived().TransformDecl(Old->getNameLoc(),
7152 *I));
John McCall84d87672009-12-10 09:41:52 +00007153 if (!InstD) {
7154 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7155 // This can happen because of dependent hiding.
7156 if (isa<UsingShadowDecl>(*I))
7157 continue;
7158 else
John McCallfaf5fb42010-08-26 23:41:50 +00007159 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007160 }
John McCalle66edc12009-11-24 19:00:30 +00007161
7162 // Expand using declarations.
7163 if (isa<UsingDecl>(InstD)) {
7164 UsingDecl *UD = cast<UsingDecl>(InstD);
7165 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7166 E = UD->shadow_end(); I != E; ++I)
7167 R.addDecl(*I);
7168 continue;
7169 }
7170
7171 R.addDecl(InstD);
7172 }
7173
7174 // Resolve a kind, but don't do any further analysis. If it's
7175 // ambiguous, the callee needs to deal with it.
7176 R.resolveKind();
7177
7178 // Rebuild the nested-name qualifier, if present.
7179 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007180 if (Old->getQualifierLoc()) {
7181 NestedNameSpecifierLoc QualifierLoc
7182 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7183 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007184 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007185
Douglas Gregor0da1d432011-02-28 20:01:57 +00007186 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007187 }
7188
Douglas Gregor9262f472010-04-27 18:19:34 +00007189 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007190 CXXRecordDecl *NamingClass
7191 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7192 Old->getNameLoc(),
7193 Old->getNamingClass()));
7194 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007195 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007196
Douglas Gregorda7be082010-04-27 16:10:10 +00007197 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007198 }
7199
7200 // If we have no template arguments, it's a normal declaration name.
7201 if (!Old->hasExplicitTemplateArgs())
7202 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7203
7204 // If we have template arguments, rebuild them, then rebuild the
7205 // templateid expression.
7206 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007207 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7208 Old->getNumTemplateArgs(),
7209 TransArgs))
7210 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007211
7212 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7213 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007214}
Mike Stump11289f42009-09-09 15:08:12 +00007215
Douglas Gregora16548e2009-08-11 05:31:07 +00007216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007217ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007218TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007219 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7220 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007221 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007222
Douglas Gregora16548e2009-08-11 05:31:07 +00007223 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007224 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007225 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007226
Mike Stump11289f42009-09-09 15:08:12 +00007227 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007228 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007229 T,
7230 E->getLocEnd());
7231}
Mike Stump11289f42009-09-09 15:08:12 +00007232
Douglas Gregora16548e2009-08-11 05:31:07 +00007233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007234ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007235TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7236 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7237 if (!LhsT)
7238 return ExprError();
7239
7240 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7241 if (!RhsT)
7242 return ExprError();
7243
7244 if (!getDerived().AlwaysRebuild() &&
7245 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7246 return SemaRef.Owned(E);
7247
7248 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7249 E->getLocStart(),
7250 LhsT, RhsT,
7251 E->getLocEnd());
7252}
7253
7254template<typename Derived>
7255ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007256TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7257 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7258 if (!T)
7259 return ExprError();
7260
7261 if (!getDerived().AlwaysRebuild() &&
7262 T == E->getQueriedTypeSourceInfo())
7263 return SemaRef.Owned(E);
7264
7265 ExprResult SubExpr;
7266 {
7267 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7268 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7269 if (SubExpr.isInvalid())
7270 return ExprError();
7271
7272 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7273 return SemaRef.Owned(E);
7274 }
7275
7276 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7277 E->getLocStart(),
7278 T,
7279 SubExpr.get(),
7280 E->getLocEnd());
7281}
7282
7283template<typename Derived>
7284ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007285TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7286 ExprResult SubExpr;
7287 {
7288 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7289 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7290 if (SubExpr.isInvalid())
7291 return ExprError();
7292
7293 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7294 return SemaRef.Owned(E);
7295 }
7296
7297 return getDerived().RebuildExpressionTrait(
7298 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7299}
7300
7301template<typename Derived>
7302ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007303TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007304 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007305 NestedNameSpecifierLoc QualifierLoc
7306 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7307 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007308 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007309
John McCall31f82722010-11-12 08:19:04 +00007310 // TODO: If this is a conversion-function-id, verify that the
7311 // destination type name (if present) resolves the same way after
7312 // instantiation as it did in the local scope.
7313
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007314 DeclarationNameInfo NameInfo
7315 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7316 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007317 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007318
John McCalle66edc12009-11-24 19:00:30 +00007319 if (!E->hasExplicitTemplateArgs()) {
7320 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007321 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007322 // Note: it is sufficient to compare the Name component of NameInfo:
7323 // if name has not changed, DNLoc has not changed either.
7324 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007325 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007326
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007327 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007328 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007329 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007330 }
John McCall6b51f282009-11-23 01:53:49 +00007331
7332 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007333 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7334 E->getNumTemplateArgs(),
7335 TransArgs))
7336 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007337
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007338 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007339 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007340 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007341}
7342
7343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007344ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007345TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007346 // CXXConstructExprs are always implicit, so when we have a
7347 // 1-argument construction we just transform that argument.
7348 if (E->getNumArgs() == 1 ||
7349 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7350 return getDerived().TransformExpr(E->getArg(0));
7351
Douglas Gregora16548e2009-08-11 05:31:07 +00007352 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7353
7354 QualType T = getDerived().TransformType(E->getType());
7355 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007356 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007357
7358 CXXConstructorDecl *Constructor
7359 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007360 getDerived().TransformDecl(E->getLocStart(),
7361 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007362 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007363 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007364
Douglas Gregora16548e2009-08-11 05:31:07 +00007365 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007366 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007367 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7368 &ArgumentChanged))
7369 return ExprError();
7370
Douglas Gregora16548e2009-08-11 05:31:07 +00007371 if (!getDerived().AlwaysRebuild() &&
7372 T == E->getType() &&
7373 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007374 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007375 // Mark the constructor as referenced.
7376 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007377 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007378 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007379 }
Mike Stump11289f42009-09-09 15:08:12 +00007380
Douglas Gregordb121ba2009-12-14 16:27:04 +00007381 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7382 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007383 move_arg(Args),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00007384 E->hadMultipleCandidates(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007385 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007386 E->getConstructionKind(),
7387 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007388}
Mike Stump11289f42009-09-09 15:08:12 +00007389
Douglas Gregora16548e2009-08-11 05:31:07 +00007390/// \brief Transform a C++ temporary-binding expression.
7391///
Douglas Gregor363b1512009-12-24 18:51:59 +00007392/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7393/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007395ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007396TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007397 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007398}
Mike Stump11289f42009-09-09 15:08:12 +00007399
John McCall5d413782010-12-06 08:20:24 +00007400/// \brief Transform a C++ expression that contains cleanups that should
7401/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007402///
John McCall5d413782010-12-06 08:20:24 +00007403/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007404/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007406ExprResult
John McCall5d413782010-12-06 08:20:24 +00007407TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007408 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007409}
Mike Stump11289f42009-09-09 15:08:12 +00007410
Douglas Gregora16548e2009-08-11 05:31:07 +00007411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007412ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007413TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007414 CXXTemporaryObjectExpr *E) {
7415 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7416 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007417 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007418
Douglas Gregora16548e2009-08-11 05:31:07 +00007419 CXXConstructorDecl *Constructor
7420 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007421 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007422 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007423 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007424 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007425
Douglas Gregora16548e2009-08-11 05:31:07 +00007426 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007427 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007428 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007429 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7430 &ArgumentChanged))
7431 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007432
Douglas Gregora16548e2009-08-11 05:31:07 +00007433 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007434 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007435 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007436 !ArgumentChanged) {
7437 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007438 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007439 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007440 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007441
7442 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7443 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007444 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007445 E->getLocEnd());
7446}
Mike Stump11289f42009-09-09 15:08:12 +00007447
Douglas Gregora16548e2009-08-11 05:31:07 +00007448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007449ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007450TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007451 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007452 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7453 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007454 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007455
Douglas Gregora16548e2009-08-11 05:31:07 +00007456 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007457 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007458 Args.reserve(E->arg_size());
7459 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7460 &ArgumentChanged))
7461 return ExprError();
7462
Douglas Gregora16548e2009-08-11 05:31:07 +00007463 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007464 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007465 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007466 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007467
Douglas Gregora16548e2009-08-11 05:31:07 +00007468 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007469 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007470 E->getLParenLoc(),
7471 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007472 E->getRParenLoc());
7473}
Mike Stump11289f42009-09-09 15:08:12 +00007474
Douglas Gregora16548e2009-08-11 05:31:07 +00007475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007476ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007477TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007478 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007479 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007480 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007481 Expr *OldBase;
7482 QualType BaseType;
7483 QualType ObjectType;
7484 if (!E->isImplicitAccess()) {
7485 OldBase = E->getBase();
7486 Base = getDerived().TransformExpr(OldBase);
7487 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007489
John McCall2d74de92009-12-01 22:10:20 +00007490 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007491 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007492 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007493 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007494 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007495 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007496 ObjectTy,
7497 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007498 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007499 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007500
John McCallba7bf592010-08-24 05:47:05 +00007501 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007502 BaseType = ((Expr*) Base.get())->getType();
7503 } else {
7504 OldBase = 0;
7505 BaseType = getDerived().TransformType(E->getBaseType());
7506 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7507 }
Mike Stump11289f42009-09-09 15:08:12 +00007508
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007509 // Transform the first part of the nested-name-specifier that qualifies
7510 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007511 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007512 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007513 E->getFirstQualifierFoundInScope(),
7514 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007515
Douglas Gregore16af532011-02-28 18:50:33 +00007516 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007517 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007518 QualifierLoc
7519 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7520 ObjectType,
7521 FirstQualifierInScope);
7522 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007523 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007524 }
Mike Stump11289f42009-09-09 15:08:12 +00007525
John McCall31f82722010-11-12 08:19:04 +00007526 // TODO: If this is a conversion-function-id, verify that the
7527 // destination type name (if present) resolves the same way after
7528 // instantiation as it did in the local scope.
7529
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007530 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007531 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007532 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007533 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007534
John McCall2d74de92009-12-01 22:10:20 +00007535 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007536 // This is a reference to a member without an explicitly-specified
7537 // template argument list. Optimize for this common case.
7538 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007539 Base.get() == OldBase &&
7540 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007541 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007542 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007543 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007544 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007545
John McCallb268a282010-08-23 23:25:46 +00007546 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007547 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007548 E->isArrow(),
7549 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007550 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007551 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007552 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007553 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007554 }
7555
John McCall6b51f282009-11-23 01:53:49 +00007556 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007557 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7558 E->getNumTemplateArgs(),
7559 TransArgs))
7560 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007561
John McCallb268a282010-08-23 23:25:46 +00007562 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007563 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007564 E->isArrow(),
7565 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007566 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007567 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007568 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007569 &TransArgs);
7570}
7571
7572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007573ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007574TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007575 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007576 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007577 QualType BaseType;
7578 if (!Old->isImplicitAccess()) {
7579 Base = getDerived().TransformExpr(Old->getBase());
7580 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007581 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007582 BaseType = ((Expr*) Base.get())->getType();
7583 } else {
7584 BaseType = getDerived().TransformType(Old->getBaseType());
7585 }
John McCall10eae182009-11-30 22:42:35 +00007586
Douglas Gregor0da1d432011-02-28 20:01:57 +00007587 NestedNameSpecifierLoc QualifierLoc;
7588 if (Old->getQualifierLoc()) {
7589 QualifierLoc
7590 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7591 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007592 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007593 }
7594
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007595 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007596 Sema::LookupOrdinaryName);
7597
7598 // Transform all the decls.
7599 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7600 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007601 NamedDecl *InstD = static_cast<NamedDecl*>(
7602 getDerived().TransformDecl(Old->getMemberLoc(),
7603 *I));
John McCall84d87672009-12-10 09:41:52 +00007604 if (!InstD) {
7605 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7606 // This can happen because of dependent hiding.
7607 if (isa<UsingShadowDecl>(*I))
7608 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007609 else {
7610 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007611 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007612 }
John McCall84d87672009-12-10 09:41:52 +00007613 }
John McCall10eae182009-11-30 22:42:35 +00007614
7615 // Expand using declarations.
7616 if (isa<UsingDecl>(InstD)) {
7617 UsingDecl *UD = cast<UsingDecl>(InstD);
7618 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7619 E = UD->shadow_end(); I != E; ++I)
7620 R.addDecl(*I);
7621 continue;
7622 }
7623
7624 R.addDecl(InstD);
7625 }
7626
7627 R.resolveKind();
7628
Douglas Gregor9262f472010-04-27 18:19:34 +00007629 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007630 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007631 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007632 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007633 Old->getMemberLoc(),
7634 Old->getNamingClass()));
7635 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007636 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007637
Douglas Gregorda7be082010-04-27 16:10:10 +00007638 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007639 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007640
John McCall10eae182009-11-30 22:42:35 +00007641 TemplateArgumentListInfo TransArgs;
7642 if (Old->hasExplicitTemplateArgs()) {
7643 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7644 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007645 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7646 Old->getNumTemplateArgs(),
7647 TransArgs))
7648 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007649 }
John McCall38836f02010-01-15 08:34:02 +00007650
7651 // FIXME: to do this check properly, we will need to preserve the
7652 // first-qualifier-in-scope here, just in case we had a dependent
7653 // base (and therefore couldn't do the check) and a
7654 // nested-name-qualifier (and therefore could do the lookup).
7655 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007656
John McCallb268a282010-08-23 23:25:46 +00007657 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007658 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007659 Old->getOperatorLoc(),
7660 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007661 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007662 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007663 R,
7664 (Old->hasExplicitTemplateArgs()
7665 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007666}
7667
7668template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007669ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007670TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00007671 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007672 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7673 if (SubExpr.isInvalid())
7674 return ExprError();
7675
7676 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007677 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007678
7679 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7680}
7681
7682template<typename Derived>
7683ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007684TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007685 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7686 if (Pattern.isInvalid())
7687 return ExprError();
7688
7689 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7690 return SemaRef.Owned(E);
7691
Douglas Gregorb8840002011-01-14 21:20:45 +00007692 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7693 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007694}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007695
7696template<typename Derived>
7697ExprResult
7698TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7699 // If E is not value-dependent, then nothing will change when we transform it.
7700 // Note: This is an instantiation-centric view.
7701 if (!E->isValueDependent())
7702 return SemaRef.Owned(E);
7703
7704 // Note: None of the implementations of TryExpandParameterPacks can ever
7705 // produce a diagnostic when given only a single unexpanded parameter pack,
7706 // so
7707 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7708 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007709 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007710 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007711 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00007712 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007713 ShouldExpand, RetainExpansion,
7714 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007715 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007716
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007717 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007718 return SemaRef.Owned(E);
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007719
7720 NamedDecl *Pack = E->getPack();
7721 if (!ShouldExpand) {
7722 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7723 Pack));
7724 if (!Pack)
7725 return ExprError();
7726 }
7727
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007728
7729 // We now know the length of the parameter pack, so build a new expression
7730 // that stores that length.
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007731 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007732 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007733 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007734}
7735
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007736template<typename Derived>
7737ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007738TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7739 SubstNonTypeTemplateParmPackExpr *E) {
7740 // Default behavior is to do nothing with this transformation.
7741 return SemaRef.Owned(E);
7742}
7743
7744template<typename Derived>
7745ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00007746TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7747 SubstNonTypeTemplateParmExpr *E) {
7748 // Default behavior is to do nothing with this transformation.
7749 return SemaRef.Owned(E);
7750}
7751
7752template<typename Derived>
7753ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00007754TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7755 MaterializeTemporaryExpr *E) {
7756 return getDerived().TransformExpr(E->GetTemporaryExpr());
7757}
7758
7759template<typename Derived>
7760ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007761TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007762 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007763}
7764
Mike Stump11289f42009-09-09 15:08:12 +00007765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007766ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007767TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007768 TypeSourceInfo *EncodedTypeInfo
7769 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7770 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007771 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007772
Douglas Gregora16548e2009-08-11 05:31:07 +00007773 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007774 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007775 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007776
7777 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007778 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007779 E->getRParenLoc());
7780}
Mike Stump11289f42009-09-09 15:08:12 +00007781
Douglas Gregora16548e2009-08-11 05:31:07 +00007782template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00007783ExprResult TreeTransform<Derived>::
7784TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7785 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7786 if (result.isInvalid()) return ExprError();
7787 Expr *subExpr = result.take();
7788
7789 if (!getDerived().AlwaysRebuild() &&
7790 subExpr == E->getSubExpr())
7791 return SemaRef.Owned(E);
7792
7793 return SemaRef.Owned(new(SemaRef.Context)
7794 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7795}
7796
7797template<typename Derived>
7798ExprResult TreeTransform<Derived>::
7799TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7800 TypeSourceInfo *TSInfo
7801 = getDerived().TransformType(E->getTypeInfoAsWritten());
7802 if (!TSInfo)
7803 return ExprError();
7804
7805 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7806 if (Result.isInvalid())
7807 return ExprError();
7808
7809 if (!getDerived().AlwaysRebuild() &&
7810 TSInfo == E->getTypeInfoAsWritten() &&
7811 Result.get() == E->getSubExpr())
7812 return SemaRef.Owned(E);
7813
7814 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7815 E->getBridgeKeywordLoc(), TSInfo,
7816 Result.get());
7817}
7818
7819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007820ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007821TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007822 // Transform arguments.
7823 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007824 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007825 Args.reserve(E->getNumArgs());
7826 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7827 &ArgChanged))
7828 return ExprError();
7829
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007830 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7831 // Class message: transform the receiver type.
7832 TypeSourceInfo *ReceiverTypeInfo
7833 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7834 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007835 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007836
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007837 // If nothing changed, just retain the existing message send.
7838 if (!getDerived().AlwaysRebuild() &&
7839 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007840 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007841
7842 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007843 SmallVector<SourceLocation, 16> SelLocs;
7844 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007845 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7846 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007847 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007848 E->getMethodDecl(),
7849 E->getLeftLoc(),
7850 move_arg(Args),
7851 E->getRightLoc());
7852 }
7853
7854 // Instance message: transform the receiver
7855 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7856 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007857 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007858 = getDerived().TransformExpr(E->getInstanceReceiver());
7859 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007860 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007861
7862 // If nothing changed, just retain the existing message send.
7863 if (!getDerived().AlwaysRebuild() &&
7864 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007865 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007866
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007867 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007868 SmallVector<SourceLocation, 16> SelLocs;
7869 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00007870 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007871 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007872 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007873 E->getMethodDecl(),
7874 E->getLeftLoc(),
7875 move_arg(Args),
7876 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007877}
7878
Mike Stump11289f42009-09-09 15:08:12 +00007879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007880ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007881TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007882 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007883}
7884
Mike Stump11289f42009-09-09 15:08:12 +00007885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007886ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007887TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007888 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007889}
7890
Mike Stump11289f42009-09-09 15:08:12 +00007891template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007892ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007893TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007894 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007895 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007896 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007897 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007898
7899 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007900
Douglas Gregord51d90d2010-04-26 20:11:03 +00007901 // If nothing changed, just retain the existing expression.
7902 if (!getDerived().AlwaysRebuild() &&
7903 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007904 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007905
John McCallb268a282010-08-23 23:25:46 +00007906 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007907 E->getLocation(),
7908 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007909}
7910
Mike Stump11289f42009-09-09 15:08:12 +00007911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007913TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007914 // 'super' and types never change. Property never changes. Just
7915 // retain the existing expression.
7916 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007917 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007918
Douglas Gregor9faee212010-04-26 20:47:02 +00007919 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007920 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007921 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007922 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007923
Douglas Gregor9faee212010-04-26 20:47:02 +00007924 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007925
Douglas Gregor9faee212010-04-26 20:47:02 +00007926 // If nothing changed, just retain the existing expression.
7927 if (!getDerived().AlwaysRebuild() &&
7928 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007929 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007930
John McCallb7bd14f2010-12-02 01:19:52 +00007931 if (E->isExplicitProperty())
7932 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7933 E->getExplicitProperty(),
7934 E->getLocation());
7935
7936 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7937 E->getType(),
7938 E->getImplicitPropertyGetter(),
7939 E->getImplicitPropertySetter(),
7940 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007941}
7942
Mike Stump11289f42009-09-09 15:08:12 +00007943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007944ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007945TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007946 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007947 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007948 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007949 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007950
Douglas Gregord51d90d2010-04-26 20:11:03 +00007951 // If nothing changed, just retain the existing expression.
7952 if (!getDerived().AlwaysRebuild() &&
7953 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007954 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007955
John McCallb268a282010-08-23 23:25:46 +00007956 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007957 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007958}
7959
Mike Stump11289f42009-09-09 15:08:12 +00007960template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007961ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007962TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007963 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007964 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007965 SubExprs.reserve(E->getNumSubExprs());
7966 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7967 SubExprs, &ArgumentChanged))
7968 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007969
Douglas Gregora16548e2009-08-11 05:31:07 +00007970 if (!getDerived().AlwaysRebuild() &&
7971 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007972 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007973
Douglas Gregora16548e2009-08-11 05:31:07 +00007974 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7975 move_arg(SubExprs),
7976 E->getRParenLoc());
7977}
7978
Mike Stump11289f42009-09-09 15:08:12 +00007979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007980ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007981TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007982 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007983
John McCall490112f2011-02-04 18:33:18 +00007984 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7985 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7986
7987 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00007988 // We built a new blockScopeInfo in call to ActOnBlockStart
7989 // in above, CapturesCXXThis need be set here from the block
7990 // expression.
7991 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7992
Chris Lattner01cf8db2011-07-20 06:58:45 +00007993 SmallVector<ParmVarDecl*, 4> params;
7994 SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007995
7996 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007997 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7998 oldBlock->param_begin(),
7999 oldBlock->param_size(),
8000 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00008001 return true;
John McCall490112f2011-02-04 18:33:18 +00008002
8003 const FunctionType *exprFunctionType = E->getFunctionType();
8004 QualType exprResultType = exprFunctionType->getResultType();
8005 if (!exprResultType.isNull()) {
8006 if (!exprResultType->isDependentType())
8007 blockScope->ReturnType = exprResultType;
8008 else if (exprResultType != getSema().Context.DependentTy)
8009 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008010 }
Douglas Gregor476e3022011-01-19 21:32:01 +00008011
8012 // If the return type has not been determined yet, leave it as a dependent
8013 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00008014 if (blockScope->ReturnType.isNull())
8015 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00008016
8017 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00008018 if (blockScope->ReturnType->isObjCObjectType()) {
8019 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00008020 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00008021 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00008022 return ExprError();
8023 }
John McCall3882ace2011-01-05 12:14:39 +00008024
John McCall490112f2011-02-04 18:33:18 +00008025 QualType functionType = getDerived().RebuildFunctionProtoType(
8026 blockScope->ReturnType,
8027 paramTypes.data(),
8028 paramTypes.size(),
8029 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00008030 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00008031 exprFunctionType->getExtInfo());
8032 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00008033
8034 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00008035 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00008036 blockScope->TheDecl->setParams(params);
Douglas Gregor476e3022011-01-19 21:32:01 +00008037
8038 // If the return type wasn't explicitly set, it will have been marked as a
8039 // dependent type (DependentTy); clear out the return type setting so
8040 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00008041 if (blockScope->ReturnType == getSema().Context.DependentTy)
8042 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00008043
John McCall3882ace2011-01-05 12:14:39 +00008044 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00008045 StmtResult body = getDerived().TransformStmt(E->getBody());
8046 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00008047 return ExprError();
8048
John McCall490112f2011-02-04 18:33:18 +00008049#ifndef NDEBUG
8050 // In builds with assertions, make sure that we captured everything we
8051 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008052 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8053 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8054 e = oldBlock->capture_end(); i != e; ++i) {
8055 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00008056
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008057 // Ignore parameter packs.
8058 if (isa<ParmVarDecl>(oldCapture) &&
8059 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8060 continue;
John McCall490112f2011-02-04 18:33:18 +00008061
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008062 VarDecl *newCapture =
8063 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8064 oldCapture));
8065 assert(blockScope->CaptureMap.count(newCapture));
8066 }
John McCall490112f2011-02-04 18:33:18 +00008067 }
8068#endif
8069
8070 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8071 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008072}
8073
Mike Stump11289f42009-09-09 15:08:12 +00008074template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008075ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008076TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008077 ValueDecl *ND
8078 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8079 E->getDecl()));
8080 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008081 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008082
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008083 if (!getDerived().AlwaysRebuild() &&
8084 ND == E->getDecl()) {
8085 // Mark it referenced in the new context regardless.
8086 // FIXME: this is a bit instantiation-specific.
8087 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8088
John McCallc3007a22010-10-26 07:05:15 +00008089 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008090 }
8091
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008092 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00008093 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008094 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008095}
Mike Stump11289f42009-09-09 15:08:12 +00008096
Tanya Lattner55808c12011-06-04 00:47:47 +00008097template<typename Derived>
8098ExprResult
8099TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00008100 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00008101}
8102
Douglas Gregora16548e2009-08-11 05:31:07 +00008103//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008104// Type reconstruction
8105//===----------------------------------------------------------------------===//
8106
Mike Stump11289f42009-09-09 15:08:12 +00008107template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008108QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8109 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008110 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008111 getDerived().getBaseEntity());
8112}
8113
Mike Stump11289f42009-09-09 15:08:12 +00008114template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008115QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8116 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008117 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008118 getDerived().getBaseEntity());
8119}
8120
Mike Stump11289f42009-09-09 15:08:12 +00008121template<typename Derived>
8122QualType
John McCall70dd5f62009-10-30 00:06:24 +00008123TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8124 bool WrittenAsLValue,
8125 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008126 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00008127 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008128}
8129
8130template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008131QualType
John McCall70dd5f62009-10-30 00:06:24 +00008132TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8133 QualType ClassType,
8134 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008135 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00008136 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008137}
8138
8139template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008140QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00008141TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8142 ArrayType::ArraySizeModifier SizeMod,
8143 const llvm::APInt *Size,
8144 Expr *SizeExpr,
8145 unsigned IndexTypeQuals,
8146 SourceRange BracketsRange) {
8147 if (SizeExpr || !Size)
8148 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8149 IndexTypeQuals, BracketsRange,
8150 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00008151
8152 QualType Types[] = {
8153 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8154 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8155 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00008156 };
8157 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8158 QualType SizeType;
8159 for (unsigned I = 0; I != NumTypes; ++I)
8160 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8161 SizeType = Types[I];
8162 break;
8163 }
Mike Stump11289f42009-09-09 15:08:12 +00008164
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008165 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8166 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00008167 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008168 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00008169 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008170}
Mike Stump11289f42009-09-09 15:08:12 +00008171
Douglas Gregord6ff3322009-08-04 16:50:30 +00008172template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008173QualType
8174TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008175 ArrayType::ArraySizeModifier SizeMod,
8176 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00008177 unsigned IndexTypeQuals,
8178 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008179 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008180 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008181}
8182
8183template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008184QualType
Mike Stump11289f42009-09-09 15:08:12 +00008185TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008186 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00008187 unsigned IndexTypeQuals,
8188 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008189 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008190 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008191}
Mike Stump11289f42009-09-09 15:08:12 +00008192
Douglas Gregord6ff3322009-08-04 16:50:30 +00008193template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008194QualType
8195TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008196 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008197 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008198 unsigned IndexTypeQuals,
8199 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008200 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008201 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008202 IndexTypeQuals, BracketsRange);
8203}
8204
8205template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008206QualType
8207TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008208 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008209 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008210 unsigned IndexTypeQuals,
8211 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008212 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008213 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008214 IndexTypeQuals, BracketsRange);
8215}
8216
8217template<typename Derived>
8218QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00008219 unsigned NumElements,
8220 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00008221 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00008222 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008223}
Mike Stump11289f42009-09-09 15:08:12 +00008224
Douglas Gregord6ff3322009-08-04 16:50:30 +00008225template<typename Derived>
8226QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8227 unsigned NumElements,
8228 SourceLocation AttributeLoc) {
8229 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8230 NumElements, true);
8231 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008232 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8233 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00008234 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008235}
Mike Stump11289f42009-09-09 15:08:12 +00008236
Douglas Gregord6ff3322009-08-04 16:50:30 +00008237template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008238QualType
8239TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00008240 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008241 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00008242 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008243}
Mike Stump11289f42009-09-09 15:08:12 +00008244
Douglas Gregord6ff3322009-08-04 16:50:30 +00008245template<typename Derived>
8246QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00008247 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008248 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00008249 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00008250 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008251 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00008252 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00008253 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008254 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008255 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008256 getDerived().getBaseEntity(),
8257 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008258}
Mike Stump11289f42009-09-09 15:08:12 +00008259
Douglas Gregord6ff3322009-08-04 16:50:30 +00008260template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008261QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8262 return SemaRef.Context.getFunctionNoProtoType(T);
8263}
8264
8265template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008266QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8267 assert(D && "no decl found");
8268 if (D->isInvalidDecl()) return QualType();
8269
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008270 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008271 TypeDecl *Ty;
8272 if (isa<UsingDecl>(D)) {
8273 UsingDecl *Using = cast<UsingDecl>(D);
8274 assert(Using->isTypeName() &&
8275 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8276
8277 // A valid resolved using typename decl points to exactly one type decl.
8278 assert(++Using->shadow_begin() == Using->shadow_end());
8279 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008280
John McCallb96ec562009-12-04 22:46:56 +00008281 } else {
8282 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8283 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8284 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8285 }
8286
8287 return SemaRef.Context.getTypeDeclType(Ty);
8288}
8289
8290template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008291QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8292 SourceLocation Loc) {
8293 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008294}
8295
8296template<typename Derived>
8297QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8298 return SemaRef.Context.getTypeOfType(Underlying);
8299}
8300
8301template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008302QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8303 SourceLocation Loc) {
8304 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008305}
8306
8307template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00008308QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8309 UnaryTransformType::UTTKind UKind,
8310 SourceLocation Loc) {
8311 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8312}
8313
8314template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00008315QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008316 TemplateName Template,
8317 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008318 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008319 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008320}
Mike Stump11289f42009-09-09 15:08:12 +00008321
Douglas Gregor1135c352009-08-06 05:28:30 +00008322template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00008323QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8324 SourceLocation KWLoc) {
8325 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8326}
8327
8328template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008329TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008330TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008331 bool TemplateKW,
8332 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008333 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008334 Template);
8335}
8336
8337template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008338TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008339TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8340 const IdentifierInfo &Name,
8341 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008342 QualType ObjectType,
8343 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008344 UnqualifiedId TemplateName;
8345 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008346 Sema::TemplateTy Template;
8347 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008348 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008349 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008350 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008351 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008352 /*EnteringContext=*/false,
8353 Template);
John McCall31f82722010-11-12 08:19:04 +00008354 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008355}
Mike Stump11289f42009-09-09 15:08:12 +00008356
Douglas Gregora16548e2009-08-11 05:31:07 +00008357template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008358TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008359TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008360 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008361 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008362 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008363 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008364 // FIXME: Bogus location information.
8365 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8366 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008367 Sema::TemplateTy Template;
8368 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008369 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008370 SS,
8371 Name,
John McCallba7bf592010-08-24 05:47:05 +00008372 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008373 /*EnteringContext=*/false,
8374 Template);
8375 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008376}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008377
Douglas Gregor71395fa2009-11-04 00:56:37 +00008378template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008379ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008380TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8381 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008382 Expr *OrigCallee,
8383 Expr *First,
8384 Expr *Second) {
8385 Expr *Callee = OrigCallee->IgnoreParenCasts();
8386 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008387
Douglas Gregora16548e2009-08-11 05:31:07 +00008388 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008389 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008390 if (!First->getType()->isOverloadableType() &&
8391 !Second->getType()->isOverloadableType())
8392 return getSema().CreateBuiltinArraySubscriptExpr(First,
8393 Callee->getLocStart(),
8394 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008395 } else if (Op == OO_Arrow) {
8396 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008397 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8398 } else if (Second == 0 || isPostIncDec) {
8399 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008400 // The argument is not of overloadable type, so try to create a
8401 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008402 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008403 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008404
John McCallb268a282010-08-23 23:25:46 +00008405 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008406 }
8407 } else {
John McCallb268a282010-08-23 23:25:46 +00008408 if (!First->getType()->isOverloadableType() &&
8409 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008410 // Neither of the arguments is an overloadable type, so try to
8411 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008412 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008413 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008414 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008415 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008416 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008417
Douglas Gregora16548e2009-08-11 05:31:07 +00008418 return move(Result);
8419 }
8420 }
Mike Stump11289f42009-09-09 15:08:12 +00008421
8422 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008423 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008424 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008425
John McCallb268a282010-08-23 23:25:46 +00008426 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008427 assert(ULE->requiresADL());
8428
8429 // FIXME: Do we have to check
8430 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008431 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008432 } else {
John McCallb268a282010-08-23 23:25:46 +00008433 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008434 }
Mike Stump11289f42009-09-09 15:08:12 +00008435
Douglas Gregora16548e2009-08-11 05:31:07 +00008436 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008437 Expr *Args[2] = { First, Second };
8438 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008439
Douglas Gregora16548e2009-08-11 05:31:07 +00008440 // Create the overloaded operator invocation for unary operators.
8441 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008442 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008443 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008444 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008445 }
Mike Stump11289f42009-09-09 15:08:12 +00008446
Douglas Gregore9d62932011-07-15 16:25:15 +00008447 if (Op == OO_Subscript) {
8448 SourceLocation LBrace;
8449 SourceLocation RBrace;
8450
8451 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8452 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8453 LBrace = SourceLocation::getFromRawEncoding(
8454 NameLoc.CXXOperatorName.BeginOpNameLoc);
8455 RBrace = SourceLocation::getFromRawEncoding(
8456 NameLoc.CXXOperatorName.EndOpNameLoc);
8457 } else {
8458 LBrace = Callee->getLocStart();
8459 RBrace = OpLoc;
8460 }
8461
8462 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8463 First, Second);
8464 }
Sebastian Redladba46e2009-10-29 20:17:01 +00008465
Douglas Gregora16548e2009-08-11 05:31:07 +00008466 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008467 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008468 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008469 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8470 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008471 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008472
Mike Stump11289f42009-09-09 15:08:12 +00008473 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008474}
Mike Stump11289f42009-09-09 15:08:12 +00008475
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008477ExprResult
John McCallb268a282010-08-23 23:25:46 +00008478TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008479 SourceLocation OperatorLoc,
8480 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008481 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008482 TypeSourceInfo *ScopeType,
8483 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008484 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008485 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008486 QualType BaseType = Base->getType();
8487 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008488 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008489 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008490 !BaseType->getAs<PointerType>()->getPointeeType()
8491 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008492 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008493 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008494 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008495 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008496 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008497 /*FIXME?*/true);
8498 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008499
Douglas Gregor678f90d2010-02-25 01:56:36 +00008500 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008501 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8502 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8503 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8504 NameInfo.setNamedTypeInfo(DestroyedType);
8505
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008506 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008507
John McCallb268a282010-08-23 23:25:46 +00008508 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008509 OperatorLoc, isArrow,
8510 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008511 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008512 /*TemplateArgs*/ 0);
8513}
8514
Douglas Gregord6ff3322009-08-04 16:50:30 +00008515} // end namespace clang
8516
8517#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H