blob: 040ba9ee12a65bde9551e3a6797a6e01393ff5bd [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000034#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000035#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000036#include <algorithm>
37
38namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000039using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000040
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// \brief A semantic tree transformation that allows one to transform one
42/// abstract syntax tree into another.
43///
Mike Stump11289f42009-09-09 15:08:12 +000044/// A new tree transformation is defined by creating a new subclass \c X of
45/// \c TreeTransform<X> and then overriding certain operations to provide
46/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000047/// instantiation is implemented as a tree transformation where the
48/// transformation of TemplateTypeParmType nodes involves substituting the
49/// template arguments for their corresponding template parameters; a similar
50/// transformation is performed for non-type template parameters and
51/// template template parameters.
52///
53/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000054/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000055/// override any of the transformation or rebuild operators by providing an
56/// operation with the same signature as the default implementation. The
57/// overridding function should not be virtual.
58///
59/// Semantic tree transformations are split into two stages, either of which
60/// can be replaced by a subclass. The "transform" step transforms an AST node
61/// or the parts of an AST node using the various transformation functions,
62/// then passes the pieces on to the "rebuild" step, which constructs a new AST
63/// node of the appropriate kind from the pieces. The default transformation
64/// routines recursively transform the operands to composite AST nodes (e.g.,
65/// the pointee type of a PointerType node) and, if any of those operand nodes
66/// were changed by the transformation, invokes the rebuild operation to create
67/// a new AST node.
68///
Mike Stump11289f42009-09-09 15:08:12 +000069/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000070/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000071/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// TransformTemplateName(), or TransformTemplateArgument() with entirely
73/// new implementations.
74///
75/// For more fine-grained transformations, subclasses can replace any of the
76/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000077/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000078/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000079/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// parameters. Additionally, subclasses can override the \c RebuildXXX
81/// functions to control how AST nodes are rebuilt when their operands change.
82/// By default, \c TreeTransform will invoke semantic analysis to rebuild
83/// AST nodes. However, certain other tree transformations (e.g, cloning) may
84/// be able to use more efficient rebuild steps.
85///
86/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000087/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000088/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
89/// operands have not changed (\c AlwaysRebuild()), and customize the
90/// default locations and entity names used for type-checking
91/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000092template<typename Derived>
93class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000094 /// \brief Private RAII object that helps us forget and then re-remember
95 /// the template argument corresponding to a partially-substituted parameter
96 /// pack.
97 class ForgetPartiallySubstitutedPackRAII {
98 Derived &Self;
99 TemplateArgument Old;
100
101 public:
102 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
103 Old = Self.ForgetPartiallySubstitutedPack();
104 }
105
106 ~ForgetPartiallySubstitutedPackRAII() {
107 Self.RememberPartiallySubstitutedPack(Old);
108 }
109 };
110
Douglas Gregord6ff3322009-08-04 16:50:30 +0000111protected:
112 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000113
Mike Stump11289f42009-09-09 15:08:12 +0000114public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000116 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000117
Douglas Gregord6ff3322009-08-04 16:50:30 +0000118 /// \brief Retrieves a reference to the derived class.
119 Derived &getDerived() { return static_cast<Derived&>(*this); }
120
121 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000122 const Derived &getDerived() const {
123 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 }
125
John McCalldadc5752010-08-24 06:29:42 +0000126 static inline ExprResult Owned(Expr *E) { return E; }
127 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000128
Douglas Gregord6ff3322009-08-04 16:50:30 +0000129 /// \brief Retrieves a reference to the semantic analysis object used for
130 /// this tree transform.
131 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000132
Douglas Gregord6ff3322009-08-04 16:50:30 +0000133 /// \brief Whether the transformation should always rebuild AST nodes, even
134 /// if none of the children have changed.
135 ///
136 /// Subclasses may override this function to specify when the transformation
137 /// should rebuild all AST nodes.
138 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Returns the location of the entity being transformed, if that
141 /// information was not available elsewhere in the AST.
142 ///
Mike Stump11289f42009-09-09 15:08:12 +0000143 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000144 /// provide an alternative implementation that provides better location
145 /// information.
146 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000147
Douglas Gregord6ff3322009-08-04 16:50:30 +0000148 /// \brief Returns the name of the entity being transformed, if that
149 /// information was not available elsewhere in the AST.
150 ///
151 /// By default, returns an empty name. Subclasses can provide an alternative
152 /// implementation with a more precise name.
153 DeclarationName getBaseEntity() { return DeclarationName(); }
154
Douglas Gregora16548e2009-08-11 05:31:07 +0000155 /// \brief Sets the "base" location and entity when that
156 /// information is known based on another transformation.
157 ///
158 /// By default, the source location and entity are ignored. Subclasses can
159 /// override this function to provide a customized implementation.
160 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000161
Douglas Gregora16548e2009-08-11 05:31:07 +0000162 /// \brief RAII object that temporarily sets the base location and entity
163 /// used for reporting diagnostics in types.
164 class TemporaryBase {
165 TreeTransform &Self;
166 SourceLocation OldLocation;
167 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000168
Douglas Gregora16548e2009-08-11 05:31:07 +0000169 public:
170 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000171 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 OldLocation = Self.getDerived().getBaseLocation();
173 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000174
175 if (Location.isValid())
176 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000177 }
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 ~TemporaryBase() {
180 Self.getDerived().setBase(OldLocation, OldEntity);
181 }
182 };
Mike Stump11289f42009-09-09 15:08:12 +0000183
184 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// transformed.
186 ///
187 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000188 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000189 /// not change. For example, template instantiation need not traverse
190 /// non-dependent types.
191 bool AlreadyTransformed(QualType T) {
192 return T.isNull();
193 }
194
Douglas Gregord196a582009-12-14 19:27:10 +0000195 /// \brief Determine whether the given call argument should be dropped, e.g.,
196 /// because it is a default argument.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine to
199 /// determine which kinds of call arguments get dropped. By default,
200 /// CXXDefaultArgument nodes are dropped (prior to transformation).
201 bool DropCallArgument(Expr *E) {
202 return E->isDefaultArgument();
203 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000204
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000205 /// \brief Determine whether we should expand a pack expansion with the
206 /// given set of parameter packs into separate arguments by repeatedly
207 /// transforming the pattern.
208 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000209 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000210 /// Subclasses can override this routine to provide different behavior.
211 ///
212 /// \param EllipsisLoc The location of the ellipsis that identifies the
213 /// pack expansion.
214 ///
215 /// \param PatternRange The source range that covers the entire pattern of
216 /// the pack expansion.
217 ///
218 /// \param Unexpanded The set of unexpanded parameter packs within the
219 /// pattern.
220 ///
221 /// \param NumUnexpanded The number of unexpanded parameter packs in
222 /// \p Unexpanded.
223 ///
224 /// \param ShouldExpand Will be set to \c true if the transformer should
225 /// expand the corresponding pack expansions into separate arguments. When
226 /// set, \c NumExpansions must also be set.
227 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000228 /// \param RetainExpansion Whether the caller should add an unexpanded
229 /// pack expansion after all of the expanded arguments. This is used
230 /// when extending explicitly-specified template argument packs per
231 /// C++0x [temp.arg.explicit]p9.
232 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000233 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000234 /// the expanded form of the corresponding pack expansion. This is both an
235 /// input and an output parameter, which can be set by the caller if the
236 /// number of expansions is known a priori (e.g., due to a prior substitution)
237 /// and will be set by the callee when the number of expansions is known.
238 /// The callee must set this value when \c ShouldExpand is \c true; it may
239 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 ///
241 /// \returns true if an error occurred (e.g., because the parameter packs
242 /// are to be instantiated with arguments of different lengths), false
243 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
244 /// must be set.
245 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
246 SourceRange PatternRange,
247 const UnexpandedParameterPack *Unexpanded,
248 unsigned NumUnexpanded,
249 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 /// \brief "Forget" about the partially-substituted pack template argument,
257 /// when performing an instantiation that must preserve the parameter pack
258 /// use.
259 ///
260 /// This routine is meant to be overridden by the template instantiator.
261 TemplateArgument ForgetPartiallySubstitutedPack() {
262 return TemplateArgument();
263 }
264
265 /// \brief "Remember" the partially-substituted pack template argument
266 /// after performing an instantiation that must preserve the parameter pack
267 /// use.
268 ///
269 /// This routine is meant to be overridden by the template instantiator.
270 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271
Douglas Gregorf3010112011-01-07 16:43:16 +0000272 /// \brief Note to the derived class when a function parameter pack is
273 /// being expanded.
274 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
275
Douglas Gregord6ff3322009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCall550e0c22009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000280 /// function. This is expensive, but we don't mind, because
281 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000286
John McCall550e0c22009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
John McCall550e0c22009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by delegating to the
291 /// appropriate TransformXXXType to build a new type. Subclasses
292 /// may override this function (to take over all type
293 /// transformations) or some set of the TransformXXXType functions
294 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000296
297 /// \brief Transform the given type-with-location into a new
298 /// type, collecting location information in the given builder
299 /// as necessary.
300 ///
John McCall31f82722010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000302
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000304 ///
Mike Stump11289f42009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000306 /// appropriate TransformXXXStmt function to transform a specific kind of
307 /// statement or the TransformExpr() function to transform an expression.
308 /// Subclasses may override this function to transform statements using some
309 /// other mechanism.
310 ///
311 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000313
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000316 /// By default, this routine transforms an expression by delegating to the
317 /// appropriate TransformXXXExpr function to build a new expression.
318 /// Subclasses may override this function to transform expressions using some
319 /// other mechanism.
320 ///
321 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000323
Douglas Gregora3efea12011-01-03 19:04:46 +0000324 /// \brief Transform the given list of expressions.
325 ///
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
331 ///
332 /// \param Inputs The set of expressions to be transformed.
333 ///
334 /// \param NumInputs The number of expressions in \c Inputs.
335 ///
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
338 /// be.
339 ///
340 /// \param Outputs The transformed input expressions will be added to this
341 /// vector.
342 ///
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
345 ///
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
348 llvm::SmallVectorImpl<Expr *> &Outputs,
349 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,
John McCall58f10c32010-03-11 09:03:00 +0000523 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000524 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000534
John McCall31f82722010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000536
John McCalldadc5752010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000539
Douglas Gregorebe10102009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000546
Douglas Gregord6ff3322009-08-04 16:50:30 +0000547 /// \brief Build a new pointer type given its pointee type.
548 ///
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump11289f42009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558
John McCall70dd5f62009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 ///
John McCall70dd5f62009-10-30 00:06:24 +0000561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000564 ///
John McCall70dd5f62009-10-30 00:06:24 +0000565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
568 bool LValue,
569 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000570
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
573 ///
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000578
Douglas Gregord6ff3322009-08-04 16:50:30 +0000579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
581 /// qualifiers.
582 ///
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
589 Expr *SizeExpr,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000592
Douglas Gregord6ff3322009-08-04 16:50:30 +0000593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000603
Douglas Gregord6ff3322009-08-04 16:50:30 +0000604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000613
Mike Stump11289f42009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump11289f42009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626 /// size modifier, size expression, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
635
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000643
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000653 /// given the element type and number of elements.
654 ///
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new function type.
662 ///
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000671
John McCall550e0c22009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCallb96ec562009-12-04 22:46:56 +0000675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
678
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681 return SemaRef.Context.getTypeDeclType(Typedef);
682 }
683
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
687 }
688
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
692 }
John McCallfcc33b02009-09-05 00:15:47 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000699
Mike Stump11289f42009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Alexis Hunte852b102011-05-24 22:41:36 +0000705 /// \brief Build a new unary transform type.
706 QualType RebuildUnaryTransformType(QualType BaseType,
707 UnaryTransformType::UTTKind UKind,
708 SourceLocation Loc);
709
Mike Stump11289f42009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 ///
712 /// By default, performs semantic analysis when building the decltype type.
713 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000715
Richard Smith30482bc2011-02-20 03:19:35 +0000716 /// \brief Build a new C++0x auto type.
717 ///
718 /// By default, builds a new AutoType with the given deduced type.
719 QualType RebuildAutoType(QualType Deduced) {
720 return SemaRef.Context.getAutoType(Deduced);
721 }
722
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// \brief Build a new template specialization type.
724 ///
725 /// By default, performs semantic analysis when building the template
726 /// specialization type. Subclasses may override this routine to provide
727 /// different behavior.
728 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000731
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000732 /// \brief Build a new parenthesized type.
733 ///
734 /// By default, builds a new ParenType type from the inner type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildParenType(QualType InnerType) {
737 return SemaRef.Context.getParenType(InnerType);
738 }
739
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000742 /// By default, builds a new ElaboratedType type from the keyword,
743 /// the nested-name-specifier and the named type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000752 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000756 /// By default, builds a new DependentNameType type from the
757 /// nested-name-specifier and the given type. Subclasses may override
758 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000771
772 if (InstName.isNull())
773 return QualType();
774
775 // If it's still dependent, make a dependent specialization.
776 if (InstName.getAsDependentTemplateName())
777 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
779 Name,
780 Args);
781
782 // Otherwise, make an elaborated type wrapping a non-dependent
783 // specialization.
784 QualType T =
785 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
786 if (T.isNull()) return QualType();
787
788 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
789 return T;
790
791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
793 T);
794 }
795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new typename type that refers to an identifier.
797 ///
798 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000808
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000810 // If the name is still dependent, just build a new dependent name type.
811 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara6150c882010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarad7548482010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCallbf8c5192010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregore677daf2010-03-31 22:19:08 +0000834 TagDecl *Tag = 0;
835 SemaRef.LookupQualifiedName(Result, DC);
836 switch (Result.getResultKind()) {
837 case LookupResult::NotFound:
838 case LookupResult::NotFoundInCurrentInstantiation:
839 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000840
Douglas Gregore677daf2010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000844
Douglas Gregore677daf2010-03-31 22:19:08 +0000845 case LookupResult::FoundOverloaded:
846 case LookupResult::FoundUnresolvedValue:
847 llvm_unreachable("Tag lookup cannot find non-tags");
848 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000849
Douglas Gregore677daf2010-03-31 22:19:08 +0000850 case LookupResult::Ambiguous:
851 // Let the LookupResult structure handle ambiguities.
852 return QualType();
853 }
854
855 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000856 // Check where the name exists but isn't a tag type and use that to emit
857 // better diagnostics.
858 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859 SemaRef.LookupQualifiedName(Result, DC);
860 switch (Result.getResultKind()) {
861 case LookupResult::Found:
862 case LookupResult::FoundOverloaded:
863 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000872 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000873 default:
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876 << Kind << Id << DC;
877 break;
878 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000881
Richard Trieucaa33d32011-06-10 03:11:26 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000885 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
886 return QualType();
887 }
888
889 // Build the elaborated-type-specifier type.
890 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
893 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000894 }
Mike Stump11289f42009-09-09 15:08:12 +0000895
Douglas Gregor822d0302011-01-12 17:07:58 +0000896 /// \brief Build a new pack expansion type.
897 ///
898 /// By default, builds a new PackExpansionType type from the given pattern.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildPackExpansionType(QualType Pattern,
901 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000906 }
907
Douglas Gregor71dc5092009-08-06 06:41:21 +0000908 /// \brief Build a new template name given a nested name specifier, a flag
909 /// indicating whether the "template" keyword was provided, and the template
910 /// that the template name refers to.
911 ///
912 /// By default, builds the new template name directly. Subclasses may override
913 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000914 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000915 bool TemplateKW,
916 TemplateDecl *Template);
917
Douglas Gregor71dc5092009-08-06 06:41:21 +0000918 /// \brief Build a new template name given a nested name specifier and the
919 /// name that is referred to as a template.
920 ///
921 /// By default, performs semantic analysis to determine whether the name can
922 /// be resolved to a specific template, then builds the appropriate kind of
923 /// template name. Subclasses may override this routine to provide different
924 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000925 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
926 const IdentifierInfo &Name,
927 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000928 QualType ObjectType,
929 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000930
Douglas Gregor71395fa2009-11-04 00:56:37 +0000931 /// \brief Build a new template name given a nested name specifier and the
932 /// overloaded operator name that is referred to as a template.
933 ///
934 /// By default, performs semantic analysis to determine whether the name can
935 /// be resolved to a specific template, then builds the appropriate kind of
936 /// template name. Subclasses may override this routine to provide different
937 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000938 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000939 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000940 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000941 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000942
943 /// \brief Build a new template name given a template template parameter pack
944 /// and the
945 ///
946 /// By default, performs semantic analysis to determine whether the name can
947 /// be resolved to a specific template, then builds the appropriate kind of
948 /// template name. Subclasses may override this routine to provide different
949 /// behavior.
950 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
951 const TemplateArgument &ArgPack) {
952 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
953 }
954
Douglas Gregorebe10102009-08-20 07:17:43 +0000955 /// \brief Build a new compound statement.
956 ///
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000959 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000960 MultiStmtArg Statements,
961 SourceLocation RBraceLoc,
962 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000963 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000964 IsStmtExpr);
965 }
966
967 /// \brief Build a new case statement.
968 ///
969 /// By default, performs semantic analysis to build the new statement.
970 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000971 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000972 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000973 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000974 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000975 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000976 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000977 ColonLoc);
978 }
Mike Stump11289f42009-09-09 15:08:12 +0000979
Douglas Gregorebe10102009-08-20 07:17:43 +0000980 /// \brief Attach the body to a new case statement.
981 ///
982 /// By default, performs semantic analysis to build the new statement.
983 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000984 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000985 getSema().ActOnCaseStmtBody(S, Body);
986 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 }
Mike Stump11289f42009-09-09 15:08:12 +0000988
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 /// \brief Build a new default statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000993 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000994 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000995 Stmt *SubStmt) {
996 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000997 /*CurScope=*/0);
998 }
Mike Stump11289f42009-09-09 15:08:12 +0000999
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 /// \brief Build a new label statement.
1001 ///
1002 /// By default, performs semantic analysis to build the new statement.
1003 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001004 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1005 SourceLocation ColonLoc, Stmt *SubStmt) {
1006 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001007 }
Mike Stump11289f42009-09-09 15:08:12 +00001008
Douglas Gregorebe10102009-08-20 07:17:43 +00001009 /// \brief Build a new "if" statement.
1010 ///
1011 /// By default, performs semantic analysis to build the new statement.
1012 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001013 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001014 VarDecl *CondVar, Stmt *Then,
1015 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001016 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001017 }
Mike Stump11289f42009-09-09 15:08:12 +00001018
Douglas Gregorebe10102009-08-20 07:17:43 +00001019 /// \brief Start building a new switch statement.
1020 ///
1021 /// By default, performs semantic analysis to build the new statement.
1022 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001023 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001024 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001025 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001026 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001027 }
Mike Stump11289f42009-09-09 15:08:12 +00001028
Douglas Gregorebe10102009-08-20 07:17:43 +00001029 /// \brief Attach the body to the switch statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001033 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001034 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001035 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001036 }
1037
1038 /// \brief Build a new while statement.
1039 ///
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001042 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1043 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001044 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001045 }
Mike Stump11289f42009-09-09 15:08:12 +00001046
Douglas Gregorebe10102009-08-20 07:17:43 +00001047 /// \brief Build a new do-while statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001051 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001052 SourceLocation WhileLoc, SourceLocation LParenLoc,
1053 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001054 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1055 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001056 }
1057
1058 /// \brief Build a new for statement.
1059 ///
1060 /// By default, performs semantic analysis to build the new statement.
1061 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001062 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1063 Stmt *Init, Sema::FullExprArg Cond,
1064 VarDecl *CondVar, Sema::FullExprArg Inc,
1065 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001066 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001067 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 }
Mike Stump11289f42009-09-09 15:08:12 +00001069
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 /// \brief Build a new goto statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001074 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1075 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001076 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001077 }
1078
1079 /// \brief Build a new indirect goto statement.
1080 ///
1081 /// By default, performs semantic analysis to build the new statement.
1082 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001083 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001084 SourceLocation StarLoc,
1085 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001086 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 }
Mike Stump11289f42009-09-09 15:08:12 +00001088
Douglas Gregorebe10102009-08-20 07:17:43 +00001089 /// \brief Build a new return statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001093 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001094 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 }
Mike Stump11289f42009-09-09 15:08:12 +00001096
Douglas Gregorebe10102009-08-20 07:17:43 +00001097 /// \brief Build a new declaration statement.
1098 ///
1099 /// By default, performs semantic analysis to build the new statement.
1100 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001101 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001102 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001103 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001104 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1105 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001106 }
Mike Stump11289f42009-09-09 15:08:12 +00001107
Anders Carlssonaaeef072010-01-24 05:50:09 +00001108 /// \brief Build a new inline asm statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001112 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001113 bool IsSimple,
1114 bool IsVolatile,
1115 unsigned NumOutputs,
1116 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001117 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001118 MultiExprArg Constraints,
1119 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001120 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001121 MultiExprArg Clobbers,
1122 SourceLocation RParenLoc,
1123 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001124 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001125 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001126 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001127 RParenLoc, MSAsm);
1128 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001129
1130 /// \brief Build a new Objective-C @try statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001134 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001135 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001136 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001137 Stmt *Finally) {
1138 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1139 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001140 }
1141
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001142 /// \brief Rebuild an Objective-C exception declaration.
1143 ///
1144 /// By default, performs semantic analysis to build the new declaration.
1145 /// Subclasses may override this routine to provide different behavior.
1146 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1147 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001148 return getSema().BuildObjCExceptionDecl(TInfo, T,
1149 ExceptionDecl->getInnerLocStart(),
1150 ExceptionDecl->getLocation(),
1151 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001152 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001153
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001154 /// \brief Build a new Objective-C @catch statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001158 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001159 SourceLocation RParenLoc,
1160 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001161 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001162 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001163 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001164 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001165
Douglas Gregor306de2f2010-04-22 23:59:56 +00001166 /// \brief Build a new Objective-C @finally statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001170 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001171 Stmt *Body) {
1172 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001173 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001174
Douglas Gregor6148de72010-04-22 22:01:21 +00001175 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001180 Expr *Operand) {
1181 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001182 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001183
Douglas Gregor6148de72010-04-22 22:01:21 +00001184 /// \brief Build a new Objective-C @synchronized statement.
1185 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001186 /// By default, performs semantic analysis to build the new statement.
1187 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001188 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001189 Expr *Object,
1190 Stmt *Body) {
1191 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1192 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001193 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001194
John McCall31168b02011-06-15 23:02:42 +00001195 /// \brief Build a new Objective-C @autoreleasepool statement.
1196 ///
1197 /// By default, performs semantic analysis to build the new statement.
1198 /// Subclasses may override this routine to provide different behavior.
1199 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1200 Stmt *Body) {
1201 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1202 }
1203
1204
Douglas Gregorf68a5082010-04-22 23:10:45 +00001205 /// \brief Build a new Objective-C fast enumeration statement.
1206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001209 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001210 SourceLocation LParenLoc,
1211 Stmt *Element,
1212 Expr *Collection,
1213 SourceLocation RParenLoc,
1214 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001215 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001216 Element,
1217 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001218 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001219 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001220 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001221
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 /// \brief Build a new C++ exception declaration.
1223 ///
1224 /// By default, performs semantic analysis to build the new decaration.
1225 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001226 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001227 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001228 SourceLocation StartLoc,
1229 SourceLocation IdLoc,
1230 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001231 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1232 StartLoc, IdLoc, Id);
1233 if (Var)
1234 getSema().CurContext->addDecl(Var);
1235 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001236 }
1237
1238 /// \brief Build a new C++ catch statement.
1239 ///
1240 /// By default, performs semantic analysis to build the new statement.
1241 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001242 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001243 VarDecl *ExceptionDecl,
1244 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001245 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1246 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001247 }
Mike Stump11289f42009-09-09 15:08:12 +00001248
Douglas Gregorebe10102009-08-20 07:17:43 +00001249 /// \brief Build a new C++ try statement.
1250 ///
1251 /// By default, performs semantic analysis to build the new statement.
1252 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001253 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001254 Stmt *TryBlock,
1255 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001256 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Richard Smith02e85f32011-04-14 22:09:26 +00001259 /// \brief Build a new C++0x range-based for statement.
1260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
1263 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1264 SourceLocation ColonLoc,
1265 Stmt *Range, Stmt *BeginEnd,
1266 Expr *Cond, Expr *Inc,
1267 Stmt *LoopVar,
1268 SourceLocation RParenLoc) {
1269 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1270 Cond, Inc, LoopVar, RParenLoc);
1271 }
1272
1273 /// \brief Attach body to a C++0x range-based for statement.
1274 ///
1275 /// By default, performs semantic analysis to finish the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
1277 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1278 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1279 }
1280
John Wiegley1c0675e2011-04-28 01:08:34 +00001281 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1282 SourceLocation TryLoc,
1283 Stmt *TryBlock,
1284 Stmt *Handler) {
1285 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1286 }
1287
1288 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1289 Expr *FilterExpr,
1290 Stmt *Block) {
1291 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1292 }
1293
1294 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1295 Stmt *Block) {
1296 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1297 }
1298
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 /// \brief Build a new expression that references a declaration.
1300 ///
1301 /// By default, performs semantic analysis to build the new expression.
1302 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001303 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001304 LookupResult &R,
1305 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001306 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1307 }
1308
1309
1310 /// \brief Build a new expression that references a declaration.
1311 ///
1312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001314 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001315 ValueDecl *VD,
1316 const DeclarationNameInfo &NameInfo,
1317 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001318 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001319 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001320
1321 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001322
1323 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 }
Mike Stump11289f42009-09-09 15:08:12 +00001325
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001327 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 /// By default, performs semantic analysis to build the new expression.
1329 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001330 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001332 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 }
1334
Douglas Gregorad8a3362009-09-04 17:36:40 +00001335 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001336 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001337 /// By default, performs semantic analysis to build the new expression.
1338 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001339 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001340 SourceLocation OperatorLoc,
1341 bool isArrow,
1342 CXXScopeSpec &SS,
1343 TypeSourceInfo *ScopeType,
1344 SourceLocation CCLoc,
1345 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001346 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001347
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 /// \brief Build a new unary operator expression.
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 RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001353 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001354 Expr *SubExpr) {
1355 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001356 }
Mike Stump11289f42009-09-09 15:08:12 +00001357
Douglas Gregor882211c2010-04-28 22:16:22 +00001358 /// \brief Build a new builtin offsetof expression.
1359 ///
1360 /// By default, performs semantic analysis to build the new expression.
1361 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001362 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001363 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001364 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001365 unsigned NumComponents,
1366 SourceLocation RParenLoc) {
1367 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1368 NumComponents, RParenLoc);
1369 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001370
Peter Collingbournee190dee2011-03-11 19:24:49 +00001371 /// \brief Build a new sizeof, alignof or vec_step expression with a
1372 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001373 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 /// By default, performs semantic analysis to build the new expression.
1375 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001376 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1377 SourceLocation OpLoc,
1378 UnaryExprOrTypeTrait ExprKind,
1379 SourceRange R) {
1380 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001381 }
1382
Peter Collingbournee190dee2011-03-11 19:24:49 +00001383 /// \brief Build a new sizeof, alignof or vec step expression with an
1384 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001385 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 /// By default, performs semantic analysis to build the new expression.
1387 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001388 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1389 UnaryExprOrTypeTrait ExprKind,
1390 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001391 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001392 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001394 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001395
Douglas Gregora16548e2009-08-11 05:31:07 +00001396 return move(Result);
1397 }
Mike Stump11289f42009-09-09 15:08:12 +00001398
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001400 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 /// By default, performs semantic analysis to build the new expression.
1402 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001403 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001405 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001407 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1408 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 RBracketLoc);
1410 }
1411
1412 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001413 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001416 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001418 SourceLocation RParenLoc,
1419 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001420 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001421 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 }
1423
1424 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001425 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001428 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001429 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001430 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001431 const DeclarationNameInfo &MemberNameInfo,
1432 ValueDecl *Member,
1433 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001434 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001435 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001436 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001437 // We have a reference to an unnamed field. This is always the
1438 // base of an anonymous struct/union member access, i.e. the
1439 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001440 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001441 assert(Member->getType()->isRecordType() &&
1442 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001443
John Wiegley01296292011-04-08 18:41:53 +00001444 ExprResult BaseResult =
1445 getSema().PerformObjectMemberConversion(Base,
1446 QualifierLoc.getNestedNameSpecifier(),
1447 FoundDecl, Member);
1448 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001449 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001450 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001451 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001452 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001453 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001454 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001455 cast<FieldDecl>(Member)->getType(),
1456 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001457 return getSema().Owned(ME);
1458 }
Mike Stump11289f42009-09-09 15:08:12 +00001459
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001460 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001461 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001462
John Wiegley01296292011-04-08 18:41:53 +00001463 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1464 if (BaseResult.isInvalid())
1465 return ExprError();
1466 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001467 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001468
John McCall16df1e52010-03-30 21:47:33 +00001469 // FIXME: this involves duplicating earlier analysis in a lot of
1470 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001471 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001472 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001473 R.resolveKind();
1474
John McCallb268a282010-08-23 23:25:46 +00001475 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001476 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001477 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 }
Mike Stump11289f42009-09-09 15:08:12 +00001479
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001481 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001484 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001485 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001486 Expr *LHS, Expr *RHS) {
1487 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001488 }
1489
1490 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001491 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 /// By default, performs semantic analysis to build the new expression.
1493 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001494 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001495 SourceLocation QuestionLoc,
1496 Expr *LHS,
1497 SourceLocation ColonLoc,
1498 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001499 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1500 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 }
1502
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001504 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001507 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001508 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001510 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001511 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001512 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 }
Mike Stump11289f42009-09-09 15:08:12 +00001514
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001516 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001519 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001520 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001522 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001523 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001524 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 }
Mike Stump11289f42009-09-09 15:08:12 +00001526
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001528 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 /// By default, performs semantic analysis to build the new expression.
1530 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001531 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 SourceLocation OpLoc,
1533 SourceLocation AccessorLoc,
1534 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001535
John McCall10eae182009-11-30 22:42:35 +00001536 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001537 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001538 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001539 OpLoc, /*IsArrow*/ false,
1540 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001541 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001542 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 }
Mike Stump11289f42009-09-09 15:08:12 +00001544
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001546 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001549 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001550 MultiExprArg Inits,
1551 SourceLocation RBraceLoc,
1552 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001553 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001554 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1555 if (Result.isInvalid() || ResultTy->isDependentType())
1556 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001557
Douglas Gregord3d93062009-11-09 17:16:50 +00001558 // Patch in the result type we were given, which may have been computed
1559 // when the initial InitListExpr was built.
1560 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1561 ILE->setType(ResultTy);
1562 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 }
Mike Stump11289f42009-09-09 15:08:12 +00001564
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001566 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 /// By default, performs semantic analysis to build the new expression.
1568 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001569 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 MultiExprArg ArrayExprs,
1571 SourceLocation EqualOrColonLoc,
1572 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001573 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001574 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001576 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001578 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001579
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 ArrayExprs.release();
1581 return move(Result);
1582 }
Mike Stump11289f42009-09-09 15:08:12 +00001583
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001585 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 /// By default, builds the implicit value initialization without performing
1587 /// any semantic analysis. Subclasses may override this routine to provide
1588 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001589 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1591 }
Mike Stump11289f42009-09-09 15:08:12 +00001592
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001594 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001597 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001598 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001599 SourceLocation RParenLoc) {
1600 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001601 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001602 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 }
1604
1605 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001606 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001609 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 MultiExprArg SubExprs,
1611 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001612 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001613 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 }
Mike Stump11289f42009-09-09 15:08:12 +00001615
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001617 ///
1618 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 /// rather than attempting to map the label statement itself.
1620 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001621 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001622 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001623 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 }
Mike Stump11289f42009-09-09 15:08:12 +00001625
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001627 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001630 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001631 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001633 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 }
Mike Stump11289f42009-09-09 15:08:12 +00001635
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 /// \brief Build a new __builtin_choose_expr expression.
1637 ///
1638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001640 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001641 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 SourceLocation RParenLoc) {
1643 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001644 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 RParenLoc);
1646 }
Mike Stump11289f42009-09-09 15:08:12 +00001647
Peter Collingbourne91147592011-04-15 00:35:48 +00001648 /// \brief Build a new generic selection expression.
1649 ///
1650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
1652 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1653 SourceLocation DefaultLoc,
1654 SourceLocation RParenLoc,
1655 Expr *ControllingExpr,
1656 TypeSourceInfo **Types,
1657 Expr **Exprs,
1658 unsigned NumAssocs) {
1659 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1660 ControllingExpr, Types, Exprs,
1661 NumAssocs);
1662 }
1663
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 /// \brief Build a new overloaded operator call expression.
1665 ///
1666 /// By default, performs semantic analysis to build the new expression.
1667 /// The semantic analysis provides the behavior of template instantiation,
1668 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001669 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 /// argument-dependent lookup, etc. Subclasses may override this routine to
1671 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001672 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001674 Expr *Callee,
1675 Expr *First,
1676 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001677
1678 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 /// reinterpret_cast.
1680 ///
1681 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001682 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001684 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 Stmt::StmtClass Class,
1686 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001687 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 SourceLocation RAngleLoc,
1689 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001690 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 SourceLocation RParenLoc) {
1692 switch (Class) {
1693 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001694 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001695 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001696 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001697
1698 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001699 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001700 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001701 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001702
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001704 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001705 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001706 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001708
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001710 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001711 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001712 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001713
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 default:
1715 assert(false && "Invalid C++ named cast");
1716 break;
1717 }
Mike Stump11289f42009-09-09 15:08:12 +00001718
John McCallfaf5fb42010-08-26 23:41:50 +00001719 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 }
Mike Stump11289f42009-09-09 15:08:12 +00001721
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 /// \brief Build a new C++ static_cast expression.
1723 ///
1724 /// By default, performs semantic analysis to build the new expression.
1725 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001726 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001728 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 SourceLocation RAngleLoc,
1730 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001731 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001733 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001734 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001735 SourceRange(LAngleLoc, RAngleLoc),
1736 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 }
1738
1739 /// \brief Build a new C++ dynamic_cast expression.
1740 ///
1741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001743 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001745 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 SourceLocation RAngleLoc,
1747 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001748 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001750 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001751 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001752 SourceRange(LAngleLoc, RAngleLoc),
1753 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 }
1755
1756 /// \brief Build a new C++ reinterpret_cast expression.
1757 ///
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001760 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001762 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 SourceLocation RAngleLoc,
1764 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001765 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001767 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001768 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001769 SourceRange(LAngleLoc, RAngleLoc),
1770 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 }
1772
1773 /// \brief Build a new C++ const_cast expression.
1774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001777 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001779 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 SourceLocation RAngleLoc,
1781 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001782 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001784 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001785 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001786 SourceRange(LAngleLoc, RAngleLoc),
1787 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 }
Mike Stump11289f42009-09-09 15:08:12 +00001789
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 /// \brief Build a new C++ functional-style cast expression.
1791 ///
1792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001794 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1795 SourceLocation LParenLoc,
1796 Expr *Sub,
1797 SourceLocation RParenLoc) {
1798 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001799 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 RParenLoc);
1801 }
Mike Stump11289f42009-09-09 15:08:12 +00001802
Douglas Gregora16548e2009-08-11 05:31:07 +00001803 /// \brief Build a new C++ typeid(type) expression.
1804 ///
1805 /// By default, performs semantic analysis to build the new expression.
1806 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001807 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001808 SourceLocation TypeidLoc,
1809 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001811 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001812 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 }
Mike Stump11289f42009-09-09 15:08:12 +00001814
Francois Pichet9f4f2072010-09-08 12:20:18 +00001815
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 /// \brief Build a new C++ typeid(expr) expression.
1817 ///
1818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001820 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001821 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001822 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001824 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001825 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001826 }
1827
Francois Pichet9f4f2072010-09-08 12:20:18 +00001828 /// \brief Build a new C++ __uuidof(type) expression.
1829 ///
1830 /// By default, performs semantic analysis to build the new expression.
1831 /// Subclasses may override this routine to provide different behavior.
1832 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1833 SourceLocation TypeidLoc,
1834 TypeSourceInfo *Operand,
1835 SourceLocation RParenLoc) {
1836 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1837 RParenLoc);
1838 }
1839
1840 /// \brief Build a new C++ __uuidof(expr) expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
1844 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1845 SourceLocation TypeidLoc,
1846 Expr *Operand,
1847 SourceLocation RParenLoc) {
1848 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1849 RParenLoc);
1850 }
1851
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 /// \brief Build a new C++ "this" expression.
1853 ///
1854 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001855 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001856 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001857 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001858 QualType ThisType,
1859 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001860 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001861 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1862 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 }
1864
1865 /// \brief Build a new C++ throw expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001869 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1870 bool IsThrownVariableInScope) {
1871 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001872 }
1873
1874 /// \brief Build a new C++ default-argument expression.
1875 ///
1876 /// By default, builds a new default-argument expression, which does not
1877 /// require any semantic analysis. Subclasses may override this routine to
1878 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001879 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001880 ParmVarDecl *Param) {
1881 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1882 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 }
1884
1885 /// \brief Build a new C++ zero-initialization expression.
1886 ///
1887 /// By default, performs semantic analysis to build the new expression.
1888 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001889 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1890 SourceLocation LParenLoc,
1891 SourceLocation RParenLoc) {
1892 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001893 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001894 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 }
Mike Stump11289f42009-09-09 15:08:12 +00001896
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 /// \brief Build a new C++ "new" expression.
1898 ///
1899 /// By default, performs semantic analysis to build the new expression.
1900 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001901 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001902 bool UseGlobal,
1903 SourceLocation PlacementLParen,
1904 MultiExprArg PlacementArgs,
1905 SourceLocation PlacementRParen,
1906 SourceRange TypeIdParens,
1907 QualType AllocatedType,
1908 TypeSourceInfo *AllocatedTypeInfo,
1909 Expr *ArraySize,
1910 SourceLocation ConstructorLParen,
1911 MultiExprArg ConstructorArgs,
1912 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001913 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 PlacementLParen,
1915 move(PlacementArgs),
1916 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001917 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001918 AllocatedType,
1919 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001920 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 ConstructorLParen,
1922 move(ConstructorArgs),
1923 ConstructorRParen);
1924 }
Mike Stump11289f42009-09-09 15:08:12 +00001925
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 /// \brief Build a new C++ "delete" expression.
1927 ///
1928 /// By default, performs semantic analysis to build the new expression.
1929 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001930 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 bool IsGlobalDelete,
1932 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001933 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001935 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 }
Mike Stump11289f42009-09-09 15:08:12 +00001937
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 /// \brief Build a new unary type trait expression.
1939 ///
1940 /// By default, performs semantic analysis to build the new expression.
1941 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001942 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001943 SourceLocation StartLoc,
1944 TypeSourceInfo *T,
1945 SourceLocation RParenLoc) {
1946 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 }
1948
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001949 /// \brief Build a new binary type trait expression.
1950 ///
1951 /// By default, performs semantic analysis to build the new expression.
1952 /// Subclasses may override this routine to provide different behavior.
1953 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1954 SourceLocation StartLoc,
1955 TypeSourceInfo *LhsT,
1956 TypeSourceInfo *RhsT,
1957 SourceLocation RParenLoc) {
1958 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1959 }
1960
John Wiegley6242b6a2011-04-28 00:16:57 +00001961 /// \brief Build a new array type trait expression.
1962 ///
1963 /// By default, performs semantic analysis to build the new expression.
1964 /// Subclasses may override this routine to provide different behavior.
1965 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1966 SourceLocation StartLoc,
1967 TypeSourceInfo *TSInfo,
1968 Expr *DimExpr,
1969 SourceLocation RParenLoc) {
1970 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1971 }
1972
John Wiegleyf9f65842011-04-25 06:54:41 +00001973 /// \brief Build a new expression trait expression.
1974 ///
1975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
1977 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1978 SourceLocation StartLoc,
1979 Expr *Queried,
1980 SourceLocation RParenLoc) {
1981 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1982 }
1983
Mike Stump11289f42009-09-09 15:08:12 +00001984 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 /// expression.
1986 ///
1987 /// By default, performs semantic analysis to build the new expression.
1988 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001989 ExprResult RebuildDependentScopeDeclRefExpr(
1990 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001991 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001992 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001994 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001995
1996 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001997 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001998 *TemplateArgs);
1999
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002000 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 }
2002
2003 /// \brief Build a new template-id expression.
2004 ///
2005 /// By default, performs semantic analysis to build the new expression.
2006 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002007 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00002008 LookupResult &R,
2009 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00002010 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00002011 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 }
2013
2014 /// \brief Build a new object-construction expression.
2015 ///
2016 /// By default, performs semantic analysis to build the new expression.
2017 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002018 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002019 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 CXXConstructorDecl *Constructor,
2021 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002022 MultiExprArg Args,
2023 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002024 CXXConstructExpr::ConstructionKind ConstructKind,
2025 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002026 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002027 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002028 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002029 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002030
Douglas Gregordb121ba2009-12-14 16:27:04 +00002031 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002032 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00002033 RequiresZeroInit, ConstructKind,
2034 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 }
2036
2037 /// \brief Build a new object-construction expression.
2038 ///
2039 /// By default, performs semantic analysis to build the new expression.
2040 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002041 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2042 SourceLocation LParenLoc,
2043 MultiExprArg Args,
2044 SourceLocation RParenLoc) {
2045 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002046 LParenLoc,
2047 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 RParenLoc);
2049 }
2050
2051 /// \brief Build a new object-construction expression.
2052 ///
2053 /// By default, performs semantic analysis to build the new expression.
2054 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002055 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2056 SourceLocation LParenLoc,
2057 MultiExprArg Args,
2058 SourceLocation RParenLoc) {
2059 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002060 LParenLoc,
2061 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002062 RParenLoc);
2063 }
Mike Stump11289f42009-09-09 15:08:12 +00002064
Douglas Gregora16548e2009-08-11 05:31:07 +00002065 /// \brief Build a new member reference expression.
2066 ///
2067 /// By default, performs semantic analysis to build the new expression.
2068 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002069 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002070 QualType BaseType,
2071 bool IsArrow,
2072 SourceLocation OperatorLoc,
2073 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002074 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002075 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002076 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002078 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002079
John McCallb268a282010-08-23 23:25:46 +00002080 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002081 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002082 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002083 MemberNameInfo,
2084 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002085 }
2086
John McCall10eae182009-11-30 22:42:35 +00002087 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002088 ///
2089 /// By default, performs semantic analysis to build the new expression.
2090 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002091 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002092 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002093 SourceLocation OperatorLoc,
2094 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002095 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002096 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002097 LookupResult &R,
2098 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002099 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002100 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002101
John McCallb268a282010-08-23 23:25:46 +00002102 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002103 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002104 SS, FirstQualifierInScope,
2105 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002106 }
Mike Stump11289f42009-09-09 15:08:12 +00002107
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002108 /// \brief Build a new noexcept expression.
2109 ///
2110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
2112 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2113 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2114 }
2115
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002116 /// \brief Build a new expression to compute the length of a parameter pack.
2117 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2118 SourceLocation PackLoc,
2119 SourceLocation RParenLoc,
2120 unsigned Length) {
2121 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2122 OperatorLoc, Pack, PackLoc,
2123 RParenLoc, Length);
2124 }
2125
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 /// \brief Build a new Objective-C @encode expression.
2127 ///
2128 /// By default, performs semantic analysis to build the new expression.
2129 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002130 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002131 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002132 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002133 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002134 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002135 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002136
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002137 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002138 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002139 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002140 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002141 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002142 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002143 MultiExprArg Args,
2144 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002145 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2146 ReceiverTypeInfo->getType(),
2147 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002148 Sel, Method, LBracLoc, SelectorLoc,
2149 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002150 }
2151
2152 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002153 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002154 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002155 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002156 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002157 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002158 MultiExprArg Args,
2159 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002160 return SemaRef.BuildInstanceMessage(Receiver,
2161 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002162 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002163 Sel, Method, LBracLoc, SelectorLoc,
2164 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002165 }
2166
Douglas Gregord51d90d2010-04-26 20:11:03 +00002167 /// \brief Build a new Objective-C ivar reference expression.
2168 ///
2169 /// By default, performs semantic analysis to build the new expression.
2170 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002171 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002172 SourceLocation IvarLoc,
2173 bool IsArrow, bool IsFreeIvar) {
2174 // FIXME: We lose track of the IsFreeIvar bit.
2175 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002176 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002177 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2178 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002179 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002180 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002181 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002182 false);
John Wiegley01296292011-04-08 18:41:53 +00002183 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002184 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002185
Douglas Gregord51d90d2010-04-26 20:11:03 +00002186 if (Result.get())
2187 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002188
John Wiegley01296292011-04-08 18:41:53 +00002189 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002190 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002191 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002192 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002193 /*TemplateArgs=*/0);
2194 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002195
2196 /// \brief Build a new Objective-C property reference expression.
2197 ///
2198 /// By default, performs semantic analysis to build the new expression.
2199 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002200 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002201 ObjCPropertyDecl *Property,
2202 SourceLocation PropertyLoc) {
2203 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002204 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002205 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2206 Sema::LookupMemberName);
2207 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002208 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002209 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002210 SS, 0, 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 Gregor9faee212010-04-26 20:47:02 +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:*/PropertyLoc, IsArrow,
2219 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002220 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002221 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002222 /*TemplateArgs=*/0);
2223 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002224
John McCallb7bd14f2010-12-02 01:19:52 +00002225 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002226 ///
2227 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002228 /// Subclasses may override this routine to provide different behavior.
2229 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2230 ObjCMethodDecl *Getter,
2231 ObjCMethodDecl *Setter,
2232 SourceLocation PropertyLoc) {
2233 // Since these expressions can only be value-dependent, we do not
2234 // need to perform semantic analysis again.
2235 return Owned(
2236 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2237 VK_LValue, OK_ObjCProperty,
2238 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002239 }
2240
Douglas Gregord51d90d2010-04-26 20:11:03 +00002241 /// \brief Build a new Objective-C "isa" expression.
2242 ///
2243 /// By default, performs semantic analysis to build the new expression.
2244 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002245 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002246 bool IsArrow) {
2247 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002248 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002249 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2250 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002251 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002252 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002253 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002254 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002255 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002256
Douglas Gregord51d90d2010-04-26 20:11:03 +00002257 if (Result.get())
2258 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002259
John Wiegley01296292011-04-08 18:41:53 +00002260 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002261 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002262 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002263 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002264 /*TemplateArgs=*/0);
2265 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002266
Douglas Gregora16548e2009-08-11 05:31:07 +00002267 /// \brief Build a new shuffle vector expression.
2268 ///
2269 /// By default, performs semantic analysis to build the new expression.
2270 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002271 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002272 MultiExprArg SubExprs,
2273 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002275 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2277 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2278 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2279 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002280
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 // Build a reference to the __builtin_shufflevector builtin
2282 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002283 ExprResult Callee
2284 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2285 VK_LValue, BuiltinLoc));
2286 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2287 if (Callee.isInvalid())
2288 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002289
2290 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 unsigned NumSubExprs = SubExprs.size();
2292 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002293 ExprResult TheCall = SemaRef.Owned(
2294 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002295 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002296 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002297 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002298 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002299
Douglas Gregora16548e2009-08-11 05:31:07 +00002300 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002301 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002302 }
John McCall31f82722010-11-12 08:19:04 +00002303
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002304 /// \brief Build a new template argument pack expansion.
2305 ///
2306 /// By default, performs semantic analysis to build a new pack expansion
2307 /// for a template argument. Subclasses may override this routine to provide
2308 /// different behavior.
2309 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002310 SourceLocation EllipsisLoc,
2311 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002312 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002313 case TemplateArgument::Expression: {
2314 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002315 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2316 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002317 if (Result.isInvalid())
2318 return TemplateArgumentLoc();
2319
2320 return TemplateArgumentLoc(Result.get(), Result.get());
2321 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002322
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002323 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002324 return TemplateArgumentLoc(TemplateArgument(
2325 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002326 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002327 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002328 Pattern.getTemplateNameLoc(),
2329 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002330
2331 case TemplateArgument::Null:
2332 case TemplateArgument::Integral:
2333 case TemplateArgument::Declaration:
2334 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002335 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002336 llvm_unreachable("Pack expansion pattern has no parameter packs");
2337
2338 case TemplateArgument::Type:
2339 if (TypeSourceInfo *Expansion
2340 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002341 EllipsisLoc,
2342 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002343 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2344 Expansion);
2345 break;
2346 }
2347
2348 return TemplateArgumentLoc();
2349 }
2350
Douglas Gregor968f23a2011-01-03 19:31:53 +00002351 /// \brief Build a new expression pack expansion.
2352 ///
2353 /// By default, performs semantic analysis to build a new pack expansion
2354 /// for an expression. Subclasses may override this routine to provide
2355 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002356 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2357 llvm::Optional<unsigned> NumExpansions) {
2358 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002359 }
2360
John McCall31f82722010-11-12 08:19:04 +00002361private:
Douglas Gregor14454802011-02-25 02:25:35 +00002362 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2363 QualType ObjectType,
2364 NamedDecl *FirstQualifierInScope,
2365 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002366
2367 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2368 QualType ObjectType,
2369 NamedDecl *FirstQualifierInScope,
2370 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002371};
Douglas Gregora16548e2009-08-11 05:31:07 +00002372
Douglas Gregorebe10102009-08-20 07:17:43 +00002373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002374StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002375 if (!S)
2376 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002377
Douglas Gregorebe10102009-08-20 07:17:43 +00002378 switch (S->getStmtClass()) {
2379 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002380
Douglas Gregorebe10102009-08-20 07:17:43 +00002381 // Transform individual statement nodes
2382#define STMT(Node, Parent) \
2383 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002384#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002385#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002386#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002387
Douglas Gregorebe10102009-08-20 07:17:43 +00002388 // Transform expressions by calling TransformExpr.
2389#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002390#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002391#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002392#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002393 {
John McCalldadc5752010-08-24 06:29:42 +00002394 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002395 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002396 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002397
John McCallb268a282010-08-23 23:25:46 +00002398 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002399 }
Mike Stump11289f42009-09-09 15:08:12 +00002400 }
2401
John McCallc3007a22010-10-26 07:05:15 +00002402 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002403}
Mike Stump11289f42009-09-09 15:08:12 +00002404
2405
Douglas Gregore922c772009-08-04 22:27:00 +00002406template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002407ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002408 if (!E)
2409 return SemaRef.Owned(E);
2410
2411 switch (E->getStmtClass()) {
2412 case Stmt::NoStmtClass: break;
2413#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002414#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002415#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002416 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002417#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002418 }
2419
John McCallc3007a22010-10-26 07:05:15 +00002420 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002421}
2422
2423template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002424bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2425 unsigned NumInputs,
2426 bool IsCall,
2427 llvm::SmallVectorImpl<Expr *> &Outputs,
2428 bool *ArgChanged) {
2429 for (unsigned I = 0; I != NumInputs; ++I) {
2430 // If requested, drop call arguments that need to be dropped.
2431 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2432 if (ArgChanged)
2433 *ArgChanged = true;
2434
2435 break;
2436 }
2437
Douglas Gregor968f23a2011-01-03 19:31:53 +00002438 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2439 Expr *Pattern = Expansion->getPattern();
2440
2441 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2442 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2443 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2444
2445 // Determine whether the set of unexpanded parameter packs can and should
2446 // be expanded.
2447 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002448 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002449 llvm::Optional<unsigned> OrigNumExpansions
2450 = Expansion->getNumExpansions();
2451 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002452 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2453 Pattern->getSourceRange(),
2454 Unexpanded.data(),
2455 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002456 Expand, RetainExpansion,
2457 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002458 return true;
2459
2460 if (!Expand) {
2461 // The transform has determined that we should perform a simple
2462 // transformation on the pack expansion, producing another pack
2463 // expansion.
2464 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2465 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2466 if (OutPattern.isInvalid())
2467 return true;
2468
2469 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002470 Expansion->getEllipsisLoc(),
2471 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002472 if (Out.isInvalid())
2473 return true;
2474
2475 if (ArgChanged)
2476 *ArgChanged = true;
2477 Outputs.push_back(Out.get());
2478 continue;
2479 }
John McCall542e7c62011-07-06 07:30:07 +00002480
2481 // Record right away that the argument was changed. This needs
2482 // to happen even if the array expands to nothing.
2483 if (ArgChanged) *ArgChanged = true;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002484
2485 // The transform has determined that we should perform an elementwise
2486 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002487 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002488 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2489 ExprResult Out = getDerived().TransformExpr(Pattern);
2490 if (Out.isInvalid())
2491 return true;
2492
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002493 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002494 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2495 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002496 if (Out.isInvalid())
2497 return true;
2498 }
2499
Douglas Gregor968f23a2011-01-03 19:31:53 +00002500 Outputs.push_back(Out.get());
2501 }
2502
2503 continue;
2504 }
2505
Douglas Gregora3efea12011-01-03 19:04:46 +00002506 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2507 if (Result.isInvalid())
2508 return true;
2509
2510 if (Result.get() != Inputs[I] && ArgChanged)
2511 *ArgChanged = true;
2512
2513 Outputs.push_back(Result.get());
2514 }
2515
2516 return false;
2517}
2518
2519template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002520NestedNameSpecifierLoc
2521TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2522 NestedNameSpecifierLoc NNS,
2523 QualType ObjectType,
2524 NamedDecl *FirstQualifierInScope) {
2525 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2526 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2527 Qualifier = Qualifier.getPrefix())
2528 Qualifiers.push_back(Qualifier);
2529
2530 CXXScopeSpec SS;
2531 while (!Qualifiers.empty()) {
2532 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2533 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2534
2535 switch (QNNS->getKind()) {
2536 case NestedNameSpecifier::Identifier:
2537 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2538 *QNNS->getAsIdentifier(),
2539 Q.getLocalBeginLoc(),
2540 Q.getLocalEndLoc(),
2541 ObjectType, false, SS,
2542 FirstQualifierInScope, false))
2543 return NestedNameSpecifierLoc();
2544
2545 break;
2546
2547 case NestedNameSpecifier::Namespace: {
2548 NamespaceDecl *NS
2549 = cast_or_null<NamespaceDecl>(
2550 getDerived().TransformDecl(
2551 Q.getLocalBeginLoc(),
2552 QNNS->getAsNamespace()));
2553 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2554 break;
2555 }
2556
2557 case NestedNameSpecifier::NamespaceAlias: {
2558 NamespaceAliasDecl *Alias
2559 = cast_or_null<NamespaceAliasDecl>(
2560 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2561 QNNS->getAsNamespaceAlias()));
2562 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2563 Q.getLocalEndLoc());
2564 break;
2565 }
2566
2567 case NestedNameSpecifier::Global:
2568 // There is no meaningful transformation that one could perform on the
2569 // global scope.
2570 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2571 break;
2572
2573 case NestedNameSpecifier::TypeSpecWithTemplate:
2574 case NestedNameSpecifier::TypeSpec: {
2575 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2576 FirstQualifierInScope, SS);
2577
2578 if (!TL)
2579 return NestedNameSpecifierLoc();
2580
2581 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2582 (SemaRef.getLangOptions().CPlusPlus0x &&
2583 TL.getType()->isEnumeralType())) {
2584 assert(!TL.getType().hasLocalQualifiers() &&
2585 "Can't get cv-qualifiers here");
2586 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2587 Q.getLocalEndLoc());
2588 break;
2589 }
Richard Trieude756fb2011-05-07 01:36:37 +00002590 // If the nested-name-specifier is an invalid type def, don't emit an
2591 // error because a previous error should have already been emitted.
2592 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2593 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2594 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2595 << TL.getType() << SS.getRange();
2596 }
Douglas Gregor14454802011-02-25 02:25:35 +00002597 return NestedNameSpecifierLoc();
2598 }
Douglas Gregore16af532011-02-28 18:50:33 +00002599 }
Douglas Gregor14454802011-02-25 02:25:35 +00002600
Douglas Gregore16af532011-02-28 18:50:33 +00002601 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002602 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002603 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002604 }
2605
2606 // Don't rebuild the nested-name-specifier if we don't have to.
2607 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2608 !getDerived().AlwaysRebuild())
2609 return NNS;
2610
2611 // If we can re-use the source-location data from the original
2612 // nested-name-specifier, do so.
2613 if (SS.location_size() == NNS.getDataLength() &&
2614 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2615 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2616
2617 // Allocate new nested-name-specifier location information.
2618 return SS.getWithLocInContext(SemaRef.Context);
2619}
2620
2621template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002622DeclarationNameInfo
2623TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002624::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002625 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002626 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002627 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002628
2629 switch (Name.getNameKind()) {
2630 case DeclarationName::Identifier:
2631 case DeclarationName::ObjCZeroArgSelector:
2632 case DeclarationName::ObjCOneArgSelector:
2633 case DeclarationName::ObjCMultiArgSelector:
2634 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002635 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002636 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002637 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002638
Douglas Gregorf816bd72009-09-03 22:13:48 +00002639 case DeclarationName::CXXConstructorName:
2640 case DeclarationName::CXXDestructorName:
2641 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002642 TypeSourceInfo *NewTInfo;
2643 CanQualType NewCanTy;
2644 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002645 NewTInfo = getDerived().TransformType(OldTInfo);
2646 if (!NewTInfo)
2647 return DeclarationNameInfo();
2648 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002649 }
2650 else {
2651 NewTInfo = 0;
2652 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002653 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002654 if (NewT.isNull())
2655 return DeclarationNameInfo();
2656 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2657 }
Mike Stump11289f42009-09-09 15:08:12 +00002658
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002659 DeclarationName NewName
2660 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2661 NewCanTy);
2662 DeclarationNameInfo NewNameInfo(NameInfo);
2663 NewNameInfo.setName(NewName);
2664 NewNameInfo.setNamedTypeInfo(NewTInfo);
2665 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002666 }
Mike Stump11289f42009-09-09 15:08:12 +00002667 }
2668
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002669 assert(0 && "Unknown name kind.");
2670 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002671}
2672
2673template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002674TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002675TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2676 TemplateName Name,
2677 SourceLocation NameLoc,
2678 QualType ObjectType,
2679 NamedDecl *FirstQualifierInScope) {
2680 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2681 TemplateDecl *Template = QTN->getTemplateDecl();
2682 assert(Template && "qualified template name must refer to a template");
2683
2684 TemplateDecl *TransTemplate
2685 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2686 Template));
2687 if (!TransTemplate)
2688 return TemplateName();
2689
2690 if (!getDerived().AlwaysRebuild() &&
2691 SS.getScopeRep() == QTN->getQualifier() &&
2692 TransTemplate == Template)
2693 return Name;
2694
2695 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2696 TransTemplate);
2697 }
2698
2699 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2700 if (SS.getScopeRep()) {
2701 // These apply to the scope specifier, not the template.
2702 ObjectType = QualType();
2703 FirstQualifierInScope = 0;
2704 }
2705
2706 if (!getDerived().AlwaysRebuild() &&
2707 SS.getScopeRep() == DTN->getQualifier() &&
2708 ObjectType.isNull())
2709 return Name;
2710
2711 if (DTN->isIdentifier()) {
2712 return getDerived().RebuildTemplateName(SS,
2713 *DTN->getIdentifier(),
2714 NameLoc,
2715 ObjectType,
2716 FirstQualifierInScope);
2717 }
2718
2719 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2720 ObjectType);
2721 }
2722
2723 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2724 TemplateDecl *TransTemplate
2725 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2726 Template));
2727 if (!TransTemplate)
2728 return TemplateName();
2729
2730 if (!getDerived().AlwaysRebuild() &&
2731 TransTemplate == Template)
2732 return Name;
2733
2734 return TemplateName(TransTemplate);
2735 }
2736
2737 if (SubstTemplateTemplateParmPackStorage *SubstPack
2738 = Name.getAsSubstTemplateTemplateParmPack()) {
2739 TemplateTemplateParmDecl *TransParam
2740 = cast_or_null<TemplateTemplateParmDecl>(
2741 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2742 if (!TransParam)
2743 return TemplateName();
2744
2745 if (!getDerived().AlwaysRebuild() &&
2746 TransParam == SubstPack->getParameterPack())
2747 return Name;
2748
2749 return getDerived().RebuildTemplateName(TransParam,
2750 SubstPack->getArgumentPack());
2751 }
2752
2753 // These should be getting filtered out before they reach the AST.
2754 llvm_unreachable("overloaded function decl survived to here");
2755 return TemplateName();
2756}
2757
2758template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002759void TreeTransform<Derived>::InventTemplateArgumentLoc(
2760 const TemplateArgument &Arg,
2761 TemplateArgumentLoc &Output) {
2762 SourceLocation Loc = getDerived().getBaseLocation();
2763 switch (Arg.getKind()) {
2764 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002765 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002766 break;
2767
2768 case TemplateArgument::Type:
2769 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002770 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002771
John McCall0ad16662009-10-29 08:12:44 +00002772 break;
2773
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002774 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002775 case TemplateArgument::TemplateExpansion: {
2776 NestedNameSpecifierLocBuilder Builder;
2777 TemplateName Template = Arg.getAsTemplate();
2778 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2779 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2780 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2781 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2782
2783 if (Arg.getKind() == TemplateArgument::Template)
2784 Output = TemplateArgumentLoc(Arg,
2785 Builder.getWithLocInContext(SemaRef.Context),
2786 Loc);
2787 else
2788 Output = TemplateArgumentLoc(Arg,
2789 Builder.getWithLocInContext(SemaRef.Context),
2790 Loc, Loc);
2791
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002792 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002793 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002794
John McCall0ad16662009-10-29 08:12:44 +00002795 case TemplateArgument::Expression:
2796 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2797 break;
2798
2799 case TemplateArgument::Declaration:
2800 case TemplateArgument::Integral:
2801 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002802 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002803 break;
2804 }
2805}
2806
2807template<typename Derived>
2808bool TreeTransform<Derived>::TransformTemplateArgument(
2809 const TemplateArgumentLoc &Input,
2810 TemplateArgumentLoc &Output) {
2811 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002812 switch (Arg.getKind()) {
2813 case TemplateArgument::Null:
2814 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002815 Output = Input;
2816 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002817
Douglas Gregore922c772009-08-04 22:27:00 +00002818 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002819 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002820 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002821 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002822
2823 DI = getDerived().TransformType(DI);
2824 if (!DI) return true;
2825
2826 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2827 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002828 }
Mike Stump11289f42009-09-09 15:08:12 +00002829
Douglas Gregore922c772009-08-04 22:27:00 +00002830 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002831 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002832 DeclarationName Name;
2833 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2834 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002835 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002836 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002837 if (!D) return true;
2838
John McCall0d07eb32009-10-29 18:45:58 +00002839 Expr *SourceExpr = Input.getSourceDeclExpression();
2840 if (SourceExpr) {
2841 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002842 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002843 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002844 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002845 }
2846
2847 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002848 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002849 }
Mike Stump11289f42009-09-09 15:08:12 +00002850
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002851 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002852 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2853 if (QualifierLoc) {
2854 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2855 if (!QualifierLoc)
2856 return true;
2857 }
2858
Douglas Gregordf846d12011-03-02 18:46:51 +00002859 CXXScopeSpec SS;
2860 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002861 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002862 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2863 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002864 if (Template.isNull())
2865 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002866
Douglas Gregor9d802122011-03-02 17:09:35 +00002867 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002868 Input.getTemplateNameLoc());
2869 return false;
2870 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002871
2872 case TemplateArgument::TemplateExpansion:
2873 llvm_unreachable("Caller should expand pack expansions");
2874
Douglas Gregore922c772009-08-04 22:27:00 +00002875 case TemplateArgument::Expression: {
2876 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002877 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002878 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002879
John McCall0ad16662009-10-29 08:12:44 +00002880 Expr *InputExpr = Input.getSourceExpression();
2881 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2882
Chris Lattnercdb591a2011-04-25 20:37:58 +00002883 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002884 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002885 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002886 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002887 }
Mike Stump11289f42009-09-09 15:08:12 +00002888
Douglas Gregore922c772009-08-04 22:27:00 +00002889 case TemplateArgument::Pack: {
2890 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2891 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002892 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002893 AEnd = Arg.pack_end();
2894 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002895
John McCall0ad16662009-10-29 08:12:44 +00002896 // FIXME: preserve source information here when we start
2897 // caring about parameter packs.
2898
John McCall0d07eb32009-10-29 18:45:58 +00002899 TemplateArgumentLoc InputArg;
2900 TemplateArgumentLoc OutputArg;
2901 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2902 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002903 return true;
2904
John McCall0d07eb32009-10-29 18:45:58 +00002905 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002906 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002907
2908 TemplateArgument *TransformedArgsPtr
2909 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2910 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2911 TransformedArgsPtr);
2912 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2913 TransformedArgs.size()),
2914 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002915 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002916 }
2917 }
Mike Stump11289f42009-09-09 15:08:12 +00002918
Douglas Gregore922c772009-08-04 22:27:00 +00002919 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002920 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002921}
2922
Douglas Gregorfe921a72010-12-20 23:36:19 +00002923/// \brief Iterator adaptor that invents template argument location information
2924/// for each of the template arguments in its underlying iterator.
2925template<typename Derived, typename InputIterator>
2926class TemplateArgumentLocInventIterator {
2927 TreeTransform<Derived> &Self;
2928 InputIterator Iter;
2929
2930public:
2931 typedef TemplateArgumentLoc value_type;
2932 typedef TemplateArgumentLoc reference;
2933 typedef typename std::iterator_traits<InputIterator>::difference_type
2934 difference_type;
2935 typedef std::input_iterator_tag iterator_category;
2936
2937 class pointer {
2938 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002939
Douglas Gregorfe921a72010-12-20 23:36:19 +00002940 public:
2941 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2942
2943 const TemplateArgumentLoc *operator->() const { return &Arg; }
2944 };
2945
2946 TemplateArgumentLocInventIterator() { }
2947
2948 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2949 InputIterator Iter)
2950 : Self(Self), Iter(Iter) { }
2951
2952 TemplateArgumentLocInventIterator &operator++() {
2953 ++Iter;
2954 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002955 }
2956
Douglas Gregorfe921a72010-12-20 23:36:19 +00002957 TemplateArgumentLocInventIterator operator++(int) {
2958 TemplateArgumentLocInventIterator Old(*this);
2959 ++(*this);
2960 return Old;
2961 }
2962
2963 reference operator*() const {
2964 TemplateArgumentLoc Result;
2965 Self.InventTemplateArgumentLoc(*Iter, Result);
2966 return Result;
2967 }
2968
2969 pointer operator->() const { return pointer(**this); }
2970
2971 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2972 const TemplateArgumentLocInventIterator &Y) {
2973 return X.Iter == Y.Iter;
2974 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002975
Douglas Gregorfe921a72010-12-20 23:36:19 +00002976 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2977 const TemplateArgumentLocInventIterator &Y) {
2978 return X.Iter != Y.Iter;
2979 }
2980};
2981
Douglas Gregor42cafa82010-12-20 17:42:22 +00002982template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002983template<typename InputIterator>
2984bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2985 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002986 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002987 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002988 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002989 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002990
2991 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2992 // Unpack argument packs, which we translate them into separate
2993 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002994 // FIXME: We could do much better if we could guarantee that the
2995 // TemplateArgumentLocInfo for the pack expansion would be usable for
2996 // all of the template arguments in the argument pack.
2997 typedef TemplateArgumentLocInventIterator<Derived,
2998 TemplateArgument::pack_iterator>
2999 PackLocIterator;
3000 if (TransformTemplateArguments(PackLocIterator(*this,
3001 In.getArgument().pack_begin()),
3002 PackLocIterator(*this,
3003 In.getArgument().pack_end()),
3004 Outputs))
3005 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003006
3007 continue;
3008 }
3009
3010 if (In.getArgument().isPackExpansion()) {
3011 // We have a pack expansion, for which we will be substituting into
3012 // the pattern.
3013 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003014 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003015 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003016 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3017 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003018
3019 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3020 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3021 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3022
3023 // Determine whether the set of unexpanded parameter packs can and should
3024 // be expanded.
3025 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003026 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003027 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003028 if (getDerived().TryExpandParameterPacks(Ellipsis,
3029 Pattern.getSourceRange(),
3030 Unexpanded.data(),
3031 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003032 Expand,
3033 RetainExpansion,
3034 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003035 return true;
3036
3037 if (!Expand) {
3038 // The transform has determined that we should perform a simple
3039 // transformation on the pack expansion, producing another pack
3040 // expansion.
3041 TemplateArgumentLoc OutPattern;
3042 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3043 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3044 return true;
3045
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003046 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3047 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003048 if (Out.getArgument().isNull())
3049 return true;
3050
3051 Outputs.addArgument(Out);
3052 continue;
3053 }
3054
3055 // The transform has determined that we should perform an elementwise
3056 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003057 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003058 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3059
3060 if (getDerived().TransformTemplateArgument(Pattern, Out))
3061 return true;
3062
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003063 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003064 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3065 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003066 if (Out.getArgument().isNull())
3067 return true;
3068 }
3069
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003070 Outputs.addArgument(Out);
3071 }
3072
Douglas Gregor48d24112011-01-10 20:53:55 +00003073 // If we're supposed to retain a pack expansion, do so by temporarily
3074 // forgetting the partially-substituted parameter pack.
3075 if (RetainExpansion) {
3076 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3077
3078 if (getDerived().TransformTemplateArgument(Pattern, Out))
3079 return true;
3080
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003081 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3082 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003083 if (Out.getArgument().isNull())
3084 return true;
3085
3086 Outputs.addArgument(Out);
3087 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003088
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003089 continue;
3090 }
3091
3092 // The simple case:
3093 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003094 return true;
3095
3096 Outputs.addArgument(Out);
3097 }
3098
3099 return false;
3100
3101}
3102
Douglas Gregord6ff3322009-08-04 16:50:30 +00003103//===----------------------------------------------------------------------===//
3104// Type transformation
3105//===----------------------------------------------------------------------===//
3106
3107template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003108QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003109 if (getDerived().AlreadyTransformed(T))
3110 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003111
John McCall550e0c22009-10-21 00:40:46 +00003112 // Temporary workaround. All of these transformations should
3113 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003114 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3115 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003116
John McCall31f82722010-11-12 08:19:04 +00003117 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003118
John McCall550e0c22009-10-21 00:40:46 +00003119 if (!NewDI)
3120 return QualType();
3121
3122 return NewDI->getType();
3123}
3124
3125template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003126TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003127 if (getDerived().AlreadyTransformed(DI->getType()))
3128 return DI;
3129
3130 TypeLocBuilder TLB;
3131
3132 TypeLoc TL = DI->getTypeLoc();
3133 TLB.reserve(TL.getFullDataSize());
3134
John McCall31f82722010-11-12 08:19:04 +00003135 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003136 if (Result.isNull())
3137 return 0;
3138
John McCallbcd03502009-12-07 02:54:59 +00003139 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003140}
3141
3142template<typename Derived>
3143QualType
John McCall31f82722010-11-12 08:19:04 +00003144TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003145 switch (T.getTypeLocClass()) {
3146#define ABSTRACT_TYPELOC(CLASS, PARENT)
3147#define TYPELOC(CLASS, PARENT) \
3148 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003149 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003150#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003151 }
Mike Stump11289f42009-09-09 15:08:12 +00003152
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003153 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003154 return QualType();
3155}
3156
3157/// FIXME: By default, this routine adds type qualifiers only to types
3158/// that can have qualifiers, and silently suppresses those qualifiers
3159/// that are not permitted (e.g., qualifiers on reference or function
3160/// types). This is the right thing for template instantiation, but
3161/// probably not for other clients.
3162template<typename Derived>
3163QualType
3164TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003165 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003166 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003167
John McCall31f82722010-11-12 08:19:04 +00003168 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003169 if (Result.isNull())
3170 return QualType();
3171
3172 // Silently suppress qualifiers if the result type can't be qualified.
3173 // FIXME: this is the right thing for template instantiation, but
3174 // probably not for other clients.
3175 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003176 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003177
John McCall31168b02011-06-15 23:02:42 +00003178 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003179 // resulting type.
3180 if (Quals.hasObjCLifetime()) {
3181 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3182 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003183 else if (Result.getObjCLifetime()) {
Douglas Gregore46db902011-06-17 22:11:49 +00003184 // Objective-C ARC:
3185 // A lifetime qualifier applied to a substituted template parameter
3186 // overrides the lifetime qualifier from the template argument.
3187 if (const SubstTemplateTypeParmType *SubstTypeParam
3188 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3189 QualType Replacement = SubstTypeParam->getReplacementType();
3190 Qualifiers Qs = Replacement.getQualifiers();
3191 Qs.removeObjCLifetime();
3192 Replacement
3193 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3194 Qs);
3195 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3196 SubstTypeParam->getReplacedParameter(),
3197 Replacement);
3198 TLB.TypeWasModifiedSafely(Result);
3199 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003200 // Otherwise, complain about the addition of a qualifier to an
3201 // already-qualified type.
3202 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003203 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003204 << Result << R;
3205
Douglas Gregore46db902011-06-17 22:11:49 +00003206 Quals.removeObjCLifetime();
3207 }
3208 }
3209 }
John McCallcb0f89a2010-06-05 06:41:15 +00003210 if (!Quals.empty()) {
3211 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3212 TLB.push<QualifiedTypeLoc>(Result);
3213 // No location information to preserve.
3214 }
John McCall550e0c22009-10-21 00:40:46 +00003215
3216 return Result;
3217}
3218
Douglas Gregor14454802011-02-25 02:25:35 +00003219template<typename Derived>
3220TypeLoc
3221TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3222 QualType ObjectType,
3223 NamedDecl *UnqualLookup,
3224 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003225 QualType T = TL.getType();
3226 if (getDerived().AlreadyTransformed(T))
3227 return TL;
3228
3229 TypeLocBuilder TLB;
3230 QualType Result;
3231
3232 if (isa<TemplateSpecializationType>(T)) {
3233 TemplateSpecializationTypeLoc SpecTL
3234 = cast<TemplateSpecializationTypeLoc>(TL);
3235
3236 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003237 getDerived().TransformTemplateName(SS,
3238 SpecTL.getTypePtr()->getTemplateName(),
3239 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003240 ObjectType, UnqualLookup);
3241 if (Template.isNull())
3242 return TypeLoc();
3243
3244 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3245 Template);
3246 } else if (isa<DependentTemplateSpecializationType>(T)) {
3247 DependentTemplateSpecializationTypeLoc SpecTL
3248 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3249
Douglas Gregor5a064722011-02-28 17:23:35 +00003250 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003251 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003252 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003253 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003254 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003255 if (Template.isNull())
3256 return TypeLoc();
3257
Douglas Gregor14454802011-02-25 02:25:35 +00003258 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003259 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003260 Template,
3261 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003262 } else {
3263 // Nothing special needs to be done for these.
3264 Result = getDerived().TransformType(TLB, TL);
3265 }
3266
3267 if (Result.isNull())
3268 return TypeLoc();
3269
3270 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3271}
3272
Douglas Gregor579c15f2011-03-02 18:32:08 +00003273template<typename Derived>
3274TypeSourceInfo *
3275TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3276 QualType ObjectType,
3277 NamedDecl *UnqualLookup,
3278 CXXScopeSpec &SS) {
3279 // FIXME: Painfully copy-paste from the above!
3280
3281 QualType T = TSInfo->getType();
3282 if (getDerived().AlreadyTransformed(T))
3283 return TSInfo;
3284
3285 TypeLocBuilder TLB;
3286 QualType Result;
3287
3288 TypeLoc TL = TSInfo->getTypeLoc();
3289 if (isa<TemplateSpecializationType>(T)) {
3290 TemplateSpecializationTypeLoc SpecTL
3291 = cast<TemplateSpecializationTypeLoc>(TL);
3292
3293 TemplateName Template
3294 = getDerived().TransformTemplateName(SS,
3295 SpecTL.getTypePtr()->getTemplateName(),
3296 SpecTL.getTemplateNameLoc(),
3297 ObjectType, UnqualLookup);
3298 if (Template.isNull())
3299 return 0;
3300
3301 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3302 Template);
3303 } else if (isa<DependentTemplateSpecializationType>(T)) {
3304 DependentTemplateSpecializationTypeLoc SpecTL
3305 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3306
3307 TemplateName Template
3308 = getDerived().RebuildTemplateName(SS,
3309 *SpecTL.getTypePtr()->getIdentifier(),
3310 SpecTL.getNameLoc(),
3311 ObjectType, UnqualLookup);
3312 if (Template.isNull())
3313 return 0;
3314
3315 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3316 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003317 Template,
3318 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003319 } else {
3320 // Nothing special needs to be done for these.
3321 Result = getDerived().TransformType(TLB, TL);
3322 }
3323
3324 if (Result.isNull())
3325 return 0;
3326
3327 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3328}
3329
John McCall550e0c22009-10-21 00:40:46 +00003330template <class TyLoc> static inline
3331QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3332 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3333 NewT.setNameLoc(T.getNameLoc());
3334 return T.getType();
3335}
3336
John McCall550e0c22009-10-21 00:40:46 +00003337template<typename Derived>
3338QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003339 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003340 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3341 NewT.setBuiltinLoc(T.getBuiltinLoc());
3342 if (T.needsExtraLocalData())
3343 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3344 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003345}
Mike Stump11289f42009-09-09 15:08:12 +00003346
Douglas Gregord6ff3322009-08-04 16:50:30 +00003347template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003348QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003349 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003350 // FIXME: recurse?
3351 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003352}
Mike Stump11289f42009-09-09 15:08:12 +00003353
Douglas Gregord6ff3322009-08-04 16:50:30 +00003354template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003355QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003356 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003357 QualType PointeeType
3358 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003359 if (PointeeType.isNull())
3360 return QualType();
3361
3362 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003363 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003364 // A dependent pointer type 'T *' has is being transformed such
3365 // that an Objective-C class type is being replaced for 'T'. The
3366 // resulting pointer type is an ObjCObjectPointerType, not a
3367 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003368 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003369
John McCall8b07ec22010-05-15 11:32:37 +00003370 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3371 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003372 return Result;
3373 }
John McCall31f82722010-11-12 08:19:04 +00003374
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003375 if (getDerived().AlwaysRebuild() ||
3376 PointeeType != TL.getPointeeLoc().getType()) {
3377 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3378 if (Result.isNull())
3379 return QualType();
3380 }
John McCall31168b02011-06-15 23:02:42 +00003381
3382 // Objective-C ARC can add lifetime qualifiers to the type that we're
3383 // pointing to.
3384 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3385
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003386 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3387 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003388 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003389}
Mike Stump11289f42009-09-09 15:08:12 +00003390
3391template<typename Derived>
3392QualType
John McCall550e0c22009-10-21 00:40:46 +00003393TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003394 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003395 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003396 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3397 if (PointeeType.isNull())
3398 return QualType();
3399
3400 QualType Result = TL.getType();
3401 if (getDerived().AlwaysRebuild() ||
3402 PointeeType != TL.getPointeeLoc().getType()) {
3403 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003404 TL.getSigilLoc());
3405 if (Result.isNull())
3406 return QualType();
3407 }
3408
Douglas Gregor049211a2010-04-22 16:50:51 +00003409 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003410 NewT.setSigilLoc(TL.getSigilLoc());
3411 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003412}
3413
John McCall70dd5f62009-10-30 00:06:24 +00003414/// Transforms a reference type. Note that somewhat paradoxically we
3415/// don't care whether the type itself is an l-value type or an r-value
3416/// type; we only care if the type was *written* as an l-value type
3417/// or an r-value type.
3418template<typename Derived>
3419QualType
3420TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003421 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003422 const ReferenceType *T = TL.getTypePtr();
3423
3424 // Note that this works with the pointee-as-written.
3425 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3426 if (PointeeType.isNull())
3427 return QualType();
3428
3429 QualType Result = TL.getType();
3430 if (getDerived().AlwaysRebuild() ||
3431 PointeeType != T->getPointeeTypeAsWritten()) {
3432 Result = getDerived().RebuildReferenceType(PointeeType,
3433 T->isSpelledAsLValue(),
3434 TL.getSigilLoc());
3435 if (Result.isNull())
3436 return QualType();
3437 }
3438
John McCall31168b02011-06-15 23:02:42 +00003439 // Objective-C ARC can add lifetime qualifiers to the type that we're
3440 // referring to.
3441 TLB.TypeWasModifiedSafely(
3442 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3443
John McCall70dd5f62009-10-30 00:06:24 +00003444 // r-value references can be rebuilt as l-value references.
3445 ReferenceTypeLoc NewTL;
3446 if (isa<LValueReferenceType>(Result))
3447 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3448 else
3449 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3450 NewTL.setSigilLoc(TL.getSigilLoc());
3451
3452 return Result;
3453}
3454
Mike Stump11289f42009-09-09 15:08:12 +00003455template<typename Derived>
3456QualType
John McCall550e0c22009-10-21 00:40:46 +00003457TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003458 LValueReferenceTypeLoc TL) {
3459 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003460}
3461
Mike Stump11289f42009-09-09 15:08:12 +00003462template<typename Derived>
3463QualType
John McCall550e0c22009-10-21 00:40:46 +00003464TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003465 RValueReferenceTypeLoc TL) {
3466 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003467}
Mike Stump11289f42009-09-09 15:08:12 +00003468
Douglas Gregord6ff3322009-08-04 16:50:30 +00003469template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003470QualType
John McCall550e0c22009-10-21 00:40:46 +00003471TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003472 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003473 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003474 if (PointeeType.isNull())
3475 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003476
Abramo Bagnara509357842011-03-05 14:42:21 +00003477 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3478 TypeSourceInfo* NewClsTInfo = 0;
3479 if (OldClsTInfo) {
3480 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3481 if (!NewClsTInfo)
3482 return QualType();
3483 }
3484
3485 const MemberPointerType *T = TL.getTypePtr();
3486 QualType OldClsType = QualType(T->getClass(), 0);
3487 QualType NewClsType;
3488 if (NewClsTInfo)
3489 NewClsType = NewClsTInfo->getType();
3490 else {
3491 NewClsType = getDerived().TransformType(OldClsType);
3492 if (NewClsType.isNull())
3493 return QualType();
3494 }
Mike Stump11289f42009-09-09 15:08:12 +00003495
John McCall550e0c22009-10-21 00:40:46 +00003496 QualType Result = TL.getType();
3497 if (getDerived().AlwaysRebuild() ||
3498 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003499 NewClsType != OldClsType) {
3500 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003501 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003502 if (Result.isNull())
3503 return QualType();
3504 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003505
John McCall550e0c22009-10-21 00:40:46 +00003506 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3507 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003508 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003509
3510 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003511}
3512
Mike Stump11289f42009-09-09 15:08:12 +00003513template<typename Derived>
3514QualType
John McCall550e0c22009-10-21 00:40:46 +00003515TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003516 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003517 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003518 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003519 if (ElementType.isNull())
3520 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003521
John McCall550e0c22009-10-21 00:40:46 +00003522 QualType Result = TL.getType();
3523 if (getDerived().AlwaysRebuild() ||
3524 ElementType != T->getElementType()) {
3525 Result = getDerived().RebuildConstantArrayType(ElementType,
3526 T->getSizeModifier(),
3527 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003528 T->getIndexTypeCVRQualifiers(),
3529 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003530 if (Result.isNull())
3531 return QualType();
3532 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003533
John McCall550e0c22009-10-21 00:40:46 +00003534 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3535 NewTL.setLBracketLoc(TL.getLBracketLoc());
3536 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003537
John McCall550e0c22009-10-21 00:40:46 +00003538 Expr *Size = TL.getSizeExpr();
3539 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003540 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003541 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3542 }
3543 NewTL.setSizeExpr(Size);
3544
3545 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003546}
Mike Stump11289f42009-09-09 15:08:12 +00003547
Douglas Gregord6ff3322009-08-04 16:50:30 +00003548template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003549QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003550 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003551 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003552 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003553 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003554 if (ElementType.isNull())
3555 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003556
John McCall550e0c22009-10-21 00:40:46 +00003557 QualType Result = TL.getType();
3558 if (getDerived().AlwaysRebuild() ||
3559 ElementType != T->getElementType()) {
3560 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003561 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003562 T->getIndexTypeCVRQualifiers(),
3563 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003564 if (Result.isNull())
3565 return QualType();
3566 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003567
John McCall550e0c22009-10-21 00:40:46 +00003568 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3569 NewTL.setLBracketLoc(TL.getLBracketLoc());
3570 NewTL.setRBracketLoc(TL.getRBracketLoc());
3571 NewTL.setSizeExpr(0);
3572
3573 return Result;
3574}
3575
3576template<typename Derived>
3577QualType
3578TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003579 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003580 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003581 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3582 if (ElementType.isNull())
3583 return QualType();
3584
3585 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003586 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003587
John McCalldadc5752010-08-24 06:29:42 +00003588 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003589 = getDerived().TransformExpr(T->getSizeExpr());
3590 if (SizeResult.isInvalid())
3591 return QualType();
3592
John McCallb268a282010-08-23 23:25:46 +00003593 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003594
3595 QualType Result = TL.getType();
3596 if (getDerived().AlwaysRebuild() ||
3597 ElementType != T->getElementType() ||
3598 Size != T->getSizeExpr()) {
3599 Result = getDerived().RebuildVariableArrayType(ElementType,
3600 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003601 Size,
John McCall550e0c22009-10-21 00:40:46 +00003602 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003603 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003604 if (Result.isNull())
3605 return QualType();
3606 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003607
John McCall550e0c22009-10-21 00:40:46 +00003608 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3609 NewTL.setLBracketLoc(TL.getLBracketLoc());
3610 NewTL.setRBracketLoc(TL.getRBracketLoc());
3611 NewTL.setSizeExpr(Size);
3612
3613 return Result;
3614}
3615
3616template<typename Derived>
3617QualType
3618TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003619 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003620 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003621 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3622 if (ElementType.isNull())
3623 return QualType();
3624
3625 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003626 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003627
John McCall33ddac02011-01-19 10:06:00 +00003628 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3629 Expr *origSize = TL.getSizeExpr();
3630 if (!origSize) origSize = T->getSizeExpr();
3631
3632 ExprResult sizeResult
3633 = getDerived().TransformExpr(origSize);
3634 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003635 return QualType();
3636
John McCall33ddac02011-01-19 10:06:00 +00003637 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003638
3639 QualType Result = TL.getType();
3640 if (getDerived().AlwaysRebuild() ||
3641 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003642 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003643 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3644 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003645 size,
John McCall550e0c22009-10-21 00:40:46 +00003646 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003647 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003648 if (Result.isNull())
3649 return QualType();
3650 }
John McCall550e0c22009-10-21 00:40:46 +00003651
3652 // We might have any sort of array type now, but fortunately they
3653 // all have the same location layout.
3654 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3655 NewTL.setLBracketLoc(TL.getLBracketLoc());
3656 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003657 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003658
3659 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003660}
Mike Stump11289f42009-09-09 15:08:12 +00003661
3662template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003663QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003664 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003665 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003666 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003667
3668 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003669 QualType ElementType = getDerived().TransformType(T->getElementType());
3670 if (ElementType.isNull())
3671 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003672
Douglas Gregore922c772009-08-04 22:27:00 +00003673 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003674 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003675
John McCalldadc5752010-08-24 06:29:42 +00003676 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003677 if (Size.isInvalid())
3678 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003679
John McCall550e0c22009-10-21 00:40:46 +00003680 QualType Result = TL.getType();
3681 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003682 ElementType != T->getElementType() ||
3683 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003684 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003685 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003686 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003687 if (Result.isNull())
3688 return QualType();
3689 }
John McCall550e0c22009-10-21 00:40:46 +00003690
3691 // Result might be dependent or not.
3692 if (isa<DependentSizedExtVectorType>(Result)) {
3693 DependentSizedExtVectorTypeLoc NewTL
3694 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3695 NewTL.setNameLoc(TL.getNameLoc());
3696 } else {
3697 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3698 NewTL.setNameLoc(TL.getNameLoc());
3699 }
3700
3701 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003702}
Mike Stump11289f42009-09-09 15:08:12 +00003703
3704template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003705QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003706 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003707 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003708 QualType ElementType = getDerived().TransformType(T->getElementType());
3709 if (ElementType.isNull())
3710 return QualType();
3711
John McCall550e0c22009-10-21 00:40:46 +00003712 QualType Result = TL.getType();
3713 if (getDerived().AlwaysRebuild() ||
3714 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003715 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003716 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003717 if (Result.isNull())
3718 return QualType();
3719 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003720
John McCall550e0c22009-10-21 00:40:46 +00003721 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3722 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003723
John McCall550e0c22009-10-21 00:40:46 +00003724 return Result;
3725}
3726
3727template<typename Derived>
3728QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003729 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003730 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003731 QualType ElementType = getDerived().TransformType(T->getElementType());
3732 if (ElementType.isNull())
3733 return QualType();
3734
3735 QualType Result = TL.getType();
3736 if (getDerived().AlwaysRebuild() ||
3737 ElementType != T->getElementType()) {
3738 Result = getDerived().RebuildExtVectorType(ElementType,
3739 T->getNumElements(),
3740 /*FIXME*/ SourceLocation());
3741 if (Result.isNull())
3742 return QualType();
3743 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003744
John McCall550e0c22009-10-21 00:40:46 +00003745 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3746 NewTL.setNameLoc(TL.getNameLoc());
3747
3748 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003749}
Mike Stump11289f42009-09-09 15:08:12 +00003750
3751template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003752ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003753TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003754 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003755 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003756 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003757 TypeSourceInfo *NewDI = 0;
3758
3759 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3760 // If we're substituting into a pack expansion type and we know the
3761 TypeLoc OldTL = OldDI->getTypeLoc();
3762 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3763
3764 TypeLocBuilder TLB;
3765 TypeLoc NewTL = OldDI->getTypeLoc();
3766 TLB.reserve(NewTL.getFullDataSize());
3767
3768 QualType Result = getDerived().TransformType(TLB,
3769 OldExpansionTL.getPatternLoc());
3770 if (Result.isNull())
3771 return 0;
3772
3773 Result = RebuildPackExpansionType(Result,
3774 OldExpansionTL.getPatternLoc().getSourceRange(),
3775 OldExpansionTL.getEllipsisLoc(),
3776 NumExpansions);
3777 if (Result.isNull())
3778 return 0;
3779
3780 PackExpansionTypeLoc NewExpansionTL
3781 = TLB.push<PackExpansionTypeLoc>(Result);
3782 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3783 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3784 } else
3785 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003786 if (!NewDI)
3787 return 0;
3788
John McCall8fb0d9d2011-05-01 22:35:37 +00003789 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003790 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003791
3792 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3793 OldParm->getDeclContext(),
3794 OldParm->getInnerLocStart(),
3795 OldParm->getLocation(),
3796 OldParm->getIdentifier(),
3797 NewDI->getType(),
3798 NewDI,
3799 OldParm->getStorageClass(),
3800 OldParm->getStorageClassAsWritten(),
3801 /* DefArg */ NULL);
3802 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3803 OldParm->getFunctionScopeIndex() + indexAdjustment);
3804 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003805}
3806
3807template<typename Derived>
3808bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003809 TransformFunctionTypeParams(SourceLocation Loc,
3810 ParmVarDecl **Params, unsigned NumParams,
3811 const QualType *ParamTypes,
3812 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3813 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003814 int indexAdjustment = 0;
3815
Douglas Gregordd472162011-01-07 00:20:55 +00003816 for (unsigned i = 0; i != NumParams; ++i) {
3817 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003818 assert(OldParm->getFunctionScopeIndex() == i);
3819
Douglas Gregor715e4612011-01-14 22:40:04 +00003820 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003821 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003822 if (OldParm->isParameterPack()) {
3823 // We have a function parameter pack that may need to be expanded.
3824 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003825
Douglas Gregor5499af42011-01-05 23:12:31 +00003826 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003827 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3828 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3829 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3830 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003831 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3832
Douglas Gregor5499af42011-01-05 23:12:31 +00003833 // Determine whether we should expand the parameter packs.
3834 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003835 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003836 llvm::Optional<unsigned> OrigNumExpansions
3837 = ExpansionTL.getTypePtr()->getNumExpansions();
3838 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003839 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3840 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003841 Unexpanded.data(),
3842 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003843 ShouldExpand,
3844 RetainExpansion,
3845 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003846 return true;
3847 }
3848
3849 if (ShouldExpand) {
3850 // Expand the function parameter pack into multiple, separate
3851 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003852 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003853 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003854 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3855 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003856 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003857 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003858 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003859 if (!NewParm)
3860 return true;
3861
Douglas Gregordd472162011-01-07 00:20:55 +00003862 OutParamTypes.push_back(NewParm->getType());
3863 if (PVars)
3864 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003865 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003866
3867 // If we're supposed to retain a pack expansion, do so by temporarily
3868 // forgetting the partially-substituted parameter pack.
3869 if (RetainExpansion) {
3870 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3871 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003872 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003873 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003874 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003875 if (!NewParm)
3876 return true;
3877
3878 OutParamTypes.push_back(NewParm->getType());
3879 if (PVars)
3880 PVars->push_back(NewParm);
3881 }
3882
John McCall8fb0d9d2011-05-01 22:35:37 +00003883 // The next parameter should have the same adjustment as the
3884 // last thing we pushed, but we post-incremented indexAdjustment
3885 // on every push. Also, if we push nothing, the adjustment should
3886 // go down by one.
3887 indexAdjustment--;
3888
Douglas Gregor5499af42011-01-05 23:12:31 +00003889 // We're done with the pack expansion.
3890 continue;
3891 }
3892
3893 // We'll substitute the parameter now without expanding the pack
3894 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003895 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3896 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003897 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003898 NumExpansions);
3899 } else {
3900 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003901 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003902 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003903 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003904
John McCall58f10c32010-03-11 09:03:00 +00003905 if (!NewParm)
3906 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003907
Douglas Gregordd472162011-01-07 00:20:55 +00003908 OutParamTypes.push_back(NewParm->getType());
3909 if (PVars)
3910 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003911 continue;
3912 }
John McCall58f10c32010-03-11 09:03:00 +00003913
3914 // Deal with the possibility that we don't have a parameter
3915 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003916 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003917 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003918 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003919 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003920 if (const PackExpansionType *Expansion
3921 = dyn_cast<PackExpansionType>(OldType)) {
3922 // We have a function parameter pack that may need to be expanded.
3923 QualType Pattern = Expansion->getPattern();
3924 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3925 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3926
3927 // Determine whether we should expand the parameter packs.
3928 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003929 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003930 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003931 Unexpanded.data(),
3932 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003933 ShouldExpand,
3934 RetainExpansion,
3935 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003936 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003937 }
3938
3939 if (ShouldExpand) {
3940 // Expand the function parameter pack into multiple, separate
3941 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003942 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003943 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3944 QualType NewType = getDerived().TransformType(Pattern);
3945 if (NewType.isNull())
3946 return true;
John McCall58f10c32010-03-11 09:03:00 +00003947
Douglas Gregordd472162011-01-07 00:20:55 +00003948 OutParamTypes.push_back(NewType);
3949 if (PVars)
3950 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003951 }
3952
3953 // We're done with the pack expansion.
3954 continue;
3955 }
3956
Douglas Gregor48d24112011-01-10 20:53:55 +00003957 // If we're supposed to retain a pack expansion, do so by temporarily
3958 // forgetting the partially-substituted parameter pack.
3959 if (RetainExpansion) {
3960 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3961 QualType NewType = getDerived().TransformType(Pattern);
3962 if (NewType.isNull())
3963 return true;
3964
3965 OutParamTypes.push_back(NewType);
3966 if (PVars)
3967 PVars->push_back(0);
3968 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003969
Douglas Gregor5499af42011-01-05 23:12:31 +00003970 // We'll substitute the parameter now without expanding the pack
3971 // expansion.
3972 OldType = Expansion->getPattern();
3973 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003974 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3975 NewType = getDerived().TransformType(OldType);
3976 } else {
3977 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003978 }
3979
Douglas Gregor5499af42011-01-05 23:12:31 +00003980 if (NewType.isNull())
3981 return true;
3982
3983 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003984 NewType = getSema().Context.getPackExpansionType(NewType,
3985 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003986
Douglas Gregordd472162011-01-07 00:20:55 +00003987 OutParamTypes.push_back(NewType);
3988 if (PVars)
3989 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003990 }
3991
John McCall8fb0d9d2011-05-01 22:35:37 +00003992#ifndef NDEBUG
3993 if (PVars) {
3994 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3995 if (ParmVarDecl *parm = (*PVars)[i])
3996 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00003997 }
John McCall8fb0d9d2011-05-01 22:35:37 +00003998#endif
3999
4000 return false;
4001}
John McCall58f10c32010-03-11 09:03:00 +00004002
4003template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004004QualType
John McCall550e0c22009-10-21 00:40:46 +00004005TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004006 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004007 // Transform the parameters and return type.
4008 //
4009 // We instantiate in source order, with the return type first followed by
4010 // the parameters, because users tend to expect this (even if they shouldn't
4011 // rely on it!).
4012 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00004013 // When the function has a trailing return type, we instantiate the
4014 // parameters before the return type, since the return type can then refer
4015 // to the parameters themselves (via decltype, sizeof, etc.).
4016 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00004017 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00004018 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004019 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004020
Douglas Gregor7fb25412010-10-01 18:44:50 +00004021 QualType ResultType;
4022
4023 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004024 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4025 TL.getParmArray(),
4026 TL.getNumArgs(),
4027 TL.getTypePtr()->arg_type_begin(),
4028 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004029 return QualType();
4030
4031 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4032 if (ResultType.isNull())
4033 return QualType();
4034 }
4035 else {
4036 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4037 if (ResultType.isNull())
4038 return QualType();
4039
Douglas Gregordd472162011-01-07 00:20:55 +00004040 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4041 TL.getParmArray(),
4042 TL.getNumArgs(),
4043 TL.getTypePtr()->arg_type_begin(),
4044 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004045 return QualType();
4046 }
4047
John McCall550e0c22009-10-21 00:40:46 +00004048 QualType Result = TL.getType();
4049 if (getDerived().AlwaysRebuild() ||
4050 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004051 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004052 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4053 Result = getDerived().RebuildFunctionProtoType(ResultType,
4054 ParamTypes.data(),
4055 ParamTypes.size(),
4056 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004057 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004058 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004059 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004060 if (Result.isNull())
4061 return QualType();
4062 }
Mike Stump11289f42009-09-09 15:08:12 +00004063
John McCall550e0c22009-10-21 00:40:46 +00004064 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004065 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4066 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004067 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004068 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4069 NewTL.setArg(i, ParamDecls[i]);
4070
4071 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004072}
Mike Stump11289f42009-09-09 15:08:12 +00004073
Douglas Gregord6ff3322009-08-04 16:50:30 +00004074template<typename Derived>
4075QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004076 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004077 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004078 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004079 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4080 if (ResultType.isNull())
4081 return QualType();
4082
4083 QualType Result = TL.getType();
4084 if (getDerived().AlwaysRebuild() ||
4085 ResultType != T->getResultType())
4086 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4087
4088 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004089 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4090 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004091 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004092
4093 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004094}
Mike Stump11289f42009-09-09 15:08:12 +00004095
John McCallb96ec562009-12-04 22:46:56 +00004096template<typename Derived> QualType
4097TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004098 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004099 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004100 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004101 if (!D)
4102 return QualType();
4103
4104 QualType Result = TL.getType();
4105 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4106 Result = getDerived().RebuildUnresolvedUsingType(D);
4107 if (Result.isNull())
4108 return QualType();
4109 }
4110
4111 // We might get an arbitrary type spec type back. We should at
4112 // least always get a type spec type, though.
4113 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4114 NewTL.setNameLoc(TL.getNameLoc());
4115
4116 return Result;
4117}
4118
Douglas Gregord6ff3322009-08-04 16:50:30 +00004119template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004120QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004121 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004122 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004123 TypedefNameDecl *Typedef
4124 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4125 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004126 if (!Typedef)
4127 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004128
John McCall550e0c22009-10-21 00:40:46 +00004129 QualType Result = TL.getType();
4130 if (getDerived().AlwaysRebuild() ||
4131 Typedef != T->getDecl()) {
4132 Result = getDerived().RebuildTypedefType(Typedef);
4133 if (Result.isNull())
4134 return QualType();
4135 }
Mike Stump11289f42009-09-09 15:08:12 +00004136
John McCall550e0c22009-10-21 00:40:46 +00004137 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4138 NewTL.setNameLoc(TL.getNameLoc());
4139
4140 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004141}
Mike Stump11289f42009-09-09 15:08:12 +00004142
Douglas Gregord6ff3322009-08-04 16:50:30 +00004143template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004144QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004145 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004146 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004147 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004148
John McCalldadc5752010-08-24 06:29:42 +00004149 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004150 if (E.isInvalid())
4151 return QualType();
4152
John McCall550e0c22009-10-21 00:40:46 +00004153 QualType Result = TL.getType();
4154 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004155 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004156 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004157 if (Result.isNull())
4158 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004159 }
John McCall550e0c22009-10-21 00:40:46 +00004160 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004161
John McCall550e0c22009-10-21 00:40:46 +00004162 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004163 NewTL.setTypeofLoc(TL.getTypeofLoc());
4164 NewTL.setLParenLoc(TL.getLParenLoc());
4165 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004166
4167 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004168}
Mike Stump11289f42009-09-09 15:08:12 +00004169
4170template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004171QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004172 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004173 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4174 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4175 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004176 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004177
John McCall550e0c22009-10-21 00:40:46 +00004178 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004179 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4180 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004181 if (Result.isNull())
4182 return QualType();
4183 }
Mike Stump11289f42009-09-09 15:08:12 +00004184
John McCall550e0c22009-10-21 00:40:46 +00004185 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004186 NewTL.setTypeofLoc(TL.getTypeofLoc());
4187 NewTL.setLParenLoc(TL.getLParenLoc());
4188 NewTL.setRParenLoc(TL.getRParenLoc());
4189 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004190
4191 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004192}
Mike Stump11289f42009-09-09 15:08:12 +00004193
4194template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004195QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004196 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004197 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004198
Douglas Gregore922c772009-08-04 22:27:00 +00004199 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004200 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004201
John McCalldadc5752010-08-24 06:29:42 +00004202 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004203 if (E.isInvalid())
4204 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004205
John McCall550e0c22009-10-21 00:40:46 +00004206 QualType Result = TL.getType();
4207 if (getDerived().AlwaysRebuild() ||
4208 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004209 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004210 if (Result.isNull())
4211 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004212 }
John McCall550e0c22009-10-21 00:40:46 +00004213 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004214
John McCall550e0c22009-10-21 00:40:46 +00004215 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4216 NewTL.setNameLoc(TL.getNameLoc());
4217
4218 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004219}
4220
4221template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004222QualType TreeTransform<Derived>::TransformUnaryTransformType(
4223 TypeLocBuilder &TLB,
4224 UnaryTransformTypeLoc TL) {
4225 QualType Result = TL.getType();
4226 if (Result->isDependentType()) {
4227 const UnaryTransformType *T = TL.getTypePtr();
4228 QualType NewBase =
4229 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4230 Result = getDerived().RebuildUnaryTransformType(NewBase,
4231 T->getUTTKind(),
4232 TL.getKWLoc());
4233 if (Result.isNull())
4234 return QualType();
4235 }
4236
4237 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4238 NewTL.setKWLoc(TL.getKWLoc());
4239 NewTL.setParensRange(TL.getParensRange());
4240 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4241 return Result;
4242}
4243
4244template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004245QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4246 AutoTypeLoc TL) {
4247 const AutoType *T = TL.getTypePtr();
4248 QualType OldDeduced = T->getDeducedType();
4249 QualType NewDeduced;
4250 if (!OldDeduced.isNull()) {
4251 NewDeduced = getDerived().TransformType(OldDeduced);
4252 if (NewDeduced.isNull())
4253 return QualType();
4254 }
4255
4256 QualType Result = TL.getType();
4257 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4258 Result = getDerived().RebuildAutoType(NewDeduced);
4259 if (Result.isNull())
4260 return QualType();
4261 }
4262
4263 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4264 NewTL.setNameLoc(TL.getNameLoc());
4265
4266 return Result;
4267}
4268
4269template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004270QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004271 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004272 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004273 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004274 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4275 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004276 if (!Record)
4277 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004278
John McCall550e0c22009-10-21 00:40:46 +00004279 QualType Result = TL.getType();
4280 if (getDerived().AlwaysRebuild() ||
4281 Record != T->getDecl()) {
4282 Result = getDerived().RebuildRecordType(Record);
4283 if (Result.isNull())
4284 return QualType();
4285 }
Mike Stump11289f42009-09-09 15:08:12 +00004286
John McCall550e0c22009-10-21 00:40:46 +00004287 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4288 NewTL.setNameLoc(TL.getNameLoc());
4289
4290 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004291}
Mike Stump11289f42009-09-09 15:08:12 +00004292
4293template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004294QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004295 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004296 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004297 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004298 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4299 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004300 if (!Enum)
4301 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004302
John McCall550e0c22009-10-21 00:40:46 +00004303 QualType Result = TL.getType();
4304 if (getDerived().AlwaysRebuild() ||
4305 Enum != T->getDecl()) {
4306 Result = getDerived().RebuildEnumType(Enum);
4307 if (Result.isNull())
4308 return QualType();
4309 }
Mike Stump11289f42009-09-09 15:08:12 +00004310
John McCall550e0c22009-10-21 00:40:46 +00004311 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4312 NewTL.setNameLoc(TL.getNameLoc());
4313
4314 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004315}
John McCallfcc33b02009-09-05 00:15:47 +00004316
John McCalle78aac42010-03-10 03:28:59 +00004317template<typename Derived>
4318QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4319 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004320 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004321 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4322 TL.getTypePtr()->getDecl());
4323 if (!D) return QualType();
4324
4325 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4326 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4327 return T;
4328}
4329
Douglas Gregord6ff3322009-08-04 16:50:30 +00004330template<typename Derived>
4331QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004332 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004333 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004334 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004335}
4336
Mike Stump11289f42009-09-09 15:08:12 +00004337template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004338QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004339 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004340 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004341 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4342
4343 // Substitute into the replacement type, which itself might involve something
4344 // that needs to be transformed. This only tends to occur with default
4345 // template arguments of template template parameters.
4346 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4347 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4348 if (Replacement.isNull())
4349 return QualType();
4350
4351 // Always canonicalize the replacement type.
4352 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4353 QualType Result
4354 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4355 Replacement);
4356
4357 // Propagate type-source information.
4358 SubstTemplateTypeParmTypeLoc NewTL
4359 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4360 NewTL.setNameLoc(TL.getNameLoc());
4361 return Result;
4362
John McCallcebee162009-10-18 09:09:24 +00004363}
4364
4365template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004366QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4367 TypeLocBuilder &TLB,
4368 SubstTemplateTypeParmPackTypeLoc TL) {
4369 return TransformTypeSpecType(TLB, TL);
4370}
4371
4372template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004373QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004374 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004375 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004376 const TemplateSpecializationType *T = TL.getTypePtr();
4377
Douglas Gregordf846d12011-03-02 18:46:51 +00004378 // The nested-name-specifier never matters in a TemplateSpecializationType,
4379 // because we can't have a dependent nested-name-specifier anyway.
4380 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004381 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004382 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4383 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004384 if (Template.isNull())
4385 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004386
John McCall31f82722010-11-12 08:19:04 +00004387 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4388}
4389
Douglas Gregorfe921a72010-12-20 23:36:19 +00004390namespace {
4391 /// \brief Simple iterator that traverses the template arguments in a
4392 /// container that provides a \c getArgLoc() member function.
4393 ///
4394 /// This iterator is intended to be used with the iterator form of
4395 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4396 template<typename ArgLocContainer>
4397 class TemplateArgumentLocContainerIterator {
4398 ArgLocContainer *Container;
4399 unsigned Index;
4400
4401 public:
4402 typedef TemplateArgumentLoc value_type;
4403 typedef TemplateArgumentLoc reference;
4404 typedef int difference_type;
4405 typedef std::input_iterator_tag iterator_category;
4406
4407 class pointer {
4408 TemplateArgumentLoc Arg;
4409
4410 public:
4411 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4412
4413 const TemplateArgumentLoc *operator->() const {
4414 return &Arg;
4415 }
4416 };
4417
4418
4419 TemplateArgumentLocContainerIterator() {}
4420
4421 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4422 unsigned Index)
4423 : Container(&Container), Index(Index) { }
4424
4425 TemplateArgumentLocContainerIterator &operator++() {
4426 ++Index;
4427 return *this;
4428 }
4429
4430 TemplateArgumentLocContainerIterator operator++(int) {
4431 TemplateArgumentLocContainerIterator Old(*this);
4432 ++(*this);
4433 return Old;
4434 }
4435
4436 TemplateArgumentLoc operator*() const {
4437 return Container->getArgLoc(Index);
4438 }
4439
4440 pointer operator->() const {
4441 return pointer(Container->getArgLoc(Index));
4442 }
4443
4444 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004445 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004446 return X.Container == Y.Container && X.Index == Y.Index;
4447 }
4448
4449 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004450 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004451 return !(X == Y);
4452 }
4453 };
4454}
4455
4456
John McCall31f82722010-11-12 08:19:04 +00004457template <typename Derived>
4458QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4459 TypeLocBuilder &TLB,
4460 TemplateSpecializationTypeLoc TL,
4461 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004462 TemplateArgumentListInfo NewTemplateArgs;
4463 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4464 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004465 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4466 ArgIterator;
4467 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4468 ArgIterator(TL, TL.getNumArgs()),
4469 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004470 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004471
John McCall0ad16662009-10-29 08:12:44 +00004472 // FIXME: maybe don't rebuild if all the template arguments are the same.
4473
4474 QualType Result =
4475 getDerived().RebuildTemplateSpecializationType(Template,
4476 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004477 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004478
4479 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004480 // Specializations of template template parameters are represented as
4481 // TemplateSpecializationTypes, and substitution of type alias templates
4482 // within a dependent context can transform them into
4483 // DependentTemplateSpecializationTypes.
4484 if (isa<DependentTemplateSpecializationType>(Result)) {
4485 DependentTemplateSpecializationTypeLoc NewTL
4486 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4487 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4488 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4489 NewTL.setNameLoc(TL.getTemplateNameLoc());
4490 NewTL.setLAngleLoc(TL.getLAngleLoc());
4491 NewTL.setRAngleLoc(TL.getRAngleLoc());
4492 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4493 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4494 return Result;
4495 }
4496
John McCall0ad16662009-10-29 08:12:44 +00004497 TemplateSpecializationTypeLoc NewTL
4498 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4499 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4500 NewTL.setLAngleLoc(TL.getLAngleLoc());
4501 NewTL.setRAngleLoc(TL.getRAngleLoc());
4502 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4503 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004504 }
Mike Stump11289f42009-09-09 15:08:12 +00004505
John McCall0ad16662009-10-29 08:12:44 +00004506 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004507}
Mike Stump11289f42009-09-09 15:08:12 +00004508
Douglas Gregor5a064722011-02-28 17:23:35 +00004509template <typename Derived>
4510QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4511 TypeLocBuilder &TLB,
4512 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004513 TemplateName Template,
4514 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004515 TemplateArgumentListInfo NewTemplateArgs;
4516 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4517 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4518 typedef TemplateArgumentLocContainerIterator<
4519 DependentTemplateSpecializationTypeLoc> ArgIterator;
4520 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4521 ArgIterator(TL, TL.getNumArgs()),
4522 NewTemplateArgs))
4523 return QualType();
4524
4525 // FIXME: maybe don't rebuild if all the template arguments are the same.
4526
4527 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4528 QualType Result
4529 = getSema().Context.getDependentTemplateSpecializationType(
4530 TL.getTypePtr()->getKeyword(),
4531 DTN->getQualifier(),
4532 DTN->getIdentifier(),
4533 NewTemplateArgs);
4534
4535 DependentTemplateSpecializationTypeLoc NewTL
4536 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4537 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004538
Douglas Gregora7a795b2011-03-01 20:11:18 +00004539 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004540 NewTL.setNameLoc(TL.getNameLoc());
4541 NewTL.setLAngleLoc(TL.getLAngleLoc());
4542 NewTL.setRAngleLoc(TL.getRAngleLoc());
4543 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4544 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4545 return Result;
4546 }
4547
4548 QualType Result
4549 = getDerived().RebuildTemplateSpecializationType(Template,
4550 TL.getNameLoc(),
4551 NewTemplateArgs);
4552
4553 if (!Result.isNull()) {
4554 /// FIXME: Wrap this in an elaborated-type-specifier?
4555 TemplateSpecializationTypeLoc NewTL
4556 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4557 NewTL.setTemplateNameLoc(TL.getNameLoc());
4558 NewTL.setLAngleLoc(TL.getLAngleLoc());
4559 NewTL.setRAngleLoc(TL.getRAngleLoc());
4560 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4561 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4562 }
4563
4564 return Result;
4565}
4566
Mike Stump11289f42009-09-09 15:08:12 +00004567template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004568QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004569TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004570 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004571 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004572
Douglas Gregor844cb502011-03-01 18:12:44 +00004573 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004574 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004575 if (TL.getQualifierLoc()) {
4576 QualifierLoc
4577 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4578 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004579 return QualType();
4580 }
Mike Stump11289f42009-09-09 15:08:12 +00004581
John McCall31f82722010-11-12 08:19:04 +00004582 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4583 if (NamedT.isNull())
4584 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004585
Richard Smith3f1b5d02011-05-05 21:57:07 +00004586 // C++0x [dcl.type.elab]p2:
4587 // If the identifier resolves to a typedef-name or the simple-template-id
4588 // resolves to an alias template specialization, the
4589 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004590 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4591 if (const TemplateSpecializationType *TST =
4592 NamedT->getAs<TemplateSpecializationType>()) {
4593 TemplateName Template = TST->getTemplateName();
4594 if (TypeAliasTemplateDecl *TAT =
4595 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4596 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4597 diag::err_tag_reference_non_tag) << 4;
4598 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4599 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004600 }
4601 }
4602
John McCall550e0c22009-10-21 00:40:46 +00004603 QualType Result = TL.getType();
4604 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004605 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004606 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004607 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004608 T->getKeyword(),
4609 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004610 if (Result.isNull())
4611 return QualType();
4612 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004613
Abramo Bagnara6150c882010-05-11 21:36:43 +00004614 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004615 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004616 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004617 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004618}
Mike Stump11289f42009-09-09 15:08:12 +00004619
4620template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004621QualType TreeTransform<Derived>::TransformAttributedType(
4622 TypeLocBuilder &TLB,
4623 AttributedTypeLoc TL) {
4624 const AttributedType *oldType = TL.getTypePtr();
4625 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4626 if (modifiedType.isNull())
4627 return QualType();
4628
4629 QualType result = TL.getType();
4630
4631 // FIXME: dependent operand expressions?
4632 if (getDerived().AlwaysRebuild() ||
4633 modifiedType != oldType->getModifiedType()) {
4634 // TODO: this is really lame; we should really be rebuilding the
4635 // equivalent type from first principles.
4636 QualType equivalentType
4637 = getDerived().TransformType(oldType->getEquivalentType());
4638 if (equivalentType.isNull())
4639 return QualType();
4640 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4641 modifiedType,
4642 equivalentType);
4643 }
4644
4645 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4646 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4647 if (TL.hasAttrOperand())
4648 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4649 if (TL.hasAttrExprOperand())
4650 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4651 else if (TL.hasAttrEnumOperand())
4652 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4653
4654 return result;
4655}
4656
4657template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004658QualType
4659TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4660 ParenTypeLoc TL) {
4661 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4662 if (Inner.isNull())
4663 return QualType();
4664
4665 QualType Result = TL.getType();
4666 if (getDerived().AlwaysRebuild() ||
4667 Inner != TL.getInnerLoc().getType()) {
4668 Result = getDerived().RebuildParenType(Inner);
4669 if (Result.isNull())
4670 return QualType();
4671 }
4672
4673 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4674 NewTL.setLParenLoc(TL.getLParenLoc());
4675 NewTL.setRParenLoc(TL.getRParenLoc());
4676 return Result;
4677}
4678
4679template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004680QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004681 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004682 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004683
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004684 NestedNameSpecifierLoc QualifierLoc
4685 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4686 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004687 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004688
John McCallc392f372010-06-11 00:33:02 +00004689 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004690 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004691 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004692 QualifierLoc,
4693 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004694 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004695 if (Result.isNull())
4696 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004697
Abramo Bagnarad7548482010-05-19 21:37:53 +00004698 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4699 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004700 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4701
Abramo Bagnarad7548482010-05-19 21:37:53 +00004702 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4703 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004704 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004705 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004706 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4707 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004708 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004709 NewTL.setNameLoc(TL.getNameLoc());
4710 }
John McCall550e0c22009-10-21 00:40:46 +00004711 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004712}
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregord6ff3322009-08-04 16:50:30 +00004714template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004715QualType TreeTransform<Derived>::
4716 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004717 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004718 NestedNameSpecifierLoc QualifierLoc;
4719 if (TL.getQualifierLoc()) {
4720 QualifierLoc
4721 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4722 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004723 return QualType();
4724 }
4725
John McCall31f82722010-11-12 08:19:04 +00004726 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004727 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004728}
4729
4730template<typename Derived>
4731QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004732TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4733 DependentTemplateSpecializationTypeLoc TL,
4734 NestedNameSpecifierLoc QualifierLoc) {
4735 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4736
4737 TemplateArgumentListInfo NewTemplateArgs;
4738 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4739 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4740
4741 typedef TemplateArgumentLocContainerIterator<
4742 DependentTemplateSpecializationTypeLoc> ArgIterator;
4743 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4744 ArgIterator(TL, TL.getNumArgs()),
4745 NewTemplateArgs))
4746 return QualType();
4747
4748 QualType Result
4749 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4750 QualifierLoc,
4751 T->getIdentifier(),
4752 TL.getNameLoc(),
4753 NewTemplateArgs);
4754 if (Result.isNull())
4755 return QualType();
4756
4757 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4758 QualType NamedT = ElabT->getNamedType();
4759
4760 // Copy information relevant to the template specialization.
4761 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004762 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004763 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004764 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4765 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004766 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004767 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004768
4769 // Copy information relevant to the elaborated type.
4770 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4771 NewTL.setKeywordLoc(TL.getKeywordLoc());
4772 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004773 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4774 DependentTemplateSpecializationTypeLoc SpecTL
4775 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004776 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004777 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004778 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004779 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4780 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004781 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004782 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004783 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004784 TemplateSpecializationTypeLoc SpecTL
4785 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004786 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004787 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4788 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004789 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004790 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004791 }
4792 return Result;
4793}
4794
4795template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004796QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4797 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004798 QualType Pattern
4799 = getDerived().TransformType(TLB, TL.getPatternLoc());
4800 if (Pattern.isNull())
4801 return QualType();
4802
4803 QualType Result = TL.getType();
4804 if (getDerived().AlwaysRebuild() ||
4805 Pattern != TL.getPatternLoc().getType()) {
4806 Result = getDerived().RebuildPackExpansionType(Pattern,
4807 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004808 TL.getEllipsisLoc(),
4809 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004810 if (Result.isNull())
4811 return QualType();
4812 }
4813
4814 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4815 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4816 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004817}
4818
4819template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004820QualType
4821TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004822 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004823 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004824 TLB.pushFullCopy(TL);
4825 return TL.getType();
4826}
4827
4828template<typename Derived>
4829QualType
4830TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004831 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004832 // ObjCObjectType is never dependent.
4833 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004834 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004835}
Mike Stump11289f42009-09-09 15:08:12 +00004836
4837template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004838QualType
4839TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004840 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004841 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004842 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004843 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004844}
4845
Douglas Gregord6ff3322009-08-04 16:50:30 +00004846//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004847// Statement transformation
4848//===----------------------------------------------------------------------===//
4849template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004850StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004851TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004852 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004853}
4854
4855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004856StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004857TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4858 return getDerived().TransformCompoundStmt(S, false);
4859}
4860
4861template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004862StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004863TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004864 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004865 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004866 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004867 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004868 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4869 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004870 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004871 if (Result.isInvalid()) {
4872 // Immediately fail if this was a DeclStmt, since it's very
4873 // likely that this will cause problems for future statements.
4874 if (isa<DeclStmt>(*B))
4875 return StmtError();
4876
4877 // Otherwise, just keep processing substatements and fail later.
4878 SubStmtInvalid = true;
4879 continue;
4880 }
Mike Stump11289f42009-09-09 15:08:12 +00004881
Douglas Gregorebe10102009-08-20 07:17:43 +00004882 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4883 Statements.push_back(Result.takeAs<Stmt>());
4884 }
Mike Stump11289f42009-09-09 15:08:12 +00004885
John McCall1ababa62010-08-27 19:56:05 +00004886 if (SubStmtInvalid)
4887 return StmtError();
4888
Douglas Gregorebe10102009-08-20 07:17:43 +00004889 if (!getDerived().AlwaysRebuild() &&
4890 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004891 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004892
4893 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4894 move_arg(Statements),
4895 S->getRBracLoc(),
4896 IsStmtExpr);
4897}
Mike Stump11289f42009-09-09 15:08:12 +00004898
Douglas Gregorebe10102009-08-20 07:17:43 +00004899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004900StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004901TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004902 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004903 {
4904 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004905 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004906
Eli Friedman06577382009-11-19 03:14:00 +00004907 // Transform the left-hand case value.
4908 LHS = getDerived().TransformExpr(S->getLHS());
4909 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004910 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004911
Eli Friedman06577382009-11-19 03:14:00 +00004912 // Transform the right-hand case value (for the GNU case-range extension).
4913 RHS = getDerived().TransformExpr(S->getRHS());
4914 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004915 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004916 }
Mike Stump11289f42009-09-09 15:08:12 +00004917
Douglas Gregorebe10102009-08-20 07:17:43 +00004918 // Build the case statement.
4919 // Case statements are always rebuilt so that they will attached to their
4920 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004921 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004922 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004923 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004924 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004925 S->getColonLoc());
4926 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004927 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004928
Douglas Gregorebe10102009-08-20 07:17:43 +00004929 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004930 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004931 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004932 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004933
Douglas Gregorebe10102009-08-20 07:17:43 +00004934 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004935 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004936}
4937
4938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004939StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004940TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004941 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004942 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004943 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004944 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004945
Douglas Gregorebe10102009-08-20 07:17:43 +00004946 // Default statements are always rebuilt
4947 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004948 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004949}
Mike Stump11289f42009-09-09 15:08:12 +00004950
Douglas Gregorebe10102009-08-20 07:17:43 +00004951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004952StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004953TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004954 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004955 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004956 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004957
Chris Lattnercab02a62011-02-17 20:34:02 +00004958 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4959 S->getDecl());
4960 if (!LD)
4961 return StmtError();
4962
4963
Douglas Gregorebe10102009-08-20 07:17:43 +00004964 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004965 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004966 cast<LabelDecl>(LD), SourceLocation(),
4967 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004968}
Mike Stump11289f42009-09-09 15:08:12 +00004969
Douglas Gregorebe10102009-08-20 07:17:43 +00004970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004971StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004972TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004973 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004974 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004975 VarDecl *ConditionVar = 0;
4976 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004977 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004978 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004979 getDerived().TransformDefinition(
4980 S->getConditionVariable()->getLocation(),
4981 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004982 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004983 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004984 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004985 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004986
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004987 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004988 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004989
4990 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004991 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004992 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4993 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004994 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004995 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004996
John McCallb268a282010-08-23 23:25:46 +00004997 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004998 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004999 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005000
John McCallb268a282010-08-23 23:25:46 +00005001 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5002 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005003 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005004
Douglas Gregorebe10102009-08-20 07:17:43 +00005005 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005006 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005007 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005008 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005009
Douglas Gregorebe10102009-08-20 07:17:43 +00005010 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005011 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005012 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005013 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005014
Douglas Gregorebe10102009-08-20 07:17:43 +00005015 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005016 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005017 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005018 Then.get() == S->getThen() &&
5019 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005020 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005021
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005022 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005023 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005024 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005025}
5026
5027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005028StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005029TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005030 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005031 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005032 VarDecl *ConditionVar = 0;
5033 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005034 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005035 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005036 getDerived().TransformDefinition(
5037 S->getConditionVariable()->getLocation(),
5038 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005039 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005040 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005041 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005042 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005043
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005044 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005045 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005046 }
Mike Stump11289f42009-09-09 15:08:12 +00005047
Douglas Gregorebe10102009-08-20 07:17:43 +00005048 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005049 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005050 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005051 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005052 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005053 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005054
Douglas Gregorebe10102009-08-20 07:17:43 +00005055 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005056 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005057 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005058 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005059
Douglas Gregorebe10102009-08-20 07:17:43 +00005060 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005061 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5062 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005063}
Mike Stump11289f42009-09-09 15:08:12 +00005064
Douglas Gregorebe10102009-08-20 07:17:43 +00005065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005066StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005067TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005068 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005069 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005070 VarDecl *ConditionVar = 0;
5071 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005072 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005073 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005074 getDerived().TransformDefinition(
5075 S->getConditionVariable()->getLocation(),
5076 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005077 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005078 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005079 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005080 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005081
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005082 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005083 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005084
5085 if (S->getCond()) {
5086 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005087 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5088 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005089 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005090 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005091 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005092 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005093 }
Mike Stump11289f42009-09-09 15:08:12 +00005094
John McCallb268a282010-08-23 23:25:46 +00005095 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5096 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005097 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005098
Douglas Gregorebe10102009-08-20 07:17:43 +00005099 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005100 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005101 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005102 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005103
Douglas Gregorebe10102009-08-20 07:17:43 +00005104 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005105 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005106 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005107 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005108 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005109
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005110 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005111 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005112}
Mike Stump11289f42009-09-09 15:08:12 +00005113
Douglas Gregorebe10102009-08-20 07:17:43 +00005114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005115StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005116TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005117 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005118 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005119 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005120 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005121
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005122 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005123 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005124 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005125 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005126
Douglas Gregorebe10102009-08-20 07:17:43 +00005127 if (!getDerived().AlwaysRebuild() &&
5128 Cond.get() == S->getCond() &&
5129 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005130 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005131
John McCallb268a282010-08-23 23:25:46 +00005132 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5133 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005134 S->getRParenLoc());
5135}
Mike Stump11289f42009-09-09 15:08:12 +00005136
Douglas Gregorebe10102009-08-20 07:17:43 +00005137template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005138StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005139TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005140 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005141 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005142 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005143 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005144
Douglas Gregorebe10102009-08-20 07:17:43 +00005145 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005146 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005147 VarDecl *ConditionVar = 0;
5148 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005149 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005150 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005151 getDerived().TransformDefinition(
5152 S->getConditionVariable()->getLocation(),
5153 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005154 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005155 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005156 } else {
5157 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005158
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005159 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005160 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005161
5162 if (S->getCond()) {
5163 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005164 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5165 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005166 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005167 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005168
John McCallb268a282010-08-23 23:25:46 +00005169 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005170 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005171 }
Mike Stump11289f42009-09-09 15:08:12 +00005172
John McCallb268a282010-08-23 23:25:46 +00005173 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5174 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005175 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005176
Douglas Gregorebe10102009-08-20 07:17:43 +00005177 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005178 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005179 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005180 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005181
John McCallb268a282010-08-23 23:25:46 +00005182 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5183 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005184 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005185
Douglas Gregorebe10102009-08-20 07:17:43 +00005186 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005187 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005188 if (Body.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 if (!getDerived().AlwaysRebuild() &&
5192 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005193 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005194 Inc.get() == S->getInc() &&
5195 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005196 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005197
Douglas Gregorebe10102009-08-20 07:17:43 +00005198 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005199 Init.get(), FullCond, ConditionVar,
5200 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005201}
5202
5203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005204StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005205TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005206 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5207 S->getLabel());
5208 if (!LD)
5209 return StmtError();
5210
Douglas Gregorebe10102009-08-20 07:17:43 +00005211 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005212 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005213 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005214}
5215
5216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005217StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005218TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005219 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005220 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005221 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005222
Douglas Gregorebe10102009-08-20 07:17:43 +00005223 if (!getDerived().AlwaysRebuild() &&
5224 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005225 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005226
5227 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005228 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005229}
5230
5231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005232StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005233TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005234 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005235}
Mike Stump11289f42009-09-09 15:08:12 +00005236
Douglas Gregorebe10102009-08-20 07:17:43 +00005237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005238StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005239TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005240 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005241}
Mike Stump11289f42009-09-09 15:08:12 +00005242
Douglas Gregorebe10102009-08-20 07:17:43 +00005243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005244StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005245TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005246 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005247 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005248 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005249
Mike Stump11289f42009-09-09 15:08:12 +00005250 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005251 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005252 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005253}
Mike Stump11289f42009-09-09 15:08:12 +00005254
Douglas Gregorebe10102009-08-20 07:17:43 +00005255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005256StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005257TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005258 bool DeclChanged = false;
5259 llvm::SmallVector<Decl *, 4> Decls;
5260 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5261 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005262 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5263 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005264 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005265 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005266
Douglas Gregorebe10102009-08-20 07:17:43 +00005267 if (Transformed != *D)
5268 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005269
Douglas Gregorebe10102009-08-20 07:17:43 +00005270 Decls.push_back(Transformed);
5271 }
Mike Stump11289f42009-09-09 15:08:12 +00005272
Douglas Gregorebe10102009-08-20 07:17:43 +00005273 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005274 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005275
5276 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005277 S->getStartLoc(), S->getEndLoc());
5278}
Mike Stump11289f42009-09-09 15:08:12 +00005279
Douglas Gregorebe10102009-08-20 07:17:43 +00005280template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005281StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005282TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005283
John McCall37ad5512010-08-23 06:44:23 +00005284 ASTOwningVector<Expr*> Constraints(getSema());
5285 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005286 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005287
John McCalldadc5752010-08-24 06:29:42 +00005288 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005289 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005290
5291 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005292
Anders Carlssonaaeef072010-01-24 05:50:09 +00005293 // Go through the outputs.
5294 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005295 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005296
Anders Carlssonaaeef072010-01-24 05:50:09 +00005297 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005298 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005299
Anders Carlssonaaeef072010-01-24 05:50:09 +00005300 // Transform the output expr.
5301 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005302 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005303 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005304 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005305
Anders Carlssonaaeef072010-01-24 05:50:09 +00005306 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005307
John McCallb268a282010-08-23 23:25:46 +00005308 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005309 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005310
Anders Carlssonaaeef072010-01-24 05:50:09 +00005311 // Go through the inputs.
5312 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005313 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005314
Anders Carlssonaaeef072010-01-24 05:50:09 +00005315 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005316 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005317
Anders Carlssonaaeef072010-01-24 05:50:09 +00005318 // Transform the input expr.
5319 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005320 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005321 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005322 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005323
Anders Carlssonaaeef072010-01-24 05:50:09 +00005324 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005325
John McCallb268a282010-08-23 23:25:46 +00005326 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005327 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005328
Anders Carlssonaaeef072010-01-24 05:50:09 +00005329 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005330 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005331
5332 // Go through the clobbers.
5333 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005334 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005335
5336 // No need to transform the asm string literal.
5337 AsmString = SemaRef.Owned(S->getAsmString());
5338
5339 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5340 S->isSimple(),
5341 S->isVolatile(),
5342 S->getNumOutputs(),
5343 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005344 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005345 move_arg(Constraints),
5346 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005347 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005348 move_arg(Clobbers),
5349 S->getRParenLoc(),
5350 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005351}
5352
5353
5354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005355StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005356TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005357 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005358 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005359 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005360 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005361
Douglas Gregor96c79492010-04-23 22:50:49 +00005362 // Transform the @catch statements (if present).
5363 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005364 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005365 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005366 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005367 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005368 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005369 if (Catch.get() != S->getCatchStmt(I))
5370 AnyCatchChanged = true;
5371 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005372 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005373
Douglas Gregor306de2f2010-04-22 23:59:56 +00005374 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005375 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005376 if (S->getFinallyStmt()) {
5377 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5378 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005379 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005380 }
5381
5382 // If nothing changed, just retain this statement.
5383 if (!getDerived().AlwaysRebuild() &&
5384 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005385 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005386 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005387 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005388
Douglas Gregor306de2f2010-04-22 23:59:56 +00005389 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005390 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5391 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005392}
Mike Stump11289f42009-09-09 15:08:12 +00005393
Douglas Gregorebe10102009-08-20 07:17:43 +00005394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005395StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005396TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005397 // Transform the @catch parameter, if there is one.
5398 VarDecl *Var = 0;
5399 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5400 TypeSourceInfo *TSInfo = 0;
5401 if (FromVar->getTypeSourceInfo()) {
5402 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5403 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005404 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005405 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005406
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005407 QualType T;
5408 if (TSInfo)
5409 T = TSInfo->getType();
5410 else {
5411 T = getDerived().TransformType(FromVar->getType());
5412 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005413 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005414 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005415
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005416 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5417 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005418 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005419 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005420
John McCalldadc5752010-08-24 06:29:42 +00005421 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005422 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005423 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005424
5425 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005426 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005427 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005428}
Mike Stump11289f42009-09-09 15:08:12 +00005429
Douglas Gregorebe10102009-08-20 07:17:43 +00005430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005431StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005432TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005433 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005434 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005435 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005436 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005437
Douglas Gregor306de2f2010-04-22 23:59:56 +00005438 // If nothing changed, just retain this statement.
5439 if (!getDerived().AlwaysRebuild() &&
5440 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005441 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005442
5443 // Build a new statement.
5444 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005445 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005446}
Mike Stump11289f42009-09-09 15:08:12 +00005447
Douglas Gregorebe10102009-08-20 07:17:43 +00005448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005449StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005450TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005451 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005452 if (S->getThrowExpr()) {
5453 Operand = getDerived().TransformExpr(S->getThrowExpr());
5454 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005455 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005456 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005457
Douglas Gregor2900c162010-04-22 21:44:01 +00005458 if (!getDerived().AlwaysRebuild() &&
5459 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005460 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005461
John McCallb268a282010-08-23 23:25:46 +00005462 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005463}
Mike Stump11289f42009-09-09 15:08:12 +00005464
Douglas Gregorebe10102009-08-20 07:17:43 +00005465template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005466StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005467TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005468 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005469 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005470 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005471 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005472 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005473
Douglas Gregor6148de72010-04-22 22:01:21 +00005474 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005475 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005476 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005477 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005478
Douglas Gregor6148de72010-04-22 22:01:21 +00005479 // If nothing change, just retain the current statement.
5480 if (!getDerived().AlwaysRebuild() &&
5481 Object.get() == S->getSynchExpr() &&
5482 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005483 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005484
5485 // Build a new statement.
5486 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005487 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005488}
5489
5490template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005491StmtResult
John McCall31168b02011-06-15 23:02:42 +00005492TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5493 ObjCAutoreleasePoolStmt *S) {
5494 // Transform the body.
5495 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5496 if (Body.isInvalid())
5497 return StmtError();
5498
5499 // If nothing changed, just retain this statement.
5500 if (!getDerived().AlwaysRebuild() &&
5501 Body.get() == S->getSubStmt())
5502 return SemaRef.Owned(S);
5503
5504 // Build a new statement.
5505 return getDerived().RebuildObjCAutoreleasePoolStmt(
5506 S->getAtLoc(), Body.get());
5507}
5508
5509template<typename Derived>
5510StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005511TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005512 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005513 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005514 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005515 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005516 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005517
Douglas Gregorf68a5082010-04-22 23:10:45 +00005518 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005519 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005520 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005521 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005522
Douglas Gregorf68a5082010-04-22 23:10:45 +00005523 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005524 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005525 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005526 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005527
Douglas Gregorf68a5082010-04-22 23:10:45 +00005528 // If nothing changed, just retain this statement.
5529 if (!getDerived().AlwaysRebuild() &&
5530 Element.get() == S->getElement() &&
5531 Collection.get() == S->getCollection() &&
5532 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005533 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005534
Douglas Gregorf68a5082010-04-22 23:10:45 +00005535 // Build a new statement.
5536 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5537 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005538 Element.get(),
5539 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005540 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005541 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005542}
5543
5544
5545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005546StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005547TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5548 // Transform the exception declaration, if any.
5549 VarDecl *Var = 0;
5550 if (S->getExceptionDecl()) {
5551 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005552 TypeSourceInfo *T = getDerived().TransformType(
5553 ExceptionDecl->getTypeSourceInfo());
5554 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005555 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005556
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005557 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005558 ExceptionDecl->getInnerLocStart(),
5559 ExceptionDecl->getLocation(),
5560 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005561 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005562 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005563 }
Mike Stump11289f42009-09-09 15:08:12 +00005564
Douglas Gregorebe10102009-08-20 07:17:43 +00005565 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005566 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005567 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005568 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005569
Douglas Gregorebe10102009-08-20 07:17:43 +00005570 if (!getDerived().AlwaysRebuild() &&
5571 !Var &&
5572 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005573 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005574
5575 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5576 Var,
John McCallb268a282010-08-23 23:25:46 +00005577 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005578}
Mike Stump11289f42009-09-09 15:08:12 +00005579
Douglas Gregorebe10102009-08-20 07:17:43 +00005580template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005581StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005582TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5583 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005584 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005585 = getDerived().TransformCompoundStmt(S->getTryBlock());
5586 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005587 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005588
Douglas Gregorebe10102009-08-20 07:17:43 +00005589 // Transform the handlers.
5590 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005591 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005592 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005593 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005594 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5595 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005596 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005597
Douglas Gregorebe10102009-08-20 07:17:43 +00005598 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5599 Handlers.push_back(Handler.takeAs<Stmt>());
5600 }
Mike Stump11289f42009-09-09 15:08:12 +00005601
Douglas Gregorebe10102009-08-20 07:17:43 +00005602 if (!getDerived().AlwaysRebuild() &&
5603 TryBlock.get() == S->getTryBlock() &&
5604 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005605 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005606
John McCallb268a282010-08-23 23:25:46 +00005607 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005608 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005609}
Mike Stump11289f42009-09-09 15:08:12 +00005610
Richard Smith02e85f32011-04-14 22:09:26 +00005611template<typename Derived>
5612StmtResult
5613TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5614 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5615 if (Range.isInvalid())
5616 return StmtError();
5617
5618 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5619 if (BeginEnd.isInvalid())
5620 return StmtError();
5621
5622 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5623 if (Cond.isInvalid())
5624 return StmtError();
5625
5626 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5627 if (Inc.isInvalid())
5628 return StmtError();
5629
5630 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5631 if (LoopVar.isInvalid())
5632 return StmtError();
5633
5634 StmtResult NewStmt = S;
5635 if (getDerived().AlwaysRebuild() ||
5636 Range.get() != S->getRangeStmt() ||
5637 BeginEnd.get() != S->getBeginEndStmt() ||
5638 Cond.get() != S->getCond() ||
5639 Inc.get() != S->getInc() ||
5640 LoopVar.get() != S->getLoopVarStmt())
5641 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5642 S->getColonLoc(), Range.get(),
5643 BeginEnd.get(), Cond.get(),
5644 Inc.get(), LoopVar.get(),
5645 S->getRParenLoc());
5646
5647 StmtResult Body = getDerived().TransformStmt(S->getBody());
5648 if (Body.isInvalid())
5649 return StmtError();
5650
5651 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5652 // it now so we have a new statement to attach the body to.
5653 if (Body.get() != S->getBody() && NewStmt.get() == S)
5654 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5655 S->getColonLoc(), Range.get(),
5656 BeginEnd.get(), Cond.get(),
5657 Inc.get(), LoopVar.get(),
5658 S->getRParenLoc());
5659
5660 if (NewStmt.get() == S)
5661 return SemaRef.Owned(S);
5662
5663 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5664}
5665
John Wiegley1c0675e2011-04-28 01:08:34 +00005666template<typename Derived>
5667StmtResult
5668TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5669 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5670 if(TryBlock.isInvalid()) return StmtError();
5671
5672 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5673 if(!getDerived().AlwaysRebuild() &&
5674 TryBlock.get() == S->getTryBlock() &&
5675 Handler.get() == S->getHandler())
5676 return SemaRef.Owned(S);
5677
5678 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5679 S->getTryLoc(),
5680 TryBlock.take(),
5681 Handler.take());
5682}
5683
5684template<typename Derived>
5685StmtResult
5686TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5687 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5688 if(Block.isInvalid()) return StmtError();
5689
5690 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5691 Block.take());
5692}
5693
5694template<typename Derived>
5695StmtResult
5696TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5697 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5698 if(FilterExpr.isInvalid()) return StmtError();
5699
5700 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5701 if(Block.isInvalid()) return StmtError();
5702
5703 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5704 FilterExpr.take(),
5705 Block.take());
5706}
5707
5708template<typename Derived>
5709StmtResult
5710TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5711 if(isa<SEHFinallyStmt>(Handler))
5712 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5713 else
5714 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5715}
5716
Douglas Gregorebe10102009-08-20 07:17:43 +00005717//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005718// Expression transformation
5719//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005721ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005722TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005723 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005724}
Mike Stump11289f42009-09-09 15:08:12 +00005725
5726template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005727ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005728TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005729 NestedNameSpecifierLoc QualifierLoc;
5730 if (E->getQualifierLoc()) {
5731 QualifierLoc
5732 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5733 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005734 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005735 }
John McCallce546572009-12-08 09:08:17 +00005736
5737 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005738 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5739 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005740 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005741 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005742
John McCall815039a2010-08-17 21:27:17 +00005743 DeclarationNameInfo NameInfo = E->getNameInfo();
5744 if (NameInfo.getName()) {
5745 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5746 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005747 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005748 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005749
5750 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005751 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005752 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005753 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005754 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005755
5756 // Mark it referenced in the new context regardless.
5757 // FIXME: this is a bit instantiation-specific.
5758 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5759
John McCallc3007a22010-10-26 07:05:15 +00005760 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005761 }
John McCallce546572009-12-08 09:08:17 +00005762
5763 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005764 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005765 TemplateArgs = &TransArgs;
5766 TransArgs.setLAngleLoc(E->getLAngleLoc());
5767 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005768 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5769 E->getNumTemplateArgs(),
5770 TransArgs))
5771 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005772 }
5773
Douglas Gregorea972d32011-02-28 21:54:11 +00005774 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5775 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005776}
Mike Stump11289f42009-09-09 15:08:12 +00005777
Douglas Gregora16548e2009-08-11 05:31:07 +00005778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005779ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005780TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005781 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005782}
Mike Stump11289f42009-09-09 15:08:12 +00005783
Douglas Gregora16548e2009-08-11 05:31:07 +00005784template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005785ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005786TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005787 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005788}
Mike Stump11289f42009-09-09 15:08:12 +00005789
Douglas Gregora16548e2009-08-11 05:31:07 +00005790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005791ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005792TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005793 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005794}
Mike Stump11289f42009-09-09 15:08:12 +00005795
Douglas Gregora16548e2009-08-11 05:31:07 +00005796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005797ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005798TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005799 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005800}
Mike Stump11289f42009-09-09 15:08:12 +00005801
Douglas Gregora16548e2009-08-11 05:31:07 +00005802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005803ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005804TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005805 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005806}
5807
5808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005809ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005810TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5811 ExprResult ControllingExpr =
5812 getDerived().TransformExpr(E->getControllingExpr());
5813 if (ControllingExpr.isInvalid())
5814 return ExprError();
5815
5816 llvm::SmallVector<Expr *, 4> AssocExprs;
5817 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5818 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5819 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5820 if (TS) {
5821 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5822 if (!AssocType)
5823 return ExprError();
5824 AssocTypes.push_back(AssocType);
5825 } else {
5826 AssocTypes.push_back(0);
5827 }
5828
5829 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5830 if (AssocExpr.isInvalid())
5831 return ExprError();
5832 AssocExprs.push_back(AssocExpr.release());
5833 }
5834
5835 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5836 E->getDefaultLoc(),
5837 E->getRParenLoc(),
5838 ControllingExpr.release(),
5839 AssocTypes.data(),
5840 AssocExprs.data(),
5841 E->getNumAssocs());
5842}
5843
5844template<typename Derived>
5845ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005846TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005847 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005848 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005849 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005850
Douglas Gregora16548e2009-08-11 05:31:07 +00005851 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005852 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005853
John McCallb268a282010-08-23 23:25:46 +00005854 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005855 E->getRParen());
5856}
5857
Mike Stump11289f42009-09-09 15:08:12 +00005858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005860TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005861 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005862 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005864
Douglas Gregora16548e2009-08-11 05:31:07 +00005865 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005866 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005867
Douglas Gregora16548e2009-08-11 05:31:07 +00005868 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5869 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005870 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005871}
Mike Stump11289f42009-09-09 15:08:12 +00005872
Douglas Gregora16548e2009-08-11 05:31:07 +00005873template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005874ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005875TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5876 // Transform the type.
5877 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5878 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005879 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005880
Douglas Gregor882211c2010-04-28 22:16:22 +00005881 // Transform all of the components into components similar to what the
5882 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005883 // FIXME: It would be slightly more efficient in the non-dependent case to
5884 // just map FieldDecls, rather than requiring the rebuilder to look for
5885 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005886 // template code that we don't care.
5887 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005888 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005889 typedef OffsetOfExpr::OffsetOfNode Node;
5890 llvm::SmallVector<Component, 4> Components;
5891 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5892 const Node &ON = E->getComponent(I);
5893 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005894 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005895 Comp.LocStart = ON.getSourceRange().getBegin();
5896 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005897 switch (ON.getKind()) {
5898 case Node::Array: {
5899 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005900 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005901 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005902 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005903
Douglas Gregor882211c2010-04-28 22:16:22 +00005904 ExprChanged = ExprChanged || Index.get() != FromIndex;
5905 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005906 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005907 break;
5908 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005909
Douglas Gregor882211c2010-04-28 22:16:22 +00005910 case Node::Field:
5911 case Node::Identifier:
5912 Comp.isBrackets = false;
5913 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005914 if (!Comp.U.IdentInfo)
5915 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005916
Douglas Gregor882211c2010-04-28 22:16:22 +00005917 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005918
Douglas Gregord1702062010-04-29 00:18:15 +00005919 case Node::Base:
5920 // Will be recomputed during the rebuild.
5921 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005922 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005923
Douglas Gregor882211c2010-04-28 22:16:22 +00005924 Components.push_back(Comp);
5925 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005926
Douglas Gregor882211c2010-04-28 22:16:22 +00005927 // If nothing changed, retain the existing expression.
5928 if (!getDerived().AlwaysRebuild() &&
5929 Type == E->getTypeSourceInfo() &&
5930 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005931 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005932
Douglas Gregor882211c2010-04-28 22:16:22 +00005933 // Build a new offsetof expression.
5934 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5935 Components.data(), Components.size(),
5936 E->getRParenLoc());
5937}
5938
5939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005940ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005941TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5942 assert(getDerived().AlreadyTransformed(E->getType()) &&
5943 "opaque value expression requires transformation");
5944 return SemaRef.Owned(E);
5945}
5946
5947template<typename Derived>
5948ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005949TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5950 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005951 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005952 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005953
John McCallbcd03502009-12-07 02:54:59 +00005954 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005955 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005956 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005957
John McCall4c98fd82009-11-04 07:28:41 +00005958 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005959 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005960
Peter Collingbournee190dee2011-03-11 19:24:49 +00005961 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5962 E->getKind(),
5963 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005964 }
Mike Stump11289f42009-09-09 15:08:12 +00005965
John McCalldadc5752010-08-24 06:29:42 +00005966 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005967 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005968 // C++0x [expr.sizeof]p1:
5969 // The operand is either an expression, which is an unevaluated operand
5970 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005971 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005972
Douglas Gregora16548e2009-08-11 05:31:07 +00005973 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5974 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005976
Douglas Gregora16548e2009-08-11 05:31:07 +00005977 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005978 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005979 }
Mike Stump11289f42009-09-09 15:08:12 +00005980
Peter Collingbournee190dee2011-03-11 19:24:49 +00005981 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5982 E->getOperatorLoc(),
5983 E->getKind(),
5984 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005985}
Mike Stump11289f42009-09-09 15:08:12 +00005986
Douglas Gregora16548e2009-08-11 05:31:07 +00005987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005988ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005989TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005990 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005991 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005992 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005993
John McCalldadc5752010-08-24 06:29:42 +00005994 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005995 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005996 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005997
5998
Douglas Gregora16548e2009-08-11 05:31:07 +00005999 if (!getDerived().AlwaysRebuild() &&
6000 LHS.get() == E->getLHS() &&
6001 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006002 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006003
John McCallb268a282010-08-23 23:25:46 +00006004 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006005 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006006 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006007 E->getRBracketLoc());
6008}
Mike Stump11289f42009-09-09 15:08:12 +00006009
6010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006011ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006012TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006013 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006014 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006015 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006016 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006017
6018 // Transform arguments.
6019 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006020 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006021 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6022 &ArgChanged))
6023 return ExprError();
6024
Douglas Gregora16548e2009-08-11 05:31:07 +00006025 if (!getDerived().AlwaysRebuild() &&
6026 Callee.get() == E->getCallee() &&
6027 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006028 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006029
Douglas Gregora16548e2009-08-11 05:31:07 +00006030 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006031 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006032 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006033 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006034 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006035 E->getRParenLoc());
6036}
Mike Stump11289f42009-09-09 15:08:12 +00006037
6038template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006039ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006040TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006041 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006042 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006043 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006044
Douglas Gregorea972d32011-02-28 21:54:11 +00006045 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006046 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006047 QualifierLoc
6048 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6049
6050 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006051 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006052 }
Mike Stump11289f42009-09-09 15:08:12 +00006053
Eli Friedman2cfcef62009-12-04 06:40:45 +00006054 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006055 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6056 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006057 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006058 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006059
John McCall16df1e52010-03-30 21:47:33 +00006060 NamedDecl *FoundDecl = E->getFoundDecl();
6061 if (FoundDecl == E->getMemberDecl()) {
6062 FoundDecl = Member;
6063 } else {
6064 FoundDecl = cast_or_null<NamedDecl>(
6065 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6066 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006067 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006068 }
6069
Douglas Gregora16548e2009-08-11 05:31:07 +00006070 if (!getDerived().AlwaysRebuild() &&
6071 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006072 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006073 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006074 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006075 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006076
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006077 // Mark it referenced in the new context regardless.
6078 // FIXME: this is a bit instantiation-specific.
6079 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00006080 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006081 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006082
John McCall6b51f282009-11-23 01:53:49 +00006083 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006084 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006085 TransArgs.setLAngleLoc(E->getLAngleLoc());
6086 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006087 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6088 E->getNumTemplateArgs(),
6089 TransArgs))
6090 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006091 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006092
Douglas Gregora16548e2009-08-11 05:31:07 +00006093 // FIXME: Bogus source location for the operator
6094 SourceLocation FakeOperatorLoc
6095 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6096
John McCall38836f02010-01-15 08:34:02 +00006097 // FIXME: to do this check properly, we will need to preserve the
6098 // first-qualifier-in-scope here, just in case we had a dependent
6099 // base (and therefore couldn't do the check) and a
6100 // nested-name-qualifier (and therefore could do the lookup).
6101 NamedDecl *FirstQualifierInScope = 0;
6102
John McCallb268a282010-08-23 23:25:46 +00006103 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006104 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006105 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006106 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006107 Member,
John McCall16df1e52010-03-30 21:47:33 +00006108 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006109 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006110 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006111 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006112}
Mike Stump11289f42009-09-09 15:08:12 +00006113
Douglas Gregora16548e2009-08-11 05:31:07 +00006114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006115ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006116TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006117 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006118 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006119 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006120
John McCalldadc5752010-08-24 06:29:42 +00006121 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006122 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006123 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006124
Douglas Gregora16548e2009-08-11 05:31:07 +00006125 if (!getDerived().AlwaysRebuild() &&
6126 LHS.get() == E->getLHS() &&
6127 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006128 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006129
Douglas Gregora16548e2009-08-11 05:31:07 +00006130 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006131 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006132}
6133
Mike Stump11289f42009-09-09 15:08:12 +00006134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006135ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006136TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006137 CompoundAssignOperator *E) {
6138 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006139}
Mike Stump11289f42009-09-09 15:08:12 +00006140
Douglas Gregora16548e2009-08-11 05:31:07 +00006141template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006142ExprResult TreeTransform<Derived>::
6143TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6144 // Just rebuild the common and RHS expressions and see whether we
6145 // get any changes.
6146
6147 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6148 if (commonExpr.isInvalid())
6149 return ExprError();
6150
6151 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6152 if (rhs.isInvalid())
6153 return ExprError();
6154
6155 if (!getDerived().AlwaysRebuild() &&
6156 commonExpr.get() == e->getCommon() &&
6157 rhs.get() == e->getFalseExpr())
6158 return SemaRef.Owned(e);
6159
6160 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6161 e->getQuestionLoc(),
6162 0,
6163 e->getColonLoc(),
6164 rhs.get());
6165}
6166
6167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006168ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006169TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006170 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006171 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006172 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006173
John McCalldadc5752010-08-24 06:29:42 +00006174 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006175 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006176 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006177
John McCalldadc5752010-08-24 06:29:42 +00006178 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006179 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006180 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006181
Douglas Gregora16548e2009-08-11 05:31:07 +00006182 if (!getDerived().AlwaysRebuild() &&
6183 Cond.get() == E->getCond() &&
6184 LHS.get() == E->getLHS() &&
6185 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006186 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006187
John McCallb268a282010-08-23 23:25:46 +00006188 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006189 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006190 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006191 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006192 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006193}
Mike Stump11289f42009-09-09 15:08:12 +00006194
6195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006196ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006197TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006198 // Implicit casts are eliminated during transformation, since they
6199 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006200 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006201}
Mike Stump11289f42009-09-09 15:08:12 +00006202
Douglas Gregora16548e2009-08-11 05:31:07 +00006203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006204ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006205TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006206 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6207 if (!Type)
6208 return ExprError();
6209
John McCalldadc5752010-08-24 06:29:42 +00006210 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006211 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006212 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006213 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006214
Douglas Gregora16548e2009-08-11 05:31:07 +00006215 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006216 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006217 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006218 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006219
John McCall97513962010-01-15 18:39:57 +00006220 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006221 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006222 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006223 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006224}
Mike Stump11289f42009-09-09 15:08:12 +00006225
Douglas Gregora16548e2009-08-11 05:31:07 +00006226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006227ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006228TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006229 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6230 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6231 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006232 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006233
John McCalldadc5752010-08-24 06:29:42 +00006234 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006235 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006236 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006237
Douglas Gregora16548e2009-08-11 05:31:07 +00006238 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006239 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006240 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006241 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006242
John McCall5d7aa7f2010-01-19 22:33:45 +00006243 // Note: the expression type doesn't necessarily match the
6244 // type-as-written, but that's okay, because it should always be
6245 // derivable from the initializer.
6246
John McCalle15bbff2010-01-18 19:35:47 +00006247 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006248 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006249 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006250}
Mike Stump11289f42009-09-09 15:08:12 +00006251
Douglas Gregora16548e2009-08-11 05:31:07 +00006252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006253ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006254TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006255 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006256 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006257 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006258
Douglas Gregora16548e2009-08-11 05:31:07 +00006259 if (!getDerived().AlwaysRebuild() &&
6260 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006261 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006262
Douglas Gregora16548e2009-08-11 05:31:07 +00006263 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006264 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006265 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006266 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006267 E->getAccessorLoc(),
6268 E->getAccessor());
6269}
Mike Stump11289f42009-09-09 15:08:12 +00006270
Douglas Gregora16548e2009-08-11 05:31:07 +00006271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006273TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006274 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006275
John McCall37ad5512010-08-23 06:44:23 +00006276 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006277 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6278 Inits, &InitChanged))
6279 return ExprError();
6280
Douglas Gregora16548e2009-08-11 05:31:07 +00006281 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006282 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006283
Douglas Gregora16548e2009-08-11 05:31:07 +00006284 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006285 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006286}
Mike Stump11289f42009-09-09 15:08:12 +00006287
Douglas Gregora16548e2009-08-11 05:31:07 +00006288template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006289ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006290TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006291 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006292
Douglas Gregorebe10102009-08-20 07:17:43 +00006293 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006294 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006295 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006296 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006297
Douglas Gregorebe10102009-08-20 07:17:43 +00006298 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006299 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006300 bool ExprChanged = false;
6301 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6302 DEnd = E->designators_end();
6303 D != DEnd; ++D) {
6304 if (D->isFieldDesignator()) {
6305 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6306 D->getDotLoc(),
6307 D->getFieldLoc()));
6308 continue;
6309 }
Mike Stump11289f42009-09-09 15:08:12 +00006310
Douglas Gregora16548e2009-08-11 05:31:07 +00006311 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006312 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006313 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006314 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006315
6316 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006317 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006318
Douglas Gregora16548e2009-08-11 05:31:07 +00006319 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6320 ArrayExprs.push_back(Index.release());
6321 continue;
6322 }
Mike Stump11289f42009-09-09 15:08:12 +00006323
Douglas Gregora16548e2009-08-11 05:31:07 +00006324 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006325 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006326 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6327 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006328 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006329
John McCalldadc5752010-08-24 06:29:42 +00006330 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006331 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006332 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006333
6334 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006335 End.get(),
6336 D->getLBracketLoc(),
6337 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006338
Douglas Gregora16548e2009-08-11 05:31:07 +00006339 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6340 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006341
Douglas Gregora16548e2009-08-11 05:31:07 +00006342 ArrayExprs.push_back(Start.release());
6343 ArrayExprs.push_back(End.release());
6344 }
Mike Stump11289f42009-09-09 15:08:12 +00006345
Douglas Gregora16548e2009-08-11 05:31:07 +00006346 if (!getDerived().AlwaysRebuild() &&
6347 Init.get() == E->getInit() &&
6348 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006349 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006350
Douglas Gregora16548e2009-08-11 05:31:07 +00006351 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6352 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006353 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006354}
Mike Stump11289f42009-09-09 15:08:12 +00006355
Douglas Gregora16548e2009-08-11 05:31:07 +00006356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006357ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006358TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006359 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006360 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006361
Douglas Gregor3da3c062009-10-28 00:29:27 +00006362 // FIXME: Will we ever have proper type location here? Will we actually
6363 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006364 QualType T = getDerived().TransformType(E->getType());
6365 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006366 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006367
Douglas Gregora16548e2009-08-11 05:31:07 +00006368 if (!getDerived().AlwaysRebuild() &&
6369 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006370 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006371
Douglas Gregora16548e2009-08-11 05:31:07 +00006372 return getDerived().RebuildImplicitValueInitExpr(T);
6373}
Mike Stump11289f42009-09-09 15:08:12 +00006374
Douglas Gregora16548e2009-08-11 05:31:07 +00006375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006376ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006377TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006378 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6379 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006380 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006381
John McCalldadc5752010-08-24 06:29:42 +00006382 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006383 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006384 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006385
Douglas Gregora16548e2009-08-11 05:31:07 +00006386 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006387 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006388 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006389 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006390
John McCallb268a282010-08-23 23:25:46 +00006391 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006392 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006393}
6394
6395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006396ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006397TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006398 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006399 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006400 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6401 &ArgumentChanged))
6402 return ExprError();
6403
Douglas Gregora16548e2009-08-11 05:31:07 +00006404 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6405 move_arg(Inits),
6406 E->getRParenLoc());
6407}
Mike Stump11289f42009-09-09 15:08:12 +00006408
Douglas Gregora16548e2009-08-11 05:31:07 +00006409/// \brief Transform an address-of-label expression.
6410///
6411/// By default, the transformation of an address-of-label expression always
6412/// rebuilds the expression, so that the label identifier can be resolved to
6413/// the corresponding label statement by semantic analysis.
6414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006415ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006416TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006417 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6418 E->getLabel());
6419 if (!LD)
6420 return ExprError();
6421
Douglas Gregora16548e2009-08-11 05:31:07 +00006422 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006423 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006424}
Mike Stump11289f42009-09-09 15:08:12 +00006425
6426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006427ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006428TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006429 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006430 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6431 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006432 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006433
Douglas Gregora16548e2009-08-11 05:31:07 +00006434 if (!getDerived().AlwaysRebuild() &&
6435 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006436 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006437
6438 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006439 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006440 E->getRParenLoc());
6441}
Mike Stump11289f42009-09-09 15:08:12 +00006442
Douglas Gregora16548e2009-08-11 05:31:07 +00006443template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006444ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006445TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006446 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006447 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006448 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006449
John McCalldadc5752010-08-24 06:29:42 +00006450 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006451 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006452 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006453
John McCalldadc5752010-08-24 06:29:42 +00006454 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006455 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006456 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006457
Douglas Gregora16548e2009-08-11 05:31:07 +00006458 if (!getDerived().AlwaysRebuild() &&
6459 Cond.get() == E->getCond() &&
6460 LHS.get() == E->getLHS() &&
6461 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006462 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006463
Douglas Gregora16548e2009-08-11 05:31:07 +00006464 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006465 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006466 E->getRParenLoc());
6467}
Mike Stump11289f42009-09-09 15:08:12 +00006468
Douglas Gregora16548e2009-08-11 05:31:07 +00006469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006471TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006472 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006473}
6474
6475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006476ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006477TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006478 switch (E->getOperator()) {
6479 case OO_New:
6480 case OO_Delete:
6481 case OO_Array_New:
6482 case OO_Array_Delete:
6483 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006484 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006485
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006486 case OO_Call: {
6487 // This is a call to an object's operator().
6488 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6489
6490 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006491 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006492 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006493 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006494
6495 // FIXME: Poor location information
6496 SourceLocation FakeLParenLoc
6497 = SemaRef.PP.getLocForEndOfToken(
6498 static_cast<Expr *>(Object.get())->getLocEnd());
6499
6500 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006501 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006502 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6503 Args))
6504 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006505
John McCallb268a282010-08-23 23:25:46 +00006506 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006507 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006508 E->getLocEnd());
6509 }
6510
6511#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6512 case OO_##Name:
6513#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6514#include "clang/Basic/OperatorKinds.def"
6515 case OO_Subscript:
6516 // Handled below.
6517 break;
6518
6519 case OO_Conditional:
6520 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006521 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006522
6523 case OO_None:
6524 case NUM_OVERLOADED_OPERATORS:
6525 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006526 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006527 }
6528
John McCalldadc5752010-08-24 06:29:42 +00006529 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006530 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006531 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006532
John McCalldadc5752010-08-24 06:29:42 +00006533 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006534 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006535 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006536
John McCalldadc5752010-08-24 06:29:42 +00006537 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006538 if (E->getNumArgs() == 2) {
6539 Second = getDerived().TransformExpr(E->getArg(1));
6540 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006541 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006542 }
Mike Stump11289f42009-09-09 15:08:12 +00006543
Douglas Gregora16548e2009-08-11 05:31:07 +00006544 if (!getDerived().AlwaysRebuild() &&
6545 Callee.get() == E->getCallee() &&
6546 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006547 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006548 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006549
Douglas Gregora16548e2009-08-11 05:31:07 +00006550 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6551 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006552 Callee.get(),
6553 First.get(),
6554 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006555}
Mike Stump11289f42009-09-09 15:08:12 +00006556
Douglas Gregora16548e2009-08-11 05:31:07 +00006557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006558ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006559TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6560 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006561}
Mike Stump11289f42009-09-09 15:08:12 +00006562
Douglas Gregora16548e2009-08-11 05:31:07 +00006563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006564ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006565TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6566 // Transform the callee.
6567 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6568 if (Callee.isInvalid())
6569 return ExprError();
6570
6571 // Transform exec config.
6572 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6573 if (EC.isInvalid())
6574 return ExprError();
6575
6576 // Transform arguments.
6577 bool ArgChanged = false;
6578 ASTOwningVector<Expr*> Args(SemaRef);
6579 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6580 &ArgChanged))
6581 return ExprError();
6582
6583 if (!getDerived().AlwaysRebuild() &&
6584 Callee.get() == E->getCallee() &&
6585 !ArgChanged)
6586 return SemaRef.Owned(E);
6587
6588 // FIXME: Wrong source location information for the '('.
6589 SourceLocation FakeLParenLoc
6590 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6591 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6592 move_arg(Args),
6593 E->getRParenLoc(), EC.get());
6594}
6595
6596template<typename Derived>
6597ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006598TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006599 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6600 if (!Type)
6601 return ExprError();
6602
John McCalldadc5752010-08-24 06:29:42 +00006603 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006604 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006605 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006606 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006607
Douglas Gregora16548e2009-08-11 05:31:07 +00006608 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006609 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006610 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006611 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006612
Douglas Gregora16548e2009-08-11 05:31:07 +00006613 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006614 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006615 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6616 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6617 SourceLocation FakeRParenLoc
6618 = SemaRef.PP.getLocForEndOfToken(
6619 E->getSubExpr()->getSourceRange().getEnd());
6620 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006621 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006622 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006623 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006624 FakeRAngleLoc,
6625 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006626 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006627 FakeRParenLoc);
6628}
Mike Stump11289f42009-09-09 15:08:12 +00006629
Douglas Gregora16548e2009-08-11 05:31:07 +00006630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006631ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006632TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6633 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006634}
Mike Stump11289f42009-09-09 15:08:12 +00006635
6636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006637ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006638TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6639 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006640}
6641
Douglas Gregora16548e2009-08-11 05:31:07 +00006642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006643ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006644TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006645 CXXReinterpretCastExpr *E) {
6646 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006647}
Mike Stump11289f42009-09-09 15:08:12 +00006648
Douglas Gregora16548e2009-08-11 05:31:07 +00006649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006650ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006651TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6652 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006653}
Mike Stump11289f42009-09-09 15:08:12 +00006654
Douglas Gregora16548e2009-08-11 05:31:07 +00006655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006656ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006657TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006658 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006659 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6660 if (!Type)
6661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006662
John McCalldadc5752010-08-24 06:29:42 +00006663 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006664 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006665 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006666 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006667
Douglas Gregora16548e2009-08-11 05:31:07 +00006668 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006669 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006670 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006671 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006672
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006673 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006674 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006675 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 E->getRParenLoc());
6677}
Mike Stump11289f42009-09-09 15:08:12 +00006678
Douglas Gregora16548e2009-08-11 05:31:07 +00006679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006680ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006681TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006683 TypeSourceInfo *TInfo
6684 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6685 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006686 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006687
Douglas Gregora16548e2009-08-11 05:31:07 +00006688 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006689 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006690 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006691
Douglas Gregor9da64192010-04-26 22:37:10 +00006692 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6693 E->getLocStart(),
6694 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006695 E->getLocEnd());
6696 }
Mike Stump11289f42009-09-09 15:08:12 +00006697
Douglas Gregora16548e2009-08-11 05:31:07 +00006698 // We don't know whether the expression is potentially evaluated until
6699 // after we perform semantic analysis, so the expression is potentially
6700 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006701 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006702 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006703
John McCalldadc5752010-08-24 06:29:42 +00006704 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006705 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006706 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006707
Douglas Gregora16548e2009-08-11 05:31:07 +00006708 if (!getDerived().AlwaysRebuild() &&
6709 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006710 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006711
Douglas Gregor9da64192010-04-26 22:37:10 +00006712 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6713 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006714 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006715 E->getLocEnd());
6716}
6717
6718template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006719ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006720TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6721 if (E->isTypeOperand()) {
6722 TypeSourceInfo *TInfo
6723 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6724 if (!TInfo)
6725 return ExprError();
6726
6727 if (!getDerived().AlwaysRebuild() &&
6728 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006729 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006730
Douglas Gregor69735112011-03-06 17:40:41 +00006731 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006732 E->getLocStart(),
6733 TInfo,
6734 E->getLocEnd());
6735 }
6736
6737 // We don't know whether the expression is potentially evaluated until
6738 // after we perform semantic analysis, so the expression is potentially
6739 // potentially evaluated.
6740 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6741
6742 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6743 if (SubExpr.isInvalid())
6744 return ExprError();
6745
6746 if (!getDerived().AlwaysRebuild() &&
6747 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006748 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006749
6750 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6751 E->getLocStart(),
6752 SubExpr.get(),
6753 E->getLocEnd());
6754}
6755
6756template<typename Derived>
6757ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006758TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006759 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006760}
Mike Stump11289f42009-09-09 15:08:12 +00006761
Douglas Gregora16548e2009-08-11 05:31:07 +00006762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006763ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006764TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006765 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006766 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006767}
Mike Stump11289f42009-09-09 15:08:12 +00006768
Douglas Gregora16548e2009-08-11 05:31:07 +00006769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006770ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006771TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006772 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith938f40b2011-06-11 17:19:42 +00006773 QualType T;
6774 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6775 T = MD->getThisType(getSema().Context);
6776 else
6777 T = getSema().Context.getPointerType(
6778 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump11289f42009-09-09 15:08:12 +00006779
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006780 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006781 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006782
Douglas Gregorb15af892010-01-07 23:12:05 +00006783 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006784}
Mike Stump11289f42009-09-09 15:08:12 +00006785
Douglas Gregora16548e2009-08-11 05:31:07 +00006786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006787ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006788TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006789 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006790 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006791 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006792
Douglas Gregora16548e2009-08-11 05:31:07 +00006793 if (!getDerived().AlwaysRebuild() &&
6794 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006795 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006796
Douglas Gregor53e191ed2011-07-06 22:04:06 +00006797 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6798 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00006799}
Mike Stump11289f42009-09-09 15:08:12 +00006800
Douglas Gregora16548e2009-08-11 05:31:07 +00006801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006802ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006803TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006804 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006805 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6806 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006807 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006808 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006809
Chandler Carruth794da4c2010-02-08 06:42:49 +00006810 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006811 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006812 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006813
Douglas Gregor033f6752009-12-23 23:03:06 +00006814 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
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 Gregor2b88c112010-09-08 00:15:04 +00006819TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6820 CXXScalarValueInitExpr *E) {
6821 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6822 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006823 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006824
Douglas Gregora16548e2009-08-11 05:31:07 +00006825 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006826 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006827 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006828
Douglas Gregor2b88c112010-09-08 00:15:04 +00006829 return getDerived().RebuildCXXScalarValueInitExpr(T,
6830 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006831 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006832}
Mike Stump11289f42009-09-09 15:08:12 +00006833
Douglas Gregora16548e2009-08-11 05:31:07 +00006834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006835ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006836TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006837 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006838 TypeSourceInfo *AllocTypeInfo
6839 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6840 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006841 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006842
Douglas Gregora16548e2009-08-11 05:31:07 +00006843 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006844 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006845 if (ArraySize.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 // Transform the placement arguments (if any).
6849 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006850 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006851 if (getDerived().TransformExprs(E->getPlacementArgs(),
6852 E->getNumPlacementArgs(), true,
6853 PlacementArgs, &ArgumentChanged))
6854 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006855
Douglas Gregorebe10102009-08-20 07:17:43 +00006856 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006857 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006858 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6859 ConstructorArgs, &ArgumentChanged))
6860 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006861
Douglas Gregord2d9da02010-02-26 00:38:10 +00006862 // Transform constructor, new operator, and delete operator.
6863 CXXConstructorDecl *Constructor = 0;
6864 if (E->getConstructor()) {
6865 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006866 getDerived().TransformDecl(E->getLocStart(),
6867 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006868 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006869 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006870 }
6871
6872 FunctionDecl *OperatorNew = 0;
6873 if (E->getOperatorNew()) {
6874 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006875 getDerived().TransformDecl(E->getLocStart(),
6876 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006877 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006878 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006879 }
6880
6881 FunctionDecl *OperatorDelete = 0;
6882 if (E->getOperatorDelete()) {
6883 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006884 getDerived().TransformDecl(E->getLocStart(),
6885 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006886 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006887 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006888 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006889
Douglas Gregora16548e2009-08-11 05:31:07 +00006890 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006891 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006892 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006893 Constructor == E->getConstructor() &&
6894 OperatorNew == E->getOperatorNew() &&
6895 OperatorDelete == E->getOperatorDelete() &&
6896 !ArgumentChanged) {
6897 // Mark any declarations we need as referenced.
6898 // FIXME: instantiation-specific.
6899 if (Constructor)
6900 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6901 if (OperatorNew)
6902 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6903 if (OperatorDelete)
6904 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006905 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006906 }
Mike Stump11289f42009-09-09 15:08:12 +00006907
Douglas Gregor0744ef62010-09-07 21:49:58 +00006908 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006909 if (!ArraySize.get()) {
6910 // If no array size was specified, but the new expression was
6911 // instantiated with an array type (e.g., "new T" where T is
6912 // instantiated with "int[4]"), extract the outer bound from the
6913 // array type as our array size. We do this with constant and
6914 // dependently-sized array types.
6915 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6916 if (!ArrayT) {
6917 // Do nothing
6918 } else if (const ConstantArrayType *ConsArrayT
6919 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006920 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006921 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6922 ConsArrayT->getSize(),
6923 SemaRef.Context.getSizeType(),
6924 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006925 AllocType = ConsArrayT->getElementType();
6926 } else if (const DependentSizedArrayType *DepArrayT
6927 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6928 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006929 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006930 AllocType = DepArrayT->getElementType();
6931 }
6932 }
6933 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006934
Douglas Gregora16548e2009-08-11 05:31:07 +00006935 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6936 E->isGlobalNew(),
6937 /*FIXME:*/E->getLocStart(),
6938 move_arg(PlacementArgs),
6939 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006940 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006941 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006942 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006943 ArraySize.get(),
Douglas Gregor3bdcff52011-06-27 16:55:54 +00006944 /*FIXME:*/E->hasInitializer()
6945 ? E->getLocStart()
6946 : SourceLocation(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006947 move_arg(ConstructorArgs),
Douglas Gregor3bdcff52011-06-27 16:55:54 +00006948 /*FIXME:*/E->hasInitializer()
6949 ? E->getLocEnd()
6950 : SourceLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006951}
Mike Stump11289f42009-09-09 15:08:12 +00006952
Douglas Gregora16548e2009-08-11 05:31:07 +00006953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006954ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006955TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006956 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006957 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006958 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006959
Douglas Gregord2d9da02010-02-26 00:38:10 +00006960 // Transform the delete operator, if known.
6961 FunctionDecl *OperatorDelete = 0;
6962 if (E->getOperatorDelete()) {
6963 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006964 getDerived().TransformDecl(E->getLocStart(),
6965 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006966 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006967 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006968 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006969
Douglas Gregora16548e2009-08-11 05:31:07 +00006970 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006971 Operand.get() == E->getArgument() &&
6972 OperatorDelete == E->getOperatorDelete()) {
6973 // Mark any declarations we need as referenced.
6974 // FIXME: instantiation-specific.
6975 if (OperatorDelete)
6976 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006977
6978 if (!E->getArgument()->isTypeDependent()) {
6979 QualType Destroyed = SemaRef.Context.getBaseElementType(
6980 E->getDestroyedType());
6981 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6982 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6983 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6984 SemaRef.LookupDestructor(Record));
6985 }
6986 }
6987
John McCallc3007a22010-10-26 07:05:15 +00006988 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006989 }
Mike Stump11289f42009-09-09 15:08:12 +00006990
Douglas Gregora16548e2009-08-11 05:31:07 +00006991 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6992 E->isGlobalDelete(),
6993 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006994 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006995}
Mike Stump11289f42009-09-09 15:08:12 +00006996
Douglas Gregora16548e2009-08-11 05:31:07 +00006997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006998ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006999TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007000 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007001 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007002 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007003 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007004
John McCallba7bf592010-08-24 05:47:05 +00007005 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007006 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007007 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007008 E->getOperatorLoc(),
7009 E->isArrow()? tok::arrow : tok::period,
7010 ObjectTypePtr,
7011 MayBePseudoDestructor);
7012 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007013 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007014
John McCallba7bf592010-08-24 05:47:05 +00007015 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007016 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7017 if (QualifierLoc) {
7018 QualifierLoc
7019 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7020 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007021 return ExprError();
7022 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007023 CXXScopeSpec SS;
7024 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007025
Douglas Gregor678f90d2010-02-25 01:56:36 +00007026 PseudoDestructorTypeStorage Destroyed;
7027 if (E->getDestroyedTypeInfo()) {
7028 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007029 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007030 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007031 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007032 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007033 Destroyed = DestroyedTypeInfo;
7034 } else if (ObjectType->isDependentType()) {
7035 // We aren't likely to be able to resolve the identifier down to a type
7036 // now anyway, so just retain the identifier.
7037 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7038 E->getDestroyedTypeLoc());
7039 } else {
7040 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007041 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007042 *E->getDestroyedTypeIdentifier(),
7043 E->getDestroyedTypeLoc(),
7044 /*Scope=*/0,
7045 SS, ObjectTypePtr,
7046 false);
7047 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007048 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007049
Douglas Gregor678f90d2010-02-25 01:56:36 +00007050 Destroyed
7051 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7052 E->getDestroyedTypeLoc());
7053 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007054
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007055 TypeSourceInfo *ScopeTypeInfo = 0;
7056 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00007057 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007058 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007059 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007060 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007061
John McCallb268a282010-08-23 23:25:46 +00007062 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007063 E->getOperatorLoc(),
7064 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007065 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007066 ScopeTypeInfo,
7067 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007068 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007069 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007070}
Mike Stump11289f42009-09-09 15:08:12 +00007071
Douglas Gregorad8a3362009-09-04 17:36:40 +00007072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007073ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007074TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007075 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007076 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7077 Sema::LookupOrdinaryName);
7078
7079 // Transform all the decls.
7080 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7081 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007082 NamedDecl *InstD = static_cast<NamedDecl*>(
7083 getDerived().TransformDecl(Old->getNameLoc(),
7084 *I));
John McCall84d87672009-12-10 09:41:52 +00007085 if (!InstD) {
7086 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7087 // This can happen because of dependent hiding.
7088 if (isa<UsingShadowDecl>(*I))
7089 continue;
7090 else
John McCallfaf5fb42010-08-26 23:41:50 +00007091 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007092 }
John McCalle66edc12009-11-24 19:00:30 +00007093
7094 // Expand using declarations.
7095 if (isa<UsingDecl>(InstD)) {
7096 UsingDecl *UD = cast<UsingDecl>(InstD);
7097 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7098 E = UD->shadow_end(); I != E; ++I)
7099 R.addDecl(*I);
7100 continue;
7101 }
7102
7103 R.addDecl(InstD);
7104 }
7105
7106 // Resolve a kind, but don't do any further analysis. If it's
7107 // ambiguous, the callee needs to deal with it.
7108 R.resolveKind();
7109
7110 // Rebuild the nested-name qualifier, if present.
7111 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007112 if (Old->getQualifierLoc()) {
7113 NestedNameSpecifierLoc QualifierLoc
7114 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7115 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007116 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007117
Douglas Gregor0da1d432011-02-28 20:01:57 +00007118 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007119 }
7120
Douglas Gregor9262f472010-04-27 18:19:34 +00007121 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007122 CXXRecordDecl *NamingClass
7123 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7124 Old->getNameLoc(),
7125 Old->getNamingClass()));
7126 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007127 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007128
Douglas Gregorda7be082010-04-27 16:10:10 +00007129 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007130 }
7131
7132 // If we have no template arguments, it's a normal declaration name.
7133 if (!Old->hasExplicitTemplateArgs())
7134 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7135
7136 // If we have template arguments, rebuild them, then rebuild the
7137 // templateid expression.
7138 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007139 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7140 Old->getNumTemplateArgs(),
7141 TransArgs))
7142 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007143
7144 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7145 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007146}
Mike Stump11289f42009-09-09 15:08:12 +00007147
Douglas Gregora16548e2009-08-11 05:31:07 +00007148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007150TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007151 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7152 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007153 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007154
Douglas Gregora16548e2009-08-11 05:31:07 +00007155 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007156 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007157 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007158
Mike Stump11289f42009-09-09 15:08:12 +00007159 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007160 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007161 T,
7162 E->getLocEnd());
7163}
Mike Stump11289f42009-09-09 15:08:12 +00007164
Douglas Gregora16548e2009-08-11 05:31:07 +00007165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007166ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007167TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7168 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7169 if (!LhsT)
7170 return ExprError();
7171
7172 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7173 if (!RhsT)
7174 return ExprError();
7175
7176 if (!getDerived().AlwaysRebuild() &&
7177 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7178 return SemaRef.Owned(E);
7179
7180 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7181 E->getLocStart(),
7182 LhsT, RhsT,
7183 E->getLocEnd());
7184}
7185
7186template<typename Derived>
7187ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007188TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7189 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7190 if (!T)
7191 return ExprError();
7192
7193 if (!getDerived().AlwaysRebuild() &&
7194 T == E->getQueriedTypeSourceInfo())
7195 return SemaRef.Owned(E);
7196
7197 ExprResult SubExpr;
7198 {
7199 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7200 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7201 if (SubExpr.isInvalid())
7202 return ExprError();
7203
7204 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7205 return SemaRef.Owned(E);
7206 }
7207
7208 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7209 E->getLocStart(),
7210 T,
7211 SubExpr.get(),
7212 E->getLocEnd());
7213}
7214
7215template<typename Derived>
7216ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007217TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7218 ExprResult SubExpr;
7219 {
7220 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7221 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7222 if (SubExpr.isInvalid())
7223 return ExprError();
7224
7225 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7226 return SemaRef.Owned(E);
7227 }
7228
7229 return getDerived().RebuildExpressionTrait(
7230 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7231}
7232
7233template<typename Derived>
7234ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007235TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007236 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007237 NestedNameSpecifierLoc QualifierLoc
7238 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7239 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007240 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007241
John McCall31f82722010-11-12 08:19:04 +00007242 // TODO: If this is a conversion-function-id, verify that the
7243 // destination type name (if present) resolves the same way after
7244 // instantiation as it did in the local scope.
7245
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007246 DeclarationNameInfo NameInfo
7247 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7248 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007249 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007250
John McCalle66edc12009-11-24 19:00:30 +00007251 if (!E->hasExplicitTemplateArgs()) {
7252 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007253 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007254 // Note: it is sufficient to compare the Name component of NameInfo:
7255 // if name has not changed, DNLoc has not changed either.
7256 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007257 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007258
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007259 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007260 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007261 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007262 }
John McCall6b51f282009-11-23 01:53:49 +00007263
7264 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007265 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7266 E->getNumTemplateArgs(),
7267 TransArgs))
7268 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007269
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007270 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007271 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007272 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007273}
7274
7275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007276ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007277TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007278 // CXXConstructExprs are always implicit, so when we have a
7279 // 1-argument construction we just transform that argument.
7280 if (E->getNumArgs() == 1 ||
7281 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7282 return getDerived().TransformExpr(E->getArg(0));
7283
Douglas Gregora16548e2009-08-11 05:31:07 +00007284 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7285
7286 QualType T = getDerived().TransformType(E->getType());
7287 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007288 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007289
7290 CXXConstructorDecl *Constructor
7291 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007292 getDerived().TransformDecl(E->getLocStart(),
7293 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007294 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007295 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007296
Douglas Gregora16548e2009-08-11 05:31:07 +00007297 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007298 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007299 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7300 &ArgumentChanged))
7301 return ExprError();
7302
Douglas Gregora16548e2009-08-11 05:31:07 +00007303 if (!getDerived().AlwaysRebuild() &&
7304 T == E->getType() &&
7305 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007306 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007307 // Mark the constructor as referenced.
7308 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007309 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007310 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007311 }
Mike Stump11289f42009-09-09 15:08:12 +00007312
Douglas Gregordb121ba2009-12-14 16:27:04 +00007313 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7314 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007315 move_arg(Args),
7316 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007317 E->getConstructionKind(),
7318 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007319}
Mike Stump11289f42009-09-09 15:08:12 +00007320
Douglas Gregora16548e2009-08-11 05:31:07 +00007321/// \brief Transform a C++ temporary-binding expression.
7322///
Douglas Gregor363b1512009-12-24 18:51:59 +00007323/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7324/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007325template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007326ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007327TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007328 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007329}
Mike Stump11289f42009-09-09 15:08:12 +00007330
John McCall5d413782010-12-06 08:20:24 +00007331/// \brief Transform a C++ expression that contains cleanups that should
7332/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007333///
John McCall5d413782010-12-06 08:20:24 +00007334/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007335/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007336template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007337ExprResult
John McCall5d413782010-12-06 08:20:24 +00007338TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007339 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007340}
Mike Stump11289f42009-09-09 15:08:12 +00007341
Douglas Gregora16548e2009-08-11 05:31:07 +00007342template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007343ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007344TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007345 CXXTemporaryObjectExpr *E) {
7346 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7347 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007348 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007349
Douglas Gregora16548e2009-08-11 05:31:07 +00007350 CXXConstructorDecl *Constructor
7351 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007352 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007353 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007354 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007356
Douglas Gregora16548e2009-08-11 05:31:07 +00007357 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007358 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007359 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007360 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7361 &ArgumentChanged))
7362 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007363
Douglas Gregora16548e2009-08-11 05:31:07 +00007364 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007365 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007366 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007367 !ArgumentChanged) {
7368 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007369 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007370 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007371 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007372
7373 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7374 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007375 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007376 E->getLocEnd());
7377}
Mike Stump11289f42009-09-09 15:08:12 +00007378
Douglas Gregora16548e2009-08-11 05:31:07 +00007379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007380ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007381TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007382 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007383 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7384 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007386
Douglas Gregora16548e2009-08-11 05:31:07 +00007387 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007388 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007389 Args.reserve(E->arg_size());
7390 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7391 &ArgumentChanged))
7392 return ExprError();
7393
Douglas Gregora16548e2009-08-11 05:31:07 +00007394 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007395 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007396 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007397 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007398
Douglas Gregora16548e2009-08-11 05:31:07 +00007399 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007400 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007401 E->getLParenLoc(),
7402 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007403 E->getRParenLoc());
7404}
Mike Stump11289f42009-09-09 15:08:12 +00007405
Douglas Gregora16548e2009-08-11 05:31:07 +00007406template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007407ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007408TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007409 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007410 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007411 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007412 Expr *OldBase;
7413 QualType BaseType;
7414 QualType ObjectType;
7415 if (!E->isImplicitAccess()) {
7416 OldBase = E->getBase();
7417 Base = getDerived().TransformExpr(OldBase);
7418 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007419 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007420
John McCall2d74de92009-12-01 22:10:20 +00007421 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007422 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007423 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007424 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007425 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007426 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007427 ObjectTy,
7428 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007429 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007430 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007431
John McCallba7bf592010-08-24 05:47:05 +00007432 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007433 BaseType = ((Expr*) Base.get())->getType();
7434 } else {
7435 OldBase = 0;
7436 BaseType = getDerived().TransformType(E->getBaseType());
7437 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7438 }
Mike Stump11289f42009-09-09 15:08:12 +00007439
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007440 // Transform the first part of the nested-name-specifier that qualifies
7441 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007442 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007443 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007444 E->getFirstQualifierFoundInScope(),
7445 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007446
Douglas Gregore16af532011-02-28 18:50:33 +00007447 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007448 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007449 QualifierLoc
7450 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7451 ObjectType,
7452 FirstQualifierInScope);
7453 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007454 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007455 }
Mike Stump11289f42009-09-09 15:08:12 +00007456
John McCall31f82722010-11-12 08:19:04 +00007457 // TODO: If this is a conversion-function-id, verify that the
7458 // destination type name (if present) resolves the same way after
7459 // instantiation as it did in the local scope.
7460
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007461 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007462 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007463 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007464 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007465
John McCall2d74de92009-12-01 22:10:20 +00007466 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007467 // This is a reference to a member without an explicitly-specified
7468 // template argument list. Optimize for this common case.
7469 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007470 Base.get() == OldBase &&
7471 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007472 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007473 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007474 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007475 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007476
John McCallb268a282010-08-23 23:25:46 +00007477 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007478 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007479 E->isArrow(),
7480 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007481 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007482 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007483 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007484 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007485 }
7486
John McCall6b51f282009-11-23 01:53:49 +00007487 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007488 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7489 E->getNumTemplateArgs(),
7490 TransArgs))
7491 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007492
John McCallb268a282010-08-23 23:25:46 +00007493 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007494 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007495 E->isArrow(),
7496 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007497 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007498 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007499 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007500 &TransArgs);
7501}
7502
7503template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007504ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007505TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007506 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007507 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007508 QualType BaseType;
7509 if (!Old->isImplicitAccess()) {
7510 Base = getDerived().TransformExpr(Old->getBase());
7511 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007512 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007513 BaseType = ((Expr*) Base.get())->getType();
7514 } else {
7515 BaseType = getDerived().TransformType(Old->getBaseType());
7516 }
John McCall10eae182009-11-30 22:42:35 +00007517
Douglas Gregor0da1d432011-02-28 20:01:57 +00007518 NestedNameSpecifierLoc QualifierLoc;
7519 if (Old->getQualifierLoc()) {
7520 QualifierLoc
7521 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7522 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007523 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007524 }
7525
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007526 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007527 Sema::LookupOrdinaryName);
7528
7529 // Transform all the decls.
7530 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7531 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007532 NamedDecl *InstD = static_cast<NamedDecl*>(
7533 getDerived().TransformDecl(Old->getMemberLoc(),
7534 *I));
John McCall84d87672009-12-10 09:41:52 +00007535 if (!InstD) {
7536 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7537 // This can happen because of dependent hiding.
7538 if (isa<UsingShadowDecl>(*I))
7539 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007540 else {
7541 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007542 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007543 }
John McCall84d87672009-12-10 09:41:52 +00007544 }
John McCall10eae182009-11-30 22:42:35 +00007545
7546 // Expand using declarations.
7547 if (isa<UsingDecl>(InstD)) {
7548 UsingDecl *UD = cast<UsingDecl>(InstD);
7549 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7550 E = UD->shadow_end(); I != E; ++I)
7551 R.addDecl(*I);
7552 continue;
7553 }
7554
7555 R.addDecl(InstD);
7556 }
7557
7558 R.resolveKind();
7559
Douglas Gregor9262f472010-04-27 18:19:34 +00007560 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007561 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007562 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007563 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007564 Old->getMemberLoc(),
7565 Old->getNamingClass()));
7566 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007567 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007568
Douglas Gregorda7be082010-04-27 16:10:10 +00007569 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007570 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007571
John McCall10eae182009-11-30 22:42:35 +00007572 TemplateArgumentListInfo TransArgs;
7573 if (Old->hasExplicitTemplateArgs()) {
7574 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7575 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007576 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7577 Old->getNumTemplateArgs(),
7578 TransArgs))
7579 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007580 }
John McCall38836f02010-01-15 08:34:02 +00007581
7582 // FIXME: to do this check properly, we will need to preserve the
7583 // first-qualifier-in-scope here, just in case we had a dependent
7584 // base (and therefore couldn't do the check) and a
7585 // nested-name-qualifier (and therefore could do the lookup).
7586 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007587
John McCallb268a282010-08-23 23:25:46 +00007588 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007589 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007590 Old->getOperatorLoc(),
7591 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007592 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007593 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007594 R,
7595 (Old->hasExplicitTemplateArgs()
7596 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007597}
7598
7599template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007600ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007601TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00007602 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007603 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7604 if (SubExpr.isInvalid())
7605 return ExprError();
7606
7607 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007608 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007609
7610 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7611}
7612
7613template<typename Derived>
7614ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007615TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007616 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7617 if (Pattern.isInvalid())
7618 return ExprError();
7619
7620 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7621 return SemaRef.Owned(E);
7622
Douglas Gregorb8840002011-01-14 21:20:45 +00007623 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7624 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007625}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007626
7627template<typename Derived>
7628ExprResult
7629TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7630 // If E is not value-dependent, then nothing will change when we transform it.
7631 // Note: This is an instantiation-centric view.
7632 if (!E->isValueDependent())
7633 return SemaRef.Owned(E);
7634
7635 // Note: None of the implementations of TryExpandParameterPacks can ever
7636 // produce a diagnostic when given only a single unexpanded parameter pack,
7637 // so
7638 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7639 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007640 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007641 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007642 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7643 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007644 ShouldExpand, RetainExpansion,
7645 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007646 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007647
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007648 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007649 return SemaRef.Owned(E);
7650
7651 // We now know the length of the parameter pack, so build a new expression
7652 // that stores that length.
7653 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7654 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007655 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007656}
7657
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007658template<typename Derived>
7659ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007660TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7661 SubstNonTypeTemplateParmPackExpr *E) {
7662 // Default behavior is to do nothing with this transformation.
7663 return SemaRef.Owned(E);
7664}
7665
7666template<typename Derived>
7667ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00007668TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7669 MaterializeTemporaryExpr *E) {
7670 return getDerived().TransformExpr(E->GetTemporaryExpr());
7671}
7672
7673template<typename Derived>
7674ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007675TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007676 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007677}
7678
Mike Stump11289f42009-09-09 15:08:12 +00007679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007680ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007681TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007682 TypeSourceInfo *EncodedTypeInfo
7683 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7684 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007685 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007686
Douglas Gregora16548e2009-08-11 05:31:07 +00007687 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007688 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007689 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007690
7691 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007692 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007693 E->getRParenLoc());
7694}
Mike Stump11289f42009-09-09 15:08:12 +00007695
Douglas Gregora16548e2009-08-11 05:31:07 +00007696template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00007697ExprResult TreeTransform<Derived>::
7698TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7699 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7700 if (result.isInvalid()) return ExprError();
7701 Expr *subExpr = result.take();
7702
7703 if (!getDerived().AlwaysRebuild() &&
7704 subExpr == E->getSubExpr())
7705 return SemaRef.Owned(E);
7706
7707 return SemaRef.Owned(new(SemaRef.Context)
7708 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7709}
7710
7711template<typename Derived>
7712ExprResult TreeTransform<Derived>::
7713TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7714 TypeSourceInfo *TSInfo
7715 = getDerived().TransformType(E->getTypeInfoAsWritten());
7716 if (!TSInfo)
7717 return ExprError();
7718
7719 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7720 if (Result.isInvalid())
7721 return ExprError();
7722
7723 if (!getDerived().AlwaysRebuild() &&
7724 TSInfo == E->getTypeInfoAsWritten() &&
7725 Result.get() == E->getSubExpr())
7726 return SemaRef.Owned(E);
7727
7728 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7729 E->getBridgeKeywordLoc(), TSInfo,
7730 Result.get());
7731}
7732
7733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007734ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007735TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007736 // Transform arguments.
7737 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007738 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007739 Args.reserve(E->getNumArgs());
7740 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7741 &ArgChanged))
7742 return ExprError();
7743
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007744 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7745 // Class message: transform the receiver type.
7746 TypeSourceInfo *ReceiverTypeInfo
7747 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7748 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007749 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007750
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007751 // If nothing changed, just retain the existing message send.
7752 if (!getDerived().AlwaysRebuild() &&
7753 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007754 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007755
7756 // Build a new class message send.
7757 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7758 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007759 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007760 E->getMethodDecl(),
7761 E->getLeftLoc(),
7762 move_arg(Args),
7763 E->getRightLoc());
7764 }
7765
7766 // Instance message: transform the receiver
7767 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7768 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007769 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007770 = getDerived().TransformExpr(E->getInstanceReceiver());
7771 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007772 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007773
7774 // If nothing changed, just retain the existing message send.
7775 if (!getDerived().AlwaysRebuild() &&
7776 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007777 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007778
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007779 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007780 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007781 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007782 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007783 E->getMethodDecl(),
7784 E->getLeftLoc(),
7785 move_arg(Args),
7786 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007787}
7788
Mike Stump11289f42009-09-09 15:08:12 +00007789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007790ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007791TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007792 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007793}
7794
Mike Stump11289f42009-09-09 15:08:12 +00007795template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007796ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007797TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007798 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007799}
7800
Mike Stump11289f42009-09-09 15:08:12 +00007801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007802ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007803TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007804 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007805 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007806 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007807 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007808
7809 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007810
Douglas Gregord51d90d2010-04-26 20:11:03 +00007811 // If nothing changed, just retain the existing expression.
7812 if (!getDerived().AlwaysRebuild() &&
7813 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007814 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007815
John McCallb268a282010-08-23 23:25:46 +00007816 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007817 E->getLocation(),
7818 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007819}
7820
Mike Stump11289f42009-09-09 15:08:12 +00007821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007822ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007823TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007824 // 'super' and types never change. Property never changes. Just
7825 // retain the existing expression.
7826 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007827 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007828
Douglas Gregor9faee212010-04-26 20:47:02 +00007829 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007830 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007831 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007832 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007833
Douglas Gregor9faee212010-04-26 20:47:02 +00007834 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007835
Douglas Gregor9faee212010-04-26 20:47:02 +00007836 // If nothing changed, just retain the existing expression.
7837 if (!getDerived().AlwaysRebuild() &&
7838 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007839 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007840
John McCallb7bd14f2010-12-02 01:19:52 +00007841 if (E->isExplicitProperty())
7842 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7843 E->getExplicitProperty(),
7844 E->getLocation());
7845
7846 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7847 E->getType(),
7848 E->getImplicitPropertyGetter(),
7849 E->getImplicitPropertySetter(),
7850 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007851}
7852
Mike Stump11289f42009-09-09 15:08:12 +00007853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007854ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007855TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007856 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007857 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007858 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007859 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007860
Douglas Gregord51d90d2010-04-26 20:11:03 +00007861 // If nothing changed, just retain the existing expression.
7862 if (!getDerived().AlwaysRebuild() &&
7863 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007864 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007865
John McCallb268a282010-08-23 23:25:46 +00007866 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007867 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007868}
7869
Mike Stump11289f42009-09-09 15:08:12 +00007870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007871ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007872TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007873 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007874 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007875 SubExprs.reserve(E->getNumSubExprs());
7876 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7877 SubExprs, &ArgumentChanged))
7878 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007879
Douglas Gregora16548e2009-08-11 05:31:07 +00007880 if (!getDerived().AlwaysRebuild() &&
7881 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007882 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007883
Douglas Gregora16548e2009-08-11 05:31:07 +00007884 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7885 move_arg(SubExprs),
7886 E->getRParenLoc());
7887}
7888
Mike Stump11289f42009-09-09 15:08:12 +00007889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007890ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007891TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007892 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007893
John McCall490112f2011-02-04 18:33:18 +00007894 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7895 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7896
7897 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00007898 // We built a new blockScopeInfo in call to ActOnBlockStart
7899 // in above, CapturesCXXThis need be set here from the block
7900 // expression.
7901 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7902
John McCall490112f2011-02-04 18:33:18 +00007903 llvm::SmallVector<ParmVarDecl*, 4> params;
7904 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007905
7906 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007907 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7908 oldBlock->param_begin(),
7909 oldBlock->param_size(),
7910 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007911 return true;
John McCall490112f2011-02-04 18:33:18 +00007912
7913 const FunctionType *exprFunctionType = E->getFunctionType();
7914 QualType exprResultType = exprFunctionType->getResultType();
7915 if (!exprResultType.isNull()) {
7916 if (!exprResultType->isDependentType())
7917 blockScope->ReturnType = exprResultType;
7918 else if (exprResultType != getSema().Context.DependentTy)
7919 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007920 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007921
7922 // If the return type has not been determined yet, leave it as a dependent
7923 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007924 if (blockScope->ReturnType.isNull())
7925 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007926
7927 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007928 if (blockScope->ReturnType->isObjCObjectType()) {
7929 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007930 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007931 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007932 return ExprError();
7933 }
John McCall3882ace2011-01-05 12:14:39 +00007934
John McCall490112f2011-02-04 18:33:18 +00007935 QualType functionType = getDerived().RebuildFunctionProtoType(
7936 blockScope->ReturnType,
7937 paramTypes.data(),
7938 paramTypes.size(),
7939 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007940 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007941 exprFunctionType->getExtInfo());
7942 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007943
7944 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007945 if (!params.empty())
7946 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007947
7948 // If the return type wasn't explicitly set, it will have been marked as a
7949 // dependent type (DependentTy); clear out the return type setting so
7950 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007951 if (blockScope->ReturnType == getSema().Context.DependentTy)
7952 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007953
John McCall3882ace2011-01-05 12:14:39 +00007954 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007955 StmtResult body = getDerived().TransformStmt(E->getBody());
7956 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007957 return ExprError();
7958
John McCall490112f2011-02-04 18:33:18 +00007959#ifndef NDEBUG
7960 // In builds with assertions, make sure that we captured everything we
7961 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007962 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
7963 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7964 e = oldBlock->capture_end(); i != e; ++i) {
7965 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007966
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007967 // Ignore parameter packs.
7968 if (isa<ParmVarDecl>(oldCapture) &&
7969 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7970 continue;
John McCall490112f2011-02-04 18:33:18 +00007971
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007972 VarDecl *newCapture =
7973 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7974 oldCapture));
7975 assert(blockScope->CaptureMap.count(newCapture));
7976 }
John McCall490112f2011-02-04 18:33:18 +00007977 }
7978#endif
7979
7980 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7981 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007982}
7983
Mike Stump11289f42009-09-09 15:08:12 +00007984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007985ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007986TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007987 ValueDecl *ND
7988 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7989 E->getDecl()));
7990 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007991 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007992
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007993 if (!getDerived().AlwaysRebuild() &&
7994 ND == E->getDecl()) {
7995 // Mark it referenced in the new context regardless.
7996 // FIXME: this is a bit instantiation-specific.
7997 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7998
John McCallc3007a22010-10-26 07:05:15 +00007999 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008000 }
8001
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008002 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00008003 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008004 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008005}
Mike Stump11289f42009-09-09 15:08:12 +00008006
Tanya Lattner55808c12011-06-04 00:47:47 +00008007template<typename Derived>
8008ExprResult
8009TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
8010 assert(false && "Cannot transform asType expressions yet");
8011 return SemaRef.Owned(E);
8012}
8013
Douglas Gregora16548e2009-08-11 05:31:07 +00008014//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008015// Type reconstruction
8016//===----------------------------------------------------------------------===//
8017
Mike Stump11289f42009-09-09 15:08:12 +00008018template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008019QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8020 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008021 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008022 getDerived().getBaseEntity());
8023}
8024
Mike Stump11289f42009-09-09 15:08:12 +00008025template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008026QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8027 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008028 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008029 getDerived().getBaseEntity());
8030}
8031
Mike Stump11289f42009-09-09 15:08:12 +00008032template<typename Derived>
8033QualType
John McCall70dd5f62009-10-30 00:06:24 +00008034TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8035 bool WrittenAsLValue,
8036 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008037 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00008038 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008039}
8040
8041template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008042QualType
John McCall70dd5f62009-10-30 00:06:24 +00008043TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8044 QualType ClassType,
8045 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008046 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00008047 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008048}
8049
8050template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008051QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00008052TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8053 ArrayType::ArraySizeModifier SizeMod,
8054 const llvm::APInt *Size,
8055 Expr *SizeExpr,
8056 unsigned IndexTypeQuals,
8057 SourceRange BracketsRange) {
8058 if (SizeExpr || !Size)
8059 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8060 IndexTypeQuals, BracketsRange,
8061 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00008062
8063 QualType Types[] = {
8064 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8065 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8066 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00008067 };
8068 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8069 QualType SizeType;
8070 for (unsigned I = 0; I != NumTypes; ++I)
8071 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8072 SizeType = Types[I];
8073 break;
8074 }
Mike Stump11289f42009-09-09 15:08:12 +00008075
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008076 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8077 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00008078 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008079 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00008080 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008081}
Mike Stump11289f42009-09-09 15:08:12 +00008082
Douglas Gregord6ff3322009-08-04 16:50:30 +00008083template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008084QualType
8085TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008086 ArrayType::ArraySizeModifier SizeMod,
8087 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00008088 unsigned IndexTypeQuals,
8089 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008090 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008091 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008092}
8093
8094template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008095QualType
Mike Stump11289f42009-09-09 15:08:12 +00008096TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008097 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00008098 unsigned IndexTypeQuals,
8099 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008100 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008101 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008102}
Mike Stump11289f42009-09-09 15:08:12 +00008103
Douglas Gregord6ff3322009-08-04 16:50:30 +00008104template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008105QualType
8106TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008107 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008108 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008109 unsigned IndexTypeQuals,
8110 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008111 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008112 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008113 IndexTypeQuals, BracketsRange);
8114}
8115
8116template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008117QualType
8118TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008119 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008120 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008121 unsigned IndexTypeQuals,
8122 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008123 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008124 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008125 IndexTypeQuals, BracketsRange);
8126}
8127
8128template<typename Derived>
8129QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00008130 unsigned NumElements,
8131 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00008132 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00008133 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008134}
Mike Stump11289f42009-09-09 15:08:12 +00008135
Douglas Gregord6ff3322009-08-04 16:50:30 +00008136template<typename Derived>
8137QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8138 unsigned NumElements,
8139 SourceLocation AttributeLoc) {
8140 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8141 NumElements, true);
8142 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008143 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8144 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00008145 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008146}
Mike Stump11289f42009-09-09 15:08:12 +00008147
Douglas Gregord6ff3322009-08-04 16:50:30 +00008148template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008149QualType
8150TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00008151 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008152 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00008153 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008154}
Mike Stump11289f42009-09-09 15:08:12 +00008155
Douglas Gregord6ff3322009-08-04 16:50:30 +00008156template<typename Derived>
8157QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00008158 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008159 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00008160 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00008161 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008162 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00008163 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00008164 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008165 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008166 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008167 getDerived().getBaseEntity(),
8168 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008169}
Mike Stump11289f42009-09-09 15:08:12 +00008170
Douglas Gregord6ff3322009-08-04 16:50:30 +00008171template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008172QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8173 return SemaRef.Context.getFunctionNoProtoType(T);
8174}
8175
8176template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008177QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8178 assert(D && "no decl found");
8179 if (D->isInvalidDecl()) return QualType();
8180
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008181 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008182 TypeDecl *Ty;
8183 if (isa<UsingDecl>(D)) {
8184 UsingDecl *Using = cast<UsingDecl>(D);
8185 assert(Using->isTypeName() &&
8186 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8187
8188 // A valid resolved using typename decl points to exactly one type decl.
8189 assert(++Using->shadow_begin() == Using->shadow_end());
8190 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008191
John McCallb96ec562009-12-04 22:46:56 +00008192 } else {
8193 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8194 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8195 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8196 }
8197
8198 return SemaRef.Context.getTypeDeclType(Ty);
8199}
8200
8201template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008202QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8203 SourceLocation Loc) {
8204 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008205}
8206
8207template<typename Derived>
8208QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8209 return SemaRef.Context.getTypeOfType(Underlying);
8210}
8211
8212template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008213QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8214 SourceLocation Loc) {
8215 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008216}
8217
8218template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00008219QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8220 UnaryTransformType::UTTKind UKind,
8221 SourceLocation Loc) {
8222 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8223}
8224
8225template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00008226QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008227 TemplateName Template,
8228 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008229 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008230 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008231}
Mike Stump11289f42009-09-09 15:08:12 +00008232
Douglas Gregor1135c352009-08-06 05:28:30 +00008233template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008234TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008235TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008236 bool TemplateKW,
8237 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008238 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008239 Template);
8240}
8241
8242template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008243TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008244TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8245 const IdentifierInfo &Name,
8246 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008247 QualType ObjectType,
8248 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008249 UnqualifiedId TemplateName;
8250 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008251 Sema::TemplateTy Template;
8252 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008253 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008254 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008255 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008256 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008257 /*EnteringContext=*/false,
8258 Template);
John McCall31f82722010-11-12 08:19:04 +00008259 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008260}
Mike Stump11289f42009-09-09 15:08:12 +00008261
Douglas Gregora16548e2009-08-11 05:31:07 +00008262template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008263TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008264TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008265 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008266 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008267 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008268 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008269 // FIXME: Bogus location information.
8270 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8271 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008272 Sema::TemplateTy Template;
8273 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008274 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008275 SS,
8276 Name,
John McCallba7bf592010-08-24 05:47:05 +00008277 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008278 /*EnteringContext=*/false,
8279 Template);
8280 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008281}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008282
Douglas Gregor71395fa2009-11-04 00:56:37 +00008283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008284ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008285TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8286 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008287 Expr *OrigCallee,
8288 Expr *First,
8289 Expr *Second) {
8290 Expr *Callee = OrigCallee->IgnoreParenCasts();
8291 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008292
Douglas Gregora16548e2009-08-11 05:31:07 +00008293 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008294 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008295 if (!First->getType()->isOverloadableType() &&
8296 !Second->getType()->isOverloadableType())
8297 return getSema().CreateBuiltinArraySubscriptExpr(First,
8298 Callee->getLocStart(),
8299 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008300 } else if (Op == OO_Arrow) {
8301 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008302 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8303 } else if (Second == 0 || isPostIncDec) {
8304 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008305 // The argument is not of overloadable type, so try to create a
8306 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008307 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008308 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008309
John McCallb268a282010-08-23 23:25:46 +00008310 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008311 }
8312 } else {
John McCallb268a282010-08-23 23:25:46 +00008313 if (!First->getType()->isOverloadableType() &&
8314 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008315 // Neither of the arguments is an overloadable type, so try to
8316 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008317 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008318 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008319 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008320 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008321 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008322
Douglas Gregora16548e2009-08-11 05:31:07 +00008323 return move(Result);
8324 }
8325 }
Mike Stump11289f42009-09-09 15:08:12 +00008326
8327 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008328 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008329 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008330
John McCallb268a282010-08-23 23:25:46 +00008331 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008332 assert(ULE->requiresADL());
8333
8334 // FIXME: Do we have to check
8335 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008336 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008337 } else {
John McCallb268a282010-08-23 23:25:46 +00008338 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008339 }
Mike Stump11289f42009-09-09 15:08:12 +00008340
Douglas Gregora16548e2009-08-11 05:31:07 +00008341 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008342 Expr *Args[2] = { First, Second };
8343 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008344
Douglas Gregora16548e2009-08-11 05:31:07 +00008345 // Create the overloaded operator invocation for unary operators.
8346 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008347 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008348 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008349 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008350 }
Mike Stump11289f42009-09-09 15:08:12 +00008351
Sebastian Redladba46e2009-10-29 20:17:01 +00008352 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00008353 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00008354 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008355 First,
8356 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00008357
Douglas Gregora16548e2009-08-11 05:31:07 +00008358 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008359 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008360 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008361 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8362 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008363 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008364
Mike Stump11289f42009-09-09 15:08:12 +00008365 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008366}
Mike Stump11289f42009-09-09 15:08:12 +00008367
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008369ExprResult
John McCallb268a282010-08-23 23:25:46 +00008370TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008371 SourceLocation OperatorLoc,
8372 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008373 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008374 TypeSourceInfo *ScopeType,
8375 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008376 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008377 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008378 QualType BaseType = Base->getType();
8379 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008380 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008381 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008382 !BaseType->getAs<PointerType>()->getPointeeType()
8383 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008384 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008385 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008386 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008387 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008388 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008389 /*FIXME?*/true);
8390 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008391
Douglas Gregor678f90d2010-02-25 01:56:36 +00008392 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008393 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8394 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8395 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8396 NameInfo.setNamedTypeInfo(DestroyedType);
8397
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008398 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008399
John McCallb268a282010-08-23 23:25:46 +00008400 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008401 OperatorLoc, isArrow,
8402 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008403 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008404 /*TemplateArgs*/ 0);
8405}
8406
Douglas Gregord6ff3322009-08-04 16:50:30 +00008407} // end namespace clang
8408
8409#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H