blob: 66ea7df4ee79e7abc36238618d7cf7b92784a556 [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.
John McCalldadc5752010-08-24 06:29:42 +00001869 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001870 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 }
1872
1873 /// \brief Build a new C++ default-argument expression.
1874 ///
1875 /// By default, builds a new default-argument expression, which does not
1876 /// require any semantic analysis. Subclasses may override this routine to
1877 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001878 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001879 ParmVarDecl *Param) {
1880 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1881 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001882 }
1883
1884 /// \brief Build a new C++ zero-initialization expression.
1885 ///
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001888 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1889 SourceLocation LParenLoc,
1890 SourceLocation RParenLoc) {
1891 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001892 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001893 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 }
Mike Stump11289f42009-09-09 15:08:12 +00001895
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 /// \brief Build a new C++ "new" expression.
1897 ///
1898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001900 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001901 bool UseGlobal,
1902 SourceLocation PlacementLParen,
1903 MultiExprArg PlacementArgs,
1904 SourceLocation PlacementRParen,
1905 SourceRange TypeIdParens,
1906 QualType AllocatedType,
1907 TypeSourceInfo *AllocatedTypeInfo,
1908 Expr *ArraySize,
1909 SourceLocation ConstructorLParen,
1910 MultiExprArg ConstructorArgs,
1911 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001912 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 PlacementLParen,
1914 move(PlacementArgs),
1915 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001916 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001917 AllocatedType,
1918 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001919 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 ConstructorLParen,
1921 move(ConstructorArgs),
1922 ConstructorRParen);
1923 }
Mike Stump11289f42009-09-09 15:08:12 +00001924
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 /// \brief Build a new C++ "delete" expression.
1926 ///
1927 /// By default, performs semantic analysis to build the new expression.
1928 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001929 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 bool IsGlobalDelete,
1931 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001932 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001934 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 }
Mike Stump11289f42009-09-09 15:08:12 +00001936
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 /// \brief Build a new unary type trait expression.
1938 ///
1939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001941 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001942 SourceLocation StartLoc,
1943 TypeSourceInfo *T,
1944 SourceLocation RParenLoc) {
1945 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 }
1947
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001948 /// \brief Build a new binary type trait expression.
1949 ///
1950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
1952 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1953 SourceLocation StartLoc,
1954 TypeSourceInfo *LhsT,
1955 TypeSourceInfo *RhsT,
1956 SourceLocation RParenLoc) {
1957 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1958 }
1959
John Wiegley6242b6a2011-04-28 00:16:57 +00001960 /// \brief Build a new array type trait expression.
1961 ///
1962 /// By default, performs semantic analysis to build the new expression.
1963 /// Subclasses may override this routine to provide different behavior.
1964 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1965 SourceLocation StartLoc,
1966 TypeSourceInfo *TSInfo,
1967 Expr *DimExpr,
1968 SourceLocation RParenLoc) {
1969 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1970 }
1971
John Wiegleyf9f65842011-04-25 06:54:41 +00001972 /// \brief Build a new expression trait expression.
1973 ///
1974 /// By default, performs semantic analysis to build the new expression.
1975 /// Subclasses may override this routine to provide different behavior.
1976 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1977 SourceLocation StartLoc,
1978 Expr *Queried,
1979 SourceLocation RParenLoc) {
1980 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1981 }
1982
Mike Stump11289f42009-09-09 15:08:12 +00001983 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 /// expression.
1985 ///
1986 /// By default, performs semantic analysis to build the new expression.
1987 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001988 ExprResult RebuildDependentScopeDeclRefExpr(
1989 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001990 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001991 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001993 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001994
1995 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001996 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001997 *TemplateArgs);
1998
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001999 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 }
2001
2002 /// \brief Build a new template-id expression.
2003 ///
2004 /// By default, performs semantic analysis to build the new expression.
2005 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002006 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00002007 LookupResult &R,
2008 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00002009 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00002010 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 }
2012
2013 /// \brief Build a new object-construction expression.
2014 ///
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002017 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002018 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 CXXConstructorDecl *Constructor,
2020 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002021 MultiExprArg Args,
2022 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002023 CXXConstructExpr::ConstructionKind ConstructKind,
2024 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002025 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002026 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002027 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002028 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002029
Douglas Gregordb121ba2009-12-14 16:27:04 +00002030 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002031 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00002032 RequiresZeroInit, ConstructKind,
2033 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 }
2035
2036 /// \brief Build a new object-construction expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002040 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2041 SourceLocation LParenLoc,
2042 MultiExprArg Args,
2043 SourceLocation RParenLoc) {
2044 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 LParenLoc,
2046 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 RParenLoc);
2048 }
2049
2050 /// \brief Build a new object-construction expression.
2051 ///
2052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002054 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2055 SourceLocation LParenLoc,
2056 MultiExprArg Args,
2057 SourceLocation RParenLoc) {
2058 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 LParenLoc,
2060 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 RParenLoc);
2062 }
Mike Stump11289f42009-09-09 15:08:12 +00002063
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 /// \brief Build a new member reference expression.
2065 ///
2066 /// By default, performs semantic analysis to build the new expression.
2067 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002068 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002069 QualType BaseType,
2070 bool IsArrow,
2071 SourceLocation OperatorLoc,
2072 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002073 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002074 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002075 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002077 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002078
John McCallb268a282010-08-23 23:25:46 +00002079 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002080 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002081 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002082 MemberNameInfo,
2083 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 }
2085
John McCall10eae182009-11-30 22:42:35 +00002086 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002090 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002091 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002092 SourceLocation OperatorLoc,
2093 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002094 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002095 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002096 LookupResult &R,
2097 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002098 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002099 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002100
John McCallb268a282010-08-23 23:25:46 +00002101 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002102 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002103 SS, FirstQualifierInScope,
2104 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002105 }
Mike Stump11289f42009-09-09 15:08:12 +00002106
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002107 /// \brief Build a new noexcept expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
2111 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2112 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2113 }
2114
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002115 /// \brief Build a new expression to compute the length of a parameter pack.
2116 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2117 SourceLocation PackLoc,
2118 SourceLocation RParenLoc,
2119 unsigned Length) {
2120 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2121 OperatorLoc, Pack, PackLoc,
2122 RParenLoc, Length);
2123 }
2124
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 /// \brief Build a new Objective-C @encode expression.
2126 ///
2127 /// By default, performs semantic analysis to build the new expression.
2128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002129 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002130 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002132 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002134 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002135
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002136 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002138 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002139 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002140 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002141 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002142 MultiExprArg Args,
2143 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002144 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2145 ReceiverTypeInfo->getType(),
2146 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002147 Sel, Method, LBracLoc, SelectorLoc,
2148 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002149 }
2150
2151 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002152 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002153 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002154 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002155 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002156 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002157 MultiExprArg Args,
2158 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002159 return SemaRef.BuildInstanceMessage(Receiver,
2160 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002161 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002162 Sel, Method, LBracLoc, SelectorLoc,
2163 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002164 }
2165
Douglas Gregord51d90d2010-04-26 20:11:03 +00002166 /// \brief Build a new Objective-C ivar reference expression.
2167 ///
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002170 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002171 SourceLocation IvarLoc,
2172 bool IsArrow, bool IsFreeIvar) {
2173 // FIXME: We lose track of the IsFreeIvar bit.
2174 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002175 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002176 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2177 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002178 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002179 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002180 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002181 false);
John Wiegley01296292011-04-08 18:41:53 +00002182 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002183 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002184
Douglas Gregord51d90d2010-04-26 20:11:03 +00002185 if (Result.get())
2186 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002187
John Wiegley01296292011-04-08 18:41:53 +00002188 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002189 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002190 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002191 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002192 /*TemplateArgs=*/0);
2193 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002194
2195 /// \brief Build a new Objective-C property reference expression.
2196 ///
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002199 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002200 ObjCPropertyDecl *Property,
2201 SourceLocation PropertyLoc) {
2202 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002203 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002204 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2205 Sema::LookupMemberName);
2206 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002207 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002208 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002209 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002210 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002211 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002212
Douglas Gregor9faee212010-04-26 20:47:02 +00002213 if (Result.get())
2214 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002215
John Wiegley01296292011-04-08 18:41:53 +00002216 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002217 /*FIXME:*/PropertyLoc, IsArrow,
2218 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002219 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002220 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002221 /*TemplateArgs=*/0);
2222 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002223
John McCallb7bd14f2010-12-02 01:19:52 +00002224 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002225 ///
2226 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002227 /// Subclasses may override this routine to provide different behavior.
2228 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2229 ObjCMethodDecl *Getter,
2230 ObjCMethodDecl *Setter,
2231 SourceLocation PropertyLoc) {
2232 // Since these expressions can only be value-dependent, we do not
2233 // need to perform semantic analysis again.
2234 return Owned(
2235 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2236 VK_LValue, OK_ObjCProperty,
2237 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002238 }
2239
Douglas Gregord51d90d2010-04-26 20:11:03 +00002240 /// \brief Build a new Objective-C "isa" expression.
2241 ///
2242 /// By default, performs semantic analysis to build the new expression.
2243 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002244 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002245 bool IsArrow) {
2246 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002247 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002248 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2249 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002250 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002251 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002252 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002253 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002254 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002255
Douglas Gregord51d90d2010-04-26 20:11:03 +00002256 if (Result.get())
2257 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002258
John Wiegley01296292011-04-08 18:41:53 +00002259 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002260 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002261 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002262 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002263 /*TemplateArgs=*/0);
2264 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002265
Douglas Gregora16548e2009-08-11 05:31:07 +00002266 /// \brief Build a new shuffle vector expression.
2267 ///
2268 /// By default, performs semantic analysis to build the new expression.
2269 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002270 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002271 MultiExprArg SubExprs,
2272 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002273 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002274 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2276 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2277 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2278 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002279
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 // Build a reference to the __builtin_shufflevector builtin
2281 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002282 ExprResult Callee
2283 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2284 VK_LValue, BuiltinLoc));
2285 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2286 if (Callee.isInvalid())
2287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002288
2289 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 unsigned NumSubExprs = SubExprs.size();
2291 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002292 ExprResult TheCall = SemaRef.Owned(
2293 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002294 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002295 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002296 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002297 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002298
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002300 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 }
John McCall31f82722010-11-12 08:19:04 +00002302
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002303 /// \brief Build a new template argument pack expansion.
2304 ///
2305 /// By default, performs semantic analysis to build a new pack expansion
2306 /// for a template argument. Subclasses may override this routine to provide
2307 /// different behavior.
2308 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002309 SourceLocation EllipsisLoc,
2310 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002311 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002312 case TemplateArgument::Expression: {
2313 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002314 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2315 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002316 if (Result.isInvalid())
2317 return TemplateArgumentLoc();
2318
2319 return TemplateArgumentLoc(Result.get(), Result.get());
2320 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002321
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002322 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002323 return TemplateArgumentLoc(TemplateArgument(
2324 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002325 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002326 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002327 Pattern.getTemplateNameLoc(),
2328 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002329
2330 case TemplateArgument::Null:
2331 case TemplateArgument::Integral:
2332 case TemplateArgument::Declaration:
2333 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002334 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002335 llvm_unreachable("Pack expansion pattern has no parameter packs");
2336
2337 case TemplateArgument::Type:
2338 if (TypeSourceInfo *Expansion
2339 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002340 EllipsisLoc,
2341 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002342 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2343 Expansion);
2344 break;
2345 }
2346
2347 return TemplateArgumentLoc();
2348 }
2349
Douglas Gregor968f23a2011-01-03 19:31:53 +00002350 /// \brief Build a new expression pack expansion.
2351 ///
2352 /// By default, performs semantic analysis to build a new pack expansion
2353 /// for an expression. Subclasses may override this routine to provide
2354 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002355 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2356 llvm::Optional<unsigned> NumExpansions) {
2357 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002358 }
2359
John McCall31f82722010-11-12 08:19:04 +00002360private:
Douglas Gregor14454802011-02-25 02:25:35 +00002361 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2362 QualType ObjectType,
2363 NamedDecl *FirstQualifierInScope,
2364 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002365
2366 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2367 QualType ObjectType,
2368 NamedDecl *FirstQualifierInScope,
2369 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002370};
Douglas Gregora16548e2009-08-11 05:31:07 +00002371
Douglas Gregorebe10102009-08-20 07:17:43 +00002372template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002373StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002374 if (!S)
2375 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002376
Douglas Gregorebe10102009-08-20 07:17:43 +00002377 switch (S->getStmtClass()) {
2378 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002379
Douglas Gregorebe10102009-08-20 07:17:43 +00002380 // Transform individual statement nodes
2381#define STMT(Node, Parent) \
2382 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002383#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002384#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002385#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002386
Douglas Gregorebe10102009-08-20 07:17:43 +00002387 // Transform expressions by calling TransformExpr.
2388#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002389#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002390#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002391#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002392 {
John McCalldadc5752010-08-24 06:29:42 +00002393 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002394 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002395 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002396
John McCallb268a282010-08-23 23:25:46 +00002397 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002398 }
Mike Stump11289f42009-09-09 15:08:12 +00002399 }
2400
John McCallc3007a22010-10-26 07:05:15 +00002401 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002402}
Mike Stump11289f42009-09-09 15:08:12 +00002403
2404
Douglas Gregore922c772009-08-04 22:27:00 +00002405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002406ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 if (!E)
2408 return SemaRef.Owned(E);
2409
2410 switch (E->getStmtClass()) {
2411 case Stmt::NoStmtClass: break;
2412#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002413#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002414#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002415 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002416#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002417 }
2418
John McCallc3007a22010-10-26 07:05:15 +00002419 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002420}
2421
2422template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002423bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2424 unsigned NumInputs,
2425 bool IsCall,
2426 llvm::SmallVectorImpl<Expr *> &Outputs,
2427 bool *ArgChanged) {
2428 for (unsigned I = 0; I != NumInputs; ++I) {
2429 // If requested, drop call arguments that need to be dropped.
2430 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2431 if (ArgChanged)
2432 *ArgChanged = true;
2433
2434 break;
2435 }
2436
Douglas Gregor968f23a2011-01-03 19:31:53 +00002437 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2438 Expr *Pattern = Expansion->getPattern();
2439
2440 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2441 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2442 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2443
2444 // Determine whether the set of unexpanded parameter packs can and should
2445 // be expanded.
2446 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002447 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002448 llvm::Optional<unsigned> OrigNumExpansions
2449 = Expansion->getNumExpansions();
2450 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002451 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2452 Pattern->getSourceRange(),
2453 Unexpanded.data(),
2454 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002455 Expand, RetainExpansion,
2456 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002457 return true;
2458
2459 if (!Expand) {
2460 // The transform has determined that we should perform a simple
2461 // transformation on the pack expansion, producing another pack
2462 // expansion.
2463 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2464 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2465 if (OutPattern.isInvalid())
2466 return true;
2467
2468 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002469 Expansion->getEllipsisLoc(),
2470 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002471 if (Out.isInvalid())
2472 return true;
2473
2474 if (ArgChanged)
2475 *ArgChanged = true;
2476 Outputs.push_back(Out.get());
2477 continue;
2478 }
John McCall542e7c62011-07-06 07:30:07 +00002479
2480 // Record right away that the argument was changed. This needs
2481 // to happen even if the array expands to nothing.
2482 if (ArgChanged) *ArgChanged = true;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002483
2484 // The transform has determined that we should perform an elementwise
2485 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002486 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002487 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2488 ExprResult Out = getDerived().TransformExpr(Pattern);
2489 if (Out.isInvalid())
2490 return true;
2491
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002492 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002493 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2494 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002495 if (Out.isInvalid())
2496 return true;
2497 }
2498
Douglas Gregor968f23a2011-01-03 19:31:53 +00002499 Outputs.push_back(Out.get());
2500 }
2501
2502 continue;
2503 }
2504
Douglas Gregora3efea12011-01-03 19:04:46 +00002505 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2506 if (Result.isInvalid())
2507 return true;
2508
2509 if (Result.get() != Inputs[I] && ArgChanged)
2510 *ArgChanged = true;
2511
2512 Outputs.push_back(Result.get());
2513 }
2514
2515 return false;
2516}
2517
2518template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002519NestedNameSpecifierLoc
2520TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2521 NestedNameSpecifierLoc NNS,
2522 QualType ObjectType,
2523 NamedDecl *FirstQualifierInScope) {
2524 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2525 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2526 Qualifier = Qualifier.getPrefix())
2527 Qualifiers.push_back(Qualifier);
2528
2529 CXXScopeSpec SS;
2530 while (!Qualifiers.empty()) {
2531 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2532 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2533
2534 switch (QNNS->getKind()) {
2535 case NestedNameSpecifier::Identifier:
2536 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2537 *QNNS->getAsIdentifier(),
2538 Q.getLocalBeginLoc(),
2539 Q.getLocalEndLoc(),
2540 ObjectType, false, SS,
2541 FirstQualifierInScope, false))
2542 return NestedNameSpecifierLoc();
2543
2544 break;
2545
2546 case NestedNameSpecifier::Namespace: {
2547 NamespaceDecl *NS
2548 = cast_or_null<NamespaceDecl>(
2549 getDerived().TransformDecl(
2550 Q.getLocalBeginLoc(),
2551 QNNS->getAsNamespace()));
2552 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2553 break;
2554 }
2555
2556 case NestedNameSpecifier::NamespaceAlias: {
2557 NamespaceAliasDecl *Alias
2558 = cast_or_null<NamespaceAliasDecl>(
2559 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2560 QNNS->getAsNamespaceAlias()));
2561 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2562 Q.getLocalEndLoc());
2563 break;
2564 }
2565
2566 case NestedNameSpecifier::Global:
2567 // There is no meaningful transformation that one could perform on the
2568 // global scope.
2569 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2570 break;
2571
2572 case NestedNameSpecifier::TypeSpecWithTemplate:
2573 case NestedNameSpecifier::TypeSpec: {
2574 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2575 FirstQualifierInScope, SS);
2576
2577 if (!TL)
2578 return NestedNameSpecifierLoc();
2579
2580 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2581 (SemaRef.getLangOptions().CPlusPlus0x &&
2582 TL.getType()->isEnumeralType())) {
2583 assert(!TL.getType().hasLocalQualifiers() &&
2584 "Can't get cv-qualifiers here");
2585 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2586 Q.getLocalEndLoc());
2587 break;
2588 }
Richard Trieude756fb2011-05-07 01:36:37 +00002589 // If the nested-name-specifier is an invalid type def, don't emit an
2590 // error because a previous error should have already been emitted.
2591 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2592 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2593 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2594 << TL.getType() << SS.getRange();
2595 }
Douglas Gregor14454802011-02-25 02:25:35 +00002596 return NestedNameSpecifierLoc();
2597 }
Douglas Gregore16af532011-02-28 18:50:33 +00002598 }
Douglas Gregor14454802011-02-25 02:25:35 +00002599
Douglas Gregore16af532011-02-28 18:50:33 +00002600 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002601 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002602 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002603 }
2604
2605 // Don't rebuild the nested-name-specifier if we don't have to.
2606 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2607 !getDerived().AlwaysRebuild())
2608 return NNS;
2609
2610 // If we can re-use the source-location data from the original
2611 // nested-name-specifier, do so.
2612 if (SS.location_size() == NNS.getDataLength() &&
2613 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2614 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2615
2616 // Allocate new nested-name-specifier location information.
2617 return SS.getWithLocInContext(SemaRef.Context);
2618}
2619
2620template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002621DeclarationNameInfo
2622TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002623::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002624 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002625 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002626 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002627
2628 switch (Name.getNameKind()) {
2629 case DeclarationName::Identifier:
2630 case DeclarationName::ObjCZeroArgSelector:
2631 case DeclarationName::ObjCOneArgSelector:
2632 case DeclarationName::ObjCMultiArgSelector:
2633 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002634 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002635 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002636 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002637
Douglas Gregorf816bd72009-09-03 22:13:48 +00002638 case DeclarationName::CXXConstructorName:
2639 case DeclarationName::CXXDestructorName:
2640 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002641 TypeSourceInfo *NewTInfo;
2642 CanQualType NewCanTy;
2643 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002644 NewTInfo = getDerived().TransformType(OldTInfo);
2645 if (!NewTInfo)
2646 return DeclarationNameInfo();
2647 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002648 }
2649 else {
2650 NewTInfo = 0;
2651 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002652 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002653 if (NewT.isNull())
2654 return DeclarationNameInfo();
2655 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2656 }
Mike Stump11289f42009-09-09 15:08:12 +00002657
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002658 DeclarationName NewName
2659 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2660 NewCanTy);
2661 DeclarationNameInfo NewNameInfo(NameInfo);
2662 NewNameInfo.setName(NewName);
2663 NewNameInfo.setNamedTypeInfo(NewTInfo);
2664 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002665 }
Mike Stump11289f42009-09-09 15:08:12 +00002666 }
2667
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002668 assert(0 && "Unknown name kind.");
2669 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002670}
2671
2672template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002673TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002674TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2675 TemplateName Name,
2676 SourceLocation NameLoc,
2677 QualType ObjectType,
2678 NamedDecl *FirstQualifierInScope) {
2679 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2680 TemplateDecl *Template = QTN->getTemplateDecl();
2681 assert(Template && "qualified template name must refer to a template");
2682
2683 TemplateDecl *TransTemplate
2684 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2685 Template));
2686 if (!TransTemplate)
2687 return TemplateName();
2688
2689 if (!getDerived().AlwaysRebuild() &&
2690 SS.getScopeRep() == QTN->getQualifier() &&
2691 TransTemplate == Template)
2692 return Name;
2693
2694 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2695 TransTemplate);
2696 }
2697
2698 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2699 if (SS.getScopeRep()) {
2700 // These apply to the scope specifier, not the template.
2701 ObjectType = QualType();
2702 FirstQualifierInScope = 0;
2703 }
2704
2705 if (!getDerived().AlwaysRebuild() &&
2706 SS.getScopeRep() == DTN->getQualifier() &&
2707 ObjectType.isNull())
2708 return Name;
2709
2710 if (DTN->isIdentifier()) {
2711 return getDerived().RebuildTemplateName(SS,
2712 *DTN->getIdentifier(),
2713 NameLoc,
2714 ObjectType,
2715 FirstQualifierInScope);
2716 }
2717
2718 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2719 ObjectType);
2720 }
2721
2722 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2723 TemplateDecl *TransTemplate
2724 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2725 Template));
2726 if (!TransTemplate)
2727 return TemplateName();
2728
2729 if (!getDerived().AlwaysRebuild() &&
2730 TransTemplate == Template)
2731 return Name;
2732
2733 return TemplateName(TransTemplate);
2734 }
2735
2736 if (SubstTemplateTemplateParmPackStorage *SubstPack
2737 = Name.getAsSubstTemplateTemplateParmPack()) {
2738 TemplateTemplateParmDecl *TransParam
2739 = cast_or_null<TemplateTemplateParmDecl>(
2740 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2741 if (!TransParam)
2742 return TemplateName();
2743
2744 if (!getDerived().AlwaysRebuild() &&
2745 TransParam == SubstPack->getParameterPack())
2746 return Name;
2747
2748 return getDerived().RebuildTemplateName(TransParam,
2749 SubstPack->getArgumentPack());
2750 }
2751
2752 // These should be getting filtered out before they reach the AST.
2753 llvm_unreachable("overloaded function decl survived to here");
2754 return TemplateName();
2755}
2756
2757template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002758void TreeTransform<Derived>::InventTemplateArgumentLoc(
2759 const TemplateArgument &Arg,
2760 TemplateArgumentLoc &Output) {
2761 SourceLocation Loc = getDerived().getBaseLocation();
2762 switch (Arg.getKind()) {
2763 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002764 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002765 break;
2766
2767 case TemplateArgument::Type:
2768 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002769 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002770
John McCall0ad16662009-10-29 08:12:44 +00002771 break;
2772
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002773 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002774 case TemplateArgument::TemplateExpansion: {
2775 NestedNameSpecifierLocBuilder Builder;
2776 TemplateName Template = Arg.getAsTemplate();
2777 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2778 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2779 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2780 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2781
2782 if (Arg.getKind() == TemplateArgument::Template)
2783 Output = TemplateArgumentLoc(Arg,
2784 Builder.getWithLocInContext(SemaRef.Context),
2785 Loc);
2786 else
2787 Output = TemplateArgumentLoc(Arg,
2788 Builder.getWithLocInContext(SemaRef.Context),
2789 Loc, Loc);
2790
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002791 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002792 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002793
John McCall0ad16662009-10-29 08:12:44 +00002794 case TemplateArgument::Expression:
2795 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2796 break;
2797
2798 case TemplateArgument::Declaration:
2799 case TemplateArgument::Integral:
2800 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002801 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002802 break;
2803 }
2804}
2805
2806template<typename Derived>
2807bool TreeTransform<Derived>::TransformTemplateArgument(
2808 const TemplateArgumentLoc &Input,
2809 TemplateArgumentLoc &Output) {
2810 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002811 switch (Arg.getKind()) {
2812 case TemplateArgument::Null:
2813 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002814 Output = Input;
2815 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002816
Douglas Gregore922c772009-08-04 22:27:00 +00002817 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002818 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002819 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002820 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002821
2822 DI = getDerived().TransformType(DI);
2823 if (!DI) return true;
2824
2825 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2826 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002827 }
Mike Stump11289f42009-09-09 15:08:12 +00002828
Douglas Gregore922c772009-08-04 22:27:00 +00002829 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002830 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002831 DeclarationName Name;
2832 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2833 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002834 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002835 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002836 if (!D) return true;
2837
John McCall0d07eb32009-10-29 18:45:58 +00002838 Expr *SourceExpr = Input.getSourceDeclExpression();
2839 if (SourceExpr) {
2840 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002841 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002842 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002843 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002844 }
2845
2846 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002847 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002848 }
Mike Stump11289f42009-09-09 15:08:12 +00002849
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002850 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002851 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2852 if (QualifierLoc) {
2853 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2854 if (!QualifierLoc)
2855 return true;
2856 }
2857
Douglas Gregordf846d12011-03-02 18:46:51 +00002858 CXXScopeSpec SS;
2859 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002860 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002861 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2862 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002863 if (Template.isNull())
2864 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002865
Douglas Gregor9d802122011-03-02 17:09:35 +00002866 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002867 Input.getTemplateNameLoc());
2868 return false;
2869 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002870
2871 case TemplateArgument::TemplateExpansion:
2872 llvm_unreachable("Caller should expand pack expansions");
2873
Douglas Gregore922c772009-08-04 22:27:00 +00002874 case TemplateArgument::Expression: {
2875 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002876 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002877 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002878
John McCall0ad16662009-10-29 08:12:44 +00002879 Expr *InputExpr = Input.getSourceExpression();
2880 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2881
Chris Lattnercdb591a2011-04-25 20:37:58 +00002882 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002883 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002884 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002885 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002886 }
Mike Stump11289f42009-09-09 15:08:12 +00002887
Douglas Gregore922c772009-08-04 22:27:00 +00002888 case TemplateArgument::Pack: {
2889 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2890 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002891 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002892 AEnd = Arg.pack_end();
2893 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002894
John McCall0ad16662009-10-29 08:12:44 +00002895 // FIXME: preserve source information here when we start
2896 // caring about parameter packs.
2897
John McCall0d07eb32009-10-29 18:45:58 +00002898 TemplateArgumentLoc InputArg;
2899 TemplateArgumentLoc OutputArg;
2900 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2901 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002902 return true;
2903
John McCall0d07eb32009-10-29 18:45:58 +00002904 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002905 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002906
2907 TemplateArgument *TransformedArgsPtr
2908 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2909 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2910 TransformedArgsPtr);
2911 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2912 TransformedArgs.size()),
2913 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002914 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002915 }
2916 }
Mike Stump11289f42009-09-09 15:08:12 +00002917
Douglas Gregore922c772009-08-04 22:27:00 +00002918 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002919 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002920}
2921
Douglas Gregorfe921a72010-12-20 23:36:19 +00002922/// \brief Iterator adaptor that invents template argument location information
2923/// for each of the template arguments in its underlying iterator.
2924template<typename Derived, typename InputIterator>
2925class TemplateArgumentLocInventIterator {
2926 TreeTransform<Derived> &Self;
2927 InputIterator Iter;
2928
2929public:
2930 typedef TemplateArgumentLoc value_type;
2931 typedef TemplateArgumentLoc reference;
2932 typedef typename std::iterator_traits<InputIterator>::difference_type
2933 difference_type;
2934 typedef std::input_iterator_tag iterator_category;
2935
2936 class pointer {
2937 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002938
Douglas Gregorfe921a72010-12-20 23:36:19 +00002939 public:
2940 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2941
2942 const TemplateArgumentLoc *operator->() const { return &Arg; }
2943 };
2944
2945 TemplateArgumentLocInventIterator() { }
2946
2947 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2948 InputIterator Iter)
2949 : Self(Self), Iter(Iter) { }
2950
2951 TemplateArgumentLocInventIterator &operator++() {
2952 ++Iter;
2953 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002954 }
2955
Douglas Gregorfe921a72010-12-20 23:36:19 +00002956 TemplateArgumentLocInventIterator operator++(int) {
2957 TemplateArgumentLocInventIterator Old(*this);
2958 ++(*this);
2959 return Old;
2960 }
2961
2962 reference operator*() const {
2963 TemplateArgumentLoc Result;
2964 Self.InventTemplateArgumentLoc(*Iter, Result);
2965 return Result;
2966 }
2967
2968 pointer operator->() const { return pointer(**this); }
2969
2970 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2971 const TemplateArgumentLocInventIterator &Y) {
2972 return X.Iter == Y.Iter;
2973 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002974
Douglas Gregorfe921a72010-12-20 23:36:19 +00002975 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2976 const TemplateArgumentLocInventIterator &Y) {
2977 return X.Iter != Y.Iter;
2978 }
2979};
2980
Douglas Gregor42cafa82010-12-20 17:42:22 +00002981template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002982template<typename InputIterator>
2983bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2984 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002985 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002986 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002987 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002988 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002989
2990 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2991 // Unpack argument packs, which we translate them into separate
2992 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002993 // FIXME: We could do much better if we could guarantee that the
2994 // TemplateArgumentLocInfo for the pack expansion would be usable for
2995 // all of the template arguments in the argument pack.
2996 typedef TemplateArgumentLocInventIterator<Derived,
2997 TemplateArgument::pack_iterator>
2998 PackLocIterator;
2999 if (TransformTemplateArguments(PackLocIterator(*this,
3000 In.getArgument().pack_begin()),
3001 PackLocIterator(*this,
3002 In.getArgument().pack_end()),
3003 Outputs))
3004 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003005
3006 continue;
3007 }
3008
3009 if (In.getArgument().isPackExpansion()) {
3010 // We have a pack expansion, for which we will be substituting into
3011 // the pattern.
3012 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003013 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003014 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003015 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3016 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003017
3018 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3019 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3020 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3021
3022 // Determine whether the set of unexpanded parameter packs can and should
3023 // be expanded.
3024 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003025 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003026 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003027 if (getDerived().TryExpandParameterPacks(Ellipsis,
3028 Pattern.getSourceRange(),
3029 Unexpanded.data(),
3030 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003031 Expand,
3032 RetainExpansion,
3033 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003034 return true;
3035
3036 if (!Expand) {
3037 // The transform has determined that we should perform a simple
3038 // transformation on the pack expansion, producing another pack
3039 // expansion.
3040 TemplateArgumentLoc OutPattern;
3041 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3042 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3043 return true;
3044
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003045 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3046 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003047 if (Out.getArgument().isNull())
3048 return true;
3049
3050 Outputs.addArgument(Out);
3051 continue;
3052 }
3053
3054 // The transform has determined that we should perform an elementwise
3055 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003056 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003057 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3058
3059 if (getDerived().TransformTemplateArgument(Pattern, Out))
3060 return true;
3061
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003062 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003063 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3064 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003065 if (Out.getArgument().isNull())
3066 return true;
3067 }
3068
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003069 Outputs.addArgument(Out);
3070 }
3071
Douglas Gregor48d24112011-01-10 20:53:55 +00003072 // If we're supposed to retain a pack expansion, do so by temporarily
3073 // forgetting the partially-substituted parameter pack.
3074 if (RetainExpansion) {
3075 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3076
3077 if (getDerived().TransformTemplateArgument(Pattern, Out))
3078 return true;
3079
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003080 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3081 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003082 if (Out.getArgument().isNull())
3083 return true;
3084
3085 Outputs.addArgument(Out);
3086 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003087
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003088 continue;
3089 }
3090
3091 // The simple case:
3092 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003093 return true;
3094
3095 Outputs.addArgument(Out);
3096 }
3097
3098 return false;
3099
3100}
3101
Douglas Gregord6ff3322009-08-04 16:50:30 +00003102//===----------------------------------------------------------------------===//
3103// Type transformation
3104//===----------------------------------------------------------------------===//
3105
3106template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003107QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003108 if (getDerived().AlreadyTransformed(T))
3109 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003110
John McCall550e0c22009-10-21 00:40:46 +00003111 // Temporary workaround. All of these transformations should
3112 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003113 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3114 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003115
John McCall31f82722010-11-12 08:19:04 +00003116 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003117
John McCall550e0c22009-10-21 00:40:46 +00003118 if (!NewDI)
3119 return QualType();
3120
3121 return NewDI->getType();
3122}
3123
3124template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003125TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003126 if (getDerived().AlreadyTransformed(DI->getType()))
3127 return DI;
3128
3129 TypeLocBuilder TLB;
3130
3131 TypeLoc TL = DI->getTypeLoc();
3132 TLB.reserve(TL.getFullDataSize());
3133
John McCall31f82722010-11-12 08:19:04 +00003134 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003135 if (Result.isNull())
3136 return 0;
3137
John McCallbcd03502009-12-07 02:54:59 +00003138 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003139}
3140
3141template<typename Derived>
3142QualType
John McCall31f82722010-11-12 08:19:04 +00003143TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003144 switch (T.getTypeLocClass()) {
3145#define ABSTRACT_TYPELOC(CLASS, PARENT)
3146#define TYPELOC(CLASS, PARENT) \
3147 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003148 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003149#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003150 }
Mike Stump11289f42009-09-09 15:08:12 +00003151
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003152 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003153 return QualType();
3154}
3155
3156/// FIXME: By default, this routine adds type qualifiers only to types
3157/// that can have qualifiers, and silently suppresses those qualifiers
3158/// that are not permitted (e.g., qualifiers on reference or function
3159/// types). This is the right thing for template instantiation, but
3160/// probably not for other clients.
3161template<typename Derived>
3162QualType
3163TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003164 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003165 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003166
John McCall31f82722010-11-12 08:19:04 +00003167 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003168 if (Result.isNull())
3169 return QualType();
3170
3171 // Silently suppress qualifiers if the result type can't be qualified.
3172 // FIXME: this is the right thing for template instantiation, but
3173 // probably not for other clients.
3174 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003175 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003176
John McCall31168b02011-06-15 23:02:42 +00003177 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003178 // resulting type.
3179 if (Quals.hasObjCLifetime()) {
3180 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3181 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003182 else if (Result.getObjCLifetime()) {
Douglas Gregore46db902011-06-17 22:11:49 +00003183 // Objective-C ARC:
3184 // A lifetime qualifier applied to a substituted template parameter
3185 // overrides the lifetime qualifier from the template argument.
3186 if (const SubstTemplateTypeParmType *SubstTypeParam
3187 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3188 QualType Replacement = SubstTypeParam->getReplacementType();
3189 Qualifiers Qs = Replacement.getQualifiers();
3190 Qs.removeObjCLifetime();
3191 Replacement
3192 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3193 Qs);
3194 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3195 SubstTypeParam->getReplacedParameter(),
3196 Replacement);
3197 TLB.TypeWasModifiedSafely(Result);
3198 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003199 // Otherwise, complain about the addition of a qualifier to an
3200 // already-qualified type.
3201 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003202 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003203 << Result << R;
3204
Douglas Gregore46db902011-06-17 22:11:49 +00003205 Quals.removeObjCLifetime();
3206 }
3207 }
3208 }
John McCallcb0f89a2010-06-05 06:41:15 +00003209 if (!Quals.empty()) {
3210 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3211 TLB.push<QualifiedTypeLoc>(Result);
3212 // No location information to preserve.
3213 }
John McCall550e0c22009-10-21 00:40:46 +00003214
3215 return Result;
3216}
3217
Douglas Gregor14454802011-02-25 02:25:35 +00003218template<typename Derived>
3219TypeLoc
3220TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3221 QualType ObjectType,
3222 NamedDecl *UnqualLookup,
3223 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003224 QualType T = TL.getType();
3225 if (getDerived().AlreadyTransformed(T))
3226 return TL;
3227
3228 TypeLocBuilder TLB;
3229 QualType Result;
3230
3231 if (isa<TemplateSpecializationType>(T)) {
3232 TemplateSpecializationTypeLoc SpecTL
3233 = cast<TemplateSpecializationTypeLoc>(TL);
3234
3235 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003236 getDerived().TransformTemplateName(SS,
3237 SpecTL.getTypePtr()->getTemplateName(),
3238 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003239 ObjectType, UnqualLookup);
3240 if (Template.isNull())
3241 return TypeLoc();
3242
3243 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3244 Template);
3245 } else if (isa<DependentTemplateSpecializationType>(T)) {
3246 DependentTemplateSpecializationTypeLoc SpecTL
3247 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3248
Douglas Gregor5a064722011-02-28 17:23:35 +00003249 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003250 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003251 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003252 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003253 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003254 if (Template.isNull())
3255 return TypeLoc();
3256
Douglas Gregor14454802011-02-25 02:25:35 +00003257 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003258 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003259 Template,
3260 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003261 } else {
3262 // Nothing special needs to be done for these.
3263 Result = getDerived().TransformType(TLB, TL);
3264 }
3265
3266 if (Result.isNull())
3267 return TypeLoc();
3268
3269 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3270}
3271
Douglas Gregor579c15f2011-03-02 18:32:08 +00003272template<typename Derived>
3273TypeSourceInfo *
3274TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3275 QualType ObjectType,
3276 NamedDecl *UnqualLookup,
3277 CXXScopeSpec &SS) {
3278 // FIXME: Painfully copy-paste from the above!
3279
3280 QualType T = TSInfo->getType();
3281 if (getDerived().AlreadyTransformed(T))
3282 return TSInfo;
3283
3284 TypeLocBuilder TLB;
3285 QualType Result;
3286
3287 TypeLoc TL = TSInfo->getTypeLoc();
3288 if (isa<TemplateSpecializationType>(T)) {
3289 TemplateSpecializationTypeLoc SpecTL
3290 = cast<TemplateSpecializationTypeLoc>(TL);
3291
3292 TemplateName Template
3293 = getDerived().TransformTemplateName(SS,
3294 SpecTL.getTypePtr()->getTemplateName(),
3295 SpecTL.getTemplateNameLoc(),
3296 ObjectType, UnqualLookup);
3297 if (Template.isNull())
3298 return 0;
3299
3300 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3301 Template);
3302 } else if (isa<DependentTemplateSpecializationType>(T)) {
3303 DependentTemplateSpecializationTypeLoc SpecTL
3304 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3305
3306 TemplateName Template
3307 = getDerived().RebuildTemplateName(SS,
3308 *SpecTL.getTypePtr()->getIdentifier(),
3309 SpecTL.getNameLoc(),
3310 ObjectType, UnqualLookup);
3311 if (Template.isNull())
3312 return 0;
3313
3314 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3315 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003316 Template,
3317 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003318 } else {
3319 // Nothing special needs to be done for these.
3320 Result = getDerived().TransformType(TLB, TL);
3321 }
3322
3323 if (Result.isNull())
3324 return 0;
3325
3326 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3327}
3328
John McCall550e0c22009-10-21 00:40:46 +00003329template <class TyLoc> static inline
3330QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3331 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3332 NewT.setNameLoc(T.getNameLoc());
3333 return T.getType();
3334}
3335
John McCall550e0c22009-10-21 00:40:46 +00003336template<typename Derived>
3337QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003338 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003339 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3340 NewT.setBuiltinLoc(T.getBuiltinLoc());
3341 if (T.needsExtraLocalData())
3342 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3343 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003344}
Mike Stump11289f42009-09-09 15:08:12 +00003345
Douglas Gregord6ff3322009-08-04 16:50:30 +00003346template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003347QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003348 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003349 // FIXME: recurse?
3350 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003351}
Mike Stump11289f42009-09-09 15:08:12 +00003352
Douglas Gregord6ff3322009-08-04 16:50:30 +00003353template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003354QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003355 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003356 QualType PointeeType
3357 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003358 if (PointeeType.isNull())
3359 return QualType();
3360
3361 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003362 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003363 // A dependent pointer type 'T *' has is being transformed such
3364 // that an Objective-C class type is being replaced for 'T'. The
3365 // resulting pointer type is an ObjCObjectPointerType, not a
3366 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003367 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003368
John McCall8b07ec22010-05-15 11:32:37 +00003369 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3370 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003371 return Result;
3372 }
John McCall31f82722010-11-12 08:19:04 +00003373
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003374 if (getDerived().AlwaysRebuild() ||
3375 PointeeType != TL.getPointeeLoc().getType()) {
3376 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3377 if (Result.isNull())
3378 return QualType();
3379 }
John McCall31168b02011-06-15 23:02:42 +00003380
3381 // Objective-C ARC can add lifetime qualifiers to the type that we're
3382 // pointing to.
3383 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3384
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003385 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3386 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003387 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003388}
Mike Stump11289f42009-09-09 15:08:12 +00003389
3390template<typename Derived>
3391QualType
John McCall550e0c22009-10-21 00:40:46 +00003392TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003393 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003394 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003395 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3396 if (PointeeType.isNull())
3397 return QualType();
3398
3399 QualType Result = TL.getType();
3400 if (getDerived().AlwaysRebuild() ||
3401 PointeeType != TL.getPointeeLoc().getType()) {
3402 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003403 TL.getSigilLoc());
3404 if (Result.isNull())
3405 return QualType();
3406 }
3407
Douglas Gregor049211a2010-04-22 16:50:51 +00003408 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003409 NewT.setSigilLoc(TL.getSigilLoc());
3410 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003411}
3412
John McCall70dd5f62009-10-30 00:06:24 +00003413/// Transforms a reference type. Note that somewhat paradoxically we
3414/// don't care whether the type itself is an l-value type or an r-value
3415/// type; we only care if the type was *written* as an l-value type
3416/// or an r-value type.
3417template<typename Derived>
3418QualType
3419TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003420 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003421 const ReferenceType *T = TL.getTypePtr();
3422
3423 // Note that this works with the pointee-as-written.
3424 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3425 if (PointeeType.isNull())
3426 return QualType();
3427
3428 QualType Result = TL.getType();
3429 if (getDerived().AlwaysRebuild() ||
3430 PointeeType != T->getPointeeTypeAsWritten()) {
3431 Result = getDerived().RebuildReferenceType(PointeeType,
3432 T->isSpelledAsLValue(),
3433 TL.getSigilLoc());
3434 if (Result.isNull())
3435 return QualType();
3436 }
3437
John McCall31168b02011-06-15 23:02:42 +00003438 // Objective-C ARC can add lifetime qualifiers to the type that we're
3439 // referring to.
3440 TLB.TypeWasModifiedSafely(
3441 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3442
John McCall70dd5f62009-10-30 00:06:24 +00003443 // r-value references can be rebuilt as l-value references.
3444 ReferenceTypeLoc NewTL;
3445 if (isa<LValueReferenceType>(Result))
3446 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3447 else
3448 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3449 NewTL.setSigilLoc(TL.getSigilLoc());
3450
3451 return Result;
3452}
3453
Mike Stump11289f42009-09-09 15:08:12 +00003454template<typename Derived>
3455QualType
John McCall550e0c22009-10-21 00:40:46 +00003456TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003457 LValueReferenceTypeLoc TL) {
3458 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003459}
3460
Mike Stump11289f42009-09-09 15:08:12 +00003461template<typename Derived>
3462QualType
John McCall550e0c22009-10-21 00:40:46 +00003463TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003464 RValueReferenceTypeLoc TL) {
3465 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003466}
Mike Stump11289f42009-09-09 15:08:12 +00003467
Douglas Gregord6ff3322009-08-04 16:50:30 +00003468template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003469QualType
John McCall550e0c22009-10-21 00:40:46 +00003470TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003471 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003472 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003473 if (PointeeType.isNull())
3474 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003475
Abramo Bagnara509357842011-03-05 14:42:21 +00003476 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3477 TypeSourceInfo* NewClsTInfo = 0;
3478 if (OldClsTInfo) {
3479 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3480 if (!NewClsTInfo)
3481 return QualType();
3482 }
3483
3484 const MemberPointerType *T = TL.getTypePtr();
3485 QualType OldClsType = QualType(T->getClass(), 0);
3486 QualType NewClsType;
3487 if (NewClsTInfo)
3488 NewClsType = NewClsTInfo->getType();
3489 else {
3490 NewClsType = getDerived().TransformType(OldClsType);
3491 if (NewClsType.isNull())
3492 return QualType();
3493 }
Mike Stump11289f42009-09-09 15:08:12 +00003494
John McCall550e0c22009-10-21 00:40:46 +00003495 QualType Result = TL.getType();
3496 if (getDerived().AlwaysRebuild() ||
3497 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003498 NewClsType != OldClsType) {
3499 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003500 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003501 if (Result.isNull())
3502 return QualType();
3503 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003504
John McCall550e0c22009-10-21 00:40:46 +00003505 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3506 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003507 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003508
3509 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003510}
3511
Mike Stump11289f42009-09-09 15:08:12 +00003512template<typename Derived>
3513QualType
John McCall550e0c22009-10-21 00:40:46 +00003514TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003515 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003516 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003517 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003518 if (ElementType.isNull())
3519 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003520
John McCall550e0c22009-10-21 00:40:46 +00003521 QualType Result = TL.getType();
3522 if (getDerived().AlwaysRebuild() ||
3523 ElementType != T->getElementType()) {
3524 Result = getDerived().RebuildConstantArrayType(ElementType,
3525 T->getSizeModifier(),
3526 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003527 T->getIndexTypeCVRQualifiers(),
3528 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003529 if (Result.isNull())
3530 return QualType();
3531 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003532
John McCall550e0c22009-10-21 00:40:46 +00003533 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3534 NewTL.setLBracketLoc(TL.getLBracketLoc());
3535 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003536
John McCall550e0c22009-10-21 00:40:46 +00003537 Expr *Size = TL.getSizeExpr();
3538 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003539 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003540 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3541 }
3542 NewTL.setSizeExpr(Size);
3543
3544 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003545}
Mike Stump11289f42009-09-09 15:08:12 +00003546
Douglas Gregord6ff3322009-08-04 16:50:30 +00003547template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003548QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003549 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003550 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003551 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003552 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003553 if (ElementType.isNull())
3554 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003555
John McCall550e0c22009-10-21 00:40:46 +00003556 QualType Result = TL.getType();
3557 if (getDerived().AlwaysRebuild() ||
3558 ElementType != T->getElementType()) {
3559 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003560 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003561 T->getIndexTypeCVRQualifiers(),
3562 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003563 if (Result.isNull())
3564 return QualType();
3565 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003566
John McCall550e0c22009-10-21 00:40:46 +00003567 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3568 NewTL.setLBracketLoc(TL.getLBracketLoc());
3569 NewTL.setRBracketLoc(TL.getRBracketLoc());
3570 NewTL.setSizeExpr(0);
3571
3572 return Result;
3573}
3574
3575template<typename Derived>
3576QualType
3577TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003578 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003579 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003580 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3581 if (ElementType.isNull())
3582 return QualType();
3583
3584 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003585 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003586
John McCalldadc5752010-08-24 06:29:42 +00003587 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003588 = getDerived().TransformExpr(T->getSizeExpr());
3589 if (SizeResult.isInvalid())
3590 return QualType();
3591
John McCallb268a282010-08-23 23:25:46 +00003592 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003593
3594 QualType Result = TL.getType();
3595 if (getDerived().AlwaysRebuild() ||
3596 ElementType != T->getElementType() ||
3597 Size != T->getSizeExpr()) {
3598 Result = getDerived().RebuildVariableArrayType(ElementType,
3599 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003600 Size,
John McCall550e0c22009-10-21 00:40:46 +00003601 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003602 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003603 if (Result.isNull())
3604 return QualType();
3605 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003606
John McCall550e0c22009-10-21 00:40:46 +00003607 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3608 NewTL.setLBracketLoc(TL.getLBracketLoc());
3609 NewTL.setRBracketLoc(TL.getRBracketLoc());
3610 NewTL.setSizeExpr(Size);
3611
3612 return Result;
3613}
3614
3615template<typename Derived>
3616QualType
3617TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003618 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003619 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003620 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3621 if (ElementType.isNull())
3622 return QualType();
3623
3624 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003625 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003626
John McCall33ddac02011-01-19 10:06:00 +00003627 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3628 Expr *origSize = TL.getSizeExpr();
3629 if (!origSize) origSize = T->getSizeExpr();
3630
3631 ExprResult sizeResult
3632 = getDerived().TransformExpr(origSize);
3633 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003634 return QualType();
3635
John McCall33ddac02011-01-19 10:06:00 +00003636 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003637
3638 QualType Result = TL.getType();
3639 if (getDerived().AlwaysRebuild() ||
3640 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003641 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003642 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3643 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003644 size,
John McCall550e0c22009-10-21 00:40:46 +00003645 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003646 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003647 if (Result.isNull())
3648 return QualType();
3649 }
John McCall550e0c22009-10-21 00:40:46 +00003650
3651 // We might have any sort of array type now, but fortunately they
3652 // all have the same location layout.
3653 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3654 NewTL.setLBracketLoc(TL.getLBracketLoc());
3655 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003656 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003657
3658 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003659}
Mike Stump11289f42009-09-09 15:08:12 +00003660
3661template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003662QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003663 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003664 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003665 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003666
3667 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003668 QualType ElementType = getDerived().TransformType(T->getElementType());
3669 if (ElementType.isNull())
3670 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003671
Douglas Gregore922c772009-08-04 22:27:00 +00003672 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003673 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003674
John McCalldadc5752010-08-24 06:29:42 +00003675 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003676 if (Size.isInvalid())
3677 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003678
John McCall550e0c22009-10-21 00:40:46 +00003679 QualType Result = TL.getType();
3680 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003681 ElementType != T->getElementType() ||
3682 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003683 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003684 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003685 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003686 if (Result.isNull())
3687 return QualType();
3688 }
John McCall550e0c22009-10-21 00:40:46 +00003689
3690 // Result might be dependent or not.
3691 if (isa<DependentSizedExtVectorType>(Result)) {
3692 DependentSizedExtVectorTypeLoc NewTL
3693 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3694 NewTL.setNameLoc(TL.getNameLoc());
3695 } else {
3696 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3697 NewTL.setNameLoc(TL.getNameLoc());
3698 }
3699
3700 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003701}
Mike Stump11289f42009-09-09 15:08:12 +00003702
3703template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003704QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003705 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003706 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003707 QualType ElementType = getDerived().TransformType(T->getElementType());
3708 if (ElementType.isNull())
3709 return QualType();
3710
John McCall550e0c22009-10-21 00:40:46 +00003711 QualType Result = TL.getType();
3712 if (getDerived().AlwaysRebuild() ||
3713 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003714 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003715 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003716 if (Result.isNull())
3717 return QualType();
3718 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003719
John McCall550e0c22009-10-21 00:40:46 +00003720 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3721 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003722
John McCall550e0c22009-10-21 00:40:46 +00003723 return Result;
3724}
3725
3726template<typename Derived>
3727QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003728 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003729 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003730 QualType ElementType = getDerived().TransformType(T->getElementType());
3731 if (ElementType.isNull())
3732 return QualType();
3733
3734 QualType Result = TL.getType();
3735 if (getDerived().AlwaysRebuild() ||
3736 ElementType != T->getElementType()) {
3737 Result = getDerived().RebuildExtVectorType(ElementType,
3738 T->getNumElements(),
3739 /*FIXME*/ SourceLocation());
3740 if (Result.isNull())
3741 return QualType();
3742 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003743
John McCall550e0c22009-10-21 00:40:46 +00003744 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3745 NewTL.setNameLoc(TL.getNameLoc());
3746
3747 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003748}
Mike Stump11289f42009-09-09 15:08:12 +00003749
3750template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003751ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003752TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003753 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003754 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003755 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003756 TypeSourceInfo *NewDI = 0;
3757
3758 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3759 // If we're substituting into a pack expansion type and we know the
3760 TypeLoc OldTL = OldDI->getTypeLoc();
3761 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3762
3763 TypeLocBuilder TLB;
3764 TypeLoc NewTL = OldDI->getTypeLoc();
3765 TLB.reserve(NewTL.getFullDataSize());
3766
3767 QualType Result = getDerived().TransformType(TLB,
3768 OldExpansionTL.getPatternLoc());
3769 if (Result.isNull())
3770 return 0;
3771
3772 Result = RebuildPackExpansionType(Result,
3773 OldExpansionTL.getPatternLoc().getSourceRange(),
3774 OldExpansionTL.getEllipsisLoc(),
3775 NumExpansions);
3776 if (Result.isNull())
3777 return 0;
3778
3779 PackExpansionTypeLoc NewExpansionTL
3780 = TLB.push<PackExpansionTypeLoc>(Result);
3781 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3782 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3783 } else
3784 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003785 if (!NewDI)
3786 return 0;
3787
John McCall8fb0d9d2011-05-01 22:35:37 +00003788 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003789 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003790
3791 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3792 OldParm->getDeclContext(),
3793 OldParm->getInnerLocStart(),
3794 OldParm->getLocation(),
3795 OldParm->getIdentifier(),
3796 NewDI->getType(),
3797 NewDI,
3798 OldParm->getStorageClass(),
3799 OldParm->getStorageClassAsWritten(),
3800 /* DefArg */ NULL);
3801 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3802 OldParm->getFunctionScopeIndex() + indexAdjustment);
3803 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003804}
3805
3806template<typename Derived>
3807bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003808 TransformFunctionTypeParams(SourceLocation Loc,
3809 ParmVarDecl **Params, unsigned NumParams,
3810 const QualType *ParamTypes,
3811 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3812 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003813 int indexAdjustment = 0;
3814
Douglas Gregordd472162011-01-07 00:20:55 +00003815 for (unsigned i = 0; i != NumParams; ++i) {
3816 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003817 assert(OldParm->getFunctionScopeIndex() == i);
3818
Douglas Gregor715e4612011-01-14 22:40:04 +00003819 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003820 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003821 if (OldParm->isParameterPack()) {
3822 // We have a function parameter pack that may need to be expanded.
3823 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003824
Douglas Gregor5499af42011-01-05 23:12:31 +00003825 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003826 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3827 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3828 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3829 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003830 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3831
Douglas Gregor5499af42011-01-05 23:12:31 +00003832 // Determine whether we should expand the parameter packs.
3833 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003834 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003835 llvm::Optional<unsigned> OrigNumExpansions
3836 = ExpansionTL.getTypePtr()->getNumExpansions();
3837 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003838 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3839 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003840 Unexpanded.data(),
3841 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003842 ShouldExpand,
3843 RetainExpansion,
3844 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003845 return true;
3846 }
3847
3848 if (ShouldExpand) {
3849 // Expand the function parameter pack into multiple, separate
3850 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003851 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003852 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003853 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3854 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003855 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003856 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003857 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003858 if (!NewParm)
3859 return true;
3860
Douglas Gregordd472162011-01-07 00:20:55 +00003861 OutParamTypes.push_back(NewParm->getType());
3862 if (PVars)
3863 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003864 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003865
3866 // If we're supposed to retain a pack expansion, do so by temporarily
3867 // forgetting the partially-substituted parameter pack.
3868 if (RetainExpansion) {
3869 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3870 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003871 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003872 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003873 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003874 if (!NewParm)
3875 return true;
3876
3877 OutParamTypes.push_back(NewParm->getType());
3878 if (PVars)
3879 PVars->push_back(NewParm);
3880 }
3881
John McCall8fb0d9d2011-05-01 22:35:37 +00003882 // The next parameter should have the same adjustment as the
3883 // last thing we pushed, but we post-incremented indexAdjustment
3884 // on every push. Also, if we push nothing, the adjustment should
3885 // go down by one.
3886 indexAdjustment--;
3887
Douglas Gregor5499af42011-01-05 23:12:31 +00003888 // We're done with the pack expansion.
3889 continue;
3890 }
3891
3892 // We'll substitute the parameter now without expanding the pack
3893 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003894 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3895 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003896 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003897 NumExpansions);
3898 } else {
3899 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003900 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003901 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003902 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003903
John McCall58f10c32010-03-11 09:03:00 +00003904 if (!NewParm)
3905 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003906
Douglas Gregordd472162011-01-07 00:20:55 +00003907 OutParamTypes.push_back(NewParm->getType());
3908 if (PVars)
3909 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003910 continue;
3911 }
John McCall58f10c32010-03-11 09:03:00 +00003912
3913 // Deal with the possibility that we don't have a parameter
3914 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003915 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003916 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003917 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003918 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003919 if (const PackExpansionType *Expansion
3920 = dyn_cast<PackExpansionType>(OldType)) {
3921 // We have a function parameter pack that may need to be expanded.
3922 QualType Pattern = Expansion->getPattern();
3923 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3924 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3925
3926 // Determine whether we should expand the parameter packs.
3927 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003928 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003929 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003930 Unexpanded.data(),
3931 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003932 ShouldExpand,
3933 RetainExpansion,
3934 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003935 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003936 }
3937
3938 if (ShouldExpand) {
3939 // Expand the function parameter pack into multiple, separate
3940 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003941 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003942 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3943 QualType NewType = getDerived().TransformType(Pattern);
3944 if (NewType.isNull())
3945 return true;
John McCall58f10c32010-03-11 09:03:00 +00003946
Douglas Gregordd472162011-01-07 00:20:55 +00003947 OutParamTypes.push_back(NewType);
3948 if (PVars)
3949 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003950 }
3951
3952 // We're done with the pack expansion.
3953 continue;
3954 }
3955
Douglas Gregor48d24112011-01-10 20:53:55 +00003956 // If we're supposed to retain a pack expansion, do so by temporarily
3957 // forgetting the partially-substituted parameter pack.
3958 if (RetainExpansion) {
3959 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3960 QualType NewType = getDerived().TransformType(Pattern);
3961 if (NewType.isNull())
3962 return true;
3963
3964 OutParamTypes.push_back(NewType);
3965 if (PVars)
3966 PVars->push_back(0);
3967 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003968
Douglas Gregor5499af42011-01-05 23:12:31 +00003969 // We'll substitute the parameter now without expanding the pack
3970 // expansion.
3971 OldType = Expansion->getPattern();
3972 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003973 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3974 NewType = getDerived().TransformType(OldType);
3975 } else {
3976 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003977 }
3978
Douglas Gregor5499af42011-01-05 23:12:31 +00003979 if (NewType.isNull())
3980 return true;
3981
3982 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003983 NewType = getSema().Context.getPackExpansionType(NewType,
3984 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003985
Douglas Gregordd472162011-01-07 00:20:55 +00003986 OutParamTypes.push_back(NewType);
3987 if (PVars)
3988 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003989 }
3990
John McCall8fb0d9d2011-05-01 22:35:37 +00003991#ifndef NDEBUG
3992 if (PVars) {
3993 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3994 if (ParmVarDecl *parm = (*PVars)[i])
3995 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00003996 }
John McCall8fb0d9d2011-05-01 22:35:37 +00003997#endif
3998
3999 return false;
4000}
John McCall58f10c32010-03-11 09:03:00 +00004001
4002template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004003QualType
John McCall550e0c22009-10-21 00:40:46 +00004004TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004005 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004006 // Transform the parameters and return type.
4007 //
4008 // We instantiate in source order, with the return type first followed by
4009 // the parameters, because users tend to expect this (even if they shouldn't
4010 // rely on it!).
4011 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00004012 // When the function has a trailing return type, we instantiate the
4013 // parameters before the return type, since the return type can then refer
4014 // to the parameters themselves (via decltype, sizeof, etc.).
4015 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00004016 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00004017 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004018 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004019
Douglas Gregor7fb25412010-10-01 18:44:50 +00004020 QualType ResultType;
4021
4022 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004023 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4024 TL.getParmArray(),
4025 TL.getNumArgs(),
4026 TL.getTypePtr()->arg_type_begin(),
4027 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004028 return QualType();
4029
4030 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4031 if (ResultType.isNull())
4032 return QualType();
4033 }
4034 else {
4035 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4036 if (ResultType.isNull())
4037 return QualType();
4038
Douglas Gregordd472162011-01-07 00:20:55 +00004039 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4040 TL.getParmArray(),
4041 TL.getNumArgs(),
4042 TL.getTypePtr()->arg_type_begin(),
4043 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004044 return QualType();
4045 }
4046
John McCall550e0c22009-10-21 00:40:46 +00004047 QualType Result = TL.getType();
4048 if (getDerived().AlwaysRebuild() ||
4049 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004050 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004051 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4052 Result = getDerived().RebuildFunctionProtoType(ResultType,
4053 ParamTypes.data(),
4054 ParamTypes.size(),
4055 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004056 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004057 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004058 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004059 if (Result.isNull())
4060 return QualType();
4061 }
Mike Stump11289f42009-09-09 15:08:12 +00004062
John McCall550e0c22009-10-21 00:40:46 +00004063 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004064 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4065 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004066 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004067 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4068 NewTL.setArg(i, ParamDecls[i]);
4069
4070 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004071}
Mike Stump11289f42009-09-09 15:08:12 +00004072
Douglas Gregord6ff3322009-08-04 16:50:30 +00004073template<typename Derived>
4074QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004075 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004076 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004077 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004078 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4079 if (ResultType.isNull())
4080 return QualType();
4081
4082 QualType Result = TL.getType();
4083 if (getDerived().AlwaysRebuild() ||
4084 ResultType != T->getResultType())
4085 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4086
4087 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004088 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4089 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004090 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004091
4092 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004093}
Mike Stump11289f42009-09-09 15:08:12 +00004094
John McCallb96ec562009-12-04 22:46:56 +00004095template<typename Derived> QualType
4096TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004097 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004098 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004099 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004100 if (!D)
4101 return QualType();
4102
4103 QualType Result = TL.getType();
4104 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4105 Result = getDerived().RebuildUnresolvedUsingType(D);
4106 if (Result.isNull())
4107 return QualType();
4108 }
4109
4110 // We might get an arbitrary type spec type back. We should at
4111 // least always get a type spec type, though.
4112 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4113 NewTL.setNameLoc(TL.getNameLoc());
4114
4115 return Result;
4116}
4117
Douglas Gregord6ff3322009-08-04 16:50:30 +00004118template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004119QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004120 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004121 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004122 TypedefNameDecl *Typedef
4123 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4124 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004125 if (!Typedef)
4126 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004127
John McCall550e0c22009-10-21 00:40:46 +00004128 QualType Result = TL.getType();
4129 if (getDerived().AlwaysRebuild() ||
4130 Typedef != T->getDecl()) {
4131 Result = getDerived().RebuildTypedefType(Typedef);
4132 if (Result.isNull())
4133 return QualType();
4134 }
Mike Stump11289f42009-09-09 15:08:12 +00004135
John McCall550e0c22009-10-21 00:40:46 +00004136 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4137 NewTL.setNameLoc(TL.getNameLoc());
4138
4139 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004140}
Mike Stump11289f42009-09-09 15:08:12 +00004141
Douglas Gregord6ff3322009-08-04 16:50:30 +00004142template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004143QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004144 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004145 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004146 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004147
John McCalldadc5752010-08-24 06:29:42 +00004148 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004149 if (E.isInvalid())
4150 return QualType();
4151
John McCall550e0c22009-10-21 00:40:46 +00004152 QualType Result = TL.getType();
4153 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004154 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004155 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004156 if (Result.isNull())
4157 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004158 }
John McCall550e0c22009-10-21 00:40:46 +00004159 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004160
John McCall550e0c22009-10-21 00:40:46 +00004161 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004162 NewTL.setTypeofLoc(TL.getTypeofLoc());
4163 NewTL.setLParenLoc(TL.getLParenLoc());
4164 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004165
4166 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004167}
Mike Stump11289f42009-09-09 15:08:12 +00004168
4169template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004170QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004171 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004172 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4173 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4174 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004175 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004176
John McCall550e0c22009-10-21 00:40:46 +00004177 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004178 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4179 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004180 if (Result.isNull())
4181 return QualType();
4182 }
Mike Stump11289f42009-09-09 15:08:12 +00004183
John McCall550e0c22009-10-21 00:40:46 +00004184 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004185 NewTL.setTypeofLoc(TL.getTypeofLoc());
4186 NewTL.setLParenLoc(TL.getLParenLoc());
4187 NewTL.setRParenLoc(TL.getRParenLoc());
4188 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004189
4190 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004191}
Mike Stump11289f42009-09-09 15:08:12 +00004192
4193template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004194QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004195 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004196 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004197
Douglas Gregore922c772009-08-04 22:27:00 +00004198 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004199 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004200
John McCalldadc5752010-08-24 06:29:42 +00004201 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004202 if (E.isInvalid())
4203 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004204
John McCall550e0c22009-10-21 00:40:46 +00004205 QualType Result = TL.getType();
4206 if (getDerived().AlwaysRebuild() ||
4207 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004208 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004209 if (Result.isNull())
4210 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004211 }
John McCall550e0c22009-10-21 00:40:46 +00004212 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004213
John McCall550e0c22009-10-21 00:40:46 +00004214 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4215 NewTL.setNameLoc(TL.getNameLoc());
4216
4217 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004218}
4219
4220template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004221QualType TreeTransform<Derived>::TransformUnaryTransformType(
4222 TypeLocBuilder &TLB,
4223 UnaryTransformTypeLoc TL) {
4224 QualType Result = TL.getType();
4225 if (Result->isDependentType()) {
4226 const UnaryTransformType *T = TL.getTypePtr();
4227 QualType NewBase =
4228 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4229 Result = getDerived().RebuildUnaryTransformType(NewBase,
4230 T->getUTTKind(),
4231 TL.getKWLoc());
4232 if (Result.isNull())
4233 return QualType();
4234 }
4235
4236 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4237 NewTL.setKWLoc(TL.getKWLoc());
4238 NewTL.setParensRange(TL.getParensRange());
4239 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4240 return Result;
4241}
4242
4243template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004244QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4245 AutoTypeLoc TL) {
4246 const AutoType *T = TL.getTypePtr();
4247 QualType OldDeduced = T->getDeducedType();
4248 QualType NewDeduced;
4249 if (!OldDeduced.isNull()) {
4250 NewDeduced = getDerived().TransformType(OldDeduced);
4251 if (NewDeduced.isNull())
4252 return QualType();
4253 }
4254
4255 QualType Result = TL.getType();
4256 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4257 Result = getDerived().RebuildAutoType(NewDeduced);
4258 if (Result.isNull())
4259 return QualType();
4260 }
4261
4262 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4263 NewTL.setNameLoc(TL.getNameLoc());
4264
4265 return Result;
4266}
4267
4268template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004269QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004270 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004271 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004272 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004273 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4274 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004275 if (!Record)
4276 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004277
John McCall550e0c22009-10-21 00:40:46 +00004278 QualType Result = TL.getType();
4279 if (getDerived().AlwaysRebuild() ||
4280 Record != T->getDecl()) {
4281 Result = getDerived().RebuildRecordType(Record);
4282 if (Result.isNull())
4283 return QualType();
4284 }
Mike Stump11289f42009-09-09 15:08:12 +00004285
John McCall550e0c22009-10-21 00:40:46 +00004286 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4287 NewTL.setNameLoc(TL.getNameLoc());
4288
4289 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004290}
Mike Stump11289f42009-09-09 15:08:12 +00004291
4292template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004293QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004294 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004295 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004296 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004297 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4298 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004299 if (!Enum)
4300 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004301
John McCall550e0c22009-10-21 00:40:46 +00004302 QualType Result = TL.getType();
4303 if (getDerived().AlwaysRebuild() ||
4304 Enum != T->getDecl()) {
4305 Result = getDerived().RebuildEnumType(Enum);
4306 if (Result.isNull())
4307 return QualType();
4308 }
Mike Stump11289f42009-09-09 15:08:12 +00004309
John McCall550e0c22009-10-21 00:40:46 +00004310 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4311 NewTL.setNameLoc(TL.getNameLoc());
4312
4313 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004314}
John McCallfcc33b02009-09-05 00:15:47 +00004315
John McCalle78aac42010-03-10 03:28:59 +00004316template<typename Derived>
4317QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4318 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004319 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004320 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4321 TL.getTypePtr()->getDecl());
4322 if (!D) return QualType();
4323
4324 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4325 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4326 return T;
4327}
4328
Douglas Gregord6ff3322009-08-04 16:50:30 +00004329template<typename Derived>
4330QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004331 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004332 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004333 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004334}
4335
Mike Stump11289f42009-09-09 15:08:12 +00004336template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004337QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004338 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004339 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004340 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4341
4342 // Substitute into the replacement type, which itself might involve something
4343 // that needs to be transformed. This only tends to occur with default
4344 // template arguments of template template parameters.
4345 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4346 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4347 if (Replacement.isNull())
4348 return QualType();
4349
4350 // Always canonicalize the replacement type.
4351 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4352 QualType Result
4353 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4354 Replacement);
4355
4356 // Propagate type-source information.
4357 SubstTemplateTypeParmTypeLoc NewTL
4358 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4359 NewTL.setNameLoc(TL.getNameLoc());
4360 return Result;
4361
John McCallcebee162009-10-18 09:09:24 +00004362}
4363
4364template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004365QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4366 TypeLocBuilder &TLB,
4367 SubstTemplateTypeParmPackTypeLoc TL) {
4368 return TransformTypeSpecType(TLB, TL);
4369}
4370
4371template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004372QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004373 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004374 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004375 const TemplateSpecializationType *T = TL.getTypePtr();
4376
Douglas Gregordf846d12011-03-02 18:46:51 +00004377 // The nested-name-specifier never matters in a TemplateSpecializationType,
4378 // because we can't have a dependent nested-name-specifier anyway.
4379 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004380 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004381 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4382 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004383 if (Template.isNull())
4384 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004385
John McCall31f82722010-11-12 08:19:04 +00004386 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4387}
4388
Douglas Gregorfe921a72010-12-20 23:36:19 +00004389namespace {
4390 /// \brief Simple iterator that traverses the template arguments in a
4391 /// container that provides a \c getArgLoc() member function.
4392 ///
4393 /// This iterator is intended to be used with the iterator form of
4394 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4395 template<typename ArgLocContainer>
4396 class TemplateArgumentLocContainerIterator {
4397 ArgLocContainer *Container;
4398 unsigned Index;
4399
4400 public:
4401 typedef TemplateArgumentLoc value_type;
4402 typedef TemplateArgumentLoc reference;
4403 typedef int difference_type;
4404 typedef std::input_iterator_tag iterator_category;
4405
4406 class pointer {
4407 TemplateArgumentLoc Arg;
4408
4409 public:
4410 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4411
4412 const TemplateArgumentLoc *operator->() const {
4413 return &Arg;
4414 }
4415 };
4416
4417
4418 TemplateArgumentLocContainerIterator() {}
4419
4420 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4421 unsigned Index)
4422 : Container(&Container), Index(Index) { }
4423
4424 TemplateArgumentLocContainerIterator &operator++() {
4425 ++Index;
4426 return *this;
4427 }
4428
4429 TemplateArgumentLocContainerIterator operator++(int) {
4430 TemplateArgumentLocContainerIterator Old(*this);
4431 ++(*this);
4432 return Old;
4433 }
4434
4435 TemplateArgumentLoc operator*() const {
4436 return Container->getArgLoc(Index);
4437 }
4438
4439 pointer operator->() const {
4440 return pointer(Container->getArgLoc(Index));
4441 }
4442
4443 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004444 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004445 return X.Container == Y.Container && X.Index == Y.Index;
4446 }
4447
4448 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004449 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004450 return !(X == Y);
4451 }
4452 };
4453}
4454
4455
John McCall31f82722010-11-12 08:19:04 +00004456template <typename Derived>
4457QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4458 TypeLocBuilder &TLB,
4459 TemplateSpecializationTypeLoc TL,
4460 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004461 TemplateArgumentListInfo NewTemplateArgs;
4462 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4463 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004464 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4465 ArgIterator;
4466 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4467 ArgIterator(TL, TL.getNumArgs()),
4468 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004469 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004470
John McCall0ad16662009-10-29 08:12:44 +00004471 // FIXME: maybe don't rebuild if all the template arguments are the same.
4472
4473 QualType Result =
4474 getDerived().RebuildTemplateSpecializationType(Template,
4475 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004476 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004477
4478 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004479 // Specializations of template template parameters are represented as
4480 // TemplateSpecializationTypes, and substitution of type alias templates
4481 // within a dependent context can transform them into
4482 // DependentTemplateSpecializationTypes.
4483 if (isa<DependentTemplateSpecializationType>(Result)) {
4484 DependentTemplateSpecializationTypeLoc NewTL
4485 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4486 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4487 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4488 NewTL.setNameLoc(TL.getTemplateNameLoc());
4489 NewTL.setLAngleLoc(TL.getLAngleLoc());
4490 NewTL.setRAngleLoc(TL.getRAngleLoc());
4491 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4492 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4493 return Result;
4494 }
4495
John McCall0ad16662009-10-29 08:12:44 +00004496 TemplateSpecializationTypeLoc NewTL
4497 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4498 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4499 NewTL.setLAngleLoc(TL.getLAngleLoc());
4500 NewTL.setRAngleLoc(TL.getRAngleLoc());
4501 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4502 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004503 }
Mike Stump11289f42009-09-09 15:08:12 +00004504
John McCall0ad16662009-10-29 08:12:44 +00004505 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004506}
Mike Stump11289f42009-09-09 15:08:12 +00004507
Douglas Gregor5a064722011-02-28 17:23:35 +00004508template <typename Derived>
4509QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4510 TypeLocBuilder &TLB,
4511 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004512 TemplateName Template,
4513 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004514 TemplateArgumentListInfo NewTemplateArgs;
4515 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4516 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4517 typedef TemplateArgumentLocContainerIterator<
4518 DependentTemplateSpecializationTypeLoc> ArgIterator;
4519 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4520 ArgIterator(TL, TL.getNumArgs()),
4521 NewTemplateArgs))
4522 return QualType();
4523
4524 // FIXME: maybe don't rebuild if all the template arguments are the same.
4525
4526 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4527 QualType Result
4528 = getSema().Context.getDependentTemplateSpecializationType(
4529 TL.getTypePtr()->getKeyword(),
4530 DTN->getQualifier(),
4531 DTN->getIdentifier(),
4532 NewTemplateArgs);
4533
4534 DependentTemplateSpecializationTypeLoc NewTL
4535 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4536 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004537
Douglas Gregora7a795b2011-03-01 20:11:18 +00004538 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004539 NewTL.setNameLoc(TL.getNameLoc());
4540 NewTL.setLAngleLoc(TL.getLAngleLoc());
4541 NewTL.setRAngleLoc(TL.getRAngleLoc());
4542 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4543 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4544 return Result;
4545 }
4546
4547 QualType Result
4548 = getDerived().RebuildTemplateSpecializationType(Template,
4549 TL.getNameLoc(),
4550 NewTemplateArgs);
4551
4552 if (!Result.isNull()) {
4553 /// FIXME: Wrap this in an elaborated-type-specifier?
4554 TemplateSpecializationTypeLoc NewTL
4555 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4556 NewTL.setTemplateNameLoc(TL.getNameLoc());
4557 NewTL.setLAngleLoc(TL.getLAngleLoc());
4558 NewTL.setRAngleLoc(TL.getRAngleLoc());
4559 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4560 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4561 }
4562
4563 return Result;
4564}
4565
Mike Stump11289f42009-09-09 15:08:12 +00004566template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004567QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004568TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004569 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004570 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004571
Douglas Gregor844cb502011-03-01 18:12:44 +00004572 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004573 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004574 if (TL.getQualifierLoc()) {
4575 QualifierLoc
4576 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4577 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004578 return QualType();
4579 }
Mike Stump11289f42009-09-09 15:08:12 +00004580
John McCall31f82722010-11-12 08:19:04 +00004581 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4582 if (NamedT.isNull())
4583 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004584
Richard Smith3f1b5d02011-05-05 21:57:07 +00004585 // C++0x [dcl.type.elab]p2:
4586 // If the identifier resolves to a typedef-name or the simple-template-id
4587 // resolves to an alias template specialization, the
4588 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004589 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4590 if (const TemplateSpecializationType *TST =
4591 NamedT->getAs<TemplateSpecializationType>()) {
4592 TemplateName Template = TST->getTemplateName();
4593 if (TypeAliasTemplateDecl *TAT =
4594 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4595 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4596 diag::err_tag_reference_non_tag) << 4;
4597 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4598 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004599 }
4600 }
4601
John McCall550e0c22009-10-21 00:40:46 +00004602 QualType Result = TL.getType();
4603 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004604 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004605 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004606 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004607 T->getKeyword(),
4608 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004609 if (Result.isNull())
4610 return QualType();
4611 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004612
Abramo Bagnara6150c882010-05-11 21:36:43 +00004613 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004614 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004615 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004616 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004617}
Mike Stump11289f42009-09-09 15:08:12 +00004618
4619template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004620QualType TreeTransform<Derived>::TransformAttributedType(
4621 TypeLocBuilder &TLB,
4622 AttributedTypeLoc TL) {
4623 const AttributedType *oldType = TL.getTypePtr();
4624 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4625 if (modifiedType.isNull())
4626 return QualType();
4627
4628 QualType result = TL.getType();
4629
4630 // FIXME: dependent operand expressions?
4631 if (getDerived().AlwaysRebuild() ||
4632 modifiedType != oldType->getModifiedType()) {
4633 // TODO: this is really lame; we should really be rebuilding the
4634 // equivalent type from first principles.
4635 QualType equivalentType
4636 = getDerived().TransformType(oldType->getEquivalentType());
4637 if (equivalentType.isNull())
4638 return QualType();
4639 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4640 modifiedType,
4641 equivalentType);
4642 }
4643
4644 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4645 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4646 if (TL.hasAttrOperand())
4647 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4648 if (TL.hasAttrExprOperand())
4649 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4650 else if (TL.hasAttrEnumOperand())
4651 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4652
4653 return result;
4654}
4655
4656template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004657QualType
4658TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4659 ParenTypeLoc TL) {
4660 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4661 if (Inner.isNull())
4662 return QualType();
4663
4664 QualType Result = TL.getType();
4665 if (getDerived().AlwaysRebuild() ||
4666 Inner != TL.getInnerLoc().getType()) {
4667 Result = getDerived().RebuildParenType(Inner);
4668 if (Result.isNull())
4669 return QualType();
4670 }
4671
4672 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4673 NewTL.setLParenLoc(TL.getLParenLoc());
4674 NewTL.setRParenLoc(TL.getRParenLoc());
4675 return Result;
4676}
4677
4678template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004679QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004680 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004681 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004682
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004683 NestedNameSpecifierLoc QualifierLoc
4684 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4685 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004686 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004687
John McCallc392f372010-06-11 00:33:02 +00004688 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004689 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004690 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004691 QualifierLoc,
4692 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004693 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004694 if (Result.isNull())
4695 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004696
Abramo Bagnarad7548482010-05-19 21:37:53 +00004697 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4698 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004699 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4700
Abramo Bagnarad7548482010-05-19 21:37:53 +00004701 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4702 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004703 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004704 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004705 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4706 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004707 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004708 NewTL.setNameLoc(TL.getNameLoc());
4709 }
John McCall550e0c22009-10-21 00:40:46 +00004710 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004711}
Mike Stump11289f42009-09-09 15:08:12 +00004712
Douglas Gregord6ff3322009-08-04 16:50:30 +00004713template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004714QualType TreeTransform<Derived>::
4715 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004716 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004717 NestedNameSpecifierLoc QualifierLoc;
4718 if (TL.getQualifierLoc()) {
4719 QualifierLoc
4720 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4721 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004722 return QualType();
4723 }
4724
John McCall31f82722010-11-12 08:19:04 +00004725 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004726 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004727}
4728
4729template<typename Derived>
4730QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004731TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4732 DependentTemplateSpecializationTypeLoc TL,
4733 NestedNameSpecifierLoc QualifierLoc) {
4734 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4735
4736 TemplateArgumentListInfo NewTemplateArgs;
4737 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4738 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4739
4740 typedef TemplateArgumentLocContainerIterator<
4741 DependentTemplateSpecializationTypeLoc> ArgIterator;
4742 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4743 ArgIterator(TL, TL.getNumArgs()),
4744 NewTemplateArgs))
4745 return QualType();
4746
4747 QualType Result
4748 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4749 QualifierLoc,
4750 T->getIdentifier(),
4751 TL.getNameLoc(),
4752 NewTemplateArgs);
4753 if (Result.isNull())
4754 return QualType();
4755
4756 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4757 QualType NamedT = ElabT->getNamedType();
4758
4759 // Copy information relevant to the template specialization.
4760 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004761 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004762 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004763 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4764 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004765 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004766 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004767
4768 // Copy information relevant to the elaborated type.
4769 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4770 NewTL.setKeywordLoc(TL.getKeywordLoc());
4771 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004772 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4773 DependentTemplateSpecializationTypeLoc SpecTL
4774 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004775 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004776 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004777 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004778 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4779 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004780 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004781 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004782 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004783 TemplateSpecializationTypeLoc SpecTL
4784 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004785 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004786 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4787 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004788 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004789 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004790 }
4791 return Result;
4792}
4793
4794template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004795QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4796 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004797 QualType Pattern
4798 = getDerived().TransformType(TLB, TL.getPatternLoc());
4799 if (Pattern.isNull())
4800 return QualType();
4801
4802 QualType Result = TL.getType();
4803 if (getDerived().AlwaysRebuild() ||
4804 Pattern != TL.getPatternLoc().getType()) {
4805 Result = getDerived().RebuildPackExpansionType(Pattern,
4806 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004807 TL.getEllipsisLoc(),
4808 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004809 if (Result.isNull())
4810 return QualType();
4811 }
4812
4813 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4814 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4815 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004816}
4817
4818template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004819QualType
4820TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004821 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004822 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004823 TLB.pushFullCopy(TL);
4824 return TL.getType();
4825}
4826
4827template<typename Derived>
4828QualType
4829TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004830 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004831 // ObjCObjectType is never dependent.
4832 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004833 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004834}
Mike Stump11289f42009-09-09 15:08:12 +00004835
4836template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004837QualType
4838TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004839 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004840 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004841 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004842 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004843}
4844
Douglas Gregord6ff3322009-08-04 16:50:30 +00004845//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004846// Statement transformation
4847//===----------------------------------------------------------------------===//
4848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004849StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004850TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004851 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004852}
4853
4854template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004855StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004856TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4857 return getDerived().TransformCompoundStmt(S, false);
4858}
4859
4860template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004861StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004862TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004863 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004864 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004865 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004866 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004867 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4868 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004869 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004870 if (Result.isInvalid()) {
4871 // Immediately fail if this was a DeclStmt, since it's very
4872 // likely that this will cause problems for future statements.
4873 if (isa<DeclStmt>(*B))
4874 return StmtError();
4875
4876 // Otherwise, just keep processing substatements and fail later.
4877 SubStmtInvalid = true;
4878 continue;
4879 }
Mike Stump11289f42009-09-09 15:08:12 +00004880
Douglas Gregorebe10102009-08-20 07:17:43 +00004881 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4882 Statements.push_back(Result.takeAs<Stmt>());
4883 }
Mike Stump11289f42009-09-09 15:08:12 +00004884
John McCall1ababa62010-08-27 19:56:05 +00004885 if (SubStmtInvalid)
4886 return StmtError();
4887
Douglas Gregorebe10102009-08-20 07:17:43 +00004888 if (!getDerived().AlwaysRebuild() &&
4889 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004890 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004891
4892 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4893 move_arg(Statements),
4894 S->getRBracLoc(),
4895 IsStmtExpr);
4896}
Mike Stump11289f42009-09-09 15:08:12 +00004897
Douglas Gregorebe10102009-08-20 07:17:43 +00004898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004899StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004900TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004901 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004902 {
4903 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004904 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004905
Eli Friedman06577382009-11-19 03:14:00 +00004906 // Transform the left-hand case value.
4907 LHS = getDerived().TransformExpr(S->getLHS());
4908 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004909 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004910
Eli Friedman06577382009-11-19 03:14:00 +00004911 // Transform the right-hand case value (for the GNU case-range extension).
4912 RHS = getDerived().TransformExpr(S->getRHS());
4913 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004914 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004915 }
Mike Stump11289f42009-09-09 15:08:12 +00004916
Douglas Gregorebe10102009-08-20 07:17:43 +00004917 // Build the case statement.
4918 // Case statements are always rebuilt so that they will attached to their
4919 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004920 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004921 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004922 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004923 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004924 S->getColonLoc());
4925 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004926 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004927
Douglas Gregorebe10102009-08-20 07:17:43 +00004928 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004929 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004930 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004931 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004932
Douglas Gregorebe10102009-08-20 07:17:43 +00004933 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004934 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004935}
4936
4937template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004938StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004939TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004940 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004941 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004942 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004943 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004944
Douglas Gregorebe10102009-08-20 07:17:43 +00004945 // Default statements are always rebuilt
4946 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004947 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004948}
Mike Stump11289f42009-09-09 15:08:12 +00004949
Douglas Gregorebe10102009-08-20 07:17:43 +00004950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004951StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004952TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004953 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004954 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004955 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004956
Chris Lattnercab02a62011-02-17 20:34:02 +00004957 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4958 S->getDecl());
4959 if (!LD)
4960 return StmtError();
4961
4962
Douglas Gregorebe10102009-08-20 07:17:43 +00004963 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004964 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004965 cast<LabelDecl>(LD), SourceLocation(),
4966 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004967}
Mike Stump11289f42009-09-09 15:08:12 +00004968
Douglas Gregorebe10102009-08-20 07:17:43 +00004969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004970StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004971TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004972 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004973 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004974 VarDecl *ConditionVar = 0;
4975 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004976 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004977 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004978 getDerived().TransformDefinition(
4979 S->getConditionVariable()->getLocation(),
4980 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004981 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004982 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004983 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004984 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004985
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004986 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004987 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004988
4989 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004990 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004991 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4992 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004993 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004994 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004995
John McCallb268a282010-08-23 23:25:46 +00004996 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004997 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004998 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004999
John McCallb268a282010-08-23 23:25:46 +00005000 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5001 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005002 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005003
Douglas Gregorebe10102009-08-20 07:17:43 +00005004 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005005 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005006 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005007 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005008
Douglas Gregorebe10102009-08-20 07:17:43 +00005009 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005010 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005011 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005012 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregorebe10102009-08-20 07:17:43 +00005014 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005015 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005016 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005017 Then.get() == S->getThen() &&
5018 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005019 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005020
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005021 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005022 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005023 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005024}
5025
5026template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005027StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005028TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005029 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005030 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005031 VarDecl *ConditionVar = 0;
5032 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005033 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005034 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005035 getDerived().TransformDefinition(
5036 S->getConditionVariable()->getLocation(),
5037 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005038 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005039 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005040 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005041 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005042
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005043 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005044 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005045 }
Mike Stump11289f42009-09-09 15:08:12 +00005046
Douglas Gregorebe10102009-08-20 07:17:43 +00005047 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005048 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005049 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005050 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005051 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005052 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005053
Douglas Gregorebe10102009-08-20 07:17:43 +00005054 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005055 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005056 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005057 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005058
Douglas Gregorebe10102009-08-20 07:17:43 +00005059 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005060 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5061 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005062}
Mike Stump11289f42009-09-09 15:08:12 +00005063
Douglas Gregorebe10102009-08-20 07:17:43 +00005064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005065StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005066TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005067 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005068 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005069 VarDecl *ConditionVar = 0;
5070 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005071 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005072 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005073 getDerived().TransformDefinition(
5074 S->getConditionVariable()->getLocation(),
5075 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005076 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005077 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005078 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005079 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005080
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005081 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005082 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005083
5084 if (S->getCond()) {
5085 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005086 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5087 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005088 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005089 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005090 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005091 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005092 }
Mike Stump11289f42009-09-09 15:08:12 +00005093
John McCallb268a282010-08-23 23:25:46 +00005094 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5095 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005096 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005097
Douglas Gregorebe10102009-08-20 07:17:43 +00005098 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005099 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005100 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005101 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005102
Douglas Gregorebe10102009-08-20 07:17:43 +00005103 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005104 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005105 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005106 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005107 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005108
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005109 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005110 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005111}
Mike Stump11289f42009-09-09 15:08:12 +00005112
Douglas Gregorebe10102009-08-20 07:17:43 +00005113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005114StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005115TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005116 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005117 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005118 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005119 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005120
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005121 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005122 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005123 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005124 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005125
Douglas Gregorebe10102009-08-20 07:17:43 +00005126 if (!getDerived().AlwaysRebuild() &&
5127 Cond.get() == S->getCond() &&
5128 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005129 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005130
John McCallb268a282010-08-23 23:25:46 +00005131 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5132 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005133 S->getRParenLoc());
5134}
Mike Stump11289f42009-09-09 15:08:12 +00005135
Douglas Gregorebe10102009-08-20 07:17:43 +00005136template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005137StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005138TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005139 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005140 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005141 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005142 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005143
Douglas Gregorebe10102009-08-20 07:17:43 +00005144 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005145 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005146 VarDecl *ConditionVar = 0;
5147 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005148 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005149 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005150 getDerived().TransformDefinition(
5151 S->getConditionVariable()->getLocation(),
5152 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005153 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005154 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005155 } else {
5156 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005157
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005158 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005159 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005160
5161 if (S->getCond()) {
5162 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005163 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5164 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005165 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005166 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005167
John McCallb268a282010-08-23 23:25:46 +00005168 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005169 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005170 }
Mike Stump11289f42009-09-09 15:08:12 +00005171
John McCallb268a282010-08-23 23:25:46 +00005172 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5173 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005174 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005175
Douglas Gregorebe10102009-08-20 07:17:43 +00005176 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005177 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005178 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005179 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005180
John McCallb268a282010-08-23 23:25:46 +00005181 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5182 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005183 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005184
Douglas Gregorebe10102009-08-20 07:17:43 +00005185 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005186 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005187 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005188 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005189
Douglas Gregorebe10102009-08-20 07:17:43 +00005190 if (!getDerived().AlwaysRebuild() &&
5191 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005192 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005193 Inc.get() == S->getInc() &&
5194 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005195 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005196
Douglas Gregorebe10102009-08-20 07:17:43 +00005197 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005198 Init.get(), FullCond, ConditionVar,
5199 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005200}
5201
5202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005203StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005204TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005205 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5206 S->getLabel());
5207 if (!LD)
5208 return StmtError();
5209
Douglas Gregorebe10102009-08-20 07:17:43 +00005210 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005211 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005212 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005213}
5214
5215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005216StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005217TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005218 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005219 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005220 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005221
Douglas Gregorebe10102009-08-20 07:17:43 +00005222 if (!getDerived().AlwaysRebuild() &&
5223 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005224 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005225
5226 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005227 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005228}
5229
5230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005231StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005232TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005233 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005234}
Mike Stump11289f42009-09-09 15:08:12 +00005235
Douglas Gregorebe10102009-08-20 07:17:43 +00005236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005237StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005238TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005239 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005240}
Mike Stump11289f42009-09-09 15:08:12 +00005241
Douglas Gregorebe10102009-08-20 07:17:43 +00005242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005243StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005244TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005245 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005246 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005247 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005248
Mike Stump11289f42009-09-09 15:08:12 +00005249 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005250 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005251 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005252}
Mike Stump11289f42009-09-09 15:08:12 +00005253
Douglas Gregorebe10102009-08-20 07:17:43 +00005254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005255StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005256TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005257 bool DeclChanged = false;
5258 llvm::SmallVector<Decl *, 4> Decls;
5259 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5260 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005261 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5262 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005263 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005264 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005265
Douglas Gregorebe10102009-08-20 07:17:43 +00005266 if (Transformed != *D)
5267 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005268
Douglas Gregorebe10102009-08-20 07:17:43 +00005269 Decls.push_back(Transformed);
5270 }
Mike Stump11289f42009-09-09 15:08:12 +00005271
Douglas Gregorebe10102009-08-20 07:17:43 +00005272 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005273 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005274
5275 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005276 S->getStartLoc(), S->getEndLoc());
5277}
Mike Stump11289f42009-09-09 15:08:12 +00005278
Douglas Gregorebe10102009-08-20 07:17:43 +00005279template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005280StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005281TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005282
John McCall37ad5512010-08-23 06:44:23 +00005283 ASTOwningVector<Expr*> Constraints(getSema());
5284 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005285 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005286
John McCalldadc5752010-08-24 06:29:42 +00005287 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005288 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005289
5290 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005291
Anders Carlssonaaeef072010-01-24 05:50:09 +00005292 // Go through the outputs.
5293 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005294 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005295
Anders Carlssonaaeef072010-01-24 05:50:09 +00005296 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005297 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005298
Anders Carlssonaaeef072010-01-24 05:50:09 +00005299 // Transform the output expr.
5300 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005301 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005302 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005303 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005304
Anders Carlssonaaeef072010-01-24 05:50:09 +00005305 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005306
John McCallb268a282010-08-23 23:25:46 +00005307 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005308 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005309
Anders Carlssonaaeef072010-01-24 05:50:09 +00005310 // Go through the inputs.
5311 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005312 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005313
Anders Carlssonaaeef072010-01-24 05:50:09 +00005314 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005315 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005316
Anders Carlssonaaeef072010-01-24 05:50:09 +00005317 // Transform the input expr.
5318 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005319 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005320 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005321 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005322
Anders Carlssonaaeef072010-01-24 05:50:09 +00005323 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005324
John McCallb268a282010-08-23 23:25:46 +00005325 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005326 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005327
Anders Carlssonaaeef072010-01-24 05:50:09 +00005328 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005329 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005330
5331 // Go through the clobbers.
5332 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005333 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005334
5335 // No need to transform the asm string literal.
5336 AsmString = SemaRef.Owned(S->getAsmString());
5337
5338 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5339 S->isSimple(),
5340 S->isVolatile(),
5341 S->getNumOutputs(),
5342 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005343 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005344 move_arg(Constraints),
5345 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005346 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005347 move_arg(Clobbers),
5348 S->getRParenLoc(),
5349 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005350}
5351
5352
5353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005354StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005355TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005356 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005357 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005358 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005359 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005360
Douglas Gregor96c79492010-04-23 22:50:49 +00005361 // Transform the @catch statements (if present).
5362 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005363 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005364 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005365 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005366 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005367 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005368 if (Catch.get() != S->getCatchStmt(I))
5369 AnyCatchChanged = true;
5370 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005371 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005372
Douglas Gregor306de2f2010-04-22 23:59:56 +00005373 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005374 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005375 if (S->getFinallyStmt()) {
5376 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5377 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005378 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005379 }
5380
5381 // If nothing changed, just retain this statement.
5382 if (!getDerived().AlwaysRebuild() &&
5383 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005384 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005385 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005386 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005387
Douglas Gregor306de2f2010-04-22 23:59:56 +00005388 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005389 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5390 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005391}
Mike Stump11289f42009-09-09 15:08:12 +00005392
Douglas Gregorebe10102009-08-20 07:17:43 +00005393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005394StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005395TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005396 // Transform the @catch parameter, if there is one.
5397 VarDecl *Var = 0;
5398 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5399 TypeSourceInfo *TSInfo = 0;
5400 if (FromVar->getTypeSourceInfo()) {
5401 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5402 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005403 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005404 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005405
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005406 QualType T;
5407 if (TSInfo)
5408 T = TSInfo->getType();
5409 else {
5410 T = getDerived().TransformType(FromVar->getType());
5411 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005412 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005413 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005414
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005415 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5416 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005417 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005418 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005419
John McCalldadc5752010-08-24 06:29:42 +00005420 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005421 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005422 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005423
5424 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005425 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005426 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005427}
Mike Stump11289f42009-09-09 15:08:12 +00005428
Douglas Gregorebe10102009-08-20 07:17:43 +00005429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005430StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005431TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005432 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005433 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005434 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005435 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005436
Douglas Gregor306de2f2010-04-22 23:59:56 +00005437 // If nothing changed, just retain this statement.
5438 if (!getDerived().AlwaysRebuild() &&
5439 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005440 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005441
5442 // Build a new statement.
5443 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005444 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005445}
Mike Stump11289f42009-09-09 15:08:12 +00005446
Douglas Gregorebe10102009-08-20 07:17:43 +00005447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005448StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005449TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005450 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005451 if (S->getThrowExpr()) {
5452 Operand = getDerived().TransformExpr(S->getThrowExpr());
5453 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005454 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005455 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005456
Douglas Gregor2900c162010-04-22 21:44:01 +00005457 if (!getDerived().AlwaysRebuild() &&
5458 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005459 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005460
John McCallb268a282010-08-23 23:25:46 +00005461 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005462}
Mike Stump11289f42009-09-09 15:08:12 +00005463
Douglas Gregorebe10102009-08-20 07:17:43 +00005464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005465StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005466TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005467 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005468 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005469 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005470 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005471 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005472
Douglas Gregor6148de72010-04-22 22:01:21 +00005473 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005474 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005475 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005476 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005477
Douglas Gregor6148de72010-04-22 22:01:21 +00005478 // If nothing change, just retain the current statement.
5479 if (!getDerived().AlwaysRebuild() &&
5480 Object.get() == S->getSynchExpr() &&
5481 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005482 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005483
5484 // Build a new statement.
5485 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005486 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005487}
5488
5489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005490StmtResult
John McCall31168b02011-06-15 23:02:42 +00005491TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5492 ObjCAutoreleasePoolStmt *S) {
5493 // Transform the body.
5494 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5495 if (Body.isInvalid())
5496 return StmtError();
5497
5498 // If nothing changed, just retain this statement.
5499 if (!getDerived().AlwaysRebuild() &&
5500 Body.get() == S->getSubStmt())
5501 return SemaRef.Owned(S);
5502
5503 // Build a new statement.
5504 return getDerived().RebuildObjCAutoreleasePoolStmt(
5505 S->getAtLoc(), Body.get());
5506}
5507
5508template<typename Derived>
5509StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005510TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005511 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005512 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005513 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005514 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005515 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005516
Douglas Gregorf68a5082010-04-22 23:10:45 +00005517 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005518 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005519 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005520 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005521
Douglas Gregorf68a5082010-04-22 23:10:45 +00005522 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005523 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005524 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005525 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005526
Douglas Gregorf68a5082010-04-22 23:10:45 +00005527 // If nothing changed, just retain this statement.
5528 if (!getDerived().AlwaysRebuild() &&
5529 Element.get() == S->getElement() &&
5530 Collection.get() == S->getCollection() &&
5531 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005532 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005533
Douglas Gregorf68a5082010-04-22 23:10:45 +00005534 // Build a new statement.
5535 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5536 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005537 Element.get(),
5538 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005539 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005540 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005541}
5542
5543
5544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005545StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005546TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5547 // Transform the exception declaration, if any.
5548 VarDecl *Var = 0;
5549 if (S->getExceptionDecl()) {
5550 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005551 TypeSourceInfo *T = getDerived().TransformType(
5552 ExceptionDecl->getTypeSourceInfo());
5553 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005554 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005555
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005556 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005557 ExceptionDecl->getInnerLocStart(),
5558 ExceptionDecl->getLocation(),
5559 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005560 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005561 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005562 }
Mike Stump11289f42009-09-09 15:08:12 +00005563
Douglas Gregorebe10102009-08-20 07:17:43 +00005564 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005565 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005566 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005567 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005568
Douglas Gregorebe10102009-08-20 07:17:43 +00005569 if (!getDerived().AlwaysRebuild() &&
5570 !Var &&
5571 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005572 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005573
5574 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5575 Var,
John McCallb268a282010-08-23 23:25:46 +00005576 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005577}
Mike Stump11289f42009-09-09 15:08:12 +00005578
Douglas Gregorebe10102009-08-20 07:17:43 +00005579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005580StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005581TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5582 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005583 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005584 = getDerived().TransformCompoundStmt(S->getTryBlock());
5585 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005586 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005587
Douglas Gregorebe10102009-08-20 07:17:43 +00005588 // Transform the handlers.
5589 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005590 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005591 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005592 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005593 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5594 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005595 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005596
Douglas Gregorebe10102009-08-20 07:17:43 +00005597 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5598 Handlers.push_back(Handler.takeAs<Stmt>());
5599 }
Mike Stump11289f42009-09-09 15:08:12 +00005600
Douglas Gregorebe10102009-08-20 07:17:43 +00005601 if (!getDerived().AlwaysRebuild() &&
5602 TryBlock.get() == S->getTryBlock() &&
5603 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005604 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005605
John McCallb268a282010-08-23 23:25:46 +00005606 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005607 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005608}
Mike Stump11289f42009-09-09 15:08:12 +00005609
Richard Smith02e85f32011-04-14 22:09:26 +00005610template<typename Derived>
5611StmtResult
5612TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5613 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5614 if (Range.isInvalid())
5615 return StmtError();
5616
5617 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5618 if (BeginEnd.isInvalid())
5619 return StmtError();
5620
5621 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5622 if (Cond.isInvalid())
5623 return StmtError();
5624
5625 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5626 if (Inc.isInvalid())
5627 return StmtError();
5628
5629 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5630 if (LoopVar.isInvalid())
5631 return StmtError();
5632
5633 StmtResult NewStmt = S;
5634 if (getDerived().AlwaysRebuild() ||
5635 Range.get() != S->getRangeStmt() ||
5636 BeginEnd.get() != S->getBeginEndStmt() ||
5637 Cond.get() != S->getCond() ||
5638 Inc.get() != S->getInc() ||
5639 LoopVar.get() != S->getLoopVarStmt())
5640 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5641 S->getColonLoc(), Range.get(),
5642 BeginEnd.get(), Cond.get(),
5643 Inc.get(), LoopVar.get(),
5644 S->getRParenLoc());
5645
5646 StmtResult Body = getDerived().TransformStmt(S->getBody());
5647 if (Body.isInvalid())
5648 return StmtError();
5649
5650 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5651 // it now so we have a new statement to attach the body to.
5652 if (Body.get() != S->getBody() && NewStmt.get() == S)
5653 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5654 S->getColonLoc(), Range.get(),
5655 BeginEnd.get(), Cond.get(),
5656 Inc.get(), LoopVar.get(),
5657 S->getRParenLoc());
5658
5659 if (NewStmt.get() == S)
5660 return SemaRef.Owned(S);
5661
5662 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5663}
5664
John Wiegley1c0675e2011-04-28 01:08:34 +00005665template<typename Derived>
5666StmtResult
5667TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5668 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5669 if(TryBlock.isInvalid()) return StmtError();
5670
5671 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5672 if(!getDerived().AlwaysRebuild() &&
5673 TryBlock.get() == S->getTryBlock() &&
5674 Handler.get() == S->getHandler())
5675 return SemaRef.Owned(S);
5676
5677 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5678 S->getTryLoc(),
5679 TryBlock.take(),
5680 Handler.take());
5681}
5682
5683template<typename Derived>
5684StmtResult
5685TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5686 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5687 if(Block.isInvalid()) return StmtError();
5688
5689 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5690 Block.take());
5691}
5692
5693template<typename Derived>
5694StmtResult
5695TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5696 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5697 if(FilterExpr.isInvalid()) return StmtError();
5698
5699 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5700 if(Block.isInvalid()) return StmtError();
5701
5702 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5703 FilterExpr.take(),
5704 Block.take());
5705}
5706
5707template<typename Derived>
5708StmtResult
5709TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5710 if(isa<SEHFinallyStmt>(Handler))
5711 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5712 else
5713 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5714}
5715
Douglas Gregorebe10102009-08-20 07:17:43 +00005716//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005717// Expression transformation
5718//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005719template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005720ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005721TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005722 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005723}
Mike Stump11289f42009-09-09 15:08:12 +00005724
5725template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005726ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005727TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005728 NestedNameSpecifierLoc QualifierLoc;
5729 if (E->getQualifierLoc()) {
5730 QualifierLoc
5731 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5732 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005733 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005734 }
John McCallce546572009-12-08 09:08:17 +00005735
5736 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005737 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5738 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005739 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005740 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005741
John McCall815039a2010-08-17 21:27:17 +00005742 DeclarationNameInfo NameInfo = E->getNameInfo();
5743 if (NameInfo.getName()) {
5744 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5745 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005746 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005747 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005748
5749 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005750 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005751 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005752 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005753 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005754
5755 // Mark it referenced in the new context regardless.
5756 // FIXME: this is a bit instantiation-specific.
5757 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5758
John McCallc3007a22010-10-26 07:05:15 +00005759 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005760 }
John McCallce546572009-12-08 09:08:17 +00005761
5762 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005763 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005764 TemplateArgs = &TransArgs;
5765 TransArgs.setLAngleLoc(E->getLAngleLoc());
5766 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005767 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5768 E->getNumTemplateArgs(),
5769 TransArgs))
5770 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005771 }
5772
Douglas Gregorea972d32011-02-28 21:54:11 +00005773 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5774 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005775}
Mike Stump11289f42009-09-09 15:08:12 +00005776
Douglas Gregora16548e2009-08-11 05:31:07 +00005777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005778ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005779TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005780 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005781}
Mike Stump11289f42009-09-09 15:08:12 +00005782
Douglas Gregora16548e2009-08-11 05:31:07 +00005783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005784ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005785TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005786 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005787}
Mike Stump11289f42009-09-09 15:08:12 +00005788
Douglas Gregora16548e2009-08-11 05:31:07 +00005789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005790ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005791TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005792 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005793}
Mike Stump11289f42009-09-09 15:08:12 +00005794
Douglas Gregora16548e2009-08-11 05:31:07 +00005795template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005796ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005797TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005798 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005799}
Mike Stump11289f42009-09-09 15:08:12 +00005800
Douglas Gregora16548e2009-08-11 05:31:07 +00005801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005802ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005803TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005804 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005805}
5806
5807template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005808ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005809TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5810 ExprResult ControllingExpr =
5811 getDerived().TransformExpr(E->getControllingExpr());
5812 if (ControllingExpr.isInvalid())
5813 return ExprError();
5814
5815 llvm::SmallVector<Expr *, 4> AssocExprs;
5816 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5817 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5818 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5819 if (TS) {
5820 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5821 if (!AssocType)
5822 return ExprError();
5823 AssocTypes.push_back(AssocType);
5824 } else {
5825 AssocTypes.push_back(0);
5826 }
5827
5828 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5829 if (AssocExpr.isInvalid())
5830 return ExprError();
5831 AssocExprs.push_back(AssocExpr.release());
5832 }
5833
5834 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5835 E->getDefaultLoc(),
5836 E->getRParenLoc(),
5837 ControllingExpr.release(),
5838 AssocTypes.data(),
5839 AssocExprs.data(),
5840 E->getNumAssocs());
5841}
5842
5843template<typename Derived>
5844ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005845TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005846 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005847 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005849
Douglas Gregora16548e2009-08-11 05:31:07 +00005850 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005851 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005852
John McCallb268a282010-08-23 23:25:46 +00005853 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005854 E->getRParen());
5855}
5856
Mike Stump11289f42009-09-09 15:08:12 +00005857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005858ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005859TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005860 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005861 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005863
Douglas Gregora16548e2009-08-11 05:31:07 +00005864 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005865 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005866
Douglas Gregora16548e2009-08-11 05:31:07 +00005867 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5868 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005869 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005870}
Mike Stump11289f42009-09-09 15:08:12 +00005871
Douglas Gregora16548e2009-08-11 05:31:07 +00005872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005873ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005874TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5875 // Transform the type.
5876 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5877 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005878 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005879
Douglas Gregor882211c2010-04-28 22:16:22 +00005880 // Transform all of the components into components similar to what the
5881 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005882 // FIXME: It would be slightly more efficient in the non-dependent case to
5883 // just map FieldDecls, rather than requiring the rebuilder to look for
5884 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005885 // template code that we don't care.
5886 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005887 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005888 typedef OffsetOfExpr::OffsetOfNode Node;
5889 llvm::SmallVector<Component, 4> Components;
5890 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5891 const Node &ON = E->getComponent(I);
5892 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005893 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005894 Comp.LocStart = ON.getSourceRange().getBegin();
5895 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005896 switch (ON.getKind()) {
5897 case Node::Array: {
5898 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005899 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005900 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005901 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005902
Douglas Gregor882211c2010-04-28 22:16:22 +00005903 ExprChanged = ExprChanged || Index.get() != FromIndex;
5904 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005905 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005906 break;
5907 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005908
Douglas Gregor882211c2010-04-28 22:16:22 +00005909 case Node::Field:
5910 case Node::Identifier:
5911 Comp.isBrackets = false;
5912 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005913 if (!Comp.U.IdentInfo)
5914 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005915
Douglas Gregor882211c2010-04-28 22:16:22 +00005916 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005917
Douglas Gregord1702062010-04-29 00:18:15 +00005918 case Node::Base:
5919 // Will be recomputed during the rebuild.
5920 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005921 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005922
Douglas Gregor882211c2010-04-28 22:16:22 +00005923 Components.push_back(Comp);
5924 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005925
Douglas Gregor882211c2010-04-28 22:16:22 +00005926 // If nothing changed, retain the existing expression.
5927 if (!getDerived().AlwaysRebuild() &&
5928 Type == E->getTypeSourceInfo() &&
5929 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005930 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005931
Douglas Gregor882211c2010-04-28 22:16:22 +00005932 // Build a new offsetof expression.
5933 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5934 Components.data(), Components.size(),
5935 E->getRParenLoc());
5936}
5937
5938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005939ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005940TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5941 assert(getDerived().AlreadyTransformed(E->getType()) &&
5942 "opaque value expression requires transformation");
5943 return SemaRef.Owned(E);
5944}
5945
5946template<typename Derived>
5947ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005948TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5949 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005950 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005951 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005952
John McCallbcd03502009-12-07 02:54:59 +00005953 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005954 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005955 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005956
John McCall4c98fd82009-11-04 07:28:41 +00005957 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005958 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005959
Peter Collingbournee190dee2011-03-11 19:24:49 +00005960 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5961 E->getKind(),
5962 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005963 }
Mike Stump11289f42009-09-09 15:08:12 +00005964
John McCalldadc5752010-08-24 06:29:42 +00005965 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005966 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005967 // C++0x [expr.sizeof]p1:
5968 // The operand is either an expression, which is an unevaluated operand
5969 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005970 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005971
Douglas Gregora16548e2009-08-11 05:31:07 +00005972 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5973 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005974 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005975
Douglas Gregora16548e2009-08-11 05:31:07 +00005976 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005977 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005978 }
Mike Stump11289f42009-09-09 15:08:12 +00005979
Peter Collingbournee190dee2011-03-11 19:24:49 +00005980 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5981 E->getOperatorLoc(),
5982 E->getKind(),
5983 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005984}
Mike Stump11289f42009-09-09 15:08:12 +00005985
Douglas Gregora16548e2009-08-11 05:31:07 +00005986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005987ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005988TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005989 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005990 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005991 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005992
John McCalldadc5752010-08-24 06:29:42 +00005993 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005994 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005995 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005996
5997
Douglas Gregora16548e2009-08-11 05:31:07 +00005998 if (!getDerived().AlwaysRebuild() &&
5999 LHS.get() == E->getLHS() &&
6000 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006001 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006002
John McCallb268a282010-08-23 23:25:46 +00006003 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006004 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006005 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006006 E->getRBracketLoc());
6007}
Mike Stump11289f42009-09-09 15:08:12 +00006008
6009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006010ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006011TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006013 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006015 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006016
6017 // Transform arguments.
6018 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006019 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006020 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6021 &ArgChanged))
6022 return ExprError();
6023
Douglas Gregora16548e2009-08-11 05:31:07 +00006024 if (!getDerived().AlwaysRebuild() &&
6025 Callee.get() == E->getCallee() &&
6026 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006027 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006028
Douglas Gregora16548e2009-08-11 05:31:07 +00006029 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006030 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006031 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006032 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006033 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006034 E->getRParenLoc());
6035}
Mike Stump11289f42009-09-09 15:08:12 +00006036
6037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006038ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006039TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006040 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006041 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006043
Douglas Gregorea972d32011-02-28 21:54:11 +00006044 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006045 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006046 QualifierLoc
6047 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6048
6049 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006050 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006051 }
Mike Stump11289f42009-09-09 15:08:12 +00006052
Eli Friedman2cfcef62009-12-04 06:40:45 +00006053 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006054 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6055 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006056 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006057 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006058
John McCall16df1e52010-03-30 21:47:33 +00006059 NamedDecl *FoundDecl = E->getFoundDecl();
6060 if (FoundDecl == E->getMemberDecl()) {
6061 FoundDecl = Member;
6062 } else {
6063 FoundDecl = cast_or_null<NamedDecl>(
6064 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6065 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006066 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006067 }
6068
Douglas Gregora16548e2009-08-11 05:31:07 +00006069 if (!getDerived().AlwaysRebuild() &&
6070 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006071 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006072 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006073 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006074 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006075
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006076 // Mark it referenced in the new context regardless.
6077 // FIXME: this is a bit instantiation-specific.
6078 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00006079 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006080 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006081
John McCall6b51f282009-11-23 01:53:49 +00006082 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006083 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006084 TransArgs.setLAngleLoc(E->getLAngleLoc());
6085 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006086 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6087 E->getNumTemplateArgs(),
6088 TransArgs))
6089 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006090 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006091
Douglas Gregora16548e2009-08-11 05:31:07 +00006092 // FIXME: Bogus source location for the operator
6093 SourceLocation FakeOperatorLoc
6094 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6095
John McCall38836f02010-01-15 08:34:02 +00006096 // FIXME: to do this check properly, we will need to preserve the
6097 // first-qualifier-in-scope here, just in case we had a dependent
6098 // base (and therefore couldn't do the check) and a
6099 // nested-name-qualifier (and therefore could do the lookup).
6100 NamedDecl *FirstQualifierInScope = 0;
6101
John McCallb268a282010-08-23 23:25:46 +00006102 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006103 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006104 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006105 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006106 Member,
John McCall16df1e52010-03-30 21:47:33 +00006107 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006108 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006109 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006110 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006111}
Mike Stump11289f42009-09-09 15:08:12 +00006112
Douglas Gregora16548e2009-08-11 05:31:07 +00006113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006114ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006115TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006116 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006117 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006118 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006119
John McCalldadc5752010-08-24 06:29:42 +00006120 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006121 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006122 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006123
Douglas Gregora16548e2009-08-11 05:31:07 +00006124 if (!getDerived().AlwaysRebuild() &&
6125 LHS.get() == E->getLHS() &&
6126 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006127 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006128
Douglas Gregora16548e2009-08-11 05:31:07 +00006129 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006130 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006131}
6132
Mike Stump11289f42009-09-09 15:08:12 +00006133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006134ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006135TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006136 CompoundAssignOperator *E) {
6137 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006138}
Mike Stump11289f42009-09-09 15:08:12 +00006139
Douglas Gregora16548e2009-08-11 05:31:07 +00006140template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006141ExprResult TreeTransform<Derived>::
6142TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6143 // Just rebuild the common and RHS expressions and see whether we
6144 // get any changes.
6145
6146 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6147 if (commonExpr.isInvalid())
6148 return ExprError();
6149
6150 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6151 if (rhs.isInvalid())
6152 return ExprError();
6153
6154 if (!getDerived().AlwaysRebuild() &&
6155 commonExpr.get() == e->getCommon() &&
6156 rhs.get() == e->getFalseExpr())
6157 return SemaRef.Owned(e);
6158
6159 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6160 e->getQuestionLoc(),
6161 0,
6162 e->getColonLoc(),
6163 rhs.get());
6164}
6165
6166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006168TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006169 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006170 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006172
John McCalldadc5752010-08-24 06:29:42 +00006173 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006174 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006175 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006176
John McCalldadc5752010-08-24 06:29:42 +00006177 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006178 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006179 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006180
Douglas Gregora16548e2009-08-11 05:31:07 +00006181 if (!getDerived().AlwaysRebuild() &&
6182 Cond.get() == E->getCond() &&
6183 LHS.get() == E->getLHS() &&
6184 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006185 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006186
John McCallb268a282010-08-23 23:25:46 +00006187 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006188 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006189 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006190 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006191 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006192}
Mike Stump11289f42009-09-09 15:08:12 +00006193
6194template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006195ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006196TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006197 // Implicit casts are eliminated during transformation, since they
6198 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006199 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006200}
Mike Stump11289f42009-09-09 15:08:12 +00006201
Douglas Gregora16548e2009-08-11 05:31:07 +00006202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006203ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006204TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006205 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6206 if (!Type)
6207 return ExprError();
6208
John McCalldadc5752010-08-24 06:29:42 +00006209 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006210 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006211 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006213
Douglas Gregora16548e2009-08-11 05:31:07 +00006214 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006215 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006216 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006217 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006218
John McCall97513962010-01-15 18:39:57 +00006219 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006220 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006221 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006222 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006223}
Mike Stump11289f42009-09-09 15:08:12 +00006224
Douglas Gregora16548e2009-08-11 05:31:07 +00006225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006226ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006227TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006228 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6229 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6230 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006231 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006232
John McCalldadc5752010-08-24 06:29:42 +00006233 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006234 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006236
Douglas Gregora16548e2009-08-11 05:31:07 +00006237 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006238 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006239 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006240 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006241
John McCall5d7aa7f2010-01-19 22:33:45 +00006242 // Note: the expression type doesn't necessarily match the
6243 // type-as-written, but that's okay, because it should always be
6244 // derivable from the initializer.
6245
John McCalle15bbff2010-01-18 19:35:47 +00006246 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006247 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006248 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006249}
Mike Stump11289f42009-09-09 15:08:12 +00006250
Douglas Gregora16548e2009-08-11 05:31:07 +00006251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006252ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006253TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006254 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006255 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006256 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006257
Douglas Gregora16548e2009-08-11 05:31:07 +00006258 if (!getDerived().AlwaysRebuild() &&
6259 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006260 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006261
Douglas Gregora16548e2009-08-11 05:31:07 +00006262 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006263 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006264 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006265 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006266 E->getAccessorLoc(),
6267 E->getAccessor());
6268}
Mike Stump11289f42009-09-09 15:08:12 +00006269
Douglas Gregora16548e2009-08-11 05:31:07 +00006270template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006271ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006272TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006273 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006274
John McCall37ad5512010-08-23 06:44:23 +00006275 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006276 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6277 Inits, &InitChanged))
6278 return ExprError();
6279
Douglas Gregora16548e2009-08-11 05:31:07 +00006280 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006281 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006282
Douglas Gregora16548e2009-08-11 05:31:07 +00006283 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006284 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006285}
Mike Stump11289f42009-09-09 15:08:12 +00006286
Douglas Gregora16548e2009-08-11 05:31:07 +00006287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006288ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006289TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006290 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006291
Douglas Gregorebe10102009-08-20 07:17:43 +00006292 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006293 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006294 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006295 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006296
Douglas Gregorebe10102009-08-20 07:17:43 +00006297 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006298 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006299 bool ExprChanged = false;
6300 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6301 DEnd = E->designators_end();
6302 D != DEnd; ++D) {
6303 if (D->isFieldDesignator()) {
6304 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6305 D->getDotLoc(),
6306 D->getFieldLoc()));
6307 continue;
6308 }
Mike Stump11289f42009-09-09 15:08:12 +00006309
Douglas Gregora16548e2009-08-11 05:31:07 +00006310 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006311 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006312 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006313 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006314
6315 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006316 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006317
Douglas Gregora16548e2009-08-11 05:31:07 +00006318 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6319 ArrayExprs.push_back(Index.release());
6320 continue;
6321 }
Mike Stump11289f42009-09-09 15:08:12 +00006322
Douglas Gregora16548e2009-08-11 05:31:07 +00006323 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006324 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006325 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6326 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006327 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006328
John McCalldadc5752010-08-24 06:29:42 +00006329 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006330 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006331 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006332
6333 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006334 End.get(),
6335 D->getLBracketLoc(),
6336 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006337
Douglas Gregora16548e2009-08-11 05:31:07 +00006338 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6339 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006340
Douglas Gregora16548e2009-08-11 05:31:07 +00006341 ArrayExprs.push_back(Start.release());
6342 ArrayExprs.push_back(End.release());
6343 }
Mike Stump11289f42009-09-09 15:08:12 +00006344
Douglas Gregora16548e2009-08-11 05:31:07 +00006345 if (!getDerived().AlwaysRebuild() &&
6346 Init.get() == E->getInit() &&
6347 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006348 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006349
Douglas Gregora16548e2009-08-11 05:31:07 +00006350 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6351 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006352 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006353}
Mike Stump11289f42009-09-09 15:08:12 +00006354
Douglas Gregora16548e2009-08-11 05:31:07 +00006355template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006356ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006357TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006358 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006359 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006360
Douglas Gregor3da3c062009-10-28 00:29:27 +00006361 // FIXME: Will we ever have proper type location here? Will we actually
6362 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006363 QualType T = getDerived().TransformType(E->getType());
6364 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006365 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006366
Douglas Gregora16548e2009-08-11 05:31:07 +00006367 if (!getDerived().AlwaysRebuild() &&
6368 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006369 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006370
Douglas Gregora16548e2009-08-11 05:31:07 +00006371 return getDerived().RebuildImplicitValueInitExpr(T);
6372}
Mike Stump11289f42009-09-09 15:08:12 +00006373
Douglas Gregora16548e2009-08-11 05:31:07 +00006374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006375ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006376TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006377 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6378 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006379 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006380
John McCalldadc5752010-08-24 06:29:42 +00006381 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006382 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006383 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006384
Douglas Gregora16548e2009-08-11 05:31:07 +00006385 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006386 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006387 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006388 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006389
John McCallb268a282010-08-23 23:25:46 +00006390 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006391 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006392}
6393
6394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006395ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006396TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006397 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006398 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006399 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6400 &ArgumentChanged))
6401 return ExprError();
6402
Douglas Gregora16548e2009-08-11 05:31:07 +00006403 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6404 move_arg(Inits),
6405 E->getRParenLoc());
6406}
Mike Stump11289f42009-09-09 15:08:12 +00006407
Douglas Gregora16548e2009-08-11 05:31:07 +00006408/// \brief Transform an address-of-label expression.
6409///
6410/// By default, the transformation of an address-of-label expression always
6411/// rebuilds the expression, so that the label identifier can be resolved to
6412/// the corresponding label statement by semantic analysis.
6413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006414ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006415TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006416 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6417 E->getLabel());
6418 if (!LD)
6419 return ExprError();
6420
Douglas Gregora16548e2009-08-11 05:31:07 +00006421 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006422 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006423}
Mike Stump11289f42009-09-09 15:08:12 +00006424
6425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006426ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006427TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006428 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006429 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6430 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006431 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006432
Douglas Gregora16548e2009-08-11 05:31:07 +00006433 if (!getDerived().AlwaysRebuild() &&
6434 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006435 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006436
6437 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006438 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006439 E->getRParenLoc());
6440}
Mike Stump11289f42009-09-09 15:08:12 +00006441
Douglas Gregora16548e2009-08-11 05:31:07 +00006442template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006443ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006444TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006445 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006446 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006447 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006448
John McCalldadc5752010-08-24 06:29:42 +00006449 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006450 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006452
John McCalldadc5752010-08-24 06:29:42 +00006453 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006454 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006455 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006456
Douglas Gregora16548e2009-08-11 05:31:07 +00006457 if (!getDerived().AlwaysRebuild() &&
6458 Cond.get() == E->getCond() &&
6459 LHS.get() == E->getLHS() &&
6460 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006461 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006462
Douglas Gregora16548e2009-08-11 05:31:07 +00006463 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006464 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006465 E->getRParenLoc());
6466}
Mike Stump11289f42009-09-09 15:08:12 +00006467
Douglas Gregora16548e2009-08-11 05:31:07 +00006468template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006469ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006470TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006471 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006472}
6473
6474template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006475ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006476TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006477 switch (E->getOperator()) {
6478 case OO_New:
6479 case OO_Delete:
6480 case OO_Array_New:
6481 case OO_Array_Delete:
6482 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006483 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006484
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006485 case OO_Call: {
6486 // This is a call to an object's operator().
6487 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6488
6489 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006490 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006491 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006492 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006493
6494 // FIXME: Poor location information
6495 SourceLocation FakeLParenLoc
6496 = SemaRef.PP.getLocForEndOfToken(
6497 static_cast<Expr *>(Object.get())->getLocEnd());
6498
6499 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006500 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006501 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6502 Args))
6503 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006504
John McCallb268a282010-08-23 23:25:46 +00006505 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006506 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006507 E->getLocEnd());
6508 }
6509
6510#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6511 case OO_##Name:
6512#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6513#include "clang/Basic/OperatorKinds.def"
6514 case OO_Subscript:
6515 // Handled below.
6516 break;
6517
6518 case OO_Conditional:
6519 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006520 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006521
6522 case OO_None:
6523 case NUM_OVERLOADED_OPERATORS:
6524 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006525 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006526 }
6527
John McCalldadc5752010-08-24 06:29:42 +00006528 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006529 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006530 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006531
John McCalldadc5752010-08-24 06:29:42 +00006532 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006533 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006534 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006535
John McCalldadc5752010-08-24 06:29:42 +00006536 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006537 if (E->getNumArgs() == 2) {
6538 Second = getDerived().TransformExpr(E->getArg(1));
6539 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006540 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006541 }
Mike Stump11289f42009-09-09 15:08:12 +00006542
Douglas Gregora16548e2009-08-11 05:31:07 +00006543 if (!getDerived().AlwaysRebuild() &&
6544 Callee.get() == E->getCallee() &&
6545 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006546 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006547 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006548
Douglas Gregora16548e2009-08-11 05:31:07 +00006549 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6550 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006551 Callee.get(),
6552 First.get(),
6553 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006554}
Mike Stump11289f42009-09-09 15:08:12 +00006555
Douglas Gregora16548e2009-08-11 05:31:07 +00006556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006557ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006558TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6559 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006560}
Mike Stump11289f42009-09-09 15:08:12 +00006561
Douglas Gregora16548e2009-08-11 05:31:07 +00006562template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006563ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006564TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6565 // Transform the callee.
6566 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6567 if (Callee.isInvalid())
6568 return ExprError();
6569
6570 // Transform exec config.
6571 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6572 if (EC.isInvalid())
6573 return ExprError();
6574
6575 // Transform arguments.
6576 bool ArgChanged = false;
6577 ASTOwningVector<Expr*> Args(SemaRef);
6578 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6579 &ArgChanged))
6580 return ExprError();
6581
6582 if (!getDerived().AlwaysRebuild() &&
6583 Callee.get() == E->getCallee() &&
6584 !ArgChanged)
6585 return SemaRef.Owned(E);
6586
6587 // FIXME: Wrong source location information for the '('.
6588 SourceLocation FakeLParenLoc
6589 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6590 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6591 move_arg(Args),
6592 E->getRParenLoc(), EC.get());
6593}
6594
6595template<typename Derived>
6596ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006597TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006598 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6599 if (!Type)
6600 return ExprError();
6601
John McCalldadc5752010-08-24 06:29:42 +00006602 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006603 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006604 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006605 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006606
Douglas Gregora16548e2009-08-11 05:31:07 +00006607 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006608 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006609 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006610 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006611
Douglas Gregora16548e2009-08-11 05:31:07 +00006612 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006613 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006614 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6615 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6616 SourceLocation FakeRParenLoc
6617 = SemaRef.PP.getLocForEndOfToken(
6618 E->getSubExpr()->getSourceRange().getEnd());
6619 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006620 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006621 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006622 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006623 FakeRAngleLoc,
6624 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006625 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006626 FakeRParenLoc);
6627}
Mike Stump11289f42009-09-09 15:08:12 +00006628
Douglas Gregora16548e2009-08-11 05:31:07 +00006629template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006630ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006631TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6632 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006633}
Mike Stump11289f42009-09-09 15:08:12 +00006634
6635template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006636ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006637TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6638 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006639}
6640
Douglas Gregora16548e2009-08-11 05:31:07 +00006641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006642ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006643TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006644 CXXReinterpretCastExpr *E) {
6645 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006646}
Mike Stump11289f42009-09-09 15:08:12 +00006647
Douglas Gregora16548e2009-08-11 05:31:07 +00006648template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006649ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006650TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6651 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006652}
Mike Stump11289f42009-09-09 15:08:12 +00006653
Douglas Gregora16548e2009-08-11 05:31:07 +00006654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006655ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006656TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006657 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006658 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6659 if (!Type)
6660 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006661
John McCalldadc5752010-08-24 06:29:42 +00006662 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006663 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006664 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006665 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006666
Douglas Gregora16548e2009-08-11 05:31:07 +00006667 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006668 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006669 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006670 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006671
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006672 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006673 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006674 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006675 E->getRParenLoc());
6676}
Mike Stump11289f42009-09-09 15:08:12 +00006677
Douglas Gregora16548e2009-08-11 05:31:07 +00006678template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006679ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006680TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006681 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006682 TypeSourceInfo *TInfo
6683 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6684 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006685 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006686
Douglas Gregora16548e2009-08-11 05:31:07 +00006687 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006688 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006689 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006690
Douglas Gregor9da64192010-04-26 22:37:10 +00006691 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6692 E->getLocStart(),
6693 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006694 E->getLocEnd());
6695 }
Mike Stump11289f42009-09-09 15:08:12 +00006696
Douglas Gregora16548e2009-08-11 05:31:07 +00006697 // We don't know whether the expression is potentially evaluated until
6698 // after we perform semantic analysis, so the expression is potentially
6699 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006700 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006701 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006702
John McCalldadc5752010-08-24 06:29:42 +00006703 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006704 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006705 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006706
Douglas Gregora16548e2009-08-11 05:31:07 +00006707 if (!getDerived().AlwaysRebuild() &&
6708 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006709 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006710
Douglas Gregor9da64192010-04-26 22:37:10 +00006711 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6712 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006713 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006714 E->getLocEnd());
6715}
6716
6717template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006718ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006719TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6720 if (E->isTypeOperand()) {
6721 TypeSourceInfo *TInfo
6722 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6723 if (!TInfo)
6724 return ExprError();
6725
6726 if (!getDerived().AlwaysRebuild() &&
6727 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006728 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006729
Douglas Gregor69735112011-03-06 17:40:41 +00006730 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006731 E->getLocStart(),
6732 TInfo,
6733 E->getLocEnd());
6734 }
6735
6736 // We don't know whether the expression is potentially evaluated until
6737 // after we perform semantic analysis, so the expression is potentially
6738 // potentially evaluated.
6739 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6740
6741 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6742 if (SubExpr.isInvalid())
6743 return ExprError();
6744
6745 if (!getDerived().AlwaysRebuild() &&
6746 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006747 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006748
6749 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6750 E->getLocStart(),
6751 SubExpr.get(),
6752 E->getLocEnd());
6753}
6754
6755template<typename Derived>
6756ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006757TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006758 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006759}
Mike Stump11289f42009-09-09 15:08:12 +00006760
Douglas Gregora16548e2009-08-11 05:31:07 +00006761template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006762ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006763TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006764 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006765 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006766}
Mike Stump11289f42009-09-09 15:08:12 +00006767
Douglas Gregora16548e2009-08-11 05:31:07 +00006768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006769ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006770TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006771 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith938f40b2011-06-11 17:19:42 +00006772 QualType T;
6773 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6774 T = MD->getThisType(getSema().Context);
6775 else
6776 T = getSema().Context.getPointerType(
6777 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump11289f42009-09-09 15:08:12 +00006778
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006779 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006780 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006781
Douglas Gregorb15af892010-01-07 23:12:05 +00006782 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006783}
Mike Stump11289f42009-09-09 15:08:12 +00006784
Douglas Gregora16548e2009-08-11 05:31:07 +00006785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006786ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006787TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006788 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006789 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006790 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006791
Douglas Gregora16548e2009-08-11 05:31:07 +00006792 if (!getDerived().AlwaysRebuild() &&
6793 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006794 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006795
John McCallb268a282010-08-23 23:25:46 +00006796 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006797}
Mike Stump11289f42009-09-09 15:08:12 +00006798
Douglas Gregora16548e2009-08-11 05:31:07 +00006799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006800ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006801TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006802 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006803 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6804 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006805 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006807
Chandler Carruth794da4c2010-02-08 06:42:49 +00006808 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006809 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006810 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006811
Douglas Gregor033f6752009-12-23 23:03:06 +00006812 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006813}
Mike Stump11289f42009-09-09 15:08:12 +00006814
Douglas Gregora16548e2009-08-11 05:31:07 +00006815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006816ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006817TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6818 CXXScalarValueInitExpr *E) {
6819 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6820 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006821 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006822
Douglas Gregora16548e2009-08-11 05:31:07 +00006823 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006824 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006825 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006826
Douglas Gregor2b88c112010-09-08 00:15:04 +00006827 return getDerived().RebuildCXXScalarValueInitExpr(T,
6828 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006829 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006830}
Mike Stump11289f42009-09-09 15:08:12 +00006831
Douglas Gregora16548e2009-08-11 05:31:07 +00006832template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006833ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006834TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006835 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006836 TypeSourceInfo *AllocTypeInfo
6837 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6838 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006839 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006840
Douglas Gregora16548e2009-08-11 05:31:07 +00006841 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006842 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006843 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006844 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006845
Douglas Gregora16548e2009-08-11 05:31:07 +00006846 // Transform the placement arguments (if any).
6847 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006848 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006849 if (getDerived().TransformExprs(E->getPlacementArgs(),
6850 E->getNumPlacementArgs(), true,
6851 PlacementArgs, &ArgumentChanged))
6852 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006853
Douglas Gregorebe10102009-08-20 07:17:43 +00006854 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006855 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006856 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6857 ConstructorArgs, &ArgumentChanged))
6858 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006859
Douglas Gregord2d9da02010-02-26 00:38:10 +00006860 // Transform constructor, new operator, and delete operator.
6861 CXXConstructorDecl *Constructor = 0;
6862 if (E->getConstructor()) {
6863 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006864 getDerived().TransformDecl(E->getLocStart(),
6865 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006866 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006867 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006868 }
6869
6870 FunctionDecl *OperatorNew = 0;
6871 if (E->getOperatorNew()) {
6872 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006873 getDerived().TransformDecl(E->getLocStart(),
6874 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006875 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006876 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006877 }
6878
6879 FunctionDecl *OperatorDelete = 0;
6880 if (E->getOperatorDelete()) {
6881 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006882 getDerived().TransformDecl(E->getLocStart(),
6883 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006884 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006885 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006886 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006887
Douglas Gregora16548e2009-08-11 05:31:07 +00006888 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006889 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006890 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006891 Constructor == E->getConstructor() &&
6892 OperatorNew == E->getOperatorNew() &&
6893 OperatorDelete == E->getOperatorDelete() &&
6894 !ArgumentChanged) {
6895 // Mark any declarations we need as referenced.
6896 // FIXME: instantiation-specific.
6897 if (Constructor)
6898 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6899 if (OperatorNew)
6900 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6901 if (OperatorDelete)
6902 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006903 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006904 }
Mike Stump11289f42009-09-09 15:08:12 +00006905
Douglas Gregor0744ef62010-09-07 21:49:58 +00006906 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006907 if (!ArraySize.get()) {
6908 // If no array size was specified, but the new expression was
6909 // instantiated with an array type (e.g., "new T" where T is
6910 // instantiated with "int[4]"), extract the outer bound from the
6911 // array type as our array size. We do this with constant and
6912 // dependently-sized array types.
6913 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6914 if (!ArrayT) {
6915 // Do nothing
6916 } else if (const ConstantArrayType *ConsArrayT
6917 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006918 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006919 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6920 ConsArrayT->getSize(),
6921 SemaRef.Context.getSizeType(),
6922 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006923 AllocType = ConsArrayT->getElementType();
6924 } else if (const DependentSizedArrayType *DepArrayT
6925 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6926 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006927 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006928 AllocType = DepArrayT->getElementType();
6929 }
6930 }
6931 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006932
Douglas Gregora16548e2009-08-11 05:31:07 +00006933 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6934 E->isGlobalNew(),
6935 /*FIXME:*/E->getLocStart(),
6936 move_arg(PlacementArgs),
6937 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006938 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006939 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006940 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006941 ArraySize.get(),
Douglas Gregor3bdcff52011-06-27 16:55:54 +00006942 /*FIXME:*/E->hasInitializer()
6943 ? E->getLocStart()
6944 : SourceLocation(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006945 move_arg(ConstructorArgs),
Douglas Gregor3bdcff52011-06-27 16:55:54 +00006946 /*FIXME:*/E->hasInitializer()
6947 ? E->getLocEnd()
6948 : SourceLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006949}
Mike Stump11289f42009-09-09 15:08:12 +00006950
Douglas Gregora16548e2009-08-11 05:31:07 +00006951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006952ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006953TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006954 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006955 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006956 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006957
Douglas Gregord2d9da02010-02-26 00:38:10 +00006958 // Transform the delete operator, if known.
6959 FunctionDecl *OperatorDelete = 0;
6960 if (E->getOperatorDelete()) {
6961 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006962 getDerived().TransformDecl(E->getLocStart(),
6963 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006964 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006965 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006966 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006967
Douglas Gregora16548e2009-08-11 05:31:07 +00006968 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006969 Operand.get() == E->getArgument() &&
6970 OperatorDelete == E->getOperatorDelete()) {
6971 // Mark any declarations we need as referenced.
6972 // FIXME: instantiation-specific.
6973 if (OperatorDelete)
6974 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006975
6976 if (!E->getArgument()->isTypeDependent()) {
6977 QualType Destroyed = SemaRef.Context.getBaseElementType(
6978 E->getDestroyedType());
6979 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6980 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6981 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6982 SemaRef.LookupDestructor(Record));
6983 }
6984 }
6985
John McCallc3007a22010-10-26 07:05:15 +00006986 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006987 }
Mike Stump11289f42009-09-09 15:08:12 +00006988
Douglas Gregora16548e2009-08-11 05:31:07 +00006989 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6990 E->isGlobalDelete(),
6991 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006992 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006993}
Mike Stump11289f42009-09-09 15:08:12 +00006994
Douglas Gregora16548e2009-08-11 05:31:07 +00006995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006996ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006997TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006998 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006999 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007000 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007001 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007002
John McCallba7bf592010-08-24 05:47:05 +00007003 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007004 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007005 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007006 E->getOperatorLoc(),
7007 E->isArrow()? tok::arrow : tok::period,
7008 ObjectTypePtr,
7009 MayBePseudoDestructor);
7010 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007011 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007012
John McCallba7bf592010-08-24 05:47:05 +00007013 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007014 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7015 if (QualifierLoc) {
7016 QualifierLoc
7017 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7018 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007019 return ExprError();
7020 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007021 CXXScopeSpec SS;
7022 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007023
Douglas Gregor678f90d2010-02-25 01:56:36 +00007024 PseudoDestructorTypeStorage Destroyed;
7025 if (E->getDestroyedTypeInfo()) {
7026 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007027 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007028 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007029 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007030 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007031 Destroyed = DestroyedTypeInfo;
7032 } else if (ObjectType->isDependentType()) {
7033 // We aren't likely to be able to resolve the identifier down to a type
7034 // now anyway, so just retain the identifier.
7035 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7036 E->getDestroyedTypeLoc());
7037 } else {
7038 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007039 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007040 *E->getDestroyedTypeIdentifier(),
7041 E->getDestroyedTypeLoc(),
7042 /*Scope=*/0,
7043 SS, ObjectTypePtr,
7044 false);
7045 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007046 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007047
Douglas Gregor678f90d2010-02-25 01:56:36 +00007048 Destroyed
7049 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7050 E->getDestroyedTypeLoc());
7051 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007052
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007053 TypeSourceInfo *ScopeTypeInfo = 0;
7054 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00007055 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007056 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007057 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007058 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007059
John McCallb268a282010-08-23 23:25:46 +00007060 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007061 E->getOperatorLoc(),
7062 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007063 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007064 ScopeTypeInfo,
7065 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007066 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007067 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007068}
Mike Stump11289f42009-09-09 15:08:12 +00007069
Douglas Gregorad8a3362009-09-04 17:36:40 +00007070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007071ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007072TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007073 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007074 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7075 Sema::LookupOrdinaryName);
7076
7077 // Transform all the decls.
7078 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7079 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007080 NamedDecl *InstD = static_cast<NamedDecl*>(
7081 getDerived().TransformDecl(Old->getNameLoc(),
7082 *I));
John McCall84d87672009-12-10 09:41:52 +00007083 if (!InstD) {
7084 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7085 // This can happen because of dependent hiding.
7086 if (isa<UsingShadowDecl>(*I))
7087 continue;
7088 else
John McCallfaf5fb42010-08-26 23:41:50 +00007089 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007090 }
John McCalle66edc12009-11-24 19:00:30 +00007091
7092 // Expand using declarations.
7093 if (isa<UsingDecl>(InstD)) {
7094 UsingDecl *UD = cast<UsingDecl>(InstD);
7095 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7096 E = UD->shadow_end(); I != E; ++I)
7097 R.addDecl(*I);
7098 continue;
7099 }
7100
7101 R.addDecl(InstD);
7102 }
7103
7104 // Resolve a kind, but don't do any further analysis. If it's
7105 // ambiguous, the callee needs to deal with it.
7106 R.resolveKind();
7107
7108 // Rebuild the nested-name qualifier, if present.
7109 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007110 if (Old->getQualifierLoc()) {
7111 NestedNameSpecifierLoc QualifierLoc
7112 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7113 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007114 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007115
Douglas Gregor0da1d432011-02-28 20:01:57 +00007116 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007117 }
7118
Douglas Gregor9262f472010-04-27 18:19:34 +00007119 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007120 CXXRecordDecl *NamingClass
7121 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7122 Old->getNameLoc(),
7123 Old->getNamingClass()));
7124 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007125 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007126
Douglas Gregorda7be082010-04-27 16:10:10 +00007127 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007128 }
7129
7130 // If we have no template arguments, it's a normal declaration name.
7131 if (!Old->hasExplicitTemplateArgs())
7132 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7133
7134 // If we have template arguments, rebuild them, then rebuild the
7135 // templateid expression.
7136 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007137 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7138 Old->getNumTemplateArgs(),
7139 TransArgs))
7140 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007141
7142 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7143 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007144}
Mike Stump11289f42009-09-09 15:08:12 +00007145
Douglas Gregora16548e2009-08-11 05:31:07 +00007146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007147ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007148TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007149 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7150 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007151 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007152
Douglas Gregora16548e2009-08-11 05:31:07 +00007153 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007154 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007155 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007156
Mike Stump11289f42009-09-09 15:08:12 +00007157 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007158 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007159 T,
7160 E->getLocEnd());
7161}
Mike Stump11289f42009-09-09 15:08:12 +00007162
Douglas Gregora16548e2009-08-11 05:31:07 +00007163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007164ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007165TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7166 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7167 if (!LhsT)
7168 return ExprError();
7169
7170 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7171 if (!RhsT)
7172 return ExprError();
7173
7174 if (!getDerived().AlwaysRebuild() &&
7175 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7176 return SemaRef.Owned(E);
7177
7178 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7179 E->getLocStart(),
7180 LhsT, RhsT,
7181 E->getLocEnd());
7182}
7183
7184template<typename Derived>
7185ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007186TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7187 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7188 if (!T)
7189 return ExprError();
7190
7191 if (!getDerived().AlwaysRebuild() &&
7192 T == E->getQueriedTypeSourceInfo())
7193 return SemaRef.Owned(E);
7194
7195 ExprResult SubExpr;
7196 {
7197 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7198 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7199 if (SubExpr.isInvalid())
7200 return ExprError();
7201
7202 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7203 return SemaRef.Owned(E);
7204 }
7205
7206 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7207 E->getLocStart(),
7208 T,
7209 SubExpr.get(),
7210 E->getLocEnd());
7211}
7212
7213template<typename Derived>
7214ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007215TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7216 ExprResult SubExpr;
7217 {
7218 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7219 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7220 if (SubExpr.isInvalid())
7221 return ExprError();
7222
7223 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7224 return SemaRef.Owned(E);
7225 }
7226
7227 return getDerived().RebuildExpressionTrait(
7228 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7229}
7230
7231template<typename Derived>
7232ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007233TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007234 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007235 NestedNameSpecifierLoc QualifierLoc
7236 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7237 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007239
John McCall31f82722010-11-12 08:19:04 +00007240 // TODO: If this is a conversion-function-id, verify that the
7241 // destination type name (if present) resolves the same way after
7242 // instantiation as it did in the local scope.
7243
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007244 DeclarationNameInfo NameInfo
7245 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7246 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007247 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007248
John McCalle66edc12009-11-24 19:00:30 +00007249 if (!E->hasExplicitTemplateArgs()) {
7250 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007251 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007252 // Note: it is sufficient to compare the Name component of NameInfo:
7253 // if name has not changed, DNLoc has not changed either.
7254 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007255 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007256
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007257 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007258 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007259 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007260 }
John McCall6b51f282009-11-23 01:53:49 +00007261
7262 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007263 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7264 E->getNumTemplateArgs(),
7265 TransArgs))
7266 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007267
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007268 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007269 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007270 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007271}
7272
7273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007274ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007275TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007276 // CXXConstructExprs are always implicit, so when we have a
7277 // 1-argument construction we just transform that argument.
7278 if (E->getNumArgs() == 1 ||
7279 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7280 return getDerived().TransformExpr(E->getArg(0));
7281
Douglas Gregora16548e2009-08-11 05:31:07 +00007282 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7283
7284 QualType T = getDerived().TransformType(E->getType());
7285 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007286 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007287
7288 CXXConstructorDecl *Constructor
7289 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007290 getDerived().TransformDecl(E->getLocStart(),
7291 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007292 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007293 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007294
Douglas Gregora16548e2009-08-11 05:31:07 +00007295 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007296 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007297 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7298 &ArgumentChanged))
7299 return ExprError();
7300
Douglas Gregora16548e2009-08-11 05:31:07 +00007301 if (!getDerived().AlwaysRebuild() &&
7302 T == E->getType() &&
7303 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007304 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007305 // Mark the constructor as referenced.
7306 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007307 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007308 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007309 }
Mike Stump11289f42009-09-09 15:08:12 +00007310
Douglas Gregordb121ba2009-12-14 16:27:04 +00007311 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7312 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007313 move_arg(Args),
7314 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007315 E->getConstructionKind(),
7316 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007317}
Mike Stump11289f42009-09-09 15:08:12 +00007318
Douglas Gregora16548e2009-08-11 05:31:07 +00007319/// \brief Transform a C++ temporary-binding expression.
7320///
Douglas Gregor363b1512009-12-24 18:51:59 +00007321/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7322/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007324ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007325TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007326 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007327}
Mike Stump11289f42009-09-09 15:08:12 +00007328
John McCall5d413782010-12-06 08:20:24 +00007329/// \brief Transform a C++ expression that contains cleanups that should
7330/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007331///
John McCall5d413782010-12-06 08:20:24 +00007332/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007333/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007335ExprResult
John McCall5d413782010-12-06 08:20:24 +00007336TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007337 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007338}
Mike Stump11289f42009-09-09 15:08:12 +00007339
Douglas Gregora16548e2009-08-11 05:31:07 +00007340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007341ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007342TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007343 CXXTemporaryObjectExpr *E) {
7344 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7345 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007347
Douglas Gregora16548e2009-08-11 05:31:07 +00007348 CXXConstructorDecl *Constructor
7349 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007350 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007351 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007352 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007353 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007354
Douglas Gregora16548e2009-08-11 05:31:07 +00007355 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007356 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007357 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007358 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7359 &ArgumentChanged))
7360 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007361
Douglas Gregora16548e2009-08-11 05:31:07 +00007362 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007363 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007364 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007365 !ArgumentChanged) {
7366 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007367 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007368 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007369 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007370
7371 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7372 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007373 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007374 E->getLocEnd());
7375}
Mike Stump11289f42009-09-09 15:08:12 +00007376
Douglas Gregora16548e2009-08-11 05:31:07 +00007377template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007378ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007379TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007380 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007381 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7382 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007383 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007384
Douglas Gregora16548e2009-08-11 05:31:07 +00007385 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007386 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007387 Args.reserve(E->arg_size());
7388 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7389 &ArgumentChanged))
7390 return ExprError();
7391
Douglas Gregora16548e2009-08-11 05:31:07 +00007392 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007393 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007394 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007395 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007396
Douglas Gregora16548e2009-08-11 05:31:07 +00007397 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007398 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007399 E->getLParenLoc(),
7400 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007401 E->getRParenLoc());
7402}
Mike Stump11289f42009-09-09 15:08:12 +00007403
Douglas Gregora16548e2009-08-11 05:31:07 +00007404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007405ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007406TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007407 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007408 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007409 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007410 Expr *OldBase;
7411 QualType BaseType;
7412 QualType ObjectType;
7413 if (!E->isImplicitAccess()) {
7414 OldBase = E->getBase();
7415 Base = getDerived().TransformExpr(OldBase);
7416 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007417 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007418
John McCall2d74de92009-12-01 22:10:20 +00007419 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007420 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007421 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007422 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007423 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007424 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007425 ObjectTy,
7426 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007427 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007428 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007429
John McCallba7bf592010-08-24 05:47:05 +00007430 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007431 BaseType = ((Expr*) Base.get())->getType();
7432 } else {
7433 OldBase = 0;
7434 BaseType = getDerived().TransformType(E->getBaseType());
7435 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7436 }
Mike Stump11289f42009-09-09 15:08:12 +00007437
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007438 // Transform the first part of the nested-name-specifier that qualifies
7439 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007440 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007441 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007442 E->getFirstQualifierFoundInScope(),
7443 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007444
Douglas Gregore16af532011-02-28 18:50:33 +00007445 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007446 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007447 QualifierLoc
7448 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7449 ObjectType,
7450 FirstQualifierInScope);
7451 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007452 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007453 }
Mike Stump11289f42009-09-09 15:08:12 +00007454
John McCall31f82722010-11-12 08:19:04 +00007455 // TODO: If this is a conversion-function-id, verify that the
7456 // destination type name (if present) resolves the same way after
7457 // instantiation as it did in the local scope.
7458
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007459 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007460 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007461 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007462 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007463
John McCall2d74de92009-12-01 22:10:20 +00007464 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007465 // This is a reference to a member without an explicitly-specified
7466 // template argument list. Optimize for this common case.
7467 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007468 Base.get() == OldBase &&
7469 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007470 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007471 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007472 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007473 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007474
John McCallb268a282010-08-23 23:25:46 +00007475 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007476 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007477 E->isArrow(),
7478 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007479 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007480 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007481 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007482 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007483 }
7484
John McCall6b51f282009-11-23 01:53:49 +00007485 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007486 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7487 E->getNumTemplateArgs(),
7488 TransArgs))
7489 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007490
John McCallb268a282010-08-23 23:25:46 +00007491 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007492 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007493 E->isArrow(),
7494 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007495 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007496 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007497 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007498 &TransArgs);
7499}
7500
7501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007502ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007503TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007504 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007505 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007506 QualType BaseType;
7507 if (!Old->isImplicitAccess()) {
7508 Base = getDerived().TransformExpr(Old->getBase());
7509 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007510 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007511 BaseType = ((Expr*) Base.get())->getType();
7512 } else {
7513 BaseType = getDerived().TransformType(Old->getBaseType());
7514 }
John McCall10eae182009-11-30 22:42:35 +00007515
Douglas Gregor0da1d432011-02-28 20:01:57 +00007516 NestedNameSpecifierLoc QualifierLoc;
7517 if (Old->getQualifierLoc()) {
7518 QualifierLoc
7519 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7520 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007521 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007522 }
7523
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007524 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007525 Sema::LookupOrdinaryName);
7526
7527 // Transform all the decls.
7528 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7529 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007530 NamedDecl *InstD = static_cast<NamedDecl*>(
7531 getDerived().TransformDecl(Old->getMemberLoc(),
7532 *I));
John McCall84d87672009-12-10 09:41:52 +00007533 if (!InstD) {
7534 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7535 // This can happen because of dependent hiding.
7536 if (isa<UsingShadowDecl>(*I))
7537 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007538 else {
7539 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007540 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007541 }
John McCall84d87672009-12-10 09:41:52 +00007542 }
John McCall10eae182009-11-30 22:42:35 +00007543
7544 // Expand using declarations.
7545 if (isa<UsingDecl>(InstD)) {
7546 UsingDecl *UD = cast<UsingDecl>(InstD);
7547 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7548 E = UD->shadow_end(); I != E; ++I)
7549 R.addDecl(*I);
7550 continue;
7551 }
7552
7553 R.addDecl(InstD);
7554 }
7555
7556 R.resolveKind();
7557
Douglas Gregor9262f472010-04-27 18:19:34 +00007558 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007559 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007560 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007561 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007562 Old->getMemberLoc(),
7563 Old->getNamingClass()));
7564 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007565 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007566
Douglas Gregorda7be082010-04-27 16:10:10 +00007567 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007568 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007569
John McCall10eae182009-11-30 22:42:35 +00007570 TemplateArgumentListInfo TransArgs;
7571 if (Old->hasExplicitTemplateArgs()) {
7572 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7573 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007574 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7575 Old->getNumTemplateArgs(),
7576 TransArgs))
7577 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007578 }
John McCall38836f02010-01-15 08:34:02 +00007579
7580 // FIXME: to do this check properly, we will need to preserve the
7581 // first-qualifier-in-scope here, just in case we had a dependent
7582 // base (and therefore couldn't do the check) and a
7583 // nested-name-qualifier (and therefore could do the lookup).
7584 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007585
John McCallb268a282010-08-23 23:25:46 +00007586 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007587 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007588 Old->getOperatorLoc(),
7589 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007590 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007591 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007592 R,
7593 (Old->hasExplicitTemplateArgs()
7594 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007595}
7596
7597template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007598ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007599TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00007600 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007601 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7602 if (SubExpr.isInvalid())
7603 return ExprError();
7604
7605 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007606 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007607
7608 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7609}
7610
7611template<typename Derived>
7612ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007613TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007614 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7615 if (Pattern.isInvalid())
7616 return ExprError();
7617
7618 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7619 return SemaRef.Owned(E);
7620
Douglas Gregorb8840002011-01-14 21:20:45 +00007621 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7622 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007623}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007624
7625template<typename Derived>
7626ExprResult
7627TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7628 // If E is not value-dependent, then nothing will change when we transform it.
7629 // Note: This is an instantiation-centric view.
7630 if (!E->isValueDependent())
7631 return SemaRef.Owned(E);
7632
7633 // Note: None of the implementations of TryExpandParameterPacks can ever
7634 // produce a diagnostic when given only a single unexpanded parameter pack,
7635 // so
7636 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7637 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007638 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007639 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007640 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7641 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007642 ShouldExpand, RetainExpansion,
7643 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007644 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007645
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007646 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007647 return SemaRef.Owned(E);
7648
7649 // We now know the length of the parameter pack, so build a new expression
7650 // that stores that length.
7651 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7652 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007653 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007654}
7655
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007656template<typename Derived>
7657ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007658TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7659 SubstNonTypeTemplateParmPackExpr *E) {
7660 // Default behavior is to do nothing with this transformation.
7661 return SemaRef.Owned(E);
7662}
7663
7664template<typename Derived>
7665ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00007666TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7667 MaterializeTemporaryExpr *E) {
7668 return getDerived().TransformExpr(E->GetTemporaryExpr());
7669}
7670
7671template<typename Derived>
7672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007673TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007674 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007675}
7676
Mike Stump11289f42009-09-09 15:08:12 +00007677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007678ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007679TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007680 TypeSourceInfo *EncodedTypeInfo
7681 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7682 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007683 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007684
Douglas Gregora16548e2009-08-11 05:31:07 +00007685 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007686 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007687 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007688
7689 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007690 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007691 E->getRParenLoc());
7692}
Mike Stump11289f42009-09-09 15:08:12 +00007693
Douglas Gregora16548e2009-08-11 05:31:07 +00007694template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00007695ExprResult TreeTransform<Derived>::
7696TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7697 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7698 if (result.isInvalid()) return ExprError();
7699 Expr *subExpr = result.take();
7700
7701 if (!getDerived().AlwaysRebuild() &&
7702 subExpr == E->getSubExpr())
7703 return SemaRef.Owned(E);
7704
7705 return SemaRef.Owned(new(SemaRef.Context)
7706 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7707}
7708
7709template<typename Derived>
7710ExprResult TreeTransform<Derived>::
7711TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7712 TypeSourceInfo *TSInfo
7713 = getDerived().TransformType(E->getTypeInfoAsWritten());
7714 if (!TSInfo)
7715 return ExprError();
7716
7717 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7718 if (Result.isInvalid())
7719 return ExprError();
7720
7721 if (!getDerived().AlwaysRebuild() &&
7722 TSInfo == E->getTypeInfoAsWritten() &&
7723 Result.get() == E->getSubExpr())
7724 return SemaRef.Owned(E);
7725
7726 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7727 E->getBridgeKeywordLoc(), TSInfo,
7728 Result.get());
7729}
7730
7731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007732ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007733TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007734 // Transform arguments.
7735 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007736 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007737 Args.reserve(E->getNumArgs());
7738 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7739 &ArgChanged))
7740 return ExprError();
7741
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007742 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7743 // Class message: transform the receiver type.
7744 TypeSourceInfo *ReceiverTypeInfo
7745 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7746 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007747 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007748
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007749 // If nothing changed, just retain the existing message send.
7750 if (!getDerived().AlwaysRebuild() &&
7751 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007752 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007753
7754 // Build a new class message send.
7755 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7756 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007757 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007758 E->getMethodDecl(),
7759 E->getLeftLoc(),
7760 move_arg(Args),
7761 E->getRightLoc());
7762 }
7763
7764 // Instance message: transform the receiver
7765 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7766 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007767 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007768 = getDerived().TransformExpr(E->getInstanceReceiver());
7769 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007770 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007771
7772 // If nothing changed, just retain the existing message send.
7773 if (!getDerived().AlwaysRebuild() &&
7774 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007775 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007776
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007777 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007778 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007779 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007780 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007781 E->getMethodDecl(),
7782 E->getLeftLoc(),
7783 move_arg(Args),
7784 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007785}
7786
Mike Stump11289f42009-09-09 15:08:12 +00007787template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007788ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007789TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007790 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007791}
7792
Mike Stump11289f42009-09-09 15:08:12 +00007793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007794ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007795TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007796 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007797}
7798
Mike Stump11289f42009-09-09 15:08:12 +00007799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007800ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007801TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007802 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007803 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007804 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007805 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007806
7807 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007808
Douglas Gregord51d90d2010-04-26 20:11:03 +00007809 // If nothing changed, just retain the existing expression.
7810 if (!getDerived().AlwaysRebuild() &&
7811 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007812 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007813
John McCallb268a282010-08-23 23:25:46 +00007814 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007815 E->getLocation(),
7816 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007817}
7818
Mike Stump11289f42009-09-09 15:08:12 +00007819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007820ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007821TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007822 // 'super' and types never change. Property never changes. Just
7823 // retain the existing expression.
7824 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007825 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007826
Douglas Gregor9faee212010-04-26 20:47:02 +00007827 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007828 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007829 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007830 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007831
Douglas Gregor9faee212010-04-26 20:47:02 +00007832 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007833
Douglas Gregor9faee212010-04-26 20:47:02 +00007834 // If nothing changed, just retain the existing expression.
7835 if (!getDerived().AlwaysRebuild() &&
7836 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007837 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007838
John McCallb7bd14f2010-12-02 01:19:52 +00007839 if (E->isExplicitProperty())
7840 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7841 E->getExplicitProperty(),
7842 E->getLocation());
7843
7844 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7845 E->getType(),
7846 E->getImplicitPropertyGetter(),
7847 E->getImplicitPropertySetter(),
7848 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007849}
7850
Mike Stump11289f42009-09-09 15:08:12 +00007851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007852ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007853TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007854 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007855 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007856 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007857 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007858
Douglas Gregord51d90d2010-04-26 20:11:03 +00007859 // If nothing changed, just retain the existing expression.
7860 if (!getDerived().AlwaysRebuild() &&
7861 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007862 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007863
John McCallb268a282010-08-23 23:25:46 +00007864 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007865 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007866}
7867
Mike Stump11289f42009-09-09 15:08:12 +00007868template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007869ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007870TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007871 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007872 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007873 SubExprs.reserve(E->getNumSubExprs());
7874 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7875 SubExprs, &ArgumentChanged))
7876 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007877
Douglas Gregora16548e2009-08-11 05:31:07 +00007878 if (!getDerived().AlwaysRebuild() &&
7879 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007880 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007881
Douglas Gregora16548e2009-08-11 05:31:07 +00007882 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7883 move_arg(SubExprs),
7884 E->getRParenLoc());
7885}
7886
Mike Stump11289f42009-09-09 15:08:12 +00007887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007888ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007889TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007890 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007891
John McCall490112f2011-02-04 18:33:18 +00007892 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7893 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7894
7895 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00007896 // We built a new blockScopeInfo in call to ActOnBlockStart
7897 // in above, CapturesCXXThis need be set here from the block
7898 // expression.
7899 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7900
John McCall490112f2011-02-04 18:33:18 +00007901 llvm::SmallVector<ParmVarDecl*, 4> params;
7902 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007903
7904 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007905 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7906 oldBlock->param_begin(),
7907 oldBlock->param_size(),
7908 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007909 return true;
John McCall490112f2011-02-04 18:33:18 +00007910
7911 const FunctionType *exprFunctionType = E->getFunctionType();
7912 QualType exprResultType = exprFunctionType->getResultType();
7913 if (!exprResultType.isNull()) {
7914 if (!exprResultType->isDependentType())
7915 blockScope->ReturnType = exprResultType;
7916 else if (exprResultType != getSema().Context.DependentTy)
7917 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007918 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007919
7920 // If the return type has not been determined yet, leave it as a dependent
7921 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007922 if (blockScope->ReturnType.isNull())
7923 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007924
7925 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007926 if (blockScope->ReturnType->isObjCObjectType()) {
7927 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007928 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007929 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007930 return ExprError();
7931 }
John McCall3882ace2011-01-05 12:14:39 +00007932
John McCall490112f2011-02-04 18:33:18 +00007933 QualType functionType = getDerived().RebuildFunctionProtoType(
7934 blockScope->ReturnType,
7935 paramTypes.data(),
7936 paramTypes.size(),
7937 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007938 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007939 exprFunctionType->getExtInfo());
7940 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007941
7942 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007943 if (!params.empty())
7944 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007945
7946 // If the return type wasn't explicitly set, it will have been marked as a
7947 // dependent type (DependentTy); clear out the return type setting so
7948 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007949 if (blockScope->ReturnType == getSema().Context.DependentTy)
7950 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007951
John McCall3882ace2011-01-05 12:14:39 +00007952 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007953 StmtResult body = getDerived().TransformStmt(E->getBody());
7954 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007955 return ExprError();
7956
John McCall490112f2011-02-04 18:33:18 +00007957#ifndef NDEBUG
7958 // In builds with assertions, make sure that we captured everything we
7959 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007960 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
7961 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7962 e = oldBlock->capture_end(); i != e; ++i) {
7963 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007964
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007965 // Ignore parameter packs.
7966 if (isa<ParmVarDecl>(oldCapture) &&
7967 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7968 continue;
John McCall490112f2011-02-04 18:33:18 +00007969
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007970 VarDecl *newCapture =
7971 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7972 oldCapture));
7973 assert(blockScope->CaptureMap.count(newCapture));
7974 }
John McCall490112f2011-02-04 18:33:18 +00007975 }
7976#endif
7977
7978 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7979 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007980}
7981
Mike Stump11289f42009-09-09 15:08:12 +00007982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007983ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007984TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007985 ValueDecl *ND
7986 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7987 E->getDecl()));
7988 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007989 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007990
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007991 if (!getDerived().AlwaysRebuild() &&
7992 ND == E->getDecl()) {
7993 // Mark it referenced in the new context regardless.
7994 // FIXME: this is a bit instantiation-specific.
7995 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7996
John McCallc3007a22010-10-26 07:05:15 +00007997 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007998 }
7999
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008000 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00008001 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008002 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008003}
Mike Stump11289f42009-09-09 15:08:12 +00008004
Tanya Lattner55808c12011-06-04 00:47:47 +00008005template<typename Derived>
8006ExprResult
8007TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
8008 assert(false && "Cannot transform asType expressions yet");
8009 return SemaRef.Owned(E);
8010}
8011
Douglas Gregora16548e2009-08-11 05:31:07 +00008012//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008013// Type reconstruction
8014//===----------------------------------------------------------------------===//
8015
Mike Stump11289f42009-09-09 15:08:12 +00008016template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008017QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8018 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008019 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008020 getDerived().getBaseEntity());
8021}
8022
Mike Stump11289f42009-09-09 15:08:12 +00008023template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008024QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8025 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008026 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008027 getDerived().getBaseEntity());
8028}
8029
Mike Stump11289f42009-09-09 15:08:12 +00008030template<typename Derived>
8031QualType
John McCall70dd5f62009-10-30 00:06:24 +00008032TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8033 bool WrittenAsLValue,
8034 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008035 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00008036 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008037}
8038
8039template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008040QualType
John McCall70dd5f62009-10-30 00:06:24 +00008041TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8042 QualType ClassType,
8043 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008044 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00008045 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008046}
8047
8048template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008049QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00008050TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8051 ArrayType::ArraySizeModifier SizeMod,
8052 const llvm::APInt *Size,
8053 Expr *SizeExpr,
8054 unsigned IndexTypeQuals,
8055 SourceRange BracketsRange) {
8056 if (SizeExpr || !Size)
8057 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8058 IndexTypeQuals, BracketsRange,
8059 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00008060
8061 QualType Types[] = {
8062 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8063 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8064 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00008065 };
8066 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8067 QualType SizeType;
8068 for (unsigned I = 0; I != NumTypes; ++I)
8069 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8070 SizeType = Types[I];
8071 break;
8072 }
Mike Stump11289f42009-09-09 15:08:12 +00008073
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008074 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8075 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00008076 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008077 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00008078 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008079}
Mike Stump11289f42009-09-09 15:08:12 +00008080
Douglas Gregord6ff3322009-08-04 16:50:30 +00008081template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008082QualType
8083TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008084 ArrayType::ArraySizeModifier SizeMod,
8085 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00008086 unsigned IndexTypeQuals,
8087 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008088 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008089 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008090}
8091
8092template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008093QualType
Mike Stump11289f42009-09-09 15:08:12 +00008094TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008095 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00008096 unsigned IndexTypeQuals,
8097 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008098 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008099 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008100}
Mike Stump11289f42009-09-09 15:08:12 +00008101
Douglas Gregord6ff3322009-08-04 16:50:30 +00008102template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008103QualType
8104TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008105 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008106 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008107 unsigned IndexTypeQuals,
8108 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008109 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008110 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008111 IndexTypeQuals, BracketsRange);
8112}
8113
8114template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008115QualType
8116TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008117 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008118 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008119 unsigned IndexTypeQuals,
8120 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008121 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008122 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008123 IndexTypeQuals, BracketsRange);
8124}
8125
8126template<typename Derived>
8127QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00008128 unsigned NumElements,
8129 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00008130 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00008131 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008132}
Mike Stump11289f42009-09-09 15:08:12 +00008133
Douglas Gregord6ff3322009-08-04 16:50:30 +00008134template<typename Derived>
8135QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8136 unsigned NumElements,
8137 SourceLocation AttributeLoc) {
8138 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8139 NumElements, true);
8140 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008141 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8142 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00008143 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008144}
Mike Stump11289f42009-09-09 15:08:12 +00008145
Douglas Gregord6ff3322009-08-04 16:50:30 +00008146template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008147QualType
8148TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00008149 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008150 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00008151 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008152}
Mike Stump11289f42009-09-09 15:08:12 +00008153
Douglas Gregord6ff3322009-08-04 16:50:30 +00008154template<typename Derived>
8155QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00008156 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008157 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00008158 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00008159 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008160 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00008161 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00008162 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008163 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008164 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008165 getDerived().getBaseEntity(),
8166 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008167}
Mike Stump11289f42009-09-09 15:08:12 +00008168
Douglas Gregord6ff3322009-08-04 16:50:30 +00008169template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008170QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8171 return SemaRef.Context.getFunctionNoProtoType(T);
8172}
8173
8174template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008175QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8176 assert(D && "no decl found");
8177 if (D->isInvalidDecl()) return QualType();
8178
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008179 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008180 TypeDecl *Ty;
8181 if (isa<UsingDecl>(D)) {
8182 UsingDecl *Using = cast<UsingDecl>(D);
8183 assert(Using->isTypeName() &&
8184 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8185
8186 // A valid resolved using typename decl points to exactly one type decl.
8187 assert(++Using->shadow_begin() == Using->shadow_end());
8188 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008189
John McCallb96ec562009-12-04 22:46:56 +00008190 } else {
8191 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8192 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8193 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8194 }
8195
8196 return SemaRef.Context.getTypeDeclType(Ty);
8197}
8198
8199template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008200QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8201 SourceLocation Loc) {
8202 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008203}
8204
8205template<typename Derived>
8206QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8207 return SemaRef.Context.getTypeOfType(Underlying);
8208}
8209
8210template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008211QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8212 SourceLocation Loc) {
8213 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008214}
8215
8216template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00008217QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8218 UnaryTransformType::UTTKind UKind,
8219 SourceLocation Loc) {
8220 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8221}
8222
8223template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00008224QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008225 TemplateName Template,
8226 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008227 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008228 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008229}
Mike Stump11289f42009-09-09 15:08:12 +00008230
Douglas Gregor1135c352009-08-06 05:28:30 +00008231template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008232TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008233TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008234 bool TemplateKW,
8235 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008236 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008237 Template);
8238}
8239
8240template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008241TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008242TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8243 const IdentifierInfo &Name,
8244 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008245 QualType ObjectType,
8246 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008247 UnqualifiedId TemplateName;
8248 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008249 Sema::TemplateTy Template;
8250 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008251 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008252 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008253 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008254 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008255 /*EnteringContext=*/false,
8256 Template);
John McCall31f82722010-11-12 08:19:04 +00008257 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008258}
Mike Stump11289f42009-09-09 15:08:12 +00008259
Douglas Gregora16548e2009-08-11 05:31:07 +00008260template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008261TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008262TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008263 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008264 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008265 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008266 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008267 // FIXME: Bogus location information.
8268 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8269 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008270 Sema::TemplateTy Template;
8271 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008272 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008273 SS,
8274 Name,
John McCallba7bf592010-08-24 05:47:05 +00008275 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008276 /*EnteringContext=*/false,
8277 Template);
8278 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008279}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008280
Douglas Gregor71395fa2009-11-04 00:56:37 +00008281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008282ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008283TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8284 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008285 Expr *OrigCallee,
8286 Expr *First,
8287 Expr *Second) {
8288 Expr *Callee = OrigCallee->IgnoreParenCasts();
8289 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008290
Douglas Gregora16548e2009-08-11 05:31:07 +00008291 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008292 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008293 if (!First->getType()->isOverloadableType() &&
8294 !Second->getType()->isOverloadableType())
8295 return getSema().CreateBuiltinArraySubscriptExpr(First,
8296 Callee->getLocStart(),
8297 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008298 } else if (Op == OO_Arrow) {
8299 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008300 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8301 } else if (Second == 0 || isPostIncDec) {
8302 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008303 // The argument is not of overloadable type, so try to create a
8304 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008305 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008306 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008307
John McCallb268a282010-08-23 23:25:46 +00008308 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008309 }
8310 } else {
John McCallb268a282010-08-23 23:25:46 +00008311 if (!First->getType()->isOverloadableType() &&
8312 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008313 // Neither of the arguments is an overloadable type, so try to
8314 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008315 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008316 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008317 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008318 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008319 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008320
Douglas Gregora16548e2009-08-11 05:31:07 +00008321 return move(Result);
8322 }
8323 }
Mike Stump11289f42009-09-09 15:08:12 +00008324
8325 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008326 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008327 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008328
John McCallb268a282010-08-23 23:25:46 +00008329 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008330 assert(ULE->requiresADL());
8331
8332 // FIXME: Do we have to check
8333 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008334 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008335 } else {
John McCallb268a282010-08-23 23:25:46 +00008336 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008337 }
Mike Stump11289f42009-09-09 15:08:12 +00008338
Douglas Gregora16548e2009-08-11 05:31:07 +00008339 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008340 Expr *Args[2] = { First, Second };
8341 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008342
Douglas Gregora16548e2009-08-11 05:31:07 +00008343 // Create the overloaded operator invocation for unary operators.
8344 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008345 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008346 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008347 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008348 }
Mike Stump11289f42009-09-09 15:08:12 +00008349
Sebastian Redladba46e2009-10-29 20:17:01 +00008350 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00008351 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00008352 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008353 First,
8354 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00008355
Douglas Gregora16548e2009-08-11 05:31:07 +00008356 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008357 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008358 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008359 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8360 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008361 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008362
Mike Stump11289f42009-09-09 15:08:12 +00008363 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008364}
Mike Stump11289f42009-09-09 15:08:12 +00008365
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008367ExprResult
John McCallb268a282010-08-23 23:25:46 +00008368TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008369 SourceLocation OperatorLoc,
8370 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008371 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008372 TypeSourceInfo *ScopeType,
8373 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008374 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008375 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008376 QualType BaseType = Base->getType();
8377 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008378 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008379 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008380 !BaseType->getAs<PointerType>()->getPointeeType()
8381 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008382 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008383 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008384 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008385 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008386 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008387 /*FIXME?*/true);
8388 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008389
Douglas Gregor678f90d2010-02-25 01:56:36 +00008390 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008391 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8392 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8393 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8394 NameInfo.setNamedTypeInfo(DestroyedType);
8395
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008396 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008397
John McCallb268a282010-08-23 23:25:46 +00008398 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008399 OperatorLoc, isArrow,
8400 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008401 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008402 /*TemplateArgs*/ 0);
8403}
8404
Douglas Gregord6ff3322009-08-04 16:50:30 +00008405} // end namespace clang
8406
8407#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H