blob: ba4ee3426a4637e1ce639a78656e3b60c68ea010 [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,
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001551 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 }
2479
2480 // The transform has determined that we should perform an elementwise
2481 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002482 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002483 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2484 ExprResult Out = getDerived().TransformExpr(Pattern);
2485 if (Out.isInvalid())
2486 return true;
2487
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002488 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002489 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2490 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002491 if (Out.isInvalid())
2492 return true;
2493 }
2494
Douglas Gregor968f23a2011-01-03 19:31:53 +00002495 if (ArgChanged)
2496 *ArgChanged = true;
2497 Outputs.push_back(Out.get());
2498 }
2499
2500 continue;
2501 }
2502
Douglas Gregora3efea12011-01-03 19:04:46 +00002503 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2504 if (Result.isInvalid())
2505 return true;
2506
2507 if (Result.get() != Inputs[I] && ArgChanged)
2508 *ArgChanged = true;
2509
2510 Outputs.push_back(Result.get());
2511 }
2512
2513 return false;
2514}
2515
2516template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002517NestedNameSpecifierLoc
2518TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2519 NestedNameSpecifierLoc NNS,
2520 QualType ObjectType,
2521 NamedDecl *FirstQualifierInScope) {
2522 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2523 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2524 Qualifier = Qualifier.getPrefix())
2525 Qualifiers.push_back(Qualifier);
2526
2527 CXXScopeSpec SS;
2528 while (!Qualifiers.empty()) {
2529 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2530 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2531
2532 switch (QNNS->getKind()) {
2533 case NestedNameSpecifier::Identifier:
2534 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2535 *QNNS->getAsIdentifier(),
2536 Q.getLocalBeginLoc(),
2537 Q.getLocalEndLoc(),
2538 ObjectType, false, SS,
2539 FirstQualifierInScope, false))
2540 return NestedNameSpecifierLoc();
2541
2542 break;
2543
2544 case NestedNameSpecifier::Namespace: {
2545 NamespaceDecl *NS
2546 = cast_or_null<NamespaceDecl>(
2547 getDerived().TransformDecl(
2548 Q.getLocalBeginLoc(),
2549 QNNS->getAsNamespace()));
2550 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2551 break;
2552 }
2553
2554 case NestedNameSpecifier::NamespaceAlias: {
2555 NamespaceAliasDecl *Alias
2556 = cast_or_null<NamespaceAliasDecl>(
2557 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2558 QNNS->getAsNamespaceAlias()));
2559 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2560 Q.getLocalEndLoc());
2561 break;
2562 }
2563
2564 case NestedNameSpecifier::Global:
2565 // There is no meaningful transformation that one could perform on the
2566 // global scope.
2567 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2568 break;
2569
2570 case NestedNameSpecifier::TypeSpecWithTemplate:
2571 case NestedNameSpecifier::TypeSpec: {
2572 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2573 FirstQualifierInScope, SS);
2574
2575 if (!TL)
2576 return NestedNameSpecifierLoc();
2577
2578 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2579 (SemaRef.getLangOptions().CPlusPlus0x &&
2580 TL.getType()->isEnumeralType())) {
2581 assert(!TL.getType().hasLocalQualifiers() &&
2582 "Can't get cv-qualifiers here");
2583 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2584 Q.getLocalEndLoc());
2585 break;
2586 }
Richard Trieude756fb2011-05-07 01:36:37 +00002587 // If the nested-name-specifier is an invalid type def, don't emit an
2588 // error because a previous error should have already been emitted.
2589 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2590 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2591 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2592 << TL.getType() << SS.getRange();
2593 }
Douglas Gregor14454802011-02-25 02:25:35 +00002594 return NestedNameSpecifierLoc();
2595 }
Douglas Gregore16af532011-02-28 18:50:33 +00002596 }
Douglas Gregor14454802011-02-25 02:25:35 +00002597
Douglas Gregore16af532011-02-28 18:50:33 +00002598 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002599 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002600 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002601 }
2602
2603 // Don't rebuild the nested-name-specifier if we don't have to.
2604 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2605 !getDerived().AlwaysRebuild())
2606 return NNS;
2607
2608 // If we can re-use the source-location data from the original
2609 // nested-name-specifier, do so.
2610 if (SS.location_size() == NNS.getDataLength() &&
2611 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2612 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2613
2614 // Allocate new nested-name-specifier location information.
2615 return SS.getWithLocInContext(SemaRef.Context);
2616}
2617
2618template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002619DeclarationNameInfo
2620TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002621::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002622 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002623 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002624 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002625
2626 switch (Name.getNameKind()) {
2627 case DeclarationName::Identifier:
2628 case DeclarationName::ObjCZeroArgSelector:
2629 case DeclarationName::ObjCOneArgSelector:
2630 case DeclarationName::ObjCMultiArgSelector:
2631 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002632 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002633 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002634 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002635
Douglas Gregorf816bd72009-09-03 22:13:48 +00002636 case DeclarationName::CXXConstructorName:
2637 case DeclarationName::CXXDestructorName:
2638 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002639 TypeSourceInfo *NewTInfo;
2640 CanQualType NewCanTy;
2641 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002642 NewTInfo = getDerived().TransformType(OldTInfo);
2643 if (!NewTInfo)
2644 return DeclarationNameInfo();
2645 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002646 }
2647 else {
2648 NewTInfo = 0;
2649 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002650 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002651 if (NewT.isNull())
2652 return DeclarationNameInfo();
2653 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2654 }
Mike Stump11289f42009-09-09 15:08:12 +00002655
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002656 DeclarationName NewName
2657 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2658 NewCanTy);
2659 DeclarationNameInfo NewNameInfo(NameInfo);
2660 NewNameInfo.setName(NewName);
2661 NewNameInfo.setNamedTypeInfo(NewTInfo);
2662 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002663 }
Mike Stump11289f42009-09-09 15:08:12 +00002664 }
2665
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002666 assert(0 && "Unknown name kind.");
2667 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002668}
2669
2670template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002671TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002672TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2673 TemplateName Name,
2674 SourceLocation NameLoc,
2675 QualType ObjectType,
2676 NamedDecl *FirstQualifierInScope) {
2677 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2678 TemplateDecl *Template = QTN->getTemplateDecl();
2679 assert(Template && "qualified template name must refer to a template");
2680
2681 TemplateDecl *TransTemplate
2682 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2683 Template));
2684 if (!TransTemplate)
2685 return TemplateName();
2686
2687 if (!getDerived().AlwaysRebuild() &&
2688 SS.getScopeRep() == QTN->getQualifier() &&
2689 TransTemplate == Template)
2690 return Name;
2691
2692 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2693 TransTemplate);
2694 }
2695
2696 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2697 if (SS.getScopeRep()) {
2698 // These apply to the scope specifier, not the template.
2699 ObjectType = QualType();
2700 FirstQualifierInScope = 0;
2701 }
2702
2703 if (!getDerived().AlwaysRebuild() &&
2704 SS.getScopeRep() == DTN->getQualifier() &&
2705 ObjectType.isNull())
2706 return Name;
2707
2708 if (DTN->isIdentifier()) {
2709 return getDerived().RebuildTemplateName(SS,
2710 *DTN->getIdentifier(),
2711 NameLoc,
2712 ObjectType,
2713 FirstQualifierInScope);
2714 }
2715
2716 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2717 ObjectType);
2718 }
2719
2720 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2721 TemplateDecl *TransTemplate
2722 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2723 Template));
2724 if (!TransTemplate)
2725 return TemplateName();
2726
2727 if (!getDerived().AlwaysRebuild() &&
2728 TransTemplate == Template)
2729 return Name;
2730
2731 return TemplateName(TransTemplate);
2732 }
2733
2734 if (SubstTemplateTemplateParmPackStorage *SubstPack
2735 = Name.getAsSubstTemplateTemplateParmPack()) {
2736 TemplateTemplateParmDecl *TransParam
2737 = cast_or_null<TemplateTemplateParmDecl>(
2738 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2739 if (!TransParam)
2740 return TemplateName();
2741
2742 if (!getDerived().AlwaysRebuild() &&
2743 TransParam == SubstPack->getParameterPack())
2744 return Name;
2745
2746 return getDerived().RebuildTemplateName(TransParam,
2747 SubstPack->getArgumentPack());
2748 }
2749
2750 // These should be getting filtered out before they reach the AST.
2751 llvm_unreachable("overloaded function decl survived to here");
2752 return TemplateName();
2753}
2754
2755template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002756void TreeTransform<Derived>::InventTemplateArgumentLoc(
2757 const TemplateArgument &Arg,
2758 TemplateArgumentLoc &Output) {
2759 SourceLocation Loc = getDerived().getBaseLocation();
2760 switch (Arg.getKind()) {
2761 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002762 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002763 break;
2764
2765 case TemplateArgument::Type:
2766 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002767 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002768
John McCall0ad16662009-10-29 08:12:44 +00002769 break;
2770
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002771 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002772 case TemplateArgument::TemplateExpansion: {
2773 NestedNameSpecifierLocBuilder Builder;
2774 TemplateName Template = Arg.getAsTemplate();
2775 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2776 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2777 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2778 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2779
2780 if (Arg.getKind() == TemplateArgument::Template)
2781 Output = TemplateArgumentLoc(Arg,
2782 Builder.getWithLocInContext(SemaRef.Context),
2783 Loc);
2784 else
2785 Output = TemplateArgumentLoc(Arg,
2786 Builder.getWithLocInContext(SemaRef.Context),
2787 Loc, Loc);
2788
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002789 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002790 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002791
John McCall0ad16662009-10-29 08:12:44 +00002792 case TemplateArgument::Expression:
2793 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2794 break;
2795
2796 case TemplateArgument::Declaration:
2797 case TemplateArgument::Integral:
2798 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002799 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002800 break;
2801 }
2802}
2803
2804template<typename Derived>
2805bool TreeTransform<Derived>::TransformTemplateArgument(
2806 const TemplateArgumentLoc &Input,
2807 TemplateArgumentLoc &Output) {
2808 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002809 switch (Arg.getKind()) {
2810 case TemplateArgument::Null:
2811 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002812 Output = Input;
2813 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002814
Douglas Gregore922c772009-08-04 22:27:00 +00002815 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002816 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002817 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002818 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002819
2820 DI = getDerived().TransformType(DI);
2821 if (!DI) return true;
2822
2823 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2824 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002825 }
Mike Stump11289f42009-09-09 15:08:12 +00002826
Douglas Gregore922c772009-08-04 22:27:00 +00002827 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002828 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002829 DeclarationName Name;
2830 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2831 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002832 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002833 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002834 if (!D) return true;
2835
John McCall0d07eb32009-10-29 18:45:58 +00002836 Expr *SourceExpr = Input.getSourceDeclExpression();
2837 if (SourceExpr) {
2838 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002839 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002840 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002841 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002842 }
2843
2844 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002845 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002846 }
Mike Stump11289f42009-09-09 15:08:12 +00002847
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002848 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002849 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2850 if (QualifierLoc) {
2851 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2852 if (!QualifierLoc)
2853 return true;
2854 }
2855
Douglas Gregordf846d12011-03-02 18:46:51 +00002856 CXXScopeSpec SS;
2857 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002858 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002859 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2860 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002861 if (Template.isNull())
2862 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002863
Douglas Gregor9d802122011-03-02 17:09:35 +00002864 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002865 Input.getTemplateNameLoc());
2866 return false;
2867 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002868
2869 case TemplateArgument::TemplateExpansion:
2870 llvm_unreachable("Caller should expand pack expansions");
2871
Douglas Gregore922c772009-08-04 22:27:00 +00002872 case TemplateArgument::Expression: {
2873 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002874 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002875 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002876
John McCall0ad16662009-10-29 08:12:44 +00002877 Expr *InputExpr = Input.getSourceExpression();
2878 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2879
Chris Lattnercdb591a2011-04-25 20:37:58 +00002880 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002881 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002882 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002883 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002884 }
Mike Stump11289f42009-09-09 15:08:12 +00002885
Douglas Gregore922c772009-08-04 22:27:00 +00002886 case TemplateArgument::Pack: {
2887 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2888 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002889 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002890 AEnd = Arg.pack_end();
2891 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002892
John McCall0ad16662009-10-29 08:12:44 +00002893 // FIXME: preserve source information here when we start
2894 // caring about parameter packs.
2895
John McCall0d07eb32009-10-29 18:45:58 +00002896 TemplateArgumentLoc InputArg;
2897 TemplateArgumentLoc OutputArg;
2898 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2899 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002900 return true;
2901
John McCall0d07eb32009-10-29 18:45:58 +00002902 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002903 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002904
2905 TemplateArgument *TransformedArgsPtr
2906 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2907 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2908 TransformedArgsPtr);
2909 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2910 TransformedArgs.size()),
2911 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002912 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002913 }
2914 }
Mike Stump11289f42009-09-09 15:08:12 +00002915
Douglas Gregore922c772009-08-04 22:27:00 +00002916 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002917 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002918}
2919
Douglas Gregorfe921a72010-12-20 23:36:19 +00002920/// \brief Iterator adaptor that invents template argument location information
2921/// for each of the template arguments in its underlying iterator.
2922template<typename Derived, typename InputIterator>
2923class TemplateArgumentLocInventIterator {
2924 TreeTransform<Derived> &Self;
2925 InputIterator Iter;
2926
2927public:
2928 typedef TemplateArgumentLoc value_type;
2929 typedef TemplateArgumentLoc reference;
2930 typedef typename std::iterator_traits<InputIterator>::difference_type
2931 difference_type;
2932 typedef std::input_iterator_tag iterator_category;
2933
2934 class pointer {
2935 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002936
Douglas Gregorfe921a72010-12-20 23:36:19 +00002937 public:
2938 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2939
2940 const TemplateArgumentLoc *operator->() const { return &Arg; }
2941 };
2942
2943 TemplateArgumentLocInventIterator() { }
2944
2945 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2946 InputIterator Iter)
2947 : Self(Self), Iter(Iter) { }
2948
2949 TemplateArgumentLocInventIterator &operator++() {
2950 ++Iter;
2951 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002952 }
2953
Douglas Gregorfe921a72010-12-20 23:36:19 +00002954 TemplateArgumentLocInventIterator operator++(int) {
2955 TemplateArgumentLocInventIterator Old(*this);
2956 ++(*this);
2957 return Old;
2958 }
2959
2960 reference operator*() const {
2961 TemplateArgumentLoc Result;
2962 Self.InventTemplateArgumentLoc(*Iter, Result);
2963 return Result;
2964 }
2965
2966 pointer operator->() const { return pointer(**this); }
2967
2968 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2969 const TemplateArgumentLocInventIterator &Y) {
2970 return X.Iter == Y.Iter;
2971 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002972
Douglas Gregorfe921a72010-12-20 23:36:19 +00002973 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2974 const TemplateArgumentLocInventIterator &Y) {
2975 return X.Iter != Y.Iter;
2976 }
2977};
2978
Douglas Gregor42cafa82010-12-20 17:42:22 +00002979template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002980template<typename InputIterator>
2981bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2982 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002983 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002984 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002985 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002986 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002987
2988 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2989 // Unpack argument packs, which we translate them into separate
2990 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002991 // FIXME: We could do much better if we could guarantee that the
2992 // TemplateArgumentLocInfo for the pack expansion would be usable for
2993 // all of the template arguments in the argument pack.
2994 typedef TemplateArgumentLocInventIterator<Derived,
2995 TemplateArgument::pack_iterator>
2996 PackLocIterator;
2997 if (TransformTemplateArguments(PackLocIterator(*this,
2998 In.getArgument().pack_begin()),
2999 PackLocIterator(*this,
3000 In.getArgument().pack_end()),
3001 Outputs))
3002 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003003
3004 continue;
3005 }
3006
3007 if (In.getArgument().isPackExpansion()) {
3008 // We have a pack expansion, for which we will be substituting into
3009 // the pattern.
3010 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003011 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003012 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003013 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3014 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003015
3016 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3017 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3018 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3019
3020 // Determine whether the set of unexpanded parameter packs can and should
3021 // be expanded.
3022 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003023 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003024 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003025 if (getDerived().TryExpandParameterPacks(Ellipsis,
3026 Pattern.getSourceRange(),
3027 Unexpanded.data(),
3028 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003029 Expand,
3030 RetainExpansion,
3031 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003032 return true;
3033
3034 if (!Expand) {
3035 // The transform has determined that we should perform a simple
3036 // transformation on the pack expansion, producing another pack
3037 // expansion.
3038 TemplateArgumentLoc OutPattern;
3039 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3040 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3041 return true;
3042
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003043 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3044 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003045 if (Out.getArgument().isNull())
3046 return true;
3047
3048 Outputs.addArgument(Out);
3049 continue;
3050 }
3051
3052 // The transform has determined that we should perform an elementwise
3053 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003054 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003055 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3056
3057 if (getDerived().TransformTemplateArgument(Pattern, Out))
3058 return true;
3059
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003060 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003061 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3062 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003063 if (Out.getArgument().isNull())
3064 return true;
3065 }
3066
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003067 Outputs.addArgument(Out);
3068 }
3069
Douglas Gregor48d24112011-01-10 20:53:55 +00003070 // If we're supposed to retain a pack expansion, do so by temporarily
3071 // forgetting the partially-substituted parameter pack.
3072 if (RetainExpansion) {
3073 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3074
3075 if (getDerived().TransformTemplateArgument(Pattern, Out))
3076 return true;
3077
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003078 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3079 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003080 if (Out.getArgument().isNull())
3081 return true;
3082
3083 Outputs.addArgument(Out);
3084 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003085
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003086 continue;
3087 }
3088
3089 // The simple case:
3090 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003091 return true;
3092
3093 Outputs.addArgument(Out);
3094 }
3095
3096 return false;
3097
3098}
3099
Douglas Gregord6ff3322009-08-04 16:50:30 +00003100//===----------------------------------------------------------------------===//
3101// Type transformation
3102//===----------------------------------------------------------------------===//
3103
3104template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003105QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003106 if (getDerived().AlreadyTransformed(T))
3107 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003108
John McCall550e0c22009-10-21 00:40:46 +00003109 // Temporary workaround. All of these transformations should
3110 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003111 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3112 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003113
John McCall31f82722010-11-12 08:19:04 +00003114 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003115
John McCall550e0c22009-10-21 00:40:46 +00003116 if (!NewDI)
3117 return QualType();
3118
3119 return NewDI->getType();
3120}
3121
3122template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003123TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003124 if (getDerived().AlreadyTransformed(DI->getType()))
3125 return DI;
3126
3127 TypeLocBuilder TLB;
3128
3129 TypeLoc TL = DI->getTypeLoc();
3130 TLB.reserve(TL.getFullDataSize());
3131
John McCall31f82722010-11-12 08:19:04 +00003132 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003133 if (Result.isNull())
3134 return 0;
3135
John McCallbcd03502009-12-07 02:54:59 +00003136 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003137}
3138
3139template<typename Derived>
3140QualType
John McCall31f82722010-11-12 08:19:04 +00003141TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003142 switch (T.getTypeLocClass()) {
3143#define ABSTRACT_TYPELOC(CLASS, PARENT)
3144#define TYPELOC(CLASS, PARENT) \
3145 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003146 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003147#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003148 }
Mike Stump11289f42009-09-09 15:08:12 +00003149
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003150 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003151 return QualType();
3152}
3153
3154/// FIXME: By default, this routine adds type qualifiers only to types
3155/// that can have qualifiers, and silently suppresses those qualifiers
3156/// that are not permitted (e.g., qualifiers on reference or function
3157/// types). This is the right thing for template instantiation, but
3158/// probably not for other clients.
3159template<typename Derived>
3160QualType
3161TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003162 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003163 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003164
John McCall31f82722010-11-12 08:19:04 +00003165 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003166 if (Result.isNull())
3167 return QualType();
3168
3169 // Silently suppress qualifiers if the result type can't be qualified.
3170 // FIXME: this is the right thing for template instantiation, but
3171 // probably not for other clients.
3172 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003173 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003174
John McCall31168b02011-06-15 23:02:42 +00003175 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
3176 // resulting type or if the resulting type already has one.
3177 if (Quals.hasObjCLifetime() &&
3178 (Result.getObjCLifetime() ||
3179 (!Result->isObjCLifetimeType() && !Result->isDependentType())))
3180 Quals.removeObjCLifetime();
3181
John McCallcb0f89a2010-06-05 06:41:15 +00003182 if (!Quals.empty()) {
3183 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3184 TLB.push<QualifiedTypeLoc>(Result);
3185 // No location information to preserve.
3186 }
John McCall550e0c22009-10-21 00:40:46 +00003187
3188 return Result;
3189}
3190
Douglas Gregor14454802011-02-25 02:25:35 +00003191template<typename Derived>
3192TypeLoc
3193TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3194 QualType ObjectType,
3195 NamedDecl *UnqualLookup,
3196 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003197 QualType T = TL.getType();
3198 if (getDerived().AlreadyTransformed(T))
3199 return TL;
3200
3201 TypeLocBuilder TLB;
3202 QualType Result;
3203
3204 if (isa<TemplateSpecializationType>(T)) {
3205 TemplateSpecializationTypeLoc SpecTL
3206 = cast<TemplateSpecializationTypeLoc>(TL);
3207
3208 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003209 getDerived().TransformTemplateName(SS,
3210 SpecTL.getTypePtr()->getTemplateName(),
3211 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003212 ObjectType, UnqualLookup);
3213 if (Template.isNull())
3214 return TypeLoc();
3215
3216 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3217 Template);
3218 } else if (isa<DependentTemplateSpecializationType>(T)) {
3219 DependentTemplateSpecializationTypeLoc SpecTL
3220 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3221
Douglas Gregor5a064722011-02-28 17:23:35 +00003222 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003223 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003224 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003225 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003226 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003227 if (Template.isNull())
3228 return TypeLoc();
3229
Douglas Gregor14454802011-02-25 02:25:35 +00003230 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003231 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003232 Template,
3233 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003234 } else {
3235 // Nothing special needs to be done for these.
3236 Result = getDerived().TransformType(TLB, TL);
3237 }
3238
3239 if (Result.isNull())
3240 return TypeLoc();
3241
3242 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3243}
3244
Douglas Gregor579c15f2011-03-02 18:32:08 +00003245template<typename Derived>
3246TypeSourceInfo *
3247TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3248 QualType ObjectType,
3249 NamedDecl *UnqualLookup,
3250 CXXScopeSpec &SS) {
3251 // FIXME: Painfully copy-paste from the above!
3252
3253 QualType T = TSInfo->getType();
3254 if (getDerived().AlreadyTransformed(T))
3255 return TSInfo;
3256
3257 TypeLocBuilder TLB;
3258 QualType Result;
3259
3260 TypeLoc TL = TSInfo->getTypeLoc();
3261 if (isa<TemplateSpecializationType>(T)) {
3262 TemplateSpecializationTypeLoc SpecTL
3263 = cast<TemplateSpecializationTypeLoc>(TL);
3264
3265 TemplateName Template
3266 = getDerived().TransformTemplateName(SS,
3267 SpecTL.getTypePtr()->getTemplateName(),
3268 SpecTL.getTemplateNameLoc(),
3269 ObjectType, UnqualLookup);
3270 if (Template.isNull())
3271 return 0;
3272
3273 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3274 Template);
3275 } else if (isa<DependentTemplateSpecializationType>(T)) {
3276 DependentTemplateSpecializationTypeLoc SpecTL
3277 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3278
3279 TemplateName Template
3280 = getDerived().RebuildTemplateName(SS,
3281 *SpecTL.getTypePtr()->getIdentifier(),
3282 SpecTL.getNameLoc(),
3283 ObjectType, UnqualLookup);
3284 if (Template.isNull())
3285 return 0;
3286
3287 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3288 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003289 Template,
3290 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003291 } else {
3292 // Nothing special needs to be done for these.
3293 Result = getDerived().TransformType(TLB, TL);
3294 }
3295
3296 if (Result.isNull())
3297 return 0;
3298
3299 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3300}
3301
John McCall550e0c22009-10-21 00:40:46 +00003302template <class TyLoc> static inline
3303QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3304 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3305 NewT.setNameLoc(T.getNameLoc());
3306 return T.getType();
3307}
3308
John McCall550e0c22009-10-21 00:40:46 +00003309template<typename Derived>
3310QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003311 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003312 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3313 NewT.setBuiltinLoc(T.getBuiltinLoc());
3314 if (T.needsExtraLocalData())
3315 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3316 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003317}
Mike Stump11289f42009-09-09 15:08:12 +00003318
Douglas Gregord6ff3322009-08-04 16:50:30 +00003319template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003320QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003321 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003322 // FIXME: recurse?
3323 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003324}
Mike Stump11289f42009-09-09 15:08:12 +00003325
Douglas Gregord6ff3322009-08-04 16:50:30 +00003326template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003327QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003328 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003329 QualType PointeeType
3330 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003331 if (PointeeType.isNull())
3332 return QualType();
3333
3334 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003335 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003336 // A dependent pointer type 'T *' has is being transformed such
3337 // that an Objective-C class type is being replaced for 'T'. The
3338 // resulting pointer type is an ObjCObjectPointerType, not a
3339 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003340 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003341
John McCall8b07ec22010-05-15 11:32:37 +00003342 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3343 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003344 return Result;
3345 }
John McCall31f82722010-11-12 08:19:04 +00003346
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003347 if (getDerived().AlwaysRebuild() ||
3348 PointeeType != TL.getPointeeLoc().getType()) {
3349 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3350 if (Result.isNull())
3351 return QualType();
3352 }
John McCall31168b02011-06-15 23:02:42 +00003353
3354 // Objective-C ARC can add lifetime qualifiers to the type that we're
3355 // pointing to.
3356 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3357
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003358 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3359 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003360 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003361}
Mike Stump11289f42009-09-09 15:08:12 +00003362
3363template<typename Derived>
3364QualType
John McCall550e0c22009-10-21 00:40:46 +00003365TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003366 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003367 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003368 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3369 if (PointeeType.isNull())
3370 return QualType();
3371
3372 QualType Result = TL.getType();
3373 if (getDerived().AlwaysRebuild() ||
3374 PointeeType != TL.getPointeeLoc().getType()) {
3375 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003376 TL.getSigilLoc());
3377 if (Result.isNull())
3378 return QualType();
3379 }
3380
Douglas Gregor049211a2010-04-22 16:50:51 +00003381 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003382 NewT.setSigilLoc(TL.getSigilLoc());
3383 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003384}
3385
John McCall70dd5f62009-10-30 00:06:24 +00003386/// Transforms a reference type. Note that somewhat paradoxically we
3387/// don't care whether the type itself is an l-value type or an r-value
3388/// type; we only care if the type was *written* as an l-value type
3389/// or an r-value type.
3390template<typename Derived>
3391QualType
3392TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003393 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003394 const ReferenceType *T = TL.getTypePtr();
3395
3396 // Note that this works with the pointee-as-written.
3397 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3398 if (PointeeType.isNull())
3399 return QualType();
3400
3401 QualType Result = TL.getType();
3402 if (getDerived().AlwaysRebuild() ||
3403 PointeeType != T->getPointeeTypeAsWritten()) {
3404 Result = getDerived().RebuildReferenceType(PointeeType,
3405 T->isSpelledAsLValue(),
3406 TL.getSigilLoc());
3407 if (Result.isNull())
3408 return QualType();
3409 }
3410
John McCall31168b02011-06-15 23:02:42 +00003411 // Objective-C ARC can add lifetime qualifiers to the type that we're
3412 // referring to.
3413 TLB.TypeWasModifiedSafely(
3414 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3415
John McCall70dd5f62009-10-30 00:06:24 +00003416 // r-value references can be rebuilt as l-value references.
3417 ReferenceTypeLoc NewTL;
3418 if (isa<LValueReferenceType>(Result))
3419 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3420 else
3421 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3422 NewTL.setSigilLoc(TL.getSigilLoc());
3423
3424 return Result;
3425}
3426
Mike Stump11289f42009-09-09 15:08:12 +00003427template<typename Derived>
3428QualType
John McCall550e0c22009-10-21 00:40:46 +00003429TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003430 LValueReferenceTypeLoc TL) {
3431 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003432}
3433
Mike Stump11289f42009-09-09 15:08:12 +00003434template<typename Derived>
3435QualType
John McCall550e0c22009-10-21 00:40:46 +00003436TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003437 RValueReferenceTypeLoc TL) {
3438 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003439}
Mike Stump11289f42009-09-09 15:08:12 +00003440
Douglas Gregord6ff3322009-08-04 16:50:30 +00003441template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003442QualType
John McCall550e0c22009-10-21 00:40:46 +00003443TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003444 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003445 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003446 if (PointeeType.isNull())
3447 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003448
Abramo Bagnara509357842011-03-05 14:42:21 +00003449 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3450 TypeSourceInfo* NewClsTInfo = 0;
3451 if (OldClsTInfo) {
3452 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3453 if (!NewClsTInfo)
3454 return QualType();
3455 }
3456
3457 const MemberPointerType *T = TL.getTypePtr();
3458 QualType OldClsType = QualType(T->getClass(), 0);
3459 QualType NewClsType;
3460 if (NewClsTInfo)
3461 NewClsType = NewClsTInfo->getType();
3462 else {
3463 NewClsType = getDerived().TransformType(OldClsType);
3464 if (NewClsType.isNull())
3465 return QualType();
3466 }
Mike Stump11289f42009-09-09 15:08:12 +00003467
John McCall550e0c22009-10-21 00:40:46 +00003468 QualType Result = TL.getType();
3469 if (getDerived().AlwaysRebuild() ||
3470 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003471 NewClsType != OldClsType) {
3472 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003473 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003474 if (Result.isNull())
3475 return QualType();
3476 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003477
John McCall550e0c22009-10-21 00:40:46 +00003478 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3479 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003480 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003481
3482 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003483}
3484
Mike Stump11289f42009-09-09 15:08:12 +00003485template<typename Derived>
3486QualType
John McCall550e0c22009-10-21 00:40:46 +00003487TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003488 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003489 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003490 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003491 if (ElementType.isNull())
3492 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003493
John McCall550e0c22009-10-21 00:40:46 +00003494 QualType Result = TL.getType();
3495 if (getDerived().AlwaysRebuild() ||
3496 ElementType != T->getElementType()) {
3497 Result = getDerived().RebuildConstantArrayType(ElementType,
3498 T->getSizeModifier(),
3499 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003500 T->getIndexTypeCVRQualifiers(),
3501 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003502 if (Result.isNull())
3503 return QualType();
3504 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003505
John McCall550e0c22009-10-21 00:40:46 +00003506 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3507 NewTL.setLBracketLoc(TL.getLBracketLoc());
3508 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003509
John McCall550e0c22009-10-21 00:40:46 +00003510 Expr *Size = TL.getSizeExpr();
3511 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003512 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003513 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3514 }
3515 NewTL.setSizeExpr(Size);
3516
3517 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003518}
Mike Stump11289f42009-09-09 15:08:12 +00003519
Douglas Gregord6ff3322009-08-04 16:50:30 +00003520template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003521QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003522 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003523 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003524 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003525 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003526 if (ElementType.isNull())
3527 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003528
John McCall550e0c22009-10-21 00:40:46 +00003529 QualType Result = TL.getType();
3530 if (getDerived().AlwaysRebuild() ||
3531 ElementType != T->getElementType()) {
3532 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003533 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003534 T->getIndexTypeCVRQualifiers(),
3535 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003536 if (Result.isNull())
3537 return QualType();
3538 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003539
John McCall550e0c22009-10-21 00:40:46 +00003540 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3541 NewTL.setLBracketLoc(TL.getLBracketLoc());
3542 NewTL.setRBracketLoc(TL.getRBracketLoc());
3543 NewTL.setSizeExpr(0);
3544
3545 return Result;
3546}
3547
3548template<typename Derived>
3549QualType
3550TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003551 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003552 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003553 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3554 if (ElementType.isNull())
3555 return QualType();
3556
3557 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003558 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003559
John McCalldadc5752010-08-24 06:29:42 +00003560 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003561 = getDerived().TransformExpr(T->getSizeExpr());
3562 if (SizeResult.isInvalid())
3563 return QualType();
3564
John McCallb268a282010-08-23 23:25:46 +00003565 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003566
3567 QualType Result = TL.getType();
3568 if (getDerived().AlwaysRebuild() ||
3569 ElementType != T->getElementType() ||
3570 Size != T->getSizeExpr()) {
3571 Result = getDerived().RebuildVariableArrayType(ElementType,
3572 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003573 Size,
John McCall550e0c22009-10-21 00:40:46 +00003574 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003575 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003576 if (Result.isNull())
3577 return QualType();
3578 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003579
John McCall550e0c22009-10-21 00:40:46 +00003580 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3581 NewTL.setLBracketLoc(TL.getLBracketLoc());
3582 NewTL.setRBracketLoc(TL.getRBracketLoc());
3583 NewTL.setSizeExpr(Size);
3584
3585 return Result;
3586}
3587
3588template<typename Derived>
3589QualType
3590TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003591 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003592 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003593 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3594 if (ElementType.isNull())
3595 return QualType();
3596
3597 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003598 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003599
John McCall33ddac02011-01-19 10:06:00 +00003600 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3601 Expr *origSize = TL.getSizeExpr();
3602 if (!origSize) origSize = T->getSizeExpr();
3603
3604 ExprResult sizeResult
3605 = getDerived().TransformExpr(origSize);
3606 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003607 return QualType();
3608
John McCall33ddac02011-01-19 10:06:00 +00003609 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003610
3611 QualType Result = TL.getType();
3612 if (getDerived().AlwaysRebuild() ||
3613 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003614 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003615 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3616 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003617 size,
John McCall550e0c22009-10-21 00:40:46 +00003618 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003619 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003620 if (Result.isNull())
3621 return QualType();
3622 }
John McCall550e0c22009-10-21 00:40:46 +00003623
3624 // We might have any sort of array type now, but fortunately they
3625 // all have the same location layout.
3626 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3627 NewTL.setLBracketLoc(TL.getLBracketLoc());
3628 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003629 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003630
3631 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003632}
Mike Stump11289f42009-09-09 15:08:12 +00003633
3634template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003635QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003636 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003637 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003638 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003639
3640 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003641 QualType ElementType = getDerived().TransformType(T->getElementType());
3642 if (ElementType.isNull())
3643 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003644
Douglas Gregore922c772009-08-04 22:27:00 +00003645 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003646 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003647
John McCalldadc5752010-08-24 06:29:42 +00003648 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003649 if (Size.isInvalid())
3650 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003651
John McCall550e0c22009-10-21 00:40:46 +00003652 QualType Result = TL.getType();
3653 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003654 ElementType != T->getElementType() ||
3655 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003656 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003657 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003658 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003659 if (Result.isNull())
3660 return QualType();
3661 }
John McCall550e0c22009-10-21 00:40:46 +00003662
3663 // Result might be dependent or not.
3664 if (isa<DependentSizedExtVectorType>(Result)) {
3665 DependentSizedExtVectorTypeLoc NewTL
3666 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3667 NewTL.setNameLoc(TL.getNameLoc());
3668 } else {
3669 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3670 NewTL.setNameLoc(TL.getNameLoc());
3671 }
3672
3673 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003674}
Mike Stump11289f42009-09-09 15:08:12 +00003675
3676template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003677QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003678 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003679 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003680 QualType ElementType = getDerived().TransformType(T->getElementType());
3681 if (ElementType.isNull())
3682 return QualType();
3683
John McCall550e0c22009-10-21 00:40:46 +00003684 QualType Result = TL.getType();
3685 if (getDerived().AlwaysRebuild() ||
3686 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003687 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003688 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003689 if (Result.isNull())
3690 return QualType();
3691 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003692
John McCall550e0c22009-10-21 00:40:46 +00003693 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3694 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003695
John McCall550e0c22009-10-21 00:40:46 +00003696 return Result;
3697}
3698
3699template<typename Derived>
3700QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003701 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003702 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003703 QualType ElementType = getDerived().TransformType(T->getElementType());
3704 if (ElementType.isNull())
3705 return QualType();
3706
3707 QualType Result = TL.getType();
3708 if (getDerived().AlwaysRebuild() ||
3709 ElementType != T->getElementType()) {
3710 Result = getDerived().RebuildExtVectorType(ElementType,
3711 T->getNumElements(),
3712 /*FIXME*/ SourceLocation());
3713 if (Result.isNull())
3714 return QualType();
3715 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003716
John McCall550e0c22009-10-21 00:40:46 +00003717 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3718 NewTL.setNameLoc(TL.getNameLoc());
3719
3720 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003721}
Mike Stump11289f42009-09-09 15:08:12 +00003722
3723template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003724ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003725TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003726 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003727 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003728 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003729 TypeSourceInfo *NewDI = 0;
3730
3731 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3732 // If we're substituting into a pack expansion type and we know the
3733 TypeLoc OldTL = OldDI->getTypeLoc();
3734 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3735
3736 TypeLocBuilder TLB;
3737 TypeLoc NewTL = OldDI->getTypeLoc();
3738 TLB.reserve(NewTL.getFullDataSize());
3739
3740 QualType Result = getDerived().TransformType(TLB,
3741 OldExpansionTL.getPatternLoc());
3742 if (Result.isNull())
3743 return 0;
3744
3745 Result = RebuildPackExpansionType(Result,
3746 OldExpansionTL.getPatternLoc().getSourceRange(),
3747 OldExpansionTL.getEllipsisLoc(),
3748 NumExpansions);
3749 if (Result.isNull())
3750 return 0;
3751
3752 PackExpansionTypeLoc NewExpansionTL
3753 = TLB.push<PackExpansionTypeLoc>(Result);
3754 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3755 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3756 } else
3757 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003758 if (!NewDI)
3759 return 0;
3760
John McCall8fb0d9d2011-05-01 22:35:37 +00003761 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003762 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003763
3764 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3765 OldParm->getDeclContext(),
3766 OldParm->getInnerLocStart(),
3767 OldParm->getLocation(),
3768 OldParm->getIdentifier(),
3769 NewDI->getType(),
3770 NewDI,
3771 OldParm->getStorageClass(),
3772 OldParm->getStorageClassAsWritten(),
3773 /* DefArg */ NULL);
3774 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3775 OldParm->getFunctionScopeIndex() + indexAdjustment);
3776 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003777}
3778
3779template<typename Derived>
3780bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003781 TransformFunctionTypeParams(SourceLocation Loc,
3782 ParmVarDecl **Params, unsigned NumParams,
3783 const QualType *ParamTypes,
3784 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3785 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003786 int indexAdjustment = 0;
3787
Douglas Gregordd472162011-01-07 00:20:55 +00003788 for (unsigned i = 0; i != NumParams; ++i) {
3789 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003790 assert(OldParm->getFunctionScopeIndex() == i);
3791
Douglas Gregor715e4612011-01-14 22:40:04 +00003792 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003793 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003794 if (OldParm->isParameterPack()) {
3795 // We have a function parameter pack that may need to be expanded.
3796 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003797
Douglas Gregor5499af42011-01-05 23:12:31 +00003798 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003799 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3800 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3801 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3802 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003803 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3804
Douglas Gregor5499af42011-01-05 23:12:31 +00003805 // Determine whether we should expand the parameter packs.
3806 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003807 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003808 llvm::Optional<unsigned> OrigNumExpansions
3809 = ExpansionTL.getTypePtr()->getNumExpansions();
3810 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003811 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3812 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003813 Unexpanded.data(),
3814 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003815 ShouldExpand,
3816 RetainExpansion,
3817 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003818 return true;
3819 }
3820
3821 if (ShouldExpand) {
3822 // Expand the function parameter pack into multiple, separate
3823 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003824 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003825 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003826 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3827 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003828 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003829 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003830 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003831 if (!NewParm)
3832 return true;
3833
Douglas Gregordd472162011-01-07 00:20:55 +00003834 OutParamTypes.push_back(NewParm->getType());
3835 if (PVars)
3836 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003837 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003838
3839 // If we're supposed to retain a pack expansion, do so by temporarily
3840 // forgetting the partially-substituted parameter pack.
3841 if (RetainExpansion) {
3842 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3843 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003844 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003845 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003846 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003847 if (!NewParm)
3848 return true;
3849
3850 OutParamTypes.push_back(NewParm->getType());
3851 if (PVars)
3852 PVars->push_back(NewParm);
3853 }
3854
John McCall8fb0d9d2011-05-01 22:35:37 +00003855 // The next parameter should have the same adjustment as the
3856 // last thing we pushed, but we post-incremented indexAdjustment
3857 // on every push. Also, if we push nothing, the adjustment should
3858 // go down by one.
3859 indexAdjustment--;
3860
Douglas Gregor5499af42011-01-05 23:12:31 +00003861 // We're done with the pack expansion.
3862 continue;
3863 }
3864
3865 // We'll substitute the parameter now without expanding the pack
3866 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003867 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3868 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003869 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003870 NumExpansions);
3871 } else {
3872 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003873 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003874 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003875 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003876
John McCall58f10c32010-03-11 09:03:00 +00003877 if (!NewParm)
3878 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003879
Douglas Gregordd472162011-01-07 00:20:55 +00003880 OutParamTypes.push_back(NewParm->getType());
3881 if (PVars)
3882 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003883 continue;
3884 }
John McCall58f10c32010-03-11 09:03:00 +00003885
3886 // Deal with the possibility that we don't have a parameter
3887 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003888 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003889 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003890 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003891 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003892 if (const PackExpansionType *Expansion
3893 = dyn_cast<PackExpansionType>(OldType)) {
3894 // We have a function parameter pack that may need to be expanded.
3895 QualType Pattern = Expansion->getPattern();
3896 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3897 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3898
3899 // Determine whether we should expand the parameter packs.
3900 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003901 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003902 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003903 Unexpanded.data(),
3904 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003905 ShouldExpand,
3906 RetainExpansion,
3907 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003908 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003909 }
3910
3911 if (ShouldExpand) {
3912 // Expand the function parameter pack into multiple, separate
3913 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003914 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003915 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3916 QualType NewType = getDerived().TransformType(Pattern);
3917 if (NewType.isNull())
3918 return true;
John McCall58f10c32010-03-11 09:03:00 +00003919
Douglas Gregordd472162011-01-07 00:20:55 +00003920 OutParamTypes.push_back(NewType);
3921 if (PVars)
3922 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003923 }
3924
3925 // We're done with the pack expansion.
3926 continue;
3927 }
3928
Douglas Gregor48d24112011-01-10 20:53:55 +00003929 // If we're supposed to retain a pack expansion, do so by temporarily
3930 // forgetting the partially-substituted parameter pack.
3931 if (RetainExpansion) {
3932 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3933 QualType NewType = getDerived().TransformType(Pattern);
3934 if (NewType.isNull())
3935 return true;
3936
3937 OutParamTypes.push_back(NewType);
3938 if (PVars)
3939 PVars->push_back(0);
3940 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003941
Douglas Gregor5499af42011-01-05 23:12:31 +00003942 // We'll substitute the parameter now without expanding the pack
3943 // expansion.
3944 OldType = Expansion->getPattern();
3945 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003946 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3947 NewType = getDerived().TransformType(OldType);
3948 } else {
3949 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003950 }
3951
Douglas Gregor5499af42011-01-05 23:12:31 +00003952 if (NewType.isNull())
3953 return true;
3954
3955 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003956 NewType = getSema().Context.getPackExpansionType(NewType,
3957 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003958
Douglas Gregordd472162011-01-07 00:20:55 +00003959 OutParamTypes.push_back(NewType);
3960 if (PVars)
3961 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003962 }
3963
John McCall8fb0d9d2011-05-01 22:35:37 +00003964#ifndef NDEBUG
3965 if (PVars) {
3966 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3967 if (ParmVarDecl *parm = (*PVars)[i])
3968 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00003969 }
John McCall8fb0d9d2011-05-01 22:35:37 +00003970#endif
3971
3972 return false;
3973}
John McCall58f10c32010-03-11 09:03:00 +00003974
3975template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003976QualType
John McCall550e0c22009-10-21 00:40:46 +00003977TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003978 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003979 // Transform the parameters and return type.
3980 //
3981 // We instantiate in source order, with the return type first followed by
3982 // the parameters, because users tend to expect this (even if they shouldn't
3983 // rely on it!).
3984 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003985 // When the function has a trailing return type, we instantiate the
3986 // parameters before the return type, since the return type can then refer
3987 // to the parameters themselves (via decltype, sizeof, etc.).
3988 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003989 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003990 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003991 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003992
Douglas Gregor7fb25412010-10-01 18:44:50 +00003993 QualType ResultType;
3994
3995 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003996 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3997 TL.getParmArray(),
3998 TL.getNumArgs(),
3999 TL.getTypePtr()->arg_type_begin(),
4000 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004001 return QualType();
4002
4003 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4004 if (ResultType.isNull())
4005 return QualType();
4006 }
4007 else {
4008 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4009 if (ResultType.isNull())
4010 return QualType();
4011
Douglas Gregordd472162011-01-07 00:20:55 +00004012 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4013 TL.getParmArray(),
4014 TL.getNumArgs(),
4015 TL.getTypePtr()->arg_type_begin(),
4016 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004017 return QualType();
4018 }
4019
John McCall550e0c22009-10-21 00:40:46 +00004020 QualType Result = TL.getType();
4021 if (getDerived().AlwaysRebuild() ||
4022 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004023 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004024 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4025 Result = getDerived().RebuildFunctionProtoType(ResultType,
4026 ParamTypes.data(),
4027 ParamTypes.size(),
4028 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004029 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004030 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004031 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004032 if (Result.isNull())
4033 return QualType();
4034 }
Mike Stump11289f42009-09-09 15:08:12 +00004035
John McCall550e0c22009-10-21 00:40:46 +00004036 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004037 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4038 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004039 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004040 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4041 NewTL.setArg(i, ParamDecls[i]);
4042
4043 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004044}
Mike Stump11289f42009-09-09 15:08:12 +00004045
Douglas Gregord6ff3322009-08-04 16:50:30 +00004046template<typename Derived>
4047QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004048 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004049 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004050 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004051 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4052 if (ResultType.isNull())
4053 return QualType();
4054
4055 QualType Result = TL.getType();
4056 if (getDerived().AlwaysRebuild() ||
4057 ResultType != T->getResultType())
4058 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4059
4060 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004061 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4062 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004063 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004064
4065 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004066}
Mike Stump11289f42009-09-09 15:08:12 +00004067
John McCallb96ec562009-12-04 22:46:56 +00004068template<typename Derived> QualType
4069TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004070 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004071 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004072 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004073 if (!D)
4074 return QualType();
4075
4076 QualType Result = TL.getType();
4077 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4078 Result = getDerived().RebuildUnresolvedUsingType(D);
4079 if (Result.isNull())
4080 return QualType();
4081 }
4082
4083 // We might get an arbitrary type spec type back. We should at
4084 // least always get a type spec type, though.
4085 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4086 NewTL.setNameLoc(TL.getNameLoc());
4087
4088 return Result;
4089}
4090
Douglas Gregord6ff3322009-08-04 16:50:30 +00004091template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004092QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004093 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004094 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004095 TypedefNameDecl *Typedef
4096 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4097 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004098 if (!Typedef)
4099 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004100
John McCall550e0c22009-10-21 00:40:46 +00004101 QualType Result = TL.getType();
4102 if (getDerived().AlwaysRebuild() ||
4103 Typedef != T->getDecl()) {
4104 Result = getDerived().RebuildTypedefType(Typedef);
4105 if (Result.isNull())
4106 return QualType();
4107 }
Mike Stump11289f42009-09-09 15:08:12 +00004108
John McCall550e0c22009-10-21 00:40:46 +00004109 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4110 NewTL.setNameLoc(TL.getNameLoc());
4111
4112 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004113}
Mike Stump11289f42009-09-09 15:08:12 +00004114
Douglas Gregord6ff3322009-08-04 16:50:30 +00004115template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004116QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004117 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004118 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004119 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004120
John McCalldadc5752010-08-24 06:29:42 +00004121 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004122 if (E.isInvalid())
4123 return QualType();
4124
John McCall550e0c22009-10-21 00:40:46 +00004125 QualType Result = TL.getType();
4126 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004127 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004128 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004129 if (Result.isNull())
4130 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004131 }
John McCall550e0c22009-10-21 00:40:46 +00004132 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004133
John McCall550e0c22009-10-21 00:40:46 +00004134 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004135 NewTL.setTypeofLoc(TL.getTypeofLoc());
4136 NewTL.setLParenLoc(TL.getLParenLoc());
4137 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004138
4139 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004140}
Mike Stump11289f42009-09-09 15:08:12 +00004141
4142template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004143QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004144 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004145 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4146 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4147 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004148 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004149
John McCall550e0c22009-10-21 00:40:46 +00004150 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004151 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4152 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004153 if (Result.isNull())
4154 return QualType();
4155 }
Mike Stump11289f42009-09-09 15:08:12 +00004156
John McCall550e0c22009-10-21 00:40:46 +00004157 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004158 NewTL.setTypeofLoc(TL.getTypeofLoc());
4159 NewTL.setLParenLoc(TL.getLParenLoc());
4160 NewTL.setRParenLoc(TL.getRParenLoc());
4161 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004162
4163 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004164}
Mike Stump11289f42009-09-09 15:08:12 +00004165
4166template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004167QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004168 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004169 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004170
Douglas Gregore922c772009-08-04 22:27:00 +00004171 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004172 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004173
John McCalldadc5752010-08-24 06:29:42 +00004174 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004175 if (E.isInvalid())
4176 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004177
John McCall550e0c22009-10-21 00:40:46 +00004178 QualType Result = TL.getType();
4179 if (getDerived().AlwaysRebuild() ||
4180 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004181 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004182 if (Result.isNull())
4183 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004184 }
John McCall550e0c22009-10-21 00:40:46 +00004185 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004186
John McCall550e0c22009-10-21 00:40:46 +00004187 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4188 NewTL.setNameLoc(TL.getNameLoc());
4189
4190 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004191}
4192
4193template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004194QualType TreeTransform<Derived>::TransformUnaryTransformType(
4195 TypeLocBuilder &TLB,
4196 UnaryTransformTypeLoc TL) {
4197 QualType Result = TL.getType();
4198 if (Result->isDependentType()) {
4199 const UnaryTransformType *T = TL.getTypePtr();
4200 QualType NewBase =
4201 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4202 Result = getDerived().RebuildUnaryTransformType(NewBase,
4203 T->getUTTKind(),
4204 TL.getKWLoc());
4205 if (Result.isNull())
4206 return QualType();
4207 }
4208
4209 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4210 NewTL.setKWLoc(TL.getKWLoc());
4211 NewTL.setParensRange(TL.getParensRange());
4212 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4213 return Result;
4214}
4215
4216template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004217QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4218 AutoTypeLoc TL) {
4219 const AutoType *T = TL.getTypePtr();
4220 QualType OldDeduced = T->getDeducedType();
4221 QualType NewDeduced;
4222 if (!OldDeduced.isNull()) {
4223 NewDeduced = getDerived().TransformType(OldDeduced);
4224 if (NewDeduced.isNull())
4225 return QualType();
4226 }
4227
4228 QualType Result = TL.getType();
4229 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4230 Result = getDerived().RebuildAutoType(NewDeduced);
4231 if (Result.isNull())
4232 return QualType();
4233 }
4234
4235 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4236 NewTL.setNameLoc(TL.getNameLoc());
4237
4238 return Result;
4239}
4240
4241template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004242QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004243 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004244 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004245 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004246 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4247 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004248 if (!Record)
4249 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004250
John McCall550e0c22009-10-21 00:40:46 +00004251 QualType Result = TL.getType();
4252 if (getDerived().AlwaysRebuild() ||
4253 Record != T->getDecl()) {
4254 Result = getDerived().RebuildRecordType(Record);
4255 if (Result.isNull())
4256 return QualType();
4257 }
Mike Stump11289f42009-09-09 15:08:12 +00004258
John McCall550e0c22009-10-21 00:40:46 +00004259 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4260 NewTL.setNameLoc(TL.getNameLoc());
4261
4262 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004263}
Mike Stump11289f42009-09-09 15:08:12 +00004264
4265template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004266QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004267 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004268 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004269 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004270 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4271 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004272 if (!Enum)
4273 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004274
John McCall550e0c22009-10-21 00:40:46 +00004275 QualType Result = TL.getType();
4276 if (getDerived().AlwaysRebuild() ||
4277 Enum != T->getDecl()) {
4278 Result = getDerived().RebuildEnumType(Enum);
4279 if (Result.isNull())
4280 return QualType();
4281 }
Mike Stump11289f42009-09-09 15:08:12 +00004282
John McCall550e0c22009-10-21 00:40:46 +00004283 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4284 NewTL.setNameLoc(TL.getNameLoc());
4285
4286 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004287}
John McCallfcc33b02009-09-05 00:15:47 +00004288
John McCalle78aac42010-03-10 03:28:59 +00004289template<typename Derived>
4290QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4291 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004292 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004293 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4294 TL.getTypePtr()->getDecl());
4295 if (!D) return QualType();
4296
4297 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4298 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4299 return T;
4300}
4301
Douglas Gregord6ff3322009-08-04 16:50:30 +00004302template<typename Derived>
4303QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004304 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004305 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004306 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004307}
4308
Mike Stump11289f42009-09-09 15:08:12 +00004309template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004310QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004311 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004312 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004313 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4314
4315 // Substitute into the replacement type, which itself might involve something
4316 // that needs to be transformed. This only tends to occur with default
4317 // template arguments of template template parameters.
4318 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4319 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4320 if (Replacement.isNull())
4321 return QualType();
4322
4323 // Always canonicalize the replacement type.
4324 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4325 QualType Result
4326 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4327 Replacement);
4328
4329 // Propagate type-source information.
4330 SubstTemplateTypeParmTypeLoc NewTL
4331 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4332 NewTL.setNameLoc(TL.getNameLoc());
4333 return Result;
4334
John McCallcebee162009-10-18 09:09:24 +00004335}
4336
4337template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004338QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4339 TypeLocBuilder &TLB,
4340 SubstTemplateTypeParmPackTypeLoc TL) {
4341 return TransformTypeSpecType(TLB, TL);
4342}
4343
4344template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004345QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004346 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004347 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004348 const TemplateSpecializationType *T = TL.getTypePtr();
4349
Douglas Gregordf846d12011-03-02 18:46:51 +00004350 // The nested-name-specifier never matters in a TemplateSpecializationType,
4351 // because we can't have a dependent nested-name-specifier anyway.
4352 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004353 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004354 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4355 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004356 if (Template.isNull())
4357 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004358
John McCall31f82722010-11-12 08:19:04 +00004359 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4360}
4361
Douglas Gregorfe921a72010-12-20 23:36:19 +00004362namespace {
4363 /// \brief Simple iterator that traverses the template arguments in a
4364 /// container that provides a \c getArgLoc() member function.
4365 ///
4366 /// This iterator is intended to be used with the iterator form of
4367 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4368 template<typename ArgLocContainer>
4369 class TemplateArgumentLocContainerIterator {
4370 ArgLocContainer *Container;
4371 unsigned Index;
4372
4373 public:
4374 typedef TemplateArgumentLoc value_type;
4375 typedef TemplateArgumentLoc reference;
4376 typedef int difference_type;
4377 typedef std::input_iterator_tag iterator_category;
4378
4379 class pointer {
4380 TemplateArgumentLoc Arg;
4381
4382 public:
4383 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4384
4385 const TemplateArgumentLoc *operator->() const {
4386 return &Arg;
4387 }
4388 };
4389
4390
4391 TemplateArgumentLocContainerIterator() {}
4392
4393 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4394 unsigned Index)
4395 : Container(&Container), Index(Index) { }
4396
4397 TemplateArgumentLocContainerIterator &operator++() {
4398 ++Index;
4399 return *this;
4400 }
4401
4402 TemplateArgumentLocContainerIterator operator++(int) {
4403 TemplateArgumentLocContainerIterator Old(*this);
4404 ++(*this);
4405 return Old;
4406 }
4407
4408 TemplateArgumentLoc operator*() const {
4409 return Container->getArgLoc(Index);
4410 }
4411
4412 pointer operator->() const {
4413 return pointer(Container->getArgLoc(Index));
4414 }
4415
4416 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004417 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004418 return X.Container == Y.Container && X.Index == Y.Index;
4419 }
4420
4421 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004422 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004423 return !(X == Y);
4424 }
4425 };
4426}
4427
4428
John McCall31f82722010-11-12 08:19:04 +00004429template <typename Derived>
4430QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4431 TypeLocBuilder &TLB,
4432 TemplateSpecializationTypeLoc TL,
4433 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004434 TemplateArgumentListInfo NewTemplateArgs;
4435 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4436 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004437 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4438 ArgIterator;
4439 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4440 ArgIterator(TL, TL.getNumArgs()),
4441 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004442 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004443
John McCall0ad16662009-10-29 08:12:44 +00004444 // FIXME: maybe don't rebuild if all the template arguments are the same.
4445
4446 QualType Result =
4447 getDerived().RebuildTemplateSpecializationType(Template,
4448 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004449 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004450
4451 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004452 // Specializations of template template parameters are represented as
4453 // TemplateSpecializationTypes, and substitution of type alias templates
4454 // within a dependent context can transform them into
4455 // DependentTemplateSpecializationTypes.
4456 if (isa<DependentTemplateSpecializationType>(Result)) {
4457 DependentTemplateSpecializationTypeLoc NewTL
4458 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4459 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4460 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4461 NewTL.setNameLoc(TL.getTemplateNameLoc());
4462 NewTL.setLAngleLoc(TL.getLAngleLoc());
4463 NewTL.setRAngleLoc(TL.getRAngleLoc());
4464 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4465 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4466 return Result;
4467 }
4468
John McCall0ad16662009-10-29 08:12:44 +00004469 TemplateSpecializationTypeLoc NewTL
4470 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4471 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4472 NewTL.setLAngleLoc(TL.getLAngleLoc());
4473 NewTL.setRAngleLoc(TL.getRAngleLoc());
4474 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4475 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004476 }
Mike Stump11289f42009-09-09 15:08:12 +00004477
John McCall0ad16662009-10-29 08:12:44 +00004478 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004479}
Mike Stump11289f42009-09-09 15:08:12 +00004480
Douglas Gregor5a064722011-02-28 17:23:35 +00004481template <typename Derived>
4482QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4483 TypeLocBuilder &TLB,
4484 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004485 TemplateName Template,
4486 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004487 TemplateArgumentListInfo NewTemplateArgs;
4488 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4489 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4490 typedef TemplateArgumentLocContainerIterator<
4491 DependentTemplateSpecializationTypeLoc> ArgIterator;
4492 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4493 ArgIterator(TL, TL.getNumArgs()),
4494 NewTemplateArgs))
4495 return QualType();
4496
4497 // FIXME: maybe don't rebuild if all the template arguments are the same.
4498
4499 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4500 QualType Result
4501 = getSema().Context.getDependentTemplateSpecializationType(
4502 TL.getTypePtr()->getKeyword(),
4503 DTN->getQualifier(),
4504 DTN->getIdentifier(),
4505 NewTemplateArgs);
4506
4507 DependentTemplateSpecializationTypeLoc NewTL
4508 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4509 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004510
Douglas Gregora7a795b2011-03-01 20:11:18 +00004511 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004512 NewTL.setNameLoc(TL.getNameLoc());
4513 NewTL.setLAngleLoc(TL.getLAngleLoc());
4514 NewTL.setRAngleLoc(TL.getRAngleLoc());
4515 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4516 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4517 return Result;
4518 }
4519
4520 QualType Result
4521 = getDerived().RebuildTemplateSpecializationType(Template,
4522 TL.getNameLoc(),
4523 NewTemplateArgs);
4524
4525 if (!Result.isNull()) {
4526 /// FIXME: Wrap this in an elaborated-type-specifier?
4527 TemplateSpecializationTypeLoc NewTL
4528 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4529 NewTL.setTemplateNameLoc(TL.getNameLoc());
4530 NewTL.setLAngleLoc(TL.getLAngleLoc());
4531 NewTL.setRAngleLoc(TL.getRAngleLoc());
4532 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4533 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4534 }
4535
4536 return Result;
4537}
4538
Mike Stump11289f42009-09-09 15:08:12 +00004539template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004540QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004541TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004542 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004543 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004544
Douglas Gregor844cb502011-03-01 18:12:44 +00004545 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004546 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004547 if (TL.getQualifierLoc()) {
4548 QualifierLoc
4549 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4550 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004551 return QualType();
4552 }
Mike Stump11289f42009-09-09 15:08:12 +00004553
John McCall31f82722010-11-12 08:19:04 +00004554 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4555 if (NamedT.isNull())
4556 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004557
Richard Smith3f1b5d02011-05-05 21:57:07 +00004558 // C++0x [dcl.type.elab]p2:
4559 // If the identifier resolves to a typedef-name or the simple-template-id
4560 // resolves to an alias template specialization, the
4561 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004562 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4563 if (const TemplateSpecializationType *TST =
4564 NamedT->getAs<TemplateSpecializationType>()) {
4565 TemplateName Template = TST->getTemplateName();
4566 if (TypeAliasTemplateDecl *TAT =
4567 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4568 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4569 diag::err_tag_reference_non_tag) << 4;
4570 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4571 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004572 }
4573 }
4574
John McCall550e0c22009-10-21 00:40:46 +00004575 QualType Result = TL.getType();
4576 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004577 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004578 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004579 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004580 T->getKeyword(),
4581 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004582 if (Result.isNull())
4583 return QualType();
4584 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004585
Abramo Bagnara6150c882010-05-11 21:36:43 +00004586 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004587 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004588 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004589 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004590}
Mike Stump11289f42009-09-09 15:08:12 +00004591
4592template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004593QualType TreeTransform<Derived>::TransformAttributedType(
4594 TypeLocBuilder &TLB,
4595 AttributedTypeLoc TL) {
4596 const AttributedType *oldType = TL.getTypePtr();
4597 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4598 if (modifiedType.isNull())
4599 return QualType();
4600
4601 QualType result = TL.getType();
4602
4603 // FIXME: dependent operand expressions?
4604 if (getDerived().AlwaysRebuild() ||
4605 modifiedType != oldType->getModifiedType()) {
4606 // TODO: this is really lame; we should really be rebuilding the
4607 // equivalent type from first principles.
4608 QualType equivalentType
4609 = getDerived().TransformType(oldType->getEquivalentType());
4610 if (equivalentType.isNull())
4611 return QualType();
4612 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4613 modifiedType,
4614 equivalentType);
4615 }
4616
4617 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4618 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4619 if (TL.hasAttrOperand())
4620 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4621 if (TL.hasAttrExprOperand())
4622 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4623 else if (TL.hasAttrEnumOperand())
4624 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4625
4626 return result;
4627}
4628
4629template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004630QualType
4631TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4632 ParenTypeLoc TL) {
4633 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4634 if (Inner.isNull())
4635 return QualType();
4636
4637 QualType Result = TL.getType();
4638 if (getDerived().AlwaysRebuild() ||
4639 Inner != TL.getInnerLoc().getType()) {
4640 Result = getDerived().RebuildParenType(Inner);
4641 if (Result.isNull())
4642 return QualType();
4643 }
4644
4645 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4646 NewTL.setLParenLoc(TL.getLParenLoc());
4647 NewTL.setRParenLoc(TL.getRParenLoc());
4648 return Result;
4649}
4650
4651template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004652QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004653 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004654 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004655
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004656 NestedNameSpecifierLoc QualifierLoc
4657 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4658 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004659 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004660
John McCallc392f372010-06-11 00:33:02 +00004661 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004662 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004663 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004664 QualifierLoc,
4665 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004666 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004667 if (Result.isNull())
4668 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004669
Abramo Bagnarad7548482010-05-19 21:37:53 +00004670 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4671 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004672 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4673
Abramo Bagnarad7548482010-05-19 21:37:53 +00004674 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4675 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004676 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004677 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004678 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4679 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004680 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004681 NewTL.setNameLoc(TL.getNameLoc());
4682 }
John McCall550e0c22009-10-21 00:40:46 +00004683 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004684}
Mike Stump11289f42009-09-09 15:08:12 +00004685
Douglas Gregord6ff3322009-08-04 16:50:30 +00004686template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004687QualType TreeTransform<Derived>::
4688 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004689 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004690 NestedNameSpecifierLoc QualifierLoc;
4691 if (TL.getQualifierLoc()) {
4692 QualifierLoc
4693 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4694 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004695 return QualType();
4696 }
4697
John McCall31f82722010-11-12 08:19:04 +00004698 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004699 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004700}
4701
4702template<typename Derived>
4703QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004704TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4705 DependentTemplateSpecializationTypeLoc TL,
4706 NestedNameSpecifierLoc QualifierLoc) {
4707 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4708
4709 TemplateArgumentListInfo NewTemplateArgs;
4710 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4711 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4712
4713 typedef TemplateArgumentLocContainerIterator<
4714 DependentTemplateSpecializationTypeLoc> ArgIterator;
4715 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4716 ArgIterator(TL, TL.getNumArgs()),
4717 NewTemplateArgs))
4718 return QualType();
4719
4720 QualType Result
4721 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4722 QualifierLoc,
4723 T->getIdentifier(),
4724 TL.getNameLoc(),
4725 NewTemplateArgs);
4726 if (Result.isNull())
4727 return QualType();
4728
4729 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4730 QualType NamedT = ElabT->getNamedType();
4731
4732 // Copy information relevant to the template specialization.
4733 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004734 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004735 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004736 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4737 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004738 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004739 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004740
4741 // Copy information relevant to the elaborated type.
4742 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4743 NewTL.setKeywordLoc(TL.getKeywordLoc());
4744 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004745 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4746 DependentTemplateSpecializationTypeLoc SpecTL
4747 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004748 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004749 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004750 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004751 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4752 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004753 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004754 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004755 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004756 TemplateSpecializationTypeLoc SpecTL
4757 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004758 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004759 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4760 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004761 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004762 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004763 }
4764 return Result;
4765}
4766
4767template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004768QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4769 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004770 QualType Pattern
4771 = getDerived().TransformType(TLB, TL.getPatternLoc());
4772 if (Pattern.isNull())
4773 return QualType();
4774
4775 QualType Result = TL.getType();
4776 if (getDerived().AlwaysRebuild() ||
4777 Pattern != TL.getPatternLoc().getType()) {
4778 Result = getDerived().RebuildPackExpansionType(Pattern,
4779 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004780 TL.getEllipsisLoc(),
4781 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004782 if (Result.isNull())
4783 return QualType();
4784 }
4785
4786 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4787 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4788 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004789}
4790
4791template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004792QualType
4793TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004794 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004795 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004796 TLB.pushFullCopy(TL);
4797 return TL.getType();
4798}
4799
4800template<typename Derived>
4801QualType
4802TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004803 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004804 // ObjCObjectType is never dependent.
4805 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004806 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004807}
Mike Stump11289f42009-09-09 15:08:12 +00004808
4809template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004810QualType
4811TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004812 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004813 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004814 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004815 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004816}
4817
Douglas Gregord6ff3322009-08-04 16:50:30 +00004818//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004819// Statement transformation
4820//===----------------------------------------------------------------------===//
4821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004822StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004823TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004824 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004825}
4826
4827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004828StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004829TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4830 return getDerived().TransformCompoundStmt(S, false);
4831}
4832
4833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004834StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004835TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004836 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004837 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004838 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004839 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004840 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4841 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004842 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004843 if (Result.isInvalid()) {
4844 // Immediately fail if this was a DeclStmt, since it's very
4845 // likely that this will cause problems for future statements.
4846 if (isa<DeclStmt>(*B))
4847 return StmtError();
4848
4849 // Otherwise, just keep processing substatements and fail later.
4850 SubStmtInvalid = true;
4851 continue;
4852 }
Mike Stump11289f42009-09-09 15:08:12 +00004853
Douglas Gregorebe10102009-08-20 07:17:43 +00004854 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4855 Statements.push_back(Result.takeAs<Stmt>());
4856 }
Mike Stump11289f42009-09-09 15:08:12 +00004857
John McCall1ababa62010-08-27 19:56:05 +00004858 if (SubStmtInvalid)
4859 return StmtError();
4860
Douglas Gregorebe10102009-08-20 07:17:43 +00004861 if (!getDerived().AlwaysRebuild() &&
4862 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004863 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004864
4865 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4866 move_arg(Statements),
4867 S->getRBracLoc(),
4868 IsStmtExpr);
4869}
Mike Stump11289f42009-09-09 15:08:12 +00004870
Douglas Gregorebe10102009-08-20 07:17:43 +00004871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004872StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004873TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004874 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004875 {
4876 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004877 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004878
Eli Friedman06577382009-11-19 03:14:00 +00004879 // Transform the left-hand case value.
4880 LHS = getDerived().TransformExpr(S->getLHS());
4881 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004882 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004883
Eli Friedman06577382009-11-19 03:14:00 +00004884 // Transform the right-hand case value (for the GNU case-range extension).
4885 RHS = getDerived().TransformExpr(S->getRHS());
4886 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004887 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004888 }
Mike Stump11289f42009-09-09 15:08:12 +00004889
Douglas Gregorebe10102009-08-20 07:17:43 +00004890 // Build the case statement.
4891 // Case statements are always rebuilt so that they will attached to their
4892 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004893 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004894 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004895 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004896 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004897 S->getColonLoc());
4898 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004899 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004900
Douglas Gregorebe10102009-08-20 07:17:43 +00004901 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004902 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004903 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004904 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004905
Douglas Gregorebe10102009-08-20 07:17:43 +00004906 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004907 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004908}
4909
4910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004911StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004912TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004913 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004914 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004915 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004916 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004917
Douglas Gregorebe10102009-08-20 07:17:43 +00004918 // Default statements are always rebuilt
4919 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004920 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004921}
Mike Stump11289f42009-09-09 15:08:12 +00004922
Douglas Gregorebe10102009-08-20 07:17:43 +00004923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004924StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004925TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004926 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004927 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004928 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004929
Chris Lattnercab02a62011-02-17 20:34:02 +00004930 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4931 S->getDecl());
4932 if (!LD)
4933 return StmtError();
4934
4935
Douglas Gregorebe10102009-08-20 07:17:43 +00004936 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004937 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004938 cast<LabelDecl>(LD), SourceLocation(),
4939 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004940}
Mike Stump11289f42009-09-09 15:08:12 +00004941
Douglas Gregorebe10102009-08-20 07:17:43 +00004942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004943StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004944TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004945 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004946 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004947 VarDecl *ConditionVar = 0;
4948 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004949 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004950 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004951 getDerived().TransformDefinition(
4952 S->getConditionVariable()->getLocation(),
4953 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004954 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004955 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004956 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004957 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004958
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004959 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004960 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004961
4962 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004963 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004964 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4965 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004966 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004967 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004968
John McCallb268a282010-08-23 23:25:46 +00004969 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004970 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004971 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004972
John McCallb268a282010-08-23 23:25:46 +00004973 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4974 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004975 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004976
Douglas Gregorebe10102009-08-20 07:17:43 +00004977 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004978 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004979 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004980 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004981
Douglas Gregorebe10102009-08-20 07:17:43 +00004982 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004983 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004984 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004985 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004986
Douglas Gregorebe10102009-08-20 07:17:43 +00004987 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004988 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004989 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004990 Then.get() == S->getThen() &&
4991 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004992 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004993
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004994 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004995 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004996 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004997}
4998
4999template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005000StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005001TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005002 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005003 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005004 VarDecl *ConditionVar = 0;
5005 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005006 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005007 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005008 getDerived().TransformDefinition(
5009 S->getConditionVariable()->getLocation(),
5010 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005011 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005012 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005013 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005014 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005015
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005016 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005017 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005018 }
Mike Stump11289f42009-09-09 15:08:12 +00005019
Douglas Gregorebe10102009-08-20 07:17:43 +00005020 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005021 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005022 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005023 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005024 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005025 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005026
Douglas Gregorebe10102009-08-20 07:17:43 +00005027 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005028 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005029 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005030 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005031
Douglas Gregorebe10102009-08-20 07:17:43 +00005032 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005033 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5034 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005035}
Mike Stump11289f42009-09-09 15:08:12 +00005036
Douglas Gregorebe10102009-08-20 07:17:43 +00005037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005038StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005039TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005040 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005041 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005042 VarDecl *ConditionVar = 0;
5043 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005044 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005045 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005046 getDerived().TransformDefinition(
5047 S->getConditionVariable()->getLocation(),
5048 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005049 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005050 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005051 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005052 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005053
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005054 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005055 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005056
5057 if (S->getCond()) {
5058 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005059 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5060 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005061 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005062 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005063 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005064 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005065 }
Mike Stump11289f42009-09-09 15:08:12 +00005066
John McCallb268a282010-08-23 23:25:46 +00005067 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5068 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005069 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005070
Douglas Gregorebe10102009-08-20 07:17:43 +00005071 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005072 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005073 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005074 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005075
Douglas Gregorebe10102009-08-20 07:17:43 +00005076 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005077 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005078 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005079 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005080 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005082 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005083 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005084}
Mike Stump11289f42009-09-09 15:08:12 +00005085
Douglas Gregorebe10102009-08-20 07:17:43 +00005086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005087StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005088TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005089 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005090 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005091 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005092 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005093
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005094 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005095 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005096 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005097 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005098
Douglas Gregorebe10102009-08-20 07:17:43 +00005099 if (!getDerived().AlwaysRebuild() &&
5100 Cond.get() == S->getCond() &&
5101 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005102 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005103
John McCallb268a282010-08-23 23:25:46 +00005104 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5105 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005106 S->getRParenLoc());
5107}
Mike Stump11289f42009-09-09 15:08:12 +00005108
Douglas Gregorebe10102009-08-20 07:17:43 +00005109template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005110StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005111TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005112 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005113 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005114 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005115 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005116
Douglas Gregorebe10102009-08-20 07:17:43 +00005117 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005118 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005119 VarDecl *ConditionVar = 0;
5120 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005121 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005122 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005123 getDerived().TransformDefinition(
5124 S->getConditionVariable()->getLocation(),
5125 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005126 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005127 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005128 } else {
5129 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005130
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005131 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005132 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005133
5134 if (S->getCond()) {
5135 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005136 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5137 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005138 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005139 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005140
John McCallb268a282010-08-23 23:25:46 +00005141 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005142 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005143 }
Mike Stump11289f42009-09-09 15:08:12 +00005144
John McCallb268a282010-08-23 23:25:46 +00005145 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5146 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005147 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005148
Douglas Gregorebe10102009-08-20 07:17:43 +00005149 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005150 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005151 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005152 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005153
John McCallb268a282010-08-23 23:25:46 +00005154 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5155 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005156 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005157
Douglas Gregorebe10102009-08-20 07:17:43 +00005158 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005159 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005160 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005161 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005162
Douglas Gregorebe10102009-08-20 07:17:43 +00005163 if (!getDerived().AlwaysRebuild() &&
5164 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005165 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005166 Inc.get() == S->getInc() &&
5167 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005168 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005169
Douglas Gregorebe10102009-08-20 07:17:43 +00005170 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005171 Init.get(), FullCond, ConditionVar,
5172 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005173}
5174
5175template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005176StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005177TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005178 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5179 S->getLabel());
5180 if (!LD)
5181 return StmtError();
5182
Douglas Gregorebe10102009-08-20 07:17:43 +00005183 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005184 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005185 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005186}
5187
5188template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005189StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005190TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005191 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005192 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005193 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005194
Douglas Gregorebe10102009-08-20 07:17:43 +00005195 if (!getDerived().AlwaysRebuild() &&
5196 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005197 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005198
5199 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005200 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005201}
5202
5203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005204StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005205TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005206 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005207}
Mike Stump11289f42009-09-09 15:08:12 +00005208
Douglas Gregorebe10102009-08-20 07:17:43 +00005209template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005210StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005211TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005212 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005213}
Mike Stump11289f42009-09-09 15:08:12 +00005214
Douglas Gregorebe10102009-08-20 07:17:43 +00005215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005216StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005217TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005218 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005219 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005220 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005221
Mike Stump11289f42009-09-09 15:08:12 +00005222 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005223 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005224 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005225}
Mike Stump11289f42009-09-09 15:08:12 +00005226
Douglas Gregorebe10102009-08-20 07:17:43 +00005227template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005228StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005229TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005230 bool DeclChanged = false;
5231 llvm::SmallVector<Decl *, 4> Decls;
5232 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5233 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005234 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5235 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005236 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005237 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005238
Douglas Gregorebe10102009-08-20 07:17:43 +00005239 if (Transformed != *D)
5240 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005241
Douglas Gregorebe10102009-08-20 07:17:43 +00005242 Decls.push_back(Transformed);
5243 }
Mike Stump11289f42009-09-09 15:08:12 +00005244
Douglas Gregorebe10102009-08-20 07:17:43 +00005245 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005246 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005247
5248 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005249 S->getStartLoc(), S->getEndLoc());
5250}
Mike Stump11289f42009-09-09 15:08:12 +00005251
Douglas Gregorebe10102009-08-20 07:17:43 +00005252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005253StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005254TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005255
John McCall37ad5512010-08-23 06:44:23 +00005256 ASTOwningVector<Expr*> Constraints(getSema());
5257 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005258 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005259
John McCalldadc5752010-08-24 06:29:42 +00005260 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005261 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005262
5263 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005264
Anders Carlssonaaeef072010-01-24 05:50:09 +00005265 // Go through the outputs.
5266 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005267 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005268
Anders Carlssonaaeef072010-01-24 05:50:09 +00005269 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005270 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005271
Anders Carlssonaaeef072010-01-24 05:50:09 +00005272 // Transform the output expr.
5273 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005274 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005275 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005276 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005277
Anders Carlssonaaeef072010-01-24 05:50:09 +00005278 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005279
John McCallb268a282010-08-23 23:25:46 +00005280 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005281 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005282
Anders Carlssonaaeef072010-01-24 05:50:09 +00005283 // Go through the inputs.
5284 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005285 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005286
Anders Carlssonaaeef072010-01-24 05:50:09 +00005287 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005288 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005289
Anders Carlssonaaeef072010-01-24 05:50:09 +00005290 // Transform the input expr.
5291 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005292 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005293 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005294 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005295
Anders Carlssonaaeef072010-01-24 05:50:09 +00005296 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005297
John McCallb268a282010-08-23 23:25:46 +00005298 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005299 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005300
Anders Carlssonaaeef072010-01-24 05:50:09 +00005301 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005302 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005303
5304 // Go through the clobbers.
5305 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005306 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005307
5308 // No need to transform the asm string literal.
5309 AsmString = SemaRef.Owned(S->getAsmString());
5310
5311 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5312 S->isSimple(),
5313 S->isVolatile(),
5314 S->getNumOutputs(),
5315 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005316 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005317 move_arg(Constraints),
5318 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005319 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005320 move_arg(Clobbers),
5321 S->getRParenLoc(),
5322 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005323}
5324
5325
5326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005327StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005328TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005329 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005330 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005331 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005332 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005333
Douglas Gregor96c79492010-04-23 22:50:49 +00005334 // Transform the @catch statements (if present).
5335 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005336 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005337 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005338 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005339 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005340 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005341 if (Catch.get() != S->getCatchStmt(I))
5342 AnyCatchChanged = true;
5343 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005344 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005345
Douglas Gregor306de2f2010-04-22 23:59:56 +00005346 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005347 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005348 if (S->getFinallyStmt()) {
5349 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5350 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005351 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005352 }
5353
5354 // If nothing changed, just retain this statement.
5355 if (!getDerived().AlwaysRebuild() &&
5356 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005357 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005358 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005359 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005360
Douglas Gregor306de2f2010-04-22 23:59:56 +00005361 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005362 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5363 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005364}
Mike Stump11289f42009-09-09 15:08:12 +00005365
Douglas Gregorebe10102009-08-20 07:17:43 +00005366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005367StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005368TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005369 // Transform the @catch parameter, if there is one.
5370 VarDecl *Var = 0;
5371 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5372 TypeSourceInfo *TSInfo = 0;
5373 if (FromVar->getTypeSourceInfo()) {
5374 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5375 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005376 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005377 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005378
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005379 QualType T;
5380 if (TSInfo)
5381 T = TSInfo->getType();
5382 else {
5383 T = getDerived().TransformType(FromVar->getType());
5384 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005385 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005386 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005387
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005388 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5389 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005390 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005391 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005392
John McCalldadc5752010-08-24 06:29:42 +00005393 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005394 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005395 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005396
5397 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005398 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005399 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005400}
Mike Stump11289f42009-09-09 15:08:12 +00005401
Douglas Gregorebe10102009-08-20 07:17:43 +00005402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005403StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005404TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005405 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005406 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005407 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005408 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005409
Douglas Gregor306de2f2010-04-22 23:59:56 +00005410 // If nothing changed, just retain this statement.
5411 if (!getDerived().AlwaysRebuild() &&
5412 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005413 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005414
5415 // Build a new statement.
5416 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005417 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005418}
Mike Stump11289f42009-09-09 15:08:12 +00005419
Douglas Gregorebe10102009-08-20 07:17:43 +00005420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005421StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005422TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005423 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005424 if (S->getThrowExpr()) {
5425 Operand = getDerived().TransformExpr(S->getThrowExpr());
5426 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005427 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005428 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005429
Douglas Gregor2900c162010-04-22 21:44:01 +00005430 if (!getDerived().AlwaysRebuild() &&
5431 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005432 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005433
John McCallb268a282010-08-23 23:25:46 +00005434 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005435}
Mike Stump11289f42009-09-09 15:08:12 +00005436
Douglas Gregorebe10102009-08-20 07:17:43 +00005437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005438StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005439TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005440 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005441 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005442 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005443 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005444 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005445
Douglas Gregor6148de72010-04-22 22:01:21 +00005446 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005447 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005448 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005449 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005450
Douglas Gregor6148de72010-04-22 22:01:21 +00005451 // If nothing change, just retain the current statement.
5452 if (!getDerived().AlwaysRebuild() &&
5453 Object.get() == S->getSynchExpr() &&
5454 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005455 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005456
5457 // Build a new statement.
5458 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005459 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005460}
5461
5462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005463StmtResult
John McCall31168b02011-06-15 23:02:42 +00005464TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5465 ObjCAutoreleasePoolStmt *S) {
5466 // Transform the body.
5467 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5468 if (Body.isInvalid())
5469 return StmtError();
5470
5471 // If nothing changed, just retain this statement.
5472 if (!getDerived().AlwaysRebuild() &&
5473 Body.get() == S->getSubStmt())
5474 return SemaRef.Owned(S);
5475
5476 // Build a new statement.
5477 return getDerived().RebuildObjCAutoreleasePoolStmt(
5478 S->getAtLoc(), Body.get());
5479}
5480
5481template<typename Derived>
5482StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005483TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005484 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005485 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005486 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005487 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005488 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005489
Douglas Gregorf68a5082010-04-22 23:10:45 +00005490 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005491 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005492 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005493 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005494
Douglas Gregorf68a5082010-04-22 23:10:45 +00005495 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005496 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005497 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005498 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005499
Douglas Gregorf68a5082010-04-22 23:10:45 +00005500 // If nothing changed, just retain this statement.
5501 if (!getDerived().AlwaysRebuild() &&
5502 Element.get() == S->getElement() &&
5503 Collection.get() == S->getCollection() &&
5504 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005505 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005506
Douglas Gregorf68a5082010-04-22 23:10:45 +00005507 // Build a new statement.
5508 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5509 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005510 Element.get(),
5511 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005512 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005513 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005514}
5515
5516
5517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005518StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005519TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5520 // Transform the exception declaration, if any.
5521 VarDecl *Var = 0;
5522 if (S->getExceptionDecl()) {
5523 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005524 TypeSourceInfo *T = getDerived().TransformType(
5525 ExceptionDecl->getTypeSourceInfo());
5526 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005527 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005528
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005529 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005530 ExceptionDecl->getInnerLocStart(),
5531 ExceptionDecl->getLocation(),
5532 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005533 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005534 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005535 }
Mike Stump11289f42009-09-09 15:08:12 +00005536
Douglas Gregorebe10102009-08-20 07:17:43 +00005537 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005538 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005539 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005540 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005541
Douglas Gregorebe10102009-08-20 07:17:43 +00005542 if (!getDerived().AlwaysRebuild() &&
5543 !Var &&
5544 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005545 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005546
5547 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5548 Var,
John McCallb268a282010-08-23 23:25:46 +00005549 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005550}
Mike Stump11289f42009-09-09 15:08:12 +00005551
Douglas Gregorebe10102009-08-20 07:17:43 +00005552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005553StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005554TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5555 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005556 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005557 = getDerived().TransformCompoundStmt(S->getTryBlock());
5558 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005559 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005560
Douglas Gregorebe10102009-08-20 07:17:43 +00005561 // Transform the handlers.
5562 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005563 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005564 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005565 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005566 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5567 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005568 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005569
Douglas Gregorebe10102009-08-20 07:17:43 +00005570 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5571 Handlers.push_back(Handler.takeAs<Stmt>());
5572 }
Mike Stump11289f42009-09-09 15:08:12 +00005573
Douglas Gregorebe10102009-08-20 07:17:43 +00005574 if (!getDerived().AlwaysRebuild() &&
5575 TryBlock.get() == S->getTryBlock() &&
5576 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005577 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005578
John McCallb268a282010-08-23 23:25:46 +00005579 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005580 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005581}
Mike Stump11289f42009-09-09 15:08:12 +00005582
Richard Smith02e85f32011-04-14 22:09:26 +00005583template<typename Derived>
5584StmtResult
5585TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5586 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5587 if (Range.isInvalid())
5588 return StmtError();
5589
5590 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5591 if (BeginEnd.isInvalid())
5592 return StmtError();
5593
5594 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5595 if (Cond.isInvalid())
5596 return StmtError();
5597
5598 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5599 if (Inc.isInvalid())
5600 return StmtError();
5601
5602 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5603 if (LoopVar.isInvalid())
5604 return StmtError();
5605
5606 StmtResult NewStmt = S;
5607 if (getDerived().AlwaysRebuild() ||
5608 Range.get() != S->getRangeStmt() ||
5609 BeginEnd.get() != S->getBeginEndStmt() ||
5610 Cond.get() != S->getCond() ||
5611 Inc.get() != S->getInc() ||
5612 LoopVar.get() != S->getLoopVarStmt())
5613 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5614 S->getColonLoc(), Range.get(),
5615 BeginEnd.get(), Cond.get(),
5616 Inc.get(), LoopVar.get(),
5617 S->getRParenLoc());
5618
5619 StmtResult Body = getDerived().TransformStmt(S->getBody());
5620 if (Body.isInvalid())
5621 return StmtError();
5622
5623 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5624 // it now so we have a new statement to attach the body to.
5625 if (Body.get() != S->getBody() && NewStmt.get() == S)
5626 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5627 S->getColonLoc(), Range.get(),
5628 BeginEnd.get(), Cond.get(),
5629 Inc.get(), LoopVar.get(),
5630 S->getRParenLoc());
5631
5632 if (NewStmt.get() == S)
5633 return SemaRef.Owned(S);
5634
5635 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5636}
5637
John Wiegley1c0675e2011-04-28 01:08:34 +00005638template<typename Derived>
5639StmtResult
5640TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5641 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5642 if(TryBlock.isInvalid()) return StmtError();
5643
5644 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5645 if(!getDerived().AlwaysRebuild() &&
5646 TryBlock.get() == S->getTryBlock() &&
5647 Handler.get() == S->getHandler())
5648 return SemaRef.Owned(S);
5649
5650 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5651 S->getTryLoc(),
5652 TryBlock.take(),
5653 Handler.take());
5654}
5655
5656template<typename Derived>
5657StmtResult
5658TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5659 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5660 if(Block.isInvalid()) return StmtError();
5661
5662 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5663 Block.take());
5664}
5665
5666template<typename Derived>
5667StmtResult
5668TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5669 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5670 if(FilterExpr.isInvalid()) return StmtError();
5671
5672 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5673 if(Block.isInvalid()) return StmtError();
5674
5675 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5676 FilterExpr.take(),
5677 Block.take());
5678}
5679
5680template<typename Derived>
5681StmtResult
5682TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5683 if(isa<SEHFinallyStmt>(Handler))
5684 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5685 else
5686 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5687}
5688
Douglas Gregorebe10102009-08-20 07:17:43 +00005689//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005690// Expression transformation
5691//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005694TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005695 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005696}
Mike Stump11289f42009-09-09 15:08:12 +00005697
5698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005699ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005700TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005701 NestedNameSpecifierLoc QualifierLoc;
5702 if (E->getQualifierLoc()) {
5703 QualifierLoc
5704 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5705 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005706 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005707 }
John McCallce546572009-12-08 09:08:17 +00005708
5709 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005710 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5711 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005712 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005713 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005714
John McCall815039a2010-08-17 21:27:17 +00005715 DeclarationNameInfo NameInfo = E->getNameInfo();
5716 if (NameInfo.getName()) {
5717 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5718 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005719 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005720 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005721
5722 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005723 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005724 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005725 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005726 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005727
5728 // Mark it referenced in the new context regardless.
5729 // FIXME: this is a bit instantiation-specific.
5730 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5731
John McCallc3007a22010-10-26 07:05:15 +00005732 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005733 }
John McCallce546572009-12-08 09:08:17 +00005734
5735 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005736 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005737 TemplateArgs = &TransArgs;
5738 TransArgs.setLAngleLoc(E->getLAngleLoc());
5739 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005740 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5741 E->getNumTemplateArgs(),
5742 TransArgs))
5743 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005744 }
5745
Douglas Gregorea972d32011-02-28 21:54:11 +00005746 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5747 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005748}
Mike Stump11289f42009-09-09 15:08:12 +00005749
Douglas Gregora16548e2009-08-11 05:31:07 +00005750template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005751ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005752TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005753 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005754}
Mike Stump11289f42009-09-09 15:08:12 +00005755
Douglas Gregora16548e2009-08-11 05:31:07 +00005756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005757ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005758TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005759 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005760}
Mike Stump11289f42009-09-09 15:08:12 +00005761
Douglas Gregora16548e2009-08-11 05:31:07 +00005762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005763ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005764TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005765 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005766}
Mike Stump11289f42009-09-09 15:08:12 +00005767
Douglas Gregora16548e2009-08-11 05:31:07 +00005768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005769ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005770TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005771 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005772}
Mike Stump11289f42009-09-09 15:08:12 +00005773
Douglas Gregora16548e2009-08-11 05:31:07 +00005774template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005775ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005776TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005777 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005778}
5779
5780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005781ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005782TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5783 ExprResult ControllingExpr =
5784 getDerived().TransformExpr(E->getControllingExpr());
5785 if (ControllingExpr.isInvalid())
5786 return ExprError();
5787
5788 llvm::SmallVector<Expr *, 4> AssocExprs;
5789 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5790 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5791 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5792 if (TS) {
5793 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5794 if (!AssocType)
5795 return ExprError();
5796 AssocTypes.push_back(AssocType);
5797 } else {
5798 AssocTypes.push_back(0);
5799 }
5800
5801 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5802 if (AssocExpr.isInvalid())
5803 return ExprError();
5804 AssocExprs.push_back(AssocExpr.release());
5805 }
5806
5807 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5808 E->getDefaultLoc(),
5809 E->getRParenLoc(),
5810 ControllingExpr.release(),
5811 AssocTypes.data(),
5812 AssocExprs.data(),
5813 E->getNumAssocs());
5814}
5815
5816template<typename Derived>
5817ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005818TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005819 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005821 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005822
Douglas Gregora16548e2009-08-11 05:31:07 +00005823 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005824 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005825
John McCallb268a282010-08-23 23:25:46 +00005826 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005827 E->getRParen());
5828}
5829
Mike Stump11289f42009-09-09 15:08:12 +00005830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005831ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005832TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005833 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005834 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005835 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005836
Douglas Gregora16548e2009-08-11 05:31:07 +00005837 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005838 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005839
Douglas Gregora16548e2009-08-11 05:31:07 +00005840 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5841 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005842 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005843}
Mike Stump11289f42009-09-09 15:08:12 +00005844
Douglas Gregora16548e2009-08-11 05:31:07 +00005845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005846ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005847TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5848 // Transform the type.
5849 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5850 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005851 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005852
Douglas Gregor882211c2010-04-28 22:16:22 +00005853 // Transform all of the components into components similar to what the
5854 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005855 // FIXME: It would be slightly more efficient in the non-dependent case to
5856 // just map FieldDecls, rather than requiring the rebuilder to look for
5857 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005858 // template code that we don't care.
5859 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005860 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005861 typedef OffsetOfExpr::OffsetOfNode Node;
5862 llvm::SmallVector<Component, 4> Components;
5863 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5864 const Node &ON = E->getComponent(I);
5865 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005866 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005867 Comp.LocStart = ON.getSourceRange().getBegin();
5868 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005869 switch (ON.getKind()) {
5870 case Node::Array: {
5871 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005872 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005873 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005874 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005875
Douglas Gregor882211c2010-04-28 22:16:22 +00005876 ExprChanged = ExprChanged || Index.get() != FromIndex;
5877 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005878 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005879 break;
5880 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005881
Douglas Gregor882211c2010-04-28 22:16:22 +00005882 case Node::Field:
5883 case Node::Identifier:
5884 Comp.isBrackets = false;
5885 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005886 if (!Comp.U.IdentInfo)
5887 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005888
Douglas Gregor882211c2010-04-28 22:16:22 +00005889 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005890
Douglas Gregord1702062010-04-29 00:18:15 +00005891 case Node::Base:
5892 // Will be recomputed during the rebuild.
5893 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005894 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005895
Douglas Gregor882211c2010-04-28 22:16:22 +00005896 Components.push_back(Comp);
5897 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005898
Douglas Gregor882211c2010-04-28 22:16:22 +00005899 // If nothing changed, retain the existing expression.
5900 if (!getDerived().AlwaysRebuild() &&
5901 Type == E->getTypeSourceInfo() &&
5902 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005903 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005904
Douglas Gregor882211c2010-04-28 22:16:22 +00005905 // Build a new offsetof expression.
5906 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5907 Components.data(), Components.size(),
5908 E->getRParenLoc());
5909}
5910
5911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005912ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005913TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5914 assert(getDerived().AlreadyTransformed(E->getType()) &&
5915 "opaque value expression requires transformation");
5916 return SemaRef.Owned(E);
5917}
5918
5919template<typename Derived>
5920ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005921TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5922 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005923 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005924 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005925
John McCallbcd03502009-12-07 02:54:59 +00005926 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005927 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005928 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005929
John McCall4c98fd82009-11-04 07:28:41 +00005930 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005931 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005932
Peter Collingbournee190dee2011-03-11 19:24:49 +00005933 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5934 E->getKind(),
5935 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005936 }
Mike Stump11289f42009-09-09 15:08:12 +00005937
John McCalldadc5752010-08-24 06:29:42 +00005938 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005939 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005940 // C++0x [expr.sizeof]p1:
5941 // The operand is either an expression, which is an unevaluated operand
5942 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005943 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005944
Douglas Gregora16548e2009-08-11 05:31:07 +00005945 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5946 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005947 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005948
Douglas Gregora16548e2009-08-11 05:31:07 +00005949 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005950 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005951 }
Mike Stump11289f42009-09-09 15:08:12 +00005952
Peter Collingbournee190dee2011-03-11 19:24:49 +00005953 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5954 E->getOperatorLoc(),
5955 E->getKind(),
5956 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005957}
Mike Stump11289f42009-09-09 15:08:12 +00005958
Douglas Gregora16548e2009-08-11 05:31:07 +00005959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005960ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005961TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005962 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005963 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005964 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005965
John McCalldadc5752010-08-24 06:29:42 +00005966 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005967 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005968 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005969
5970
Douglas Gregora16548e2009-08-11 05:31:07 +00005971 if (!getDerived().AlwaysRebuild() &&
5972 LHS.get() == E->getLHS() &&
5973 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005974 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005975
John McCallb268a282010-08-23 23:25:46 +00005976 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005977 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005978 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005979 E->getRBracketLoc());
5980}
Mike Stump11289f42009-09-09 15:08:12 +00005981
5982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005983ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005984TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005985 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005986 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005987 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005988 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005989
5990 // Transform arguments.
5991 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005992 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005993 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5994 &ArgChanged))
5995 return ExprError();
5996
Douglas Gregora16548e2009-08-11 05:31:07 +00005997 if (!getDerived().AlwaysRebuild() &&
5998 Callee.get() == E->getCallee() &&
5999 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006000 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006001
Douglas Gregora16548e2009-08-11 05:31:07 +00006002 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006003 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006004 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006005 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006006 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006007 E->getRParenLoc());
6008}
Mike Stump11289f42009-09-09 15:08:12 +00006009
6010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006011ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006012TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006013 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006015 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregorea972d32011-02-28 21:54:11 +00006017 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006018 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006019 QualifierLoc
6020 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6021
6022 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006023 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006024 }
Mike Stump11289f42009-09-09 15:08:12 +00006025
Eli Friedman2cfcef62009-12-04 06:40:45 +00006026 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006027 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6028 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006029 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006031
John McCall16df1e52010-03-30 21:47:33 +00006032 NamedDecl *FoundDecl = E->getFoundDecl();
6033 if (FoundDecl == E->getMemberDecl()) {
6034 FoundDecl = Member;
6035 } else {
6036 FoundDecl = cast_or_null<NamedDecl>(
6037 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6038 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006039 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006040 }
6041
Douglas Gregora16548e2009-08-11 05:31:07 +00006042 if (!getDerived().AlwaysRebuild() &&
6043 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006044 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006045 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006046 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006047 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006048
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006049 // Mark it referenced in the new context regardless.
6050 // FIXME: this is a bit instantiation-specific.
6051 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00006052 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006053 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006054
John McCall6b51f282009-11-23 01:53:49 +00006055 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006056 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006057 TransArgs.setLAngleLoc(E->getLAngleLoc());
6058 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006059 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6060 E->getNumTemplateArgs(),
6061 TransArgs))
6062 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006063 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006064
Douglas Gregora16548e2009-08-11 05:31:07 +00006065 // FIXME: Bogus source location for the operator
6066 SourceLocation FakeOperatorLoc
6067 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6068
John McCall38836f02010-01-15 08:34:02 +00006069 // FIXME: to do this check properly, we will need to preserve the
6070 // first-qualifier-in-scope here, just in case we had a dependent
6071 // base (and therefore couldn't do the check) and a
6072 // nested-name-qualifier (and therefore could do the lookup).
6073 NamedDecl *FirstQualifierInScope = 0;
6074
John McCallb268a282010-08-23 23:25:46 +00006075 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006076 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006077 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006078 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006079 Member,
John McCall16df1e52010-03-30 21:47:33 +00006080 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006081 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006082 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006083 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006084}
Mike Stump11289f42009-09-09 15:08:12 +00006085
Douglas Gregora16548e2009-08-11 05:31:07 +00006086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006087ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006088TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006089 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006090 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006091 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006092
John McCalldadc5752010-08-24 06:29:42 +00006093 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006094 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006095 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006096
Douglas Gregora16548e2009-08-11 05:31:07 +00006097 if (!getDerived().AlwaysRebuild() &&
6098 LHS.get() == E->getLHS() &&
6099 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006100 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006101
Douglas Gregora16548e2009-08-11 05:31:07 +00006102 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006103 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006104}
6105
Mike Stump11289f42009-09-09 15:08:12 +00006106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006107ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006108TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006109 CompoundAssignOperator *E) {
6110 return getDerived().TransformBinaryOperator(E);
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 McCallc07a0c72011-02-17 10:25:35 +00006114ExprResult TreeTransform<Derived>::
6115TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6116 // Just rebuild the common and RHS expressions and see whether we
6117 // get any changes.
6118
6119 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6120 if (commonExpr.isInvalid())
6121 return ExprError();
6122
6123 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6124 if (rhs.isInvalid())
6125 return ExprError();
6126
6127 if (!getDerived().AlwaysRebuild() &&
6128 commonExpr.get() == e->getCommon() &&
6129 rhs.get() == e->getFalseExpr())
6130 return SemaRef.Owned(e);
6131
6132 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6133 e->getQuestionLoc(),
6134 0,
6135 e->getColonLoc(),
6136 rhs.get());
6137}
6138
6139template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006140ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006141TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006142 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006143 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006144 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006145
John McCalldadc5752010-08-24 06:29:42 +00006146 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006147 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006148 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006149
John McCalldadc5752010-08-24 06:29:42 +00006150 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006151 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006152 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006153
Douglas Gregora16548e2009-08-11 05:31:07 +00006154 if (!getDerived().AlwaysRebuild() &&
6155 Cond.get() == E->getCond() &&
6156 LHS.get() == E->getLHS() &&
6157 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006158 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006159
John McCallb268a282010-08-23 23:25:46 +00006160 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006161 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006162 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006163 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006164 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006165}
Mike Stump11289f42009-09-09 15:08:12 +00006166
6167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006168ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006169TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006170 // Implicit casts are eliminated during transformation, since they
6171 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006172 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006173}
Mike Stump11289f42009-09-09 15:08:12 +00006174
Douglas Gregora16548e2009-08-11 05:31:07 +00006175template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006176ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006177TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006178 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6179 if (!Type)
6180 return ExprError();
6181
John McCalldadc5752010-08-24 06:29:42 +00006182 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006183 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006184 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006185 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006186
Douglas Gregora16548e2009-08-11 05:31:07 +00006187 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006188 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006189 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006190 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006191
John McCall97513962010-01-15 18:39:57 +00006192 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006193 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006194 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006195 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006196}
Mike Stump11289f42009-09-09 15:08:12 +00006197
Douglas Gregora16548e2009-08-11 05:31:07 +00006198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006199ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006200TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006201 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6202 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6203 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006204 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006205
John McCalldadc5752010-08-24 06:29:42 +00006206 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006207 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006208 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006209
Douglas Gregora16548e2009-08-11 05:31:07 +00006210 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006211 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006212 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006213 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006214
John McCall5d7aa7f2010-01-19 22:33:45 +00006215 // Note: the expression type doesn't necessarily match the
6216 // type-as-written, but that's okay, because it should always be
6217 // derivable from the initializer.
6218
John McCalle15bbff2010-01-18 19:35:47 +00006219 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006220 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006221 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006222}
Mike Stump11289f42009-09-09 15:08:12 +00006223
Douglas Gregora16548e2009-08-11 05:31:07 +00006224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006225ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006226TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006227 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006228 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006229 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006230
Douglas Gregora16548e2009-08-11 05:31:07 +00006231 if (!getDerived().AlwaysRebuild() &&
6232 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006233 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006234
Douglas Gregora16548e2009-08-11 05:31:07 +00006235 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006236 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006237 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006238 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006239 E->getAccessorLoc(),
6240 E->getAccessor());
6241}
Mike Stump11289f42009-09-09 15:08:12 +00006242
Douglas Gregora16548e2009-08-11 05:31:07 +00006243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006244ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006245TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006246 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006247
John McCall37ad5512010-08-23 06:44:23 +00006248 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006249 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6250 Inits, &InitChanged))
6251 return ExprError();
6252
Douglas Gregora16548e2009-08-11 05:31:07 +00006253 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006254 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006255
Douglas Gregora16548e2009-08-11 05:31:07 +00006256 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006257 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006258}
Mike Stump11289f42009-09-09 15:08:12 +00006259
Douglas Gregora16548e2009-08-11 05:31:07 +00006260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006261ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006262TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006263 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006264
Douglas Gregorebe10102009-08-20 07:17:43 +00006265 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006266 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006267 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006269
Douglas Gregorebe10102009-08-20 07:17:43 +00006270 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006271 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006272 bool ExprChanged = false;
6273 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6274 DEnd = E->designators_end();
6275 D != DEnd; ++D) {
6276 if (D->isFieldDesignator()) {
6277 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6278 D->getDotLoc(),
6279 D->getFieldLoc()));
6280 continue;
6281 }
Mike Stump11289f42009-09-09 15:08:12 +00006282
Douglas Gregora16548e2009-08-11 05:31:07 +00006283 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006284 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006285 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006287
6288 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006289 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006290
Douglas Gregora16548e2009-08-11 05:31:07 +00006291 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6292 ArrayExprs.push_back(Index.release());
6293 continue;
6294 }
Mike Stump11289f42009-09-09 15:08:12 +00006295
Douglas Gregora16548e2009-08-11 05:31:07 +00006296 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006297 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006298 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6299 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006300 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006301
John McCalldadc5752010-08-24 06:29:42 +00006302 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006303 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006304 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006305
6306 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006307 End.get(),
6308 D->getLBracketLoc(),
6309 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006310
Douglas Gregora16548e2009-08-11 05:31:07 +00006311 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6312 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006313
Douglas Gregora16548e2009-08-11 05:31:07 +00006314 ArrayExprs.push_back(Start.release());
6315 ArrayExprs.push_back(End.release());
6316 }
Mike Stump11289f42009-09-09 15:08:12 +00006317
Douglas Gregora16548e2009-08-11 05:31:07 +00006318 if (!getDerived().AlwaysRebuild() &&
6319 Init.get() == E->getInit() &&
6320 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006321 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006322
Douglas Gregora16548e2009-08-11 05:31:07 +00006323 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6324 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006325 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006326}
Mike Stump11289f42009-09-09 15:08:12 +00006327
Douglas Gregora16548e2009-08-11 05:31:07 +00006328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006329ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006330TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006331 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006332 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006333
Douglas Gregor3da3c062009-10-28 00:29:27 +00006334 // FIXME: Will we ever have proper type location here? Will we actually
6335 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006336 QualType T = getDerived().TransformType(E->getType());
6337 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006338 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006339
Douglas Gregora16548e2009-08-11 05:31:07 +00006340 if (!getDerived().AlwaysRebuild() &&
6341 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006342 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006343
Douglas Gregora16548e2009-08-11 05:31:07 +00006344 return getDerived().RebuildImplicitValueInitExpr(T);
6345}
Mike Stump11289f42009-09-09 15:08:12 +00006346
Douglas Gregora16548e2009-08-11 05:31:07 +00006347template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006348ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006349TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006350 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6351 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006353
John McCalldadc5752010-08-24 06:29:42 +00006354 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006355 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006356 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006357
Douglas Gregora16548e2009-08-11 05:31:07 +00006358 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006359 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006360 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006361 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006362
John McCallb268a282010-08-23 23:25:46 +00006363 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006364 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006365}
6366
6367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006369TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006370 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006371 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006372 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6373 &ArgumentChanged))
6374 return ExprError();
6375
Douglas Gregora16548e2009-08-11 05:31:07 +00006376 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6377 move_arg(Inits),
6378 E->getRParenLoc());
6379}
Mike Stump11289f42009-09-09 15:08:12 +00006380
Douglas Gregora16548e2009-08-11 05:31:07 +00006381/// \brief Transform an address-of-label expression.
6382///
6383/// By default, the transformation of an address-of-label expression always
6384/// rebuilds the expression, so that the label identifier can be resolved to
6385/// the corresponding label statement by semantic analysis.
6386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006387ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006388TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006389 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6390 E->getLabel());
6391 if (!LD)
6392 return ExprError();
6393
Douglas Gregora16548e2009-08-11 05:31:07 +00006394 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006395 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006396}
Mike Stump11289f42009-09-09 15:08:12 +00006397
6398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006399ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006400TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006401 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006402 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6403 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006404 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006405
Douglas Gregora16548e2009-08-11 05:31:07 +00006406 if (!getDerived().AlwaysRebuild() &&
6407 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006408 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006409
6410 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006411 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006412 E->getRParenLoc());
6413}
Mike Stump11289f42009-09-09 15:08:12 +00006414
Douglas Gregora16548e2009-08-11 05:31:07 +00006415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006416ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006417TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006418 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006419 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006420 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006421
John McCalldadc5752010-08-24 06:29:42 +00006422 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006423 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006424 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006425
John McCalldadc5752010-08-24 06:29:42 +00006426 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006427 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006428 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006429
Douglas Gregora16548e2009-08-11 05:31:07 +00006430 if (!getDerived().AlwaysRebuild() &&
6431 Cond.get() == E->getCond() &&
6432 LHS.get() == E->getLHS() &&
6433 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006434 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006435
Douglas Gregora16548e2009-08-11 05:31:07 +00006436 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006437 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 E->getRParenLoc());
6439}
Mike Stump11289f42009-09-09 15:08:12 +00006440
Douglas Gregora16548e2009-08-11 05:31:07 +00006441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006442ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006443TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006444 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006445}
6446
6447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006448ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006449TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006450 switch (E->getOperator()) {
6451 case OO_New:
6452 case OO_Delete:
6453 case OO_Array_New:
6454 case OO_Array_Delete:
6455 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006456 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006457
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006458 case OO_Call: {
6459 // This is a call to an object's operator().
6460 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6461
6462 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006463 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006464 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006465 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006466
6467 // FIXME: Poor location information
6468 SourceLocation FakeLParenLoc
6469 = SemaRef.PP.getLocForEndOfToken(
6470 static_cast<Expr *>(Object.get())->getLocEnd());
6471
6472 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006473 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006474 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6475 Args))
6476 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006477
John McCallb268a282010-08-23 23:25:46 +00006478 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006479 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006480 E->getLocEnd());
6481 }
6482
6483#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6484 case OO_##Name:
6485#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6486#include "clang/Basic/OperatorKinds.def"
6487 case OO_Subscript:
6488 // Handled below.
6489 break;
6490
6491 case OO_Conditional:
6492 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006493 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006494
6495 case OO_None:
6496 case NUM_OVERLOADED_OPERATORS:
6497 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006498 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006499 }
6500
John McCalldadc5752010-08-24 06:29:42 +00006501 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006502 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006503 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006504
John McCalldadc5752010-08-24 06:29:42 +00006505 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006506 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006507 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006508
John McCalldadc5752010-08-24 06:29:42 +00006509 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006510 if (E->getNumArgs() == 2) {
6511 Second = getDerived().TransformExpr(E->getArg(1));
6512 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006513 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006514 }
Mike Stump11289f42009-09-09 15:08:12 +00006515
Douglas Gregora16548e2009-08-11 05:31:07 +00006516 if (!getDerived().AlwaysRebuild() &&
6517 Callee.get() == E->getCallee() &&
6518 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006519 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006520 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006521
Douglas Gregora16548e2009-08-11 05:31:07 +00006522 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6523 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006524 Callee.get(),
6525 First.get(),
6526 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006527}
Mike Stump11289f42009-09-09 15:08:12 +00006528
Douglas Gregora16548e2009-08-11 05:31:07 +00006529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006530ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006531TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6532 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006533}
Mike Stump11289f42009-09-09 15:08:12 +00006534
Douglas Gregora16548e2009-08-11 05:31:07 +00006535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006536ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006537TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6538 // Transform the callee.
6539 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6540 if (Callee.isInvalid())
6541 return ExprError();
6542
6543 // Transform exec config.
6544 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6545 if (EC.isInvalid())
6546 return ExprError();
6547
6548 // Transform arguments.
6549 bool ArgChanged = false;
6550 ASTOwningVector<Expr*> Args(SemaRef);
6551 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6552 &ArgChanged))
6553 return ExprError();
6554
6555 if (!getDerived().AlwaysRebuild() &&
6556 Callee.get() == E->getCallee() &&
6557 !ArgChanged)
6558 return SemaRef.Owned(E);
6559
6560 // FIXME: Wrong source location information for the '('.
6561 SourceLocation FakeLParenLoc
6562 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6563 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6564 move_arg(Args),
6565 E->getRParenLoc(), EC.get());
6566}
6567
6568template<typename Derived>
6569ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006570TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006571 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6572 if (!Type)
6573 return ExprError();
6574
John McCalldadc5752010-08-24 06:29:42 +00006575 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006576 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006577 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006578 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006579
Douglas Gregora16548e2009-08-11 05:31:07 +00006580 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006581 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006582 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006583 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006584
Douglas Gregora16548e2009-08-11 05:31:07 +00006585 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006586 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006587 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6588 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6589 SourceLocation FakeRParenLoc
6590 = SemaRef.PP.getLocForEndOfToken(
6591 E->getSubExpr()->getSourceRange().getEnd());
6592 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006593 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006594 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006595 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006596 FakeRAngleLoc,
6597 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006598 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006599 FakeRParenLoc);
6600}
Mike Stump11289f42009-09-09 15:08:12 +00006601
Douglas Gregora16548e2009-08-11 05:31:07 +00006602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006603ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006604TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6605 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006606}
Mike Stump11289f42009-09-09 15:08:12 +00006607
6608template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006609ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006610TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6611 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006612}
6613
Douglas Gregora16548e2009-08-11 05:31:07 +00006614template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006615ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006616TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006617 CXXReinterpretCastExpr *E) {
6618 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006619}
Mike Stump11289f42009-09-09 15:08:12 +00006620
Douglas Gregora16548e2009-08-11 05:31:07 +00006621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006622ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006623TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6624 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006625}
Mike Stump11289f42009-09-09 15:08:12 +00006626
Douglas Gregora16548e2009-08-11 05:31:07 +00006627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006628ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006629TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006630 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006631 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6632 if (!Type)
6633 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006634
John McCalldadc5752010-08-24 06:29:42 +00006635 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006636 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006637 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006638 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006639
Douglas Gregora16548e2009-08-11 05:31:07 +00006640 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006641 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006642 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006643 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006644
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006645 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006646 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006647 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006648 E->getRParenLoc());
6649}
Mike Stump11289f42009-09-09 15:08:12 +00006650
Douglas Gregora16548e2009-08-11 05:31:07 +00006651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006652ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006653TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006654 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006655 TypeSourceInfo *TInfo
6656 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6657 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006659
Douglas Gregora16548e2009-08-11 05:31:07 +00006660 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006661 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006662 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006663
Douglas Gregor9da64192010-04-26 22:37:10 +00006664 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6665 E->getLocStart(),
6666 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006667 E->getLocEnd());
6668 }
Mike Stump11289f42009-09-09 15:08:12 +00006669
Douglas Gregora16548e2009-08-11 05:31:07 +00006670 // We don't know whether the expression is potentially evaluated until
6671 // after we perform semantic analysis, so the expression is potentially
6672 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006673 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006674 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006675
John McCalldadc5752010-08-24 06:29:42 +00006676 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006677 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006678 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006679
Douglas Gregora16548e2009-08-11 05:31:07 +00006680 if (!getDerived().AlwaysRebuild() &&
6681 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006682 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006683
Douglas Gregor9da64192010-04-26 22:37:10 +00006684 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6685 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006686 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006687 E->getLocEnd());
6688}
6689
6690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006691ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006692TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6693 if (E->isTypeOperand()) {
6694 TypeSourceInfo *TInfo
6695 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6696 if (!TInfo)
6697 return ExprError();
6698
6699 if (!getDerived().AlwaysRebuild() &&
6700 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006701 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006702
Douglas Gregor69735112011-03-06 17:40:41 +00006703 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006704 E->getLocStart(),
6705 TInfo,
6706 E->getLocEnd());
6707 }
6708
6709 // We don't know whether the expression is potentially evaluated until
6710 // after we perform semantic analysis, so the expression is potentially
6711 // potentially evaluated.
6712 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6713
6714 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6715 if (SubExpr.isInvalid())
6716 return ExprError();
6717
6718 if (!getDerived().AlwaysRebuild() &&
6719 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006720 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006721
6722 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6723 E->getLocStart(),
6724 SubExpr.get(),
6725 E->getLocEnd());
6726}
6727
6728template<typename Derived>
6729ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006730TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006731 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006732}
Mike Stump11289f42009-09-09 15:08:12 +00006733
Douglas Gregora16548e2009-08-11 05:31:07 +00006734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006735ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006736TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006737 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006738 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006739}
Mike Stump11289f42009-09-09 15:08:12 +00006740
Douglas Gregora16548e2009-08-11 05:31:07 +00006741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006742ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006743TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006744 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith938f40b2011-06-11 17:19:42 +00006745 QualType T;
6746 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6747 T = MD->getThisType(getSema().Context);
6748 else
6749 T = getSema().Context.getPointerType(
6750 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump11289f42009-09-09 15:08:12 +00006751
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006752 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006753 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006754
Douglas Gregorb15af892010-01-07 23:12:05 +00006755 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006756}
Mike Stump11289f42009-09-09 15:08:12 +00006757
Douglas Gregora16548e2009-08-11 05:31:07 +00006758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006759ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006760TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006761 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006762 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006763 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006764
Douglas Gregora16548e2009-08-11 05:31:07 +00006765 if (!getDerived().AlwaysRebuild() &&
6766 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006767 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006768
John McCallb268a282010-08-23 23:25:46 +00006769 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006770}
Mike Stump11289f42009-09-09 15:08:12 +00006771
Douglas Gregora16548e2009-08-11 05:31:07 +00006772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006773ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006774TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006775 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006776 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6777 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006778 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006779 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006780
Chandler Carruth794da4c2010-02-08 06:42:49 +00006781 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006782 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006783 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006784
Douglas Gregor033f6752009-12-23 23:03:06 +00006785 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006786}
Mike Stump11289f42009-09-09 15:08:12 +00006787
Douglas Gregora16548e2009-08-11 05:31:07 +00006788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006789ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006790TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6791 CXXScalarValueInitExpr *E) {
6792 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6793 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006794 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006795
Douglas Gregora16548e2009-08-11 05:31:07 +00006796 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006797 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006798 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006799
Douglas Gregor2b88c112010-09-08 00:15:04 +00006800 return getDerived().RebuildCXXScalarValueInitExpr(T,
6801 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006802 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006803}
Mike Stump11289f42009-09-09 15:08:12 +00006804
Douglas Gregora16548e2009-08-11 05:31:07 +00006805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006806ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006807TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006808 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006809 TypeSourceInfo *AllocTypeInfo
6810 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6811 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006813
Douglas Gregora16548e2009-08-11 05:31:07 +00006814 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006815 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006816 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006817 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006818
Douglas Gregora16548e2009-08-11 05:31:07 +00006819 // Transform the placement arguments (if any).
6820 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006821 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006822 if (getDerived().TransformExprs(E->getPlacementArgs(),
6823 E->getNumPlacementArgs(), true,
6824 PlacementArgs, &ArgumentChanged))
6825 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006826
Douglas Gregorebe10102009-08-20 07:17:43 +00006827 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006828 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006829 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6830 ConstructorArgs, &ArgumentChanged))
6831 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006832
Douglas Gregord2d9da02010-02-26 00:38:10 +00006833 // Transform constructor, new operator, and delete operator.
6834 CXXConstructorDecl *Constructor = 0;
6835 if (E->getConstructor()) {
6836 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006837 getDerived().TransformDecl(E->getLocStart(),
6838 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006839 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006840 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006841 }
6842
6843 FunctionDecl *OperatorNew = 0;
6844 if (E->getOperatorNew()) {
6845 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006846 getDerived().TransformDecl(E->getLocStart(),
6847 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006848 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006849 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006850 }
6851
6852 FunctionDecl *OperatorDelete = 0;
6853 if (E->getOperatorDelete()) {
6854 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006855 getDerived().TransformDecl(E->getLocStart(),
6856 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006857 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006858 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006859 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006860
Douglas Gregora16548e2009-08-11 05:31:07 +00006861 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006862 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006863 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006864 Constructor == E->getConstructor() &&
6865 OperatorNew == E->getOperatorNew() &&
6866 OperatorDelete == E->getOperatorDelete() &&
6867 !ArgumentChanged) {
6868 // Mark any declarations we need as referenced.
6869 // FIXME: instantiation-specific.
6870 if (Constructor)
6871 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6872 if (OperatorNew)
6873 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6874 if (OperatorDelete)
6875 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006876 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006877 }
Mike Stump11289f42009-09-09 15:08:12 +00006878
Douglas Gregor0744ef62010-09-07 21:49:58 +00006879 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006880 if (!ArraySize.get()) {
6881 // If no array size was specified, but the new expression was
6882 // instantiated with an array type (e.g., "new T" where T is
6883 // instantiated with "int[4]"), extract the outer bound from the
6884 // array type as our array size. We do this with constant and
6885 // dependently-sized array types.
6886 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6887 if (!ArrayT) {
6888 // Do nothing
6889 } else if (const ConstantArrayType *ConsArrayT
6890 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006891 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006892 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6893 ConsArrayT->getSize(),
6894 SemaRef.Context.getSizeType(),
6895 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006896 AllocType = ConsArrayT->getElementType();
6897 } else if (const DependentSizedArrayType *DepArrayT
6898 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6899 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006900 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006901 AllocType = DepArrayT->getElementType();
6902 }
6903 }
6904 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006905
Douglas Gregora16548e2009-08-11 05:31:07 +00006906 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6907 E->isGlobalNew(),
6908 /*FIXME:*/E->getLocStart(),
6909 move_arg(PlacementArgs),
6910 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006911 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006912 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006913 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006914 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006915 /*FIXME:*/E->getLocStart(),
6916 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006917 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006918}
Mike Stump11289f42009-09-09 15:08:12 +00006919
Douglas Gregora16548e2009-08-11 05:31:07 +00006920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006922TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006923 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006924 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006925 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006926
Douglas Gregord2d9da02010-02-26 00:38:10 +00006927 // Transform the delete operator, if known.
6928 FunctionDecl *OperatorDelete = 0;
6929 if (E->getOperatorDelete()) {
6930 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006931 getDerived().TransformDecl(E->getLocStart(),
6932 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006933 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006934 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006935 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006936
Douglas Gregora16548e2009-08-11 05:31:07 +00006937 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006938 Operand.get() == E->getArgument() &&
6939 OperatorDelete == E->getOperatorDelete()) {
6940 // Mark any declarations we need as referenced.
6941 // FIXME: instantiation-specific.
6942 if (OperatorDelete)
6943 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006944
6945 if (!E->getArgument()->isTypeDependent()) {
6946 QualType Destroyed = SemaRef.Context.getBaseElementType(
6947 E->getDestroyedType());
6948 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6949 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6950 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6951 SemaRef.LookupDestructor(Record));
6952 }
6953 }
6954
John McCallc3007a22010-10-26 07:05:15 +00006955 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006956 }
Mike Stump11289f42009-09-09 15:08:12 +00006957
Douglas Gregora16548e2009-08-11 05:31:07 +00006958 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6959 E->isGlobalDelete(),
6960 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006961 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006962}
Mike Stump11289f42009-09-09 15:08:12 +00006963
Douglas Gregora16548e2009-08-11 05:31:07 +00006964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006965ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006966TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006967 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006968 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006969 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006971
John McCallba7bf592010-08-24 05:47:05 +00006972 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006973 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006974 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006975 E->getOperatorLoc(),
6976 E->isArrow()? tok::arrow : tok::period,
6977 ObjectTypePtr,
6978 MayBePseudoDestructor);
6979 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006980 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006981
John McCallba7bf592010-08-24 05:47:05 +00006982 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006983 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6984 if (QualifierLoc) {
6985 QualifierLoc
6986 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6987 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006988 return ExprError();
6989 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006990 CXXScopeSpec SS;
6991 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006992
Douglas Gregor678f90d2010-02-25 01:56:36 +00006993 PseudoDestructorTypeStorage Destroyed;
6994 if (E->getDestroyedTypeInfo()) {
6995 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006996 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00006997 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006998 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006999 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007000 Destroyed = DestroyedTypeInfo;
7001 } else if (ObjectType->isDependentType()) {
7002 // We aren't likely to be able to resolve the identifier down to a type
7003 // now anyway, so just retain the identifier.
7004 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7005 E->getDestroyedTypeLoc());
7006 } else {
7007 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007008 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007009 *E->getDestroyedTypeIdentifier(),
7010 E->getDestroyedTypeLoc(),
7011 /*Scope=*/0,
7012 SS, ObjectTypePtr,
7013 false);
7014 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007015 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007016
Douglas Gregor678f90d2010-02-25 01:56:36 +00007017 Destroyed
7018 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7019 E->getDestroyedTypeLoc());
7020 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007021
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007022 TypeSourceInfo *ScopeTypeInfo = 0;
7023 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00007024 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007025 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007026 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007027 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007028
John McCallb268a282010-08-23 23:25:46 +00007029 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007030 E->getOperatorLoc(),
7031 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007032 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007033 ScopeTypeInfo,
7034 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007035 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007036 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007037}
Mike Stump11289f42009-09-09 15:08:12 +00007038
Douglas Gregorad8a3362009-09-04 17:36:40 +00007039template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007040ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007041TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007042 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007043 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7044 Sema::LookupOrdinaryName);
7045
7046 // Transform all the decls.
7047 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7048 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007049 NamedDecl *InstD = static_cast<NamedDecl*>(
7050 getDerived().TransformDecl(Old->getNameLoc(),
7051 *I));
John McCall84d87672009-12-10 09:41:52 +00007052 if (!InstD) {
7053 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7054 // This can happen because of dependent hiding.
7055 if (isa<UsingShadowDecl>(*I))
7056 continue;
7057 else
John McCallfaf5fb42010-08-26 23:41:50 +00007058 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007059 }
John McCalle66edc12009-11-24 19:00:30 +00007060
7061 // Expand using declarations.
7062 if (isa<UsingDecl>(InstD)) {
7063 UsingDecl *UD = cast<UsingDecl>(InstD);
7064 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7065 E = UD->shadow_end(); I != E; ++I)
7066 R.addDecl(*I);
7067 continue;
7068 }
7069
7070 R.addDecl(InstD);
7071 }
7072
7073 // Resolve a kind, but don't do any further analysis. If it's
7074 // ambiguous, the callee needs to deal with it.
7075 R.resolveKind();
7076
7077 // Rebuild the nested-name qualifier, if present.
7078 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007079 if (Old->getQualifierLoc()) {
7080 NestedNameSpecifierLoc QualifierLoc
7081 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7082 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007083 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007084
Douglas Gregor0da1d432011-02-28 20:01:57 +00007085 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007086 }
7087
Douglas Gregor9262f472010-04-27 18:19:34 +00007088 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007089 CXXRecordDecl *NamingClass
7090 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7091 Old->getNameLoc(),
7092 Old->getNamingClass()));
7093 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007094 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007095
Douglas Gregorda7be082010-04-27 16:10:10 +00007096 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007097 }
7098
7099 // If we have no template arguments, it's a normal declaration name.
7100 if (!Old->hasExplicitTemplateArgs())
7101 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7102
7103 // If we have template arguments, rebuild them, then rebuild the
7104 // templateid expression.
7105 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007106 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7107 Old->getNumTemplateArgs(),
7108 TransArgs))
7109 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007110
7111 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7112 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007113}
Mike Stump11289f42009-09-09 15:08:12 +00007114
Douglas Gregora16548e2009-08-11 05:31:07 +00007115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007116ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007117TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007118 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7119 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007120 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007121
Douglas Gregora16548e2009-08-11 05:31:07 +00007122 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007123 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007124 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007125
Mike Stump11289f42009-09-09 15:08:12 +00007126 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007127 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007128 T,
7129 E->getLocEnd());
7130}
Mike Stump11289f42009-09-09 15:08:12 +00007131
Douglas Gregora16548e2009-08-11 05:31:07 +00007132template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007133ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007134TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7135 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7136 if (!LhsT)
7137 return ExprError();
7138
7139 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7140 if (!RhsT)
7141 return ExprError();
7142
7143 if (!getDerived().AlwaysRebuild() &&
7144 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7145 return SemaRef.Owned(E);
7146
7147 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7148 E->getLocStart(),
7149 LhsT, RhsT,
7150 E->getLocEnd());
7151}
7152
7153template<typename Derived>
7154ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007155TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7156 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7157 if (!T)
7158 return ExprError();
7159
7160 if (!getDerived().AlwaysRebuild() &&
7161 T == E->getQueriedTypeSourceInfo())
7162 return SemaRef.Owned(E);
7163
7164 ExprResult SubExpr;
7165 {
7166 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7167 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7168 if (SubExpr.isInvalid())
7169 return ExprError();
7170
7171 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7172 return SemaRef.Owned(E);
7173 }
7174
7175 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7176 E->getLocStart(),
7177 T,
7178 SubExpr.get(),
7179 E->getLocEnd());
7180}
7181
7182template<typename Derived>
7183ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007184TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7185 ExprResult SubExpr;
7186 {
7187 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7188 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7189 if (SubExpr.isInvalid())
7190 return ExprError();
7191
7192 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7193 return SemaRef.Owned(E);
7194 }
7195
7196 return getDerived().RebuildExpressionTrait(
7197 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7198}
7199
7200template<typename Derived>
7201ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007202TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007203 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007204 NestedNameSpecifierLoc QualifierLoc
7205 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7206 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007207 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007208
John McCall31f82722010-11-12 08:19:04 +00007209 // TODO: If this is a conversion-function-id, verify that the
7210 // destination type name (if present) resolves the same way after
7211 // instantiation as it did in the local scope.
7212
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007213 DeclarationNameInfo NameInfo
7214 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7215 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007216 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007217
John McCalle66edc12009-11-24 19:00:30 +00007218 if (!E->hasExplicitTemplateArgs()) {
7219 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007220 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007221 // Note: it is sufficient to compare the Name component of NameInfo:
7222 // if name has not changed, DNLoc has not changed either.
7223 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007224 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007225
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007226 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007227 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007228 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007229 }
John McCall6b51f282009-11-23 01:53:49 +00007230
7231 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007232 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7233 E->getNumTemplateArgs(),
7234 TransArgs))
7235 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007236
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007237 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007238 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007239 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007240}
7241
7242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007243ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007244TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007245 // CXXConstructExprs are always implicit, so when we have a
7246 // 1-argument construction we just transform that argument.
7247 if (E->getNumArgs() == 1 ||
7248 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7249 return getDerived().TransformExpr(E->getArg(0));
7250
Douglas Gregora16548e2009-08-11 05:31:07 +00007251 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7252
7253 QualType T = getDerived().TransformType(E->getType());
7254 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007255 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007256
7257 CXXConstructorDecl *Constructor
7258 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007259 getDerived().TransformDecl(E->getLocStart(),
7260 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007261 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007262 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007263
Douglas Gregora16548e2009-08-11 05:31:07 +00007264 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007265 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007266 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7267 &ArgumentChanged))
7268 return ExprError();
7269
Douglas Gregora16548e2009-08-11 05:31:07 +00007270 if (!getDerived().AlwaysRebuild() &&
7271 T == E->getType() &&
7272 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007273 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007274 // Mark the constructor as referenced.
7275 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007276 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007277 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007278 }
Mike Stump11289f42009-09-09 15:08:12 +00007279
Douglas Gregordb121ba2009-12-14 16:27:04 +00007280 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7281 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007282 move_arg(Args),
7283 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007284 E->getConstructionKind(),
7285 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007286}
Mike Stump11289f42009-09-09 15:08:12 +00007287
Douglas Gregora16548e2009-08-11 05:31:07 +00007288/// \brief Transform a C++ temporary-binding expression.
7289///
Douglas Gregor363b1512009-12-24 18:51:59 +00007290/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7291/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007292template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007293ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007294TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007295 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007296}
Mike Stump11289f42009-09-09 15:08:12 +00007297
John McCall5d413782010-12-06 08:20:24 +00007298/// \brief Transform a C++ expression that contains cleanups that should
7299/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007300///
John McCall5d413782010-12-06 08:20:24 +00007301/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007302/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007303template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007304ExprResult
John McCall5d413782010-12-06 08:20:24 +00007305TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007306 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007307}
Mike Stump11289f42009-09-09 15:08:12 +00007308
Douglas Gregora16548e2009-08-11 05:31:07 +00007309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007310ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007311TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007312 CXXTemporaryObjectExpr *E) {
7313 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7314 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007316
Douglas Gregora16548e2009-08-11 05:31:07 +00007317 CXXConstructorDecl *Constructor
7318 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007319 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007320 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007321 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007322 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007323
Douglas Gregora16548e2009-08-11 05:31:07 +00007324 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007325 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007326 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007327 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7328 &ArgumentChanged))
7329 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007330
Douglas Gregora16548e2009-08-11 05:31:07 +00007331 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007332 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007333 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007334 !ArgumentChanged) {
7335 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007336 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007337 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007338 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007339
7340 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7341 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007342 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007343 E->getLocEnd());
7344}
Mike Stump11289f42009-09-09 15:08:12 +00007345
Douglas Gregora16548e2009-08-11 05:31:07 +00007346template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007347ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007348TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007349 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007350 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7351 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007353
Douglas Gregora16548e2009-08-11 05:31:07 +00007354 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007355 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007356 Args.reserve(E->arg_size());
7357 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7358 &ArgumentChanged))
7359 return ExprError();
7360
Douglas Gregora16548e2009-08-11 05:31:07 +00007361 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007362 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007363 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007364 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007365
Douglas Gregora16548e2009-08-11 05:31:07 +00007366 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007367 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007368 E->getLParenLoc(),
7369 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007370 E->getRParenLoc());
7371}
Mike Stump11289f42009-09-09 15:08:12 +00007372
Douglas Gregora16548e2009-08-11 05:31:07 +00007373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007374ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007375TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007376 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007377 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007378 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007379 Expr *OldBase;
7380 QualType BaseType;
7381 QualType ObjectType;
7382 if (!E->isImplicitAccess()) {
7383 OldBase = E->getBase();
7384 Base = getDerived().TransformExpr(OldBase);
7385 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007386 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007387
John McCall2d74de92009-12-01 22:10:20 +00007388 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007389 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007390 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007391 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007392 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007393 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007394 ObjectTy,
7395 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007396 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007397 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007398
John McCallba7bf592010-08-24 05:47:05 +00007399 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007400 BaseType = ((Expr*) Base.get())->getType();
7401 } else {
7402 OldBase = 0;
7403 BaseType = getDerived().TransformType(E->getBaseType());
7404 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7405 }
Mike Stump11289f42009-09-09 15:08:12 +00007406
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007407 // Transform the first part of the nested-name-specifier that qualifies
7408 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007409 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007410 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007411 E->getFirstQualifierFoundInScope(),
7412 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007413
Douglas Gregore16af532011-02-28 18:50:33 +00007414 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007415 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007416 QualifierLoc
7417 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7418 ObjectType,
7419 FirstQualifierInScope);
7420 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007421 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007422 }
Mike Stump11289f42009-09-09 15:08:12 +00007423
John McCall31f82722010-11-12 08:19:04 +00007424 // TODO: If this is a conversion-function-id, verify that the
7425 // destination type name (if present) resolves the same way after
7426 // instantiation as it did in the local scope.
7427
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007428 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007429 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007430 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007431 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007432
John McCall2d74de92009-12-01 22:10:20 +00007433 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007434 // This is a reference to a member without an explicitly-specified
7435 // template argument list. Optimize for this common case.
7436 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007437 Base.get() == OldBase &&
7438 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007439 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007440 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007441 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007442 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007443
John McCallb268a282010-08-23 23:25:46 +00007444 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007445 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007446 E->isArrow(),
7447 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007448 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007449 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007450 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007451 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007452 }
7453
John McCall6b51f282009-11-23 01:53:49 +00007454 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007455 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7456 E->getNumTemplateArgs(),
7457 TransArgs))
7458 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007459
John McCallb268a282010-08-23 23:25:46 +00007460 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007461 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007462 E->isArrow(),
7463 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007464 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007465 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007466 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007467 &TransArgs);
7468}
7469
7470template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007471ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007472TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007473 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007474 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007475 QualType BaseType;
7476 if (!Old->isImplicitAccess()) {
7477 Base = getDerived().TransformExpr(Old->getBase());
7478 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007479 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007480 BaseType = ((Expr*) Base.get())->getType();
7481 } else {
7482 BaseType = getDerived().TransformType(Old->getBaseType());
7483 }
John McCall10eae182009-11-30 22:42:35 +00007484
Douglas Gregor0da1d432011-02-28 20:01:57 +00007485 NestedNameSpecifierLoc QualifierLoc;
7486 if (Old->getQualifierLoc()) {
7487 QualifierLoc
7488 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7489 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007490 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007491 }
7492
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007493 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007494 Sema::LookupOrdinaryName);
7495
7496 // Transform all the decls.
7497 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7498 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007499 NamedDecl *InstD = static_cast<NamedDecl*>(
7500 getDerived().TransformDecl(Old->getMemberLoc(),
7501 *I));
John McCall84d87672009-12-10 09:41:52 +00007502 if (!InstD) {
7503 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7504 // This can happen because of dependent hiding.
7505 if (isa<UsingShadowDecl>(*I))
7506 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007507 else {
7508 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007509 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007510 }
John McCall84d87672009-12-10 09:41:52 +00007511 }
John McCall10eae182009-11-30 22:42:35 +00007512
7513 // Expand using declarations.
7514 if (isa<UsingDecl>(InstD)) {
7515 UsingDecl *UD = cast<UsingDecl>(InstD);
7516 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7517 E = UD->shadow_end(); I != E; ++I)
7518 R.addDecl(*I);
7519 continue;
7520 }
7521
7522 R.addDecl(InstD);
7523 }
7524
7525 R.resolveKind();
7526
Douglas Gregor9262f472010-04-27 18:19:34 +00007527 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007528 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007529 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007530 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007531 Old->getMemberLoc(),
7532 Old->getNamingClass()));
7533 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007534 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007535
Douglas Gregorda7be082010-04-27 16:10:10 +00007536 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007537 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007538
John McCall10eae182009-11-30 22:42:35 +00007539 TemplateArgumentListInfo TransArgs;
7540 if (Old->hasExplicitTemplateArgs()) {
7541 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7542 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007543 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7544 Old->getNumTemplateArgs(),
7545 TransArgs))
7546 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007547 }
John McCall38836f02010-01-15 08:34:02 +00007548
7549 // FIXME: to do this check properly, we will need to preserve the
7550 // first-qualifier-in-scope here, just in case we had a dependent
7551 // base (and therefore couldn't do the check) and a
7552 // nested-name-qualifier (and therefore could do the lookup).
7553 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007554
John McCallb268a282010-08-23 23:25:46 +00007555 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007556 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007557 Old->getOperatorLoc(),
7558 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007559 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007560 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007561 R,
7562 (Old->hasExplicitTemplateArgs()
7563 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007564}
7565
7566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007567ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007568TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00007569 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007570 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7571 if (SubExpr.isInvalid())
7572 return ExprError();
7573
7574 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007575 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007576
7577 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7578}
7579
7580template<typename Derived>
7581ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007582TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007583 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7584 if (Pattern.isInvalid())
7585 return ExprError();
7586
7587 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7588 return SemaRef.Owned(E);
7589
Douglas Gregorb8840002011-01-14 21:20:45 +00007590 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7591 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007592}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007593
7594template<typename Derived>
7595ExprResult
7596TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7597 // If E is not value-dependent, then nothing will change when we transform it.
7598 // Note: This is an instantiation-centric view.
7599 if (!E->isValueDependent())
7600 return SemaRef.Owned(E);
7601
7602 // Note: None of the implementations of TryExpandParameterPacks can ever
7603 // produce a diagnostic when given only a single unexpanded parameter pack,
7604 // so
7605 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7606 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007607 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007608 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007609 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7610 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007611 ShouldExpand, RetainExpansion,
7612 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007613 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007614
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007615 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007616 return SemaRef.Owned(E);
7617
7618 // We now know the length of the parameter pack, so build a new expression
7619 // that stores that length.
7620 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7621 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007622 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007623}
7624
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007625template<typename Derived>
7626ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007627TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7628 SubstNonTypeTemplateParmPackExpr *E) {
7629 // Default behavior is to do nothing with this transformation.
7630 return SemaRef.Owned(E);
7631}
7632
7633template<typename Derived>
7634ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007635TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007636 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007637}
7638
Mike Stump11289f42009-09-09 15:08:12 +00007639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007640ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007641TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007642 TypeSourceInfo *EncodedTypeInfo
7643 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7644 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007646
Douglas Gregora16548e2009-08-11 05:31:07 +00007647 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007648 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007649 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007650
7651 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007652 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007653 E->getRParenLoc());
7654}
Mike Stump11289f42009-09-09 15:08:12 +00007655
Douglas Gregora16548e2009-08-11 05:31:07 +00007656template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00007657ExprResult TreeTransform<Derived>::
7658TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7659 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7660 if (result.isInvalid()) return ExprError();
7661 Expr *subExpr = result.take();
7662
7663 if (!getDerived().AlwaysRebuild() &&
7664 subExpr == E->getSubExpr())
7665 return SemaRef.Owned(E);
7666
7667 return SemaRef.Owned(new(SemaRef.Context)
7668 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7669}
7670
7671template<typename Derived>
7672ExprResult TreeTransform<Derived>::
7673TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7674 TypeSourceInfo *TSInfo
7675 = getDerived().TransformType(E->getTypeInfoAsWritten());
7676 if (!TSInfo)
7677 return ExprError();
7678
7679 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7680 if (Result.isInvalid())
7681 return ExprError();
7682
7683 if (!getDerived().AlwaysRebuild() &&
7684 TSInfo == E->getTypeInfoAsWritten() &&
7685 Result.get() == E->getSubExpr())
7686 return SemaRef.Owned(E);
7687
7688 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7689 E->getBridgeKeywordLoc(), TSInfo,
7690 Result.get());
7691}
7692
7693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007694ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007695TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007696 // Transform arguments.
7697 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007698 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007699 Args.reserve(E->getNumArgs());
7700 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7701 &ArgChanged))
7702 return ExprError();
7703
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007704 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7705 // Class message: transform the receiver type.
7706 TypeSourceInfo *ReceiverTypeInfo
7707 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7708 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007709 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007710
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007711 // If nothing changed, just retain the existing message send.
7712 if (!getDerived().AlwaysRebuild() &&
7713 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007714 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007715
7716 // Build a new class message send.
7717 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7718 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007719 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007720 E->getMethodDecl(),
7721 E->getLeftLoc(),
7722 move_arg(Args),
7723 E->getRightLoc());
7724 }
7725
7726 // Instance message: transform the receiver
7727 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7728 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007729 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007730 = getDerived().TransformExpr(E->getInstanceReceiver());
7731 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007732 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007733
7734 // If nothing changed, just retain the existing message send.
7735 if (!getDerived().AlwaysRebuild() &&
7736 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007737 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007738
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007739 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007740 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007741 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007742 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007743 E->getMethodDecl(),
7744 E->getLeftLoc(),
7745 move_arg(Args),
7746 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007747}
7748
Mike Stump11289f42009-09-09 15:08:12 +00007749template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007750ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007751TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007752 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007753}
7754
Mike Stump11289f42009-09-09 15:08:12 +00007755template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007756ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007757TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007758 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007759}
7760
Mike Stump11289f42009-09-09 15:08:12 +00007761template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007762ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007763TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007764 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007765 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007766 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007767 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007768
7769 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007770
Douglas Gregord51d90d2010-04-26 20:11:03 +00007771 // If nothing changed, just retain the existing expression.
7772 if (!getDerived().AlwaysRebuild() &&
7773 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007774 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007775
John McCallb268a282010-08-23 23:25:46 +00007776 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007777 E->getLocation(),
7778 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007779}
7780
Mike Stump11289f42009-09-09 15:08:12 +00007781template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007782ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007783TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007784 // 'super' and types never change. Property never changes. Just
7785 // retain the existing expression.
7786 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007787 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007788
Douglas Gregor9faee212010-04-26 20:47:02 +00007789 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007790 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007791 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007792 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007793
Douglas Gregor9faee212010-04-26 20:47:02 +00007794 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007795
Douglas Gregor9faee212010-04-26 20:47:02 +00007796 // If nothing changed, just retain the existing expression.
7797 if (!getDerived().AlwaysRebuild() &&
7798 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007799 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007800
John McCallb7bd14f2010-12-02 01:19:52 +00007801 if (E->isExplicitProperty())
7802 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7803 E->getExplicitProperty(),
7804 E->getLocation());
7805
7806 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7807 E->getType(),
7808 E->getImplicitPropertyGetter(),
7809 E->getImplicitPropertySetter(),
7810 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007811}
7812
Mike Stump11289f42009-09-09 15:08:12 +00007813template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007814ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007815TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007816 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007817 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007818 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007819 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007820
Douglas Gregord51d90d2010-04-26 20:11:03 +00007821 // If nothing changed, just retain the existing expression.
7822 if (!getDerived().AlwaysRebuild() &&
7823 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007824 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007825
John McCallb268a282010-08-23 23:25:46 +00007826 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007827 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007828}
7829
Mike Stump11289f42009-09-09 15:08:12 +00007830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007831ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007832TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007833 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007834 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007835 SubExprs.reserve(E->getNumSubExprs());
7836 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7837 SubExprs, &ArgumentChanged))
7838 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007839
Douglas Gregora16548e2009-08-11 05:31:07 +00007840 if (!getDerived().AlwaysRebuild() &&
7841 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007842 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007843
Douglas Gregora16548e2009-08-11 05:31:07 +00007844 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7845 move_arg(SubExprs),
7846 E->getRParenLoc());
7847}
7848
Mike Stump11289f42009-09-09 15:08:12 +00007849template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007850ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007851TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007852 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007853
John McCall490112f2011-02-04 18:33:18 +00007854 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7855 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7856
7857 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00007858 // We built a new blockScopeInfo in call to ActOnBlockStart
7859 // in above, CapturesCXXThis need be set here from the block
7860 // expression.
7861 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7862
John McCall490112f2011-02-04 18:33:18 +00007863 llvm::SmallVector<ParmVarDecl*, 4> params;
7864 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007865
7866 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007867 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7868 oldBlock->param_begin(),
7869 oldBlock->param_size(),
7870 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007871 return true;
John McCall490112f2011-02-04 18:33:18 +00007872
7873 const FunctionType *exprFunctionType = E->getFunctionType();
7874 QualType exprResultType = exprFunctionType->getResultType();
7875 if (!exprResultType.isNull()) {
7876 if (!exprResultType->isDependentType())
7877 blockScope->ReturnType = exprResultType;
7878 else if (exprResultType != getSema().Context.DependentTy)
7879 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007880 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007881
7882 // If the return type has not been determined yet, leave it as a dependent
7883 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007884 if (blockScope->ReturnType.isNull())
7885 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007886
7887 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007888 if (blockScope->ReturnType->isObjCObjectType()) {
7889 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007890 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007891 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007892 return ExprError();
7893 }
John McCall3882ace2011-01-05 12:14:39 +00007894
John McCall490112f2011-02-04 18:33:18 +00007895 QualType functionType = getDerived().RebuildFunctionProtoType(
7896 blockScope->ReturnType,
7897 paramTypes.data(),
7898 paramTypes.size(),
7899 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007900 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007901 exprFunctionType->getExtInfo());
7902 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007903
7904 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007905 if (!params.empty())
7906 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007907
7908 // If the return type wasn't explicitly set, it will have been marked as a
7909 // dependent type (DependentTy); clear out the return type setting so
7910 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007911 if (blockScope->ReturnType == getSema().Context.DependentTy)
7912 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007913
John McCall3882ace2011-01-05 12:14:39 +00007914 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007915 StmtResult body = getDerived().TransformStmt(E->getBody());
7916 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007917 return ExprError();
7918
John McCall490112f2011-02-04 18:33:18 +00007919#ifndef NDEBUG
7920 // In builds with assertions, make sure that we captured everything we
7921 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007922 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
7923 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7924 e = oldBlock->capture_end(); i != e; ++i) {
7925 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007926
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007927 // Ignore parameter packs.
7928 if (isa<ParmVarDecl>(oldCapture) &&
7929 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7930 continue;
John McCall490112f2011-02-04 18:33:18 +00007931
Douglas Gregor4385d8b2011-05-20 15:32:55 +00007932 VarDecl *newCapture =
7933 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7934 oldCapture));
7935 assert(blockScope->CaptureMap.count(newCapture));
7936 }
John McCall490112f2011-02-04 18:33:18 +00007937 }
7938#endif
7939
7940 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7941 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007942}
7943
Mike Stump11289f42009-09-09 15:08:12 +00007944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007945ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007946TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007947 ValueDecl *ND
7948 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7949 E->getDecl()));
7950 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007951 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007952
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007953 if (!getDerived().AlwaysRebuild() &&
7954 ND == E->getDecl()) {
7955 // Mark it referenced in the new context regardless.
7956 // FIXME: this is a bit instantiation-specific.
7957 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7958
John McCallc3007a22010-10-26 07:05:15 +00007959 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007960 }
7961
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007962 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007963 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007964 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007965}
Mike Stump11289f42009-09-09 15:08:12 +00007966
Tanya Lattner55808c12011-06-04 00:47:47 +00007967template<typename Derived>
7968ExprResult
7969TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
7970 assert(false && "Cannot transform asType expressions yet");
7971 return SemaRef.Owned(E);
7972}
7973
Douglas Gregora16548e2009-08-11 05:31:07 +00007974//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007975// Type reconstruction
7976//===----------------------------------------------------------------------===//
7977
Mike Stump11289f42009-09-09 15:08:12 +00007978template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007979QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7980 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007981 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007982 getDerived().getBaseEntity());
7983}
7984
Mike Stump11289f42009-09-09 15:08:12 +00007985template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007986QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7987 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007988 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007989 getDerived().getBaseEntity());
7990}
7991
Mike Stump11289f42009-09-09 15:08:12 +00007992template<typename Derived>
7993QualType
John McCall70dd5f62009-10-30 00:06:24 +00007994TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7995 bool WrittenAsLValue,
7996 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007997 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007998 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007999}
8000
8001template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008002QualType
John McCall70dd5f62009-10-30 00:06:24 +00008003TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8004 QualType ClassType,
8005 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008006 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00008007 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008008}
8009
8010template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008011QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00008012TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8013 ArrayType::ArraySizeModifier SizeMod,
8014 const llvm::APInt *Size,
8015 Expr *SizeExpr,
8016 unsigned IndexTypeQuals,
8017 SourceRange BracketsRange) {
8018 if (SizeExpr || !Size)
8019 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8020 IndexTypeQuals, BracketsRange,
8021 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00008022
8023 QualType Types[] = {
8024 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8025 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8026 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00008027 };
8028 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8029 QualType SizeType;
8030 for (unsigned I = 0; I != NumTypes; ++I)
8031 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8032 SizeType = Types[I];
8033 break;
8034 }
Mike Stump11289f42009-09-09 15:08:12 +00008035
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008036 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8037 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00008038 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008039 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00008040 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008041}
Mike Stump11289f42009-09-09 15:08:12 +00008042
Douglas Gregord6ff3322009-08-04 16:50:30 +00008043template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008044QualType
8045TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008046 ArrayType::ArraySizeModifier SizeMod,
8047 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00008048 unsigned IndexTypeQuals,
8049 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008050 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008051 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008052}
8053
8054template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008055QualType
Mike Stump11289f42009-09-09 15:08:12 +00008056TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008057 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00008058 unsigned IndexTypeQuals,
8059 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008060 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008061 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008062}
Mike Stump11289f42009-09-09 15:08:12 +00008063
Douglas Gregord6ff3322009-08-04 16:50:30 +00008064template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008065QualType
8066TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008067 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008068 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008069 unsigned IndexTypeQuals,
8070 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008071 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008072 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008073 IndexTypeQuals, BracketsRange);
8074}
8075
8076template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008077QualType
8078TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008079 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008080 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008081 unsigned IndexTypeQuals,
8082 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008083 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008084 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008085 IndexTypeQuals, BracketsRange);
8086}
8087
8088template<typename Derived>
8089QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00008090 unsigned NumElements,
8091 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00008092 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00008093 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008094}
Mike Stump11289f42009-09-09 15:08:12 +00008095
Douglas Gregord6ff3322009-08-04 16:50:30 +00008096template<typename Derived>
8097QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8098 unsigned NumElements,
8099 SourceLocation AttributeLoc) {
8100 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8101 NumElements, true);
8102 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008103 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8104 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00008105 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008106}
Mike Stump11289f42009-09-09 15:08:12 +00008107
Douglas Gregord6ff3322009-08-04 16:50:30 +00008108template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008109QualType
8110TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00008111 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008112 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00008113 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008114}
Mike Stump11289f42009-09-09 15:08:12 +00008115
Douglas Gregord6ff3322009-08-04 16:50:30 +00008116template<typename Derived>
8117QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00008118 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008119 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00008120 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00008121 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008122 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00008123 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00008124 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008125 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008126 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008127 getDerived().getBaseEntity(),
8128 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008129}
Mike Stump11289f42009-09-09 15:08:12 +00008130
Douglas Gregord6ff3322009-08-04 16:50:30 +00008131template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008132QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8133 return SemaRef.Context.getFunctionNoProtoType(T);
8134}
8135
8136template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008137QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8138 assert(D && "no decl found");
8139 if (D->isInvalidDecl()) return QualType();
8140
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008141 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008142 TypeDecl *Ty;
8143 if (isa<UsingDecl>(D)) {
8144 UsingDecl *Using = cast<UsingDecl>(D);
8145 assert(Using->isTypeName() &&
8146 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8147
8148 // A valid resolved using typename decl points to exactly one type decl.
8149 assert(++Using->shadow_begin() == Using->shadow_end());
8150 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008151
John McCallb96ec562009-12-04 22:46:56 +00008152 } else {
8153 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8154 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8155 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8156 }
8157
8158 return SemaRef.Context.getTypeDeclType(Ty);
8159}
8160
8161template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008162QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8163 SourceLocation Loc) {
8164 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008165}
8166
8167template<typename Derived>
8168QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8169 return SemaRef.Context.getTypeOfType(Underlying);
8170}
8171
8172template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008173QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8174 SourceLocation Loc) {
8175 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008176}
8177
8178template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00008179QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8180 UnaryTransformType::UTTKind UKind,
8181 SourceLocation Loc) {
8182 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8183}
8184
8185template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00008186QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008187 TemplateName Template,
8188 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008189 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008190 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008191}
Mike Stump11289f42009-09-09 15:08:12 +00008192
Douglas Gregor1135c352009-08-06 05:28:30 +00008193template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008194TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008195TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008196 bool TemplateKW,
8197 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008198 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008199 Template);
8200}
8201
8202template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008203TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008204TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8205 const IdentifierInfo &Name,
8206 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008207 QualType ObjectType,
8208 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008209 UnqualifiedId TemplateName;
8210 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008211 Sema::TemplateTy Template;
8212 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008213 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008214 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008215 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008216 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008217 /*EnteringContext=*/false,
8218 Template);
John McCall31f82722010-11-12 08:19:04 +00008219 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008220}
Mike Stump11289f42009-09-09 15:08:12 +00008221
Douglas Gregora16548e2009-08-11 05:31:07 +00008222template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008223TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008224TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008225 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008226 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008227 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008228 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008229 // FIXME: Bogus location information.
8230 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8231 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008232 Sema::TemplateTy Template;
8233 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008234 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008235 SS,
8236 Name,
John McCallba7bf592010-08-24 05:47:05 +00008237 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008238 /*EnteringContext=*/false,
8239 Template);
8240 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008241}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008242
Douglas Gregor71395fa2009-11-04 00:56:37 +00008243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008244ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008245TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8246 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008247 Expr *OrigCallee,
8248 Expr *First,
8249 Expr *Second) {
8250 Expr *Callee = OrigCallee->IgnoreParenCasts();
8251 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008252
Douglas Gregora16548e2009-08-11 05:31:07 +00008253 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008254 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008255 if (!First->getType()->isOverloadableType() &&
8256 !Second->getType()->isOverloadableType())
8257 return getSema().CreateBuiltinArraySubscriptExpr(First,
8258 Callee->getLocStart(),
8259 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008260 } else if (Op == OO_Arrow) {
8261 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008262 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8263 } else if (Second == 0 || isPostIncDec) {
8264 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008265 // The argument is not of overloadable type, so try to create a
8266 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008267 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008268 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008269
John McCallb268a282010-08-23 23:25:46 +00008270 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008271 }
8272 } else {
John McCallb268a282010-08-23 23:25:46 +00008273 if (!First->getType()->isOverloadableType() &&
8274 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008275 // Neither of the arguments is an overloadable type, so try to
8276 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008277 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008278 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008279 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008280 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008282
Douglas Gregora16548e2009-08-11 05:31:07 +00008283 return move(Result);
8284 }
8285 }
Mike Stump11289f42009-09-09 15:08:12 +00008286
8287 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008288 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008289 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008290
John McCallb268a282010-08-23 23:25:46 +00008291 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008292 assert(ULE->requiresADL());
8293
8294 // FIXME: Do we have to check
8295 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008296 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008297 } else {
John McCallb268a282010-08-23 23:25:46 +00008298 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008299 }
Mike Stump11289f42009-09-09 15:08:12 +00008300
Douglas Gregora16548e2009-08-11 05:31:07 +00008301 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008302 Expr *Args[2] = { First, Second };
8303 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008304
Douglas Gregora16548e2009-08-11 05:31:07 +00008305 // Create the overloaded operator invocation for unary operators.
8306 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008307 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008308 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008309 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008310 }
Mike Stump11289f42009-09-09 15:08:12 +00008311
Sebastian Redladba46e2009-10-29 20:17:01 +00008312 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00008313 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00008314 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008315 First,
8316 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00008317
Douglas Gregora16548e2009-08-11 05:31:07 +00008318 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008319 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008320 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008321 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8322 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008323 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008324
Mike Stump11289f42009-09-09 15:08:12 +00008325 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008326}
Mike Stump11289f42009-09-09 15:08:12 +00008327
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008329ExprResult
John McCallb268a282010-08-23 23:25:46 +00008330TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008331 SourceLocation OperatorLoc,
8332 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008333 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008334 TypeSourceInfo *ScopeType,
8335 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008336 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008337 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008338 QualType BaseType = Base->getType();
8339 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008340 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008341 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008342 !BaseType->getAs<PointerType>()->getPointeeType()
8343 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008344 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008345 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008346 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008347 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008348 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008349 /*FIXME?*/true);
8350 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008351
Douglas Gregor678f90d2010-02-25 01:56:36 +00008352 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008353 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8354 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8355 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8356 NameInfo.setNamedTypeInfo(DestroyedType);
8357
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008358 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008359
John McCallb268a282010-08-23 23:25:46 +00008360 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008361 OperatorLoc, isArrow,
8362 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008363 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008364 /*TemplateArgs*/ 0);
8365}
8366
Douglas Gregord6ff3322009-08-04 16:50:30 +00008367} // end namespace clang
8368
8369#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H